Ember
Loading...
Searching...
No Matches
MainPanel Class Reference

Central panel for managing and displaying behavior tree scenes. More...

#include <MainPanel.h>

Inheritance diagram for MainPanel:
EmberUI::Panel IPanel

Public Types

using SceneChangedCallback = std::function<void(IScene *newScene, int newIndex)>
using WelcomeActionCallback = std::function<void(const std::string &action, const std::string &param)>

Public Member Functions

 MainPanel (wxWindow *parent)
wxString GetTitle () const override
 Returns the display title of the panel.
wxString GetPanelType () const override
 Returns the panel type identifier.
int AddScene (std::unique_ptr< IScene > scene)
 Add a new scene to the panel.
int InsertScene (int index, std::unique_ptr< IScene > scene)
 Insert a scene at a specific position.
bool RemoveScene (int index, bool force=false)
 Remove a scene by index.
ISceneGetActiveScene () const
 Get the currently active scene.
ISceneGetScene (int index) const
 Get a scene by index.
size_t GetSceneCount () const
 Get the number of scenes.
void SwitchToNextScene ()
 Switch to the next scene (cyclic)
void SwitchToPreviousScene ()
 Switch to the previous scene (cyclic)
bool SetActiveScene (int index)
 Set the active scene by index.
int CreateNewScene ()
 Create a new empty behavior tree scene.
int CreateNewScene (const wxString &customTitle)
 Create a new empty behavior tree scene with custom title.
void UpdateActiveSceneTitle (const wxString &newTitle)
 Update the title of the active scene.
wxAuiNotebook * GetNotebook () const
void ApplyCanvasBackgroundColor (const wxColour &color)
 Apply canvas background color to all scenes.
void SetSceneChangedCallback (SceneChangedCallback callback)
void SetWelcomeActionCallback (WelcomeActionCallback cb)
void ShowWelcome ()
void ShowScenes ()
Public Member Functions inherited from EmberUI::Panel
 Panel (wxWindow *parent, const wxString &name="Panel", long style=wxTAB_TRAVERSAL)
 Constructs the panel with optional name and style.
virtual ~Panel ()
wxPanel * GetPanel () override
 Returns this panel as wxPanel pointer.
wxString GetTitle () const override
 Returns the panel title.
wxString GetPanelType () const override
 Returns the panel type identifier.
void Initialize () override
 Initializes the panel layout and appearance.
void Refresh () override
 Refreshes panel content.
void OnActivated () override
 Called when the panel is activated.
void OnDeactivated () override
 Called when the panel is deactivated.
void Cleanup () override
 Cleans up panel resources.
bool IsValid () const override
 Returns true if the panel has been initialized.
wxString SerializeState () const override
 Serializes panel state to a string.
void DeserializeState (const wxString &state) override
 Restores panel state from a serialized string.
bool HasUnsavedChanges () const override
 Returns true if there are unsaved changes.
bool Save () override
 Saves panel state; returns true on success.
bool SupportsOperation (const wxString &operation) const override
 Returns true if the panel supports the given operation.
bool ExecuteOperation (const wxString &operation, const wxString &parameter="") override
 Executes a named operation with optional parameter.
wxString GetName () const override
 Returns the panel name.
void SetName (const wxString &name) override
 Sets the panel name.
void SetTitle (const wxString &title)
 Sets the panel title.
void SetPanelType (const wxString &type)
 Sets the panel type identifier.
Public Member Functions inherited from IPanel
virtual ~IPanel ()=default

Private Types

enum  {
  ID_NEW_SCENE_BUTTON = wxID_HIGHEST + 1000 , ID_SCENE_NOTEBOOK , ID_OVERLAY_BUTTON , ID_OVERLAY_SHOW_ALL = wxID_HIGHEST + 2000 ,
  ID_OVERLAY_HIDE_ALL , ID_OVERLAY_GRID , ID_OVERLAY_MINIMAP , ID_OVERLAY_BREADCRUMB ,
  ID_OVERLAY_COORDINATE , ID_OVERLAY_SELECTED_NODE , ID_OVERLAY_TREE_INFO , ID_OVERLAY_FPS ,
  ID_OVERLAY_CONTROLS_HELP
}

Private Member Functions

void CreateLayout () override
 Hook: creates the panel layout. Override to customize.
void CreateToolbar ()
void DoCreateLayout ()
void DoCreateToolbar ()
wxPanel * CreateWelcomePanel ()
void OnTabChanged (wxAuiNotebookEvent &event)
void OnTabClosed (wxAuiNotebookEvent &event)
void OnNewSceneButton (wxCommandEvent &event)
void OnOverlayButton (wxCommandEvent &event)
void OnOverlayMenuItem (wxCommandEvent &event)
void UpdateOverlayButtonState ()
void ApplyOverlayToActiveCanvas ()
wxString GenerateSceneTitle () const
bool SceneTitleExists (const wxString &title) const
 wxDECLARE_EVENT_TABLE ()

Private Attributes

wxStaticText * m_title
wxToolBar * m_toolbar
wxSimplebook * m_book = nullptr
wxPanel * m_welcomePanel = nullptr
wxAuiNotebook * m_sceneNotebook
std::vector< std::unique_ptr< IScene > > m_scenes
int m_activeSceneIndex
int m_nextSceneNumber
bool m_isClosingTab = false
SceneChangedCallback m_sceneChangedCallback
WelcomeActionCallback m_welcomeActionCallback

Additional Inherited Members

Protected Member Functions inherited from EmberUI::Panel
virtual void ApplyTheme ()
 Hook: applies theme colors and fonts. Override to customize.
virtual void UpdateContent ()
 Hook: updates displayed content. Override to refresh data.
virtual void HandleActivation ()
 Hook: handles panel activation. Override to customize.
virtual void HandleDeactivation ()
 Hook: handles panel deactivation. Override to customize.
virtual bool ValidateState () const
 Hook: validates panel state; returns true if valid.
void MarkChanged ()
 Marks the panel as having unsaved changes.
void MarkSaved ()
 Clears the unsaved-changes flag.
wxSizer * GetMainSizer () const
 Returns the main sizer for layout.
void SetMainSizer (wxSizer *sizer)
 Sets the main sizer.
virtual void OnPanelSize (wxSizeEvent &event)
 Hook: handles panel resize events.
virtual void OnPanelPaint (wxPaintEvent &event)
 Hook: handles panel paint events.

Detailed Description

Central panel for managing and displaying behavior tree scenes.

MainPanel is the primary workspace area in EmberForge where behavior trees are visualized and edited. It manages multiple scenes using a tabbed notebook interface, allowing users to work with several behavior trees simultaneously.

Features

  • Multi-scene support: Open and edit multiple behavior trees in tabs
  • Scene navigation: Switch between scenes with keyboard shortcuts or buttons
  • Dynamic scene creation: Create new scenes on-the-fly
  • Tab management: Close, rename, and reorder scene tabs

Usage

// Create and add a scene
auto scene = std::make_unique<BehaviorTreeScene>(mainPanel->GetNotebook());
int index = mainPanel->AddScene(std::move(scene));
// Get the active scene
IScene* active = mainPanel->GetActiveScene();
// Navigate between scenes
mainPanel->SwitchToNextScene();
Interface for scene-based UI components (e.g., views or screens).
Definition IScene.h:7
See also
IScene, BehaviorTreeScene, Panel

Definition at line 43 of file MainPanel.h.

Member Typedef Documentation

◆ SceneChangedCallback

using MainPanel::SceneChangedCallback = std::function<void(IScene *newScene, int newIndex)>

Definition at line 139 of file MainPanel.h.

◆ WelcomeActionCallback

using MainPanel::WelcomeActionCallback = std::function<void(const std::string &action, const std::string &param)>

Definition at line 142 of file MainPanel.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_NEW_SCENE_BUTTON 
ID_SCENE_NOTEBOOK 
ID_OVERLAY_BUTTON 
ID_OVERLAY_SHOW_ALL 
ID_OVERLAY_HIDE_ALL 
ID_OVERLAY_GRID 
ID_OVERLAY_MINIMAP 
ID_OVERLAY_BREADCRUMB 
ID_OVERLAY_COORDINATE 
ID_OVERLAY_SELECTED_NODE 
ID_OVERLAY_TREE_INFO 
ID_OVERLAY_FPS 
ID_OVERLAY_CONTROLS_HELP 

Definition at line 149 of file MainPanel.h.

Constructor & Destructor Documentation

◆ MainPanel()

MainPanel::MainPanel ( wxWindow * parent)

Member Function Documentation

◆ AddScene()

int MainPanel::AddScene ( std::unique_ptr< IScene > scene)

Add a new scene to the panel.

Parameters
sceneThe scene to add
Returns
int Index of the added scene

Definition at line 324 of file MainPanel.cpp.

◆ ApplyCanvasBackgroundColor()

void MainPanel::ApplyCanvasBackgroundColor ( const wxColour & color)

Apply canvas background color to all scenes.

Parameters
colorBackground color to apply

Definition at line 676 of file MainPanel.cpp.

◆ ApplyOverlayToActiveCanvas()

void MainPanel::ApplyOverlayToActiveCanvas ( )
private

Definition at line 776 of file MainPanel.cpp.

◆ CreateLayout()

void MainPanel::CreateLayout ( )
overrideprivatevirtual

Hook: creates the panel layout. Override to customize.

Reimplemented from EmberUI::Panel.

Definition at line 28 of file MainPanel.cpp.

◆ CreateNewScene() [1/2]

int MainPanel::CreateNewScene ( )

Create a new empty behavior tree scene.

Returns
int Index of the created scene

Definition at line 461 of file MainPanel.cpp.

◆ CreateNewScene() [2/2]

int MainPanel::CreateNewScene ( const wxString & customTitle)

Create a new empty behavior tree scene with custom title.

Parameters
customTitleThe title for the new scene
Returns
int Index of the created scene

Definition at line 511 of file MainPanel.cpp.

◆ CreateToolbar()

void MainPanel::CreateToolbar ( )
private

Definition at line 281 of file MainPanel.cpp.

◆ CreateWelcomePanel()

wxPanel * MainPanel::CreateWelcomePanel ( )
private

Definition at line 64 of file MainPanel.cpp.

◆ DoCreateLayout()

void MainPanel::DoCreateLayout ( )
private

Definition at line 32 of file MainPanel.cpp.

◆ DoCreateToolbar()

void MainPanel::DoCreateToolbar ( )
private

Definition at line 285 of file MainPanel.cpp.

◆ GenerateSceneTitle()

wxString MainPanel::GenerateSceneTitle ( ) const
private

Definition at line 477 of file MainPanel.cpp.

◆ GetActiveScene()

IScene * MainPanel::GetActiveScene ( ) const

Get the currently active scene.

Returns
IScene* Active scene or nullptr if no scenes

Definition at line 425 of file MainPanel.cpp.

◆ GetNotebook()

wxAuiNotebook * MainPanel::GetNotebook ( ) const
inline

Definition at line 131 of file MainPanel.h.

◆ GetPanelType()

wxString MainPanel::GetPanelType ( ) const
inlineoverridevirtual

Returns the panel type identifier.

Implements IPanel.

Definition at line 49 of file MainPanel.h.

◆ GetScene()

IScene * MainPanel::GetScene ( int index) const

Get a scene by index.

Parameters
indexIndex of the scene
Returns
IScene* Scene at index or nullptr if invalid index

Definition at line 432 of file MainPanel.cpp.

◆ GetSceneCount()

size_t MainPanel::GetSceneCount ( ) const
inline

Get the number of scenes.

Returns
size_t Number of scenes in the panel

Definition at line 92 of file MainPanel.h.

◆ GetTitle()

wxString MainPanel::GetTitle ( ) const
inlineoverridevirtual

Returns the display title of the panel.

Implements IPanel.

Definition at line 48 of file MainPanel.h.

◆ InsertScene()

int MainPanel::InsertScene ( int index,
std::unique_ptr< IScene > scene )

Insert a scene at a specific position.

Parameters
indexPosition to insert at
sceneThe scene to insert
Returns
int Index where the scene was inserted, or -1 on failure

Definition at line 360 of file MainPanel.cpp.

◆ OnNewSceneButton()

void MainPanel::OnNewSceneButton ( wxCommandEvent & event)
private

Definition at line 572 of file MainPanel.cpp.

◆ OnOverlayButton()

void MainPanel::OnOverlayButton ( wxCommandEvent & event)
private

Definition at line 707 of file MainPanel.cpp.

◆ OnOverlayMenuItem()

void MainPanel::OnOverlayMenuItem ( wxCommandEvent & event)
private

Definition at line 733 of file MainPanel.cpp.

◆ OnTabChanged()

void MainPanel::OnTabChanged ( wxAuiNotebookEvent & event)
private

Definition at line 543 of file MainPanel.cpp.

◆ OnTabClosed()

void MainPanel::OnTabClosed ( wxAuiNotebookEvent & event)
private

Definition at line 598 of file MainPanel.cpp.

◆ RemoveScene()

bool MainPanel::RemoveScene ( int index,
bool force = false )

Remove a scene by index.

Parameters
indexIndex of the scene to remove
forceIf true, skip unsaved changes confirmation
Returns
bool True if removal was successful

Definition at line 378 of file MainPanel.cpp.

◆ SceneTitleExists()

bool MainPanel::SceneTitleExists ( const wxString & title) const
private

Definition at line 502 of file MainPanel.cpp.

◆ SetActiveScene()

bool MainPanel::SetActiveScene ( int index)

Set the active scene by index.

Parameters
indexIndex of the scene to activate
Returns
bool True if activation was successful

Definition at line 439 of file MainPanel.cpp.

◆ SetSceneChangedCallback()

void MainPanel::SetSceneChangedCallback ( SceneChangedCallback callback)
inline

Definition at line 140 of file MainPanel.h.

◆ SetWelcomeActionCallback()

void MainPanel::SetWelcomeActionCallback ( WelcomeActionCallback cb)
inline

Definition at line 143 of file MainPanel.h.

◆ ShowScenes()

void MainPanel::ShowScenes ( )

Definition at line 271 of file MainPanel.cpp.

◆ ShowWelcome()

void MainPanel::ShowWelcome ( )

Definition at line 261 of file MainPanel.cpp.

◆ SwitchToNextScene()

void MainPanel::SwitchToNextScene ( )

Switch to the next scene (cyclic)

Definition at line 688 of file MainPanel.cpp.

◆ SwitchToPreviousScene()

void MainPanel::SwitchToPreviousScene ( )

Switch to the previous scene (cyclic)

Definition at line 697 of file MainPanel.cpp.

◆ UpdateActiveSceneTitle()

void MainPanel::UpdateActiveSceneTitle ( const wxString & newTitle)

Update the title of the active scene.

Parameters
newTitleThe new title for the scene

Definition at line 526 of file MainPanel.cpp.

◆ UpdateOverlayButtonState()

void MainPanel::UpdateOverlayButtonState ( )
private

Definition at line 798 of file MainPanel.cpp.

◆ wxDECLARE_EVENT_TABLE()

MainPanel::wxDECLARE_EVENT_TABLE ( )
private

Member Data Documentation

◆ m_activeSceneIndex

int MainPanel::m_activeSceneIndex
private

Definition at line 191 of file MainPanel.h.

◆ m_book

wxSimplebook* MainPanel::m_book = nullptr
private

Definition at line 186 of file MainPanel.h.

◆ m_isClosingTab

bool MainPanel::m_isClosingTab = false
private

Definition at line 193 of file MainPanel.h.

◆ m_nextSceneNumber

int MainPanel::m_nextSceneNumber
private

Definition at line 192 of file MainPanel.h.

◆ m_sceneChangedCallback

SceneChangedCallback MainPanel::m_sceneChangedCallback
private

Definition at line 194 of file MainPanel.h.

◆ m_sceneNotebook

wxAuiNotebook* MainPanel::m_sceneNotebook
private

Definition at line 188 of file MainPanel.h.

◆ m_scenes

std::vector<std::unique_ptr<IScene> > MainPanel::m_scenes
private

Definition at line 190 of file MainPanel.h.

◆ m_title

wxStaticText* MainPanel::m_title
private

Definition at line 184 of file MainPanel.h.

◆ m_toolbar

wxToolBar* MainPanel::m_toolbar
private

Definition at line 185 of file MainPanel.h.

◆ m_welcomeActionCallback

WelcomeActionCallback MainPanel::m_welcomeActionCallback
private

Definition at line 195 of file MainPanel.h.

◆ m_welcomePanel

wxPanel* MainPanel::m_welcomePanel = nullptr
private

Definition at line 187 of file MainPanel.h.


The documentation for this class was generated from the following files: