Ember
Loading...
Searching...
No Matches
CustomAuiNotebook.cpp
Go to the documentation of this file.
2#include "Utils/Logger.h"
4#include <wx/dcbuffer.h>
5
6namespace EmberForge {
7
8// Event IDs for the buttons
9enum { ID_ADD_TAB_BUTTON = wxID_HIGHEST + 5000, ID_MENU_BUTTON };
10
12
13 CustomAuiNotebook::CustomAuiNotebook(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size,
14 long style)
15 : wxAuiNotebook(parent, id, pos, size, style), m_addButton(nullptr), m_menuButton(nullptr), m_buttonsEnabled(true) {
16 // Create and set our custom tab art
17 m_customTabArt = new CustomTabArt();
18 SetArtProvider(m_customTabArt);
19
20 // Load button icons and create the buttons
21 LoadButtonIcons();
22 CreateButtons();
23}
24
26 // Load plus button icons
27 wxString plusIconPath = ResourcePath::GetDir("buttons/plus");
28 m_plusNormal = wxBitmap(plusIconPath + "Plus_Normal_20.png", wxBITMAP_TYPE_PNG);
29 m_plusHovered = wxBitmap(plusIconPath + "Plus_Hovered_20.png", wxBITMAP_TYPE_PNG);
30 m_plusPressed = wxBitmap(plusIconPath + "Plus_Pressed_20.png", wxBITMAP_TYPE_PNG);
31
32 // Load menu button icons
33 wxString menuIconPath = ResourcePath::GetDir("buttons/menu");
34 m_menuNormal = wxBitmap(menuIconPath + "Menu_Normal_20.png", wxBITMAP_TYPE_PNG);
35 m_menuHovered = wxBitmap(menuIconPath + "Menu_Hovered_20.png", wxBITMAP_TYPE_PNG);
36 m_menuPressed = wxBitmap(menuIconPath + "Menu_Pressed_20.png", wxBITMAP_TYPE_PNG);
37}
38
40 // Get the parent (SidePanel) to create buttons as its children
41 // This allows buttons to be positioned over the tab bar area
42 wxWindow *parentPanel = GetParent();
43 if (!parentPanel) {
44 LOG_ERROR("CustomAuiNotebook", "Cannot create buttons - no parent panel");
45 return;
46 }
47
48 // Create add tab button as child of parent panel
49 m_addButton = new wxBitmapButton(parentPanel, ID_ADD_TAB_BUTTON, m_plusNormal, wxDefaultPosition,
50 wxSize(BUTTON_SIZE, BUTTON_SIZE), wxBORDER_NONE);
51 m_addButton->SetBitmapMargins(2, 2);
52 if (m_plusHovered.IsOk()) {
53 m_addButton->SetBitmapHover(m_plusHovered);
54 }
55 if (m_plusPressed.IsOk()) {
56 m_addButton->SetBitmapPressed(m_plusPressed);
57 }
58 m_addButton->SetToolTip("Add a new tab");
59
60 // Bind button click event
61 m_addButton->Bind(wxEVT_BUTTON, &CustomAuiNotebook::OnAddButtonClicked, this);
62
63 // Create menu button as child of parent panel
64 m_menuButton = new wxBitmapButton(parentPanel, ID_MENU_BUTTON, m_menuNormal, wxDefaultPosition,
65 wxSize(BUTTON_SIZE, BUTTON_SIZE), wxBORDER_NONE);
66 m_menuButton->SetBitmapMargins(2, 2);
67 if (m_menuHovered.IsOk()) {
68 m_menuButton->SetBitmapHover(m_menuHovered);
69 }
70 if (m_menuPressed.IsOk()) {
71 m_menuButton->SetBitmapPressed(m_menuPressed);
72 }
73 m_menuButton->SetToolTip("Panel options");
74
75 // Bind button click event
76 m_menuButton->Bind(wxEVT_BUTTON, &CustomAuiNotebook::OnMenuButtonClicked, this);
77
78 // Position the buttons initially
80}
81
83 if (!m_addButton || !m_menuButton) {
84 return;
85 }
86
87 // Get the notebook's position relative to its parent (SidePanel)
88 wxPoint notebookPos = GetPosition();
89 wxSize notebookSize = GetSize();
90
91 // Get the tab bar height
92 int tabHeight = GetTabCtrlHeight();
93 if (tabHeight <= 0) {
94 tabHeight = 25; // Default fallback
95 }
96
97 // Calculate vertical center of the tab bar (relative to parent's coordinate space)
98 int buttonY = notebookPos.y + (tabHeight - BUTTON_SIZE) / 2;
99 if (buttonY < notebookPos.y + 2)
100 buttonY = notebookPos.y + 2;
101
102 // Position menu button at the right edge of the notebook
103 int menuX = notebookPos.x + notebookSize.GetWidth() - BUTTON_MARGIN - BUTTON_SIZE;
104 m_menuButton->SetPosition(wxPoint(menuX, buttonY));
105
106 // Position add button to the left of menu button
107 int addX = menuX - BUTTON_SPACING - BUTTON_SIZE;
108 m_addButton->SetPosition(wxPoint(addX, buttonY));
109
110 // Make sure buttons are visible
113
114 // Raise buttons to ensure they're on top
115 m_addButton->Raise();
116 m_menuButton->Raise();
117}
118
120 m_buttonsEnabled = enabled;
121 if (m_addButton) {
122 m_addButton->Show(enabled);
123 }
124 if (m_menuButton) {
125 m_menuButton->Show(enabled);
126 }
127 Refresh();
128}
129
130void CustomAuiNotebook::OnSize(wxSizeEvent &event) {
131 event.Skip();
132 // Update button positions when the notebook is resized
134}
135
136void CustomAuiNotebook::OnAddButtonClicked(wxCommandEvent &event) {
137 // Send the custom event to the parent (SidePanel)
138 wxCommandEvent addEvent(EVT_TAB_ART_ADD_BUTTON);
139 addEvent.SetEventObject(this);
140 GetParent()->GetEventHandler()->ProcessEvent(addEvent);
141}
142
143void CustomAuiNotebook::OnMenuButtonClicked(wxCommandEvent &event) {
144 // Send the custom event to the parent (SidePanel)
145 wxCommandEvent menuEvent(EVT_TAB_ART_MENU_BUTTON);
146 menuEvent.SetEventObject(this);
147 GetParent()->GetEventHandler()->ProcessEvent(menuEvent);
148}
149
150} // namespace EmberForge
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
#define LOG_ERROR(category, message)
Definition Logger.h:116
Centralized resource path management for EmberForge.
Custom wxAuiNotebook that integrates Add Tab and Menu buttons into the tab bar.
void OnAddButtonClicked(wxCommandEvent &event)
void SetTabBarButtonsEnabled(bool enabled)
Enable or disable the integrated tab bar buttons.
void OnMenuButtonClicked(wxCommandEvent &event)
void OnSize(wxSizeEvent &event)
Custom tab art provider that uses the application's accent color.
static wxString GetDir(const wxString &relativeDir)
Get the full path to a resource directory.
wxBEGIN_EVENT_TABLE(LogTab, wxPanel) EVT_CHOICE(ID_LEVEL_FILTER