Ember
Loading...
Searching...
No Matches
NodeWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/Node.h"
4#include <memory>
5#include <wx/panel.h>
6#include <wx/wx.h>
7
8namespace EmberForge {
9
16class NodeWidget : public wxPanel {
17 public:
21 enum class RenderStyle {
22 Compact, // Minimal representation
23 Normal, // Standard representation with icon and text
24 Detailed, // Full representation with all node information
25 Debug // Debug view with internal state
26 };
27
31 enum class InteractionState {
32 Normal, // Default state
33 Hovered, // Mouse hovering over node
34 Selected, // Node is selected
35 Dragging, // Node is being dragged
36 Editing // Node is being edited
37 };
38
45 NodeWidget(wxWindow *parent, EmberCore::Node *node, RenderStyle style = RenderStyle::Normal);
46
50 virtual ~NodeWidget();
51
52 // Node management
53 void SetNode(EmberCore::Node *node);
54 EmberCore::Node *GetNode() const { return node_; }
55 bool HasNode() const { return node_ != nullptr; }
56
57 // Visual properties
59 void SetRenderStyle(RenderStyle style);
60
63
64 // Selection
66 void SetSelected(bool selected);
67
68 // Editing
70 void StartEditing();
71 void StopEditing(bool save_changes = true);
72
73 // Visual state synchronization
74 void UpdateFromNode();
75 void SyncVisualState();
76
77 // Size and layout
78 wxSize GetPreferredSize() const;
79 wxSize CalculateMinSize() const;
80 void SetCustomSize(const wxSize &size);
81
82 // Appearance customization
83 void SetNodeColors(const wxColour &background, const wxColour &border, const wxColour &text);
84 void SetNodeFont(const wxFont &font);
86
87 // Animation support
89 void StopPulseAnimation();
90 void SetHighlighted(bool highlighted);
91
92 // Drag & Drop support
93 bool IsDraggable() const { return is_draggable_; }
94 void SetDraggable(bool draggable) { is_draggable_ = draggable; }
95
96 // Event callbacks
97 using NodeClickCallback = std::function<void(NodeWidget *, EmberCore::Node *)>;
98 using NodeDoubleClickCallback = std::function<void(NodeWidget *, EmberCore::Node *)>;
99 using NodeDragCallback = std::function<void(NodeWidget *, const wxPoint &delta)>;
100 using NodeEditCallback = std::function<void(NodeWidget *, const wxString &new_name)>;
101
106
107 protected:
108 // Rendering methods
109 virtual void OnPaint(wxPaintEvent &event);
110 virtual void OnSize(wxSizeEvent &event);
111 virtual void OnEraseBackground(wxEraseEvent &event);
112
113 // Mouse events
114 virtual void OnMouseEnter(wxMouseEvent &event);
115 virtual void OnMouseLeave(wxMouseEvent &event);
116 virtual void OnMouseDown(wxMouseEvent &event);
117 virtual void OnMouseUp(wxMouseEvent &event);
118 virtual void OnMouseMove(wxMouseEvent &event);
119 virtual void OnMouseDoubleClick(wxMouseEvent &event);
120 virtual void OnRightClick(wxContextMenuEvent &event);
121
122 // Keyboard events
123 virtual void OnKeyDown(wxKeyEvent &event);
124 virtual void OnChar(wxKeyEvent &event);
125
126 // Focus events
127 virtual void OnSetFocus(wxFocusEvent &event);
128 virtual void OnKillFocus(wxFocusEvent &event);
129
130 // Drawing helpers
131 void DrawNodeBackground(wxDC &dc, const wxRect &rect);
132 void DrawNodeBorder(wxDC &dc, const wxRect &rect);
133 void DrawNodeIcon(wxDC &dc, const wxRect &icon_rect);
134 void DrawNodeText(wxDC &dc, const wxRect &text_rect);
135 void DrawNodeStatus(wxDC &dc, const wxRect &status_rect);
136 void DrawConnectionPoints(wxDC &dc);
137
138 // Layout helpers
139 wxRect GetContentRect() const;
140 wxRect GetIconRect() const;
141 wxRect GetTextRect() const;
142 wxRect GetStatusRect() const;
143 std::vector<wxPoint> GetConnectionPoints() const;
144
145 // State helpers
146 wxColour GetBackgroundColor() const;
147 wxColour GetBorderColor() const;
148 wxColour GetTextColor() const;
149 wxBitmap GetNodeIcon() const;
150 wxString GetDisplayText() const;
151
152 // Animation helpers
153 void OnAnimationTimer(wxTimerEvent &event);
154 void UpdateAnimation();
155
156 private:
157 // Core data
161
162 // Visual properties
166 wxColour text_color_;
168
169 // Interaction state
174
175 // Animation
179
180 // Text editing
181 wxTextCtrl *edit_control_;
183
184 // Event callbacks
189
190 // Helper methods
191 void InitializeWidget();
192 void UpdateColors();
193 void CreateEditControl();
194 void DestroyEditControl();
195 void ShowContextMenu(const wxPoint &position);
196
197 // Constants
198 static const int BORDER_WIDTH = 2;
199 static const int PADDING = 6;
200 static const int ICON_SIZE = 16;
201 static const int MIN_WIDTH = 80;
202 static const int MIN_HEIGHT = 32;
203
204 DECLARE_EVENT_TABLE()
205};
206
207} // namespace EmberForge
Represents a node in a behavior tree structure.
Definition Node.h:20
virtual void OnMouseMove(wxMouseEvent &event)
virtual void OnKillFocus(wxFocusEvent &event)
InteractionState
Node interaction states.
Definition NodeWidget.h:31
static const int ICON_SIZE
Definition NodeWidget.h:200
void DrawNodeBackground(wxDC &dc, const wxRect &rect)
void DrawNodeText(wxDC &dc, const wxRect &text_rect)
void SetDraggable(bool draggable)
Definition NodeWidget.h:94
virtual void OnMouseLeave(wxMouseEvent &event)
NodeWidget(wxWindow *parent, EmberCore::Node *node, RenderStyle style=RenderStyle::Normal)
Constructor.
bool HasNode() const
Definition NodeWidget.h:55
virtual void OnSetFocus(wxFocusEvent &event)
wxRect GetIconRect() const
void SetNodeFont(const wxFont &font)
virtual void OnPaint(wxPaintEvent &event)
void DrawConnectionPoints(wxDC &dc)
RenderStyle GetRenderStyle() const
Definition NodeWidget.h:58
NodeEditCallback edit_callback_
Definition NodeWidget.h:188
wxTextCtrl * edit_control_
Definition NodeWidget.h:181
void SetInteractionState(InteractionState state)
static const int MIN_WIDTH
Definition NodeWidget.h:201
wxBitmap GetNodeIcon() const
static const int PADDING
Definition NodeWidget.h:199
void OnAnimationTimer(wxTimerEvent &event)
void SetNodeEditCallback(NodeEditCallback callback)
Definition NodeWidget.h:105
std::function< void(NodeWidget *, EmberCore::Node *)> NodeDoubleClickCallback
Definition NodeWidget.h:98
void DrawNodeIcon(wxDC &dc, const wxRect &icon_rect)
bool IsDraggable() const
Definition NodeWidget.h:93
EmberCore::Node * GetNode() const
Definition NodeWidget.h:54
void ShowContextMenu(const wxPoint &position)
void SetNode(EmberCore::Node *node)
virtual void OnEraseBackground(wxEraseEvent &event)
NodeClickCallback click_callback_
Definition NodeWidget.h:185
virtual void OnSize(wxSizeEvent &event)
wxSize CalculateMinSize() const
virtual ~NodeWidget()
Destructor.
wxColour GetTextColor() const
virtual void OnKeyDown(wxKeyEvent &event)
static const int MIN_HEIGHT
Definition NodeWidget.h:202
bool IsEditing() const
Definition NodeWidget.h:69
virtual void OnMouseEnter(wxMouseEvent &event)
virtual void OnRightClick(wxContextMenuEvent &event)
void SetSelected(bool selected)
InteractionState interaction_state_
Definition NodeWidget.h:160
void SetNodeColors(const wxColour &background, const wxColour &border, const wxColour &text)
static const int BORDER_WIDTH
Definition NodeWidget.h:198
void DrawNodeStatus(wxDC &dc, const wxRect &status_rect)
void SetNodeDragCallback(NodeDragCallback callback)
Definition NodeWidget.h:104
wxRect GetStatusRect() const
virtual void OnChar(wxKeyEvent &event)
wxRect GetTextRect() const
void SetNodeDoubleClickCallback(NodeDoubleClickCallback callback)
Definition NodeWidget.h:103
RenderStyle
Node rendering styles.
Definition NodeWidget.h:21
void StopEditing(bool save_changes=true)
NodeDragCallback drag_callback_
Definition NodeWidget.h:187
std::function< void(NodeWidget *, const wxString &new_name)> NodeEditCallback
Definition NodeWidget.h:100
bool IsSelected() const
Definition NodeWidget.h:65
wxSize GetPreferredSize() const
wxString GetDisplayText() const
NodeDoubleClickCallback double_click_callback_
Definition NodeWidget.h:186
void SetNodeClickCallback(NodeClickCallback callback)
Definition NodeWidget.h:102
wxColour GetBackgroundColor() const
virtual void OnMouseDoubleClick(wxMouseEvent &event)
EmberCore::Node * node_
Definition NodeWidget.h:158
std::vector< wxPoint > GetConnectionPoints() const
virtual void OnMouseUp(wxMouseEvent &event)
RenderStyle render_style_
Definition NodeWidget.h:159
wxColour GetBorderColor() const
InteractionState GetInteractionState() const
Definition NodeWidget.h:61
void SetHighlighted(bool highlighted)
wxRect GetContentRect() const
void SetRenderStyle(RenderStyle style)
virtual void OnMouseDown(wxMouseEvent &event)
void DrawNodeBorder(wxDC &dc, const wxRect &rect)
void SetCustomSize(const wxSize &size)
std::function< void(NodeWidget *, EmberCore::Node *)> NodeClickCallback
Definition NodeWidget.h:97
std::function< void(NodeWidget *, const wxPoint &delta)> NodeDragCallback
Definition NodeWidget.h:99