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) {
81 // Update accent color before drawing
83
84 // Call the base class implementation to draw the tab
85 int result = wxAuiFlatTabArt::DrawPageTab(dc, wnd, page, rect);
86
87 // Now draw our custom accent-colored indicator line on top for active tabs
88 if (page.active) {
89 dc.SetBrush(wxBrush(m_accentColor));
90 dc.SetPen(*wxTRANSPARENT_PEN);
91
92 // Draw a thicker indicator line at the top (or bottom if tabs are at bottom)
93 const int THICKNESS = wnd->FromDIP(2);
94
95 const int y = m_flags & wxAUI_NB_BOTTOM ? page.rect.GetBottom() - THICKNESS : page.rect.GetTop();
96
97 dc.DrawRectangle(page.rect.GetLeft() + 1, y, page.rect.GetWidth() - 1, THICKNESS);
98 }
99
100 return result;
101}
102
104 if (!m_buttonsEnabled) {
105 return 0;
106 }
107 // Two buttons + spacing + margins
108 return (BUTTON_SIZE * 2) + BUTTON_SPACING + (BUTTON_MARGIN * 2);
109}
110
111void CustomTabArt::DrawTabBarButtons(wxDC &dc, wxWindow *wnd, const wxRect &rect) {
113 return;
114 }
115
116 // Calculate button positions at the right side of the tab bar
117 int tabHeight = rect.GetHeight();
118 int buttonY = rect.GetTop() + (tabHeight - BUTTON_SIZE) / 2;
119
120 // Menu button is at the far right
121 int menuX = rect.GetRight() - BUTTON_MARGIN - BUTTON_SIZE;
122 m_menuButtonRect = wxRect(menuX, buttonY, BUTTON_SIZE, BUTTON_SIZE);
123
124 // Plus button is to the left of menu button
125 int plusX = menuX - BUTTON_SPACING - BUTTON_SIZE;
126 m_plusButtonRect = wxRect(plusX, buttonY, BUTTON_SIZE, BUTTON_SIZE);
127
128 // Select appropriate bitmap based on state for plus button
129 wxBitmap plusBmp;
131 plusBmp = m_plusPressed;
132 } else if (m_hoveredButton == TabBarButton::AddTab && m_plusHovered.IsOk()) {
133 plusBmp = m_plusHovered;
134 } else if (m_plusNormal.IsOk()) {
135 plusBmp = m_plusNormal;
136 }
137
138 // Select appropriate bitmap based on state for menu button
139 wxBitmap menuBmp;
141 menuBmp = m_menuPressed;
142 } else if (m_hoveredButton == TabBarButton::Menu && m_menuHovered.IsOk()) {
143 menuBmp = m_menuHovered;
144 } else if (m_menuNormal.IsOk()) {
145 menuBmp = m_menuNormal;
146 }
147
148 // Draw the buttons
149 if (plusBmp.IsOk()) {
150 dc.DrawBitmap(plusBmp, m_plusButtonRect.GetLeft(), m_plusButtonRect.GetTop(), true);
151 }
152 if (menuBmp.IsOk()) {
153 dc.DrawBitmap(menuBmp, m_menuButtonRect.GetLeft(), m_menuButtonRect.GetTop(), true);
154 }
155}
156
158 if (!m_buttonsEnabled) {
159 return TabBarButton::None;
160 }
161
162 if (m_plusButtonRect.Contains(x, y)) {
164 }
165 if (m_menuButtonRect.Contains(x, y)) {
166 return TabBarButton::Menu;
167 }
168 return TabBarButton::None;
169}
170
172
174
175} // 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)