Ember
Loading...
Searching...
No Matches
CustomTabArt.cpp
Go to the documentation of this file.
4#include <wx/dcgraph.h>
5
6namespace EmberForge {
7
8// Define the custom events
9wxDEFINE_EVENT(EVT_TAB_ART_ADD_BUTTON, wxCommandEvent);
10wxDEFINE_EVENT(EVT_TAB_ART_MENU_BUTTON, wxCommandEvent);
11
14 m_buttonsEnabled(true), m_iconsLoaded(false) {
15 // Initialize with the current accent color
17}
18
19wxAuiTabArt *CustomTabArt::Clone() {
20 CustomTabArt *art = new CustomTabArt();
21 art->SetNormalFont(m_normalFont);
22 art->SetSelectedFont(m_selectedFont);
23 art->SetMeasuringFont(m_measuringFont);
25
26 // Copy button state
35
36 return art;
37}
38
40 // Get the accent color from preferences
42}
43
45 // Return a larger indent to accommodate bigger buttons
46 return 8;
47}
48
49int CustomTabArt::GetBestTabCtrlSize(wxWindow *wnd, const wxAuiNotebookPageArray &pages,
50 const wxSize &requiredBmpSize) {
51 // Get the base size from parent
52 int baseSize = wxAuiFlatTabArt::GetBestTabCtrlSize(wnd, pages, requiredBmpSize);
53
54 // Ensure minimum height to accommodate our 36px buttons plus some padding
55 const int MIN_TAB_HEIGHT = 42;
56
57 return std::max(baseSize, MIN_TAB_HEIGHT);
58}
59
61 if (m_iconsLoaded) {
62 return;
63 }
64
65 // Load plus button icons
66 wxString plusIconPath = ResourcePath::GetDir("buttons/plus");
67 m_plusNormal = wxBitmap(plusIconPath + "Plus_Normal_20.png", wxBITMAP_TYPE_PNG);
68 m_plusHovered = wxBitmap(plusIconPath + "Plus_Hovered_20.png", wxBITMAP_TYPE_PNG);
69 m_plusPressed = wxBitmap(plusIconPath + "Plus_Pressed_20.png", wxBITMAP_TYPE_PNG);
70
71 // Load menu button icons
72 wxString menuIconPath = ResourcePath::GetDir("buttons/menu");
73 m_menuNormal = wxBitmap(menuIconPath + "Menu_Normal_20.png", wxBITMAP_TYPE_PNG);
74 m_menuHovered = wxBitmap(menuIconPath + "Menu_Hovered_20.png", wxBITMAP_TYPE_PNG);
75 m_menuPressed = wxBitmap(menuIconPath + "Menu_Pressed_20.png", wxBITMAP_TYPE_PNG);
76
77 m_iconsLoaded = true;
78}
79
80int CustomTabArt::DrawPageTab(wxDC &dc, wxWindow *wnd, wxAuiNotebookPage &page, const wxRect &rect) {
82
83 bool isNonClosable = page.window && page.window->GetName() == "BlackboardScene";
84
85 std::vector<wxAuiTabContainerButton> savedButtons;
86 if (isNonClosable) {
87 savedButtons = std::move(page.buttons);
88 page.buttons.clear();
89 }
90
91 int result = wxAuiFlatTabArt::DrawPageTab(dc, wnd, page, rect);
92
93 if (isNonClosable) {
94 page.buttons = std::move(savedButtons);
95 }
96
97 const int THICKNESS = wnd->FromDIP(2);
98 const int y = m_flags & wxAUI_NB_BOTTOM ? page.rect.GetBottom() - THICKNESS : page.rect.GetTop();
99
100 if (isNonClosable) {
101 wxColour bbColor(150, 100, 200);
102 dc.SetBrush(wxBrush(bbColor));
103 dc.SetPen(*wxTRANSPARENT_PEN);
104 dc.DrawRectangle(page.rect.GetLeft() + 1, y, page.rect.GetWidth() - 1, THICKNESS);
105 } else if (page.active) {
106 dc.SetBrush(wxBrush(m_accentColor));
107 dc.SetPen(*wxTRANSPARENT_PEN);
108 dc.DrawRectangle(page.rect.GetLeft() + 1, y, page.rect.GetWidth() - 1, THICKNESS);
109 }
110
111 return result;
112}
113
115 if (!m_buttonsEnabled) {
116 return 0;
117 }
118 // Two buttons + spacing + margins
119 return (BUTTON_SIZE * 2) + BUTTON_SPACING + (BUTTON_MARGIN * 2);
120}
121
122void CustomTabArt::DrawTabBarButtons(wxDC &dc, wxWindow *wnd, const wxRect &rect) {
124 return;
125 }
126
127 // Calculate button positions at the right side of the tab bar
128 int tabHeight = rect.GetHeight();
129 int buttonY = rect.GetTop() + (tabHeight - BUTTON_SIZE) / 2;
130
131 // Menu button is at the far right
132 int menuX = rect.GetRight() - BUTTON_MARGIN - BUTTON_SIZE;
133 m_menuButtonRect = wxRect(menuX, buttonY, BUTTON_SIZE, BUTTON_SIZE);
134
135 // Plus button is to the left of menu button
136 int plusX = menuX - BUTTON_SPACING - BUTTON_SIZE;
137 m_plusButtonRect = wxRect(plusX, buttonY, BUTTON_SIZE, BUTTON_SIZE);
138
139 // Select appropriate bitmap based on state for plus button
140 wxBitmap plusBmp;
142 plusBmp = m_plusPressed;
143 } else if (m_hoveredButton == TabBarButton::AddTab && m_plusHovered.IsOk()) {
144 plusBmp = m_plusHovered;
145 } else if (m_plusNormal.IsOk()) {
146 plusBmp = m_plusNormal;
147 }
148
149 // Select appropriate bitmap based on state for menu button
150 wxBitmap menuBmp;
152 menuBmp = m_menuPressed;
153 } else if (m_hoveredButton == TabBarButton::Menu && m_menuHovered.IsOk()) {
154 menuBmp = m_menuHovered;
155 } else if (m_menuNormal.IsOk()) {
156 menuBmp = m_menuNormal;
157 }
158
159 // Draw the buttons
160 if (plusBmp.IsOk()) {
161 dc.DrawBitmap(plusBmp, m_plusButtonRect.GetLeft(), m_plusButtonRect.GetTop(), true);
162 }
163 if (menuBmp.IsOk()) {
164 dc.DrawBitmap(menuBmp, m_menuButtonRect.GetLeft(), m_menuButtonRect.GetTop(), true);
165 }
166}
167
169 if (!m_buttonsEnabled) {
170 return TabBarButton::None;
171 }
172
173 if (m_plusButtonRect.Contains(x, y)) {
175 }
176 if (m_menuButtonRect.Contains(x, y)) {
177 return TabBarButton::Menu;
178 }
179 return TabBarButton::None;
180}
181
183
185
186} // namespace EmberForge
Centralized resource path management for EmberForge.
static wxColour GetAccentColor()
Get the accent color as a wxColour for UI elements.
void DrawTabBarButtons(wxDC &dc, wxWindow *wnd, const wxRect &rect)
Draw the tab bar buttons (+ and menu) at the right side of the tab area.
int GetBestTabCtrlSize(wxWindow *wnd, const wxAuiNotebookPageArray &pages, const wxSize &requiredBmpSize) override
Override to get a taller tab bar.
void LoadButtonIcons()
Load button icons from resources Must be called after construction when a window context is available...
static const int BUTTON_MARGIN
int GetButtonAreaWidth() const
Get the width reserved for buttons on the right side of the tab bar.
static const int BUTTON_SPACING
void SetHoveredButton(TabBarButton button)
Set the hovered button state (for visual feedback)
TabBarButton ButtonHitTest(int x, int y) const
Test if a point hits one of the tab bar buttons.
void UpdateAccentColor()
Update the highlight color to match the current accent color preference.
int GetIndentSize() override
Override to increase tab bar height for larger buttons.
static const int BUTTON_SIZE
int DrawPageTab(wxDC &dc, wxWindow *wnd, wxAuiNotebookPage &page, const wxRect &rect) override
wxAuiTabArt * Clone() override
void SetPressedButton(TabBarButton button)
Set the pressed button state (for visual feedback)
static wxString GetDir(const wxString &relativeDir)
Get the full path to a resource directory.
wxDEFINE_EVENT(EVT_TAB_ART_ADD_BUTTON, wxCommandEvent)