Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ImNodesCanvasEditor.h
Go to the documentation of this file.
1/**
2 * @file ImNodesCanvasEditor.h
3 * @brief ICanvasEditor adapter for ImNodes-based editors (VisualScript)
4 * @details Wraps ImNodes::BeginNodeEditor/EndNodeEditor with standardized interface
5 *
6 * @design
7 * - Minimal wrapper around imnodes
8 * - Exposes pan control via EditorContextGetPanning/EditorContextResetPanning
9 * - Zoom is read-only (always 1.0f - imnodes doesn't support zoom)
10 * - Coordinates use grid space (pan-independent storage)
11 * - Grid delegated to CanvasGridRenderer with Style_VisualScript preset
12 *
13 * @usage
14 * // In VisualScriptEditorPanel::RenderCanvas()
15 * m_canvasEditor = std::make_unique<ImNodesCanvasEditor>("VisualScript", canvasScreenPos, canvasSize);
16 *
17 * m_canvasEditor->BeginRender();
18 * {
19 * // Render nodes using ImNodes API as usual
20 * ImNodes::BeginNode(nodeId);
21 * // ... node content
22 * ImNodes::EndNode();
23 * }
24 * m_canvasEditor->EndRender();
25 *
26 * @compatibility C++14
27 */
28
29#pragma once
30
31#include "ICanvasEditor.h"
32#include "../../third_party/imnodes/imnodes.h"
33#include <string>
34#include <vector>
35#include <tuple>
36
37namespace Olympe
38{
40 {
41 public:
42 /**
43 * @brief Construct imnodes-based canvas editor
44 * @param name Identifier for this editor (e.g., "VisualScript")
45 * @param canvasScreenPos Top-left corner of canvas on screen (pixels)
46 * @param canvasSize Width/height of canvas area (pixels)
47 * @param imnodesContext Optional ImNodes context (nullptr = use current)
48 */
50 const char* name,
52 ImVec2 canvasSize,
54 );
55
56 virtual ~ImNodesCanvasEditor() = default;
57
58 // ====================================================================
59 // Lifecycle Management
60 // ====================================================================
61
62 /**
63 * @brief Begin rendering cycle (calls ImNodes::BeginNodeEditor)
64 */
65 virtual void BeginRender() override;
66
67 /**
68 * @brief End rendering cycle (calls ImNodes::EndNodeEditor)
69 */
70 virtual void EndRender() override;
71
72 // ====================================================================
73 // Coordinate Transformation Systems
74 // ====================================================================
75
76 /**
77 * @brief Transform screen space to canvas space
78 * @details For imnodes (zoom=1.0):
79 * canvas = screen - canvasScreenPos - pan
80 */
81 virtual ImVec2 ScreenToCanvas(const ImVec2& screenPos) const override;
82
83 /**
84 * @brief Transform canvas space to screen space
85 * @details For imnodes (zoom=1.0):
86 * screen = canvas + pan + canvasScreenPos
87 */
88 virtual ImVec2 CanvasToScreen(const ImVec2& canvasPos) const override;
89
90 /**
91 * @brief Transform editor space to grid space (removes pan)
92 * @details For imnodes:
93 * grid = editor - pan
94 */
95 virtual ImVec2 EditorToGrid(const ImVec2& editorPos) const override;
96
97 /**
98 * @brief Transform grid space to editor space (adds pan)
99 * @details For imnodes:
100 * editor = grid + pan
101 */
102 virtual ImVec2 GridToEditor(const ImVec2& gridPos) const override;
103
104 // ====================================================================
105 // Pan Management
106 // ====================================================================
107
108 /**
109 * @brief Get current pan offset
110 * @return EditorContextGetPanning() from imnodes
111 */
112 virtual ImVec2 GetPan() const override;
113
114 /**
115 * @brief Set pan offset
116 * @param offset New pan offset
117 * @details Calls EditorContextResetPanning()
118 */
119 virtual void SetPan(const ImVec2& offset) override;
120
121 /**
122 * @brief Pan by delta
123 */
124 virtual void PanBy(const ImVec2& delta) override;
125
126 /**
127 * @brief Reset pan to origin
128 */
129 virtual void ResetPan() override;
130
131 // ====================================================================
132 // Zoom Management
133 // ====================================================================
134
135 /**
136 * @brief Get current zoom level
137 * @return Always 1.0f (imnodes doesn't support zoom)
138 */
139 virtual float GetZoom() const override { return 1.0f; }
140
141 /**
142 * @brief Set zoom level (no-op for imnodes)
143 * @details This is a no-op because imnodes doesn't expose zoom control.
144 * If zoom is needed, use CustomCanvasEditor instead.
145 */
146 virtual void SetZoom(float scale, const ImVec2* zoomCenter = nullptr) override
147 {
148 (void)scale;
150 // No-op: imnodes doesn't support zoom
151 }
152
153 /**
154 * @brief Zoom by multiplier (no-op for imnodes)
155 */
156 virtual void ZoomBy(float factor, const ImVec2* zoomCenter = nullptr) override
157 {
158 (void)factor;
160 // No-op: imnodes doesn't support zoom
161 }
162
163 /**
164 * @brief Get zoom limits
165 * @return {1.0f, 1.0f} (fixed, no zoom support)
166 */
167 virtual ImVec2 GetZoomLimits() const override { return ImVec2(1.0f, 1.0f); }
168
169 /**
170 * @brief Reset zoom to 1.0x (no-op, already 1.0f)
171 */
172 virtual void ResetZoom() override
173 {
174 // No-op: already at 1.0f
175 }
176
177 /**
178 * @brief Reset view to defaults (pan only, zoom already 1.0f)
179 */
180 virtual void ResetView() override
181 {
182 ResetPan();
183 // Zoom is already 1.0f, no need to reset
184 }
185
186 // ====================================================================
187 // Grid Management
188 // ====================================================================
189
190 /**
191 * @brief Get current grid configuration
192 * @return GridConfig from CanvasGridRenderer with current pan/zoom
193 */
194 virtual CanvasGridRenderer::GridConfig GetGridConfig() const override;
195
196 /**
197 * @brief Render grid
198 * @param preset Style preset (typically Style_VisualScript)
199 */
201
202 /**
203 * @brief Set grid visibility
204 * @param enabled True to show grid
205 */
206 virtual void SetGridVisible(bool enabled) override;
207
208 /**
209 * @brief Check if grid is visible
210 * @return True if grid will be rendered
211 */
212 virtual bool IsGridVisible() const override { return m_gridVisible; }
213
214 // ====================================================================
215 // Canvas Properties
216 // ====================================================================
217
218 /**
219 * @brief Get canvas screen position
220 * @return Stored canvasScreenPos
221 */
222 virtual ImVec2 GetCanvasScreenPos() const override { return m_canvasScreenPos; }
223
224 /**
225 * @brief Get canvas size
226 * @return Stored canvasSize
227 */
228 virtual ImVec2 GetCanvasSize() const override { return m_canvasSize; }
229
230 /**
231 * @brief Set canvas screen position (call each frame to update)
232 * @param screenPos Top-left corner position in screen space
233 * @details Required for minimap coordinate calculations each frame
234 */
235 virtual void SetCanvasScreenPos(const ImVec2& screenPos) override { m_canvasScreenPos = screenPos; }
236
237 /**
238 * @brief Set canvas size (call each frame to update)
239 * @param size Width and height in screen space
240 * @details Required for minimap rendering calculations each frame
241 */
242 virtual void SetCanvasSize(const ImVec2& size) override { m_canvasSize = size; }
243
244 /**
245 * @brief Get canvas visible bounds in canvas space
246 * @param outMin Top-left corner of visible area
247 * @param outMax Bottom-right corner of visible area
248 */
249 virtual void GetCanvasVisibleBounds(ImVec2& outMin, ImVec2& outMax) const override;
250
251 /**
252 * @brief Check if point is in canvas
253 * @param screenPos Position in screen space
254 * @return True if within canvas bounds
255 */
256 virtual bool IsPointInCanvas(const ImVec2& screenPos) const override;
257
258 // ====================================================================
259 // Context Information
260 // ====================================================================
261
262 /**
263 * @brief Check if canvas is hovered
264 * @return Result of ImNodes::IsEditorHovered()
265 */
266 virtual bool IsCanvasHovered() const override;
267
268 /**
269 * @brief Get canvas name
270 * @return Stored canvas name
271 */
272 virtual const char* GetCanvasName() const override { return m_name.c_str(); }
273
274 // ====================================================================
275 // Minimap Management
276 // ====================================================================
277
278 /**
279 * @brief Render minimap overlay
280 * @details Calls ImNodes::MiniMap() with configured size and position
281 */
282 virtual void RenderMinimap() override;
283
284 /**
285 * @brief Enable/disable minimap rendering
286 * @param enabled True to show minimap
287 */
288 virtual void SetMinimapVisible(bool enabled) override;
289
290 /**
291 * @brief Check if minimap is visible
292 * @return True if minimap will be rendered
293 */
294 virtual bool IsMinimapVisible() const override { return m_minimapVisible; }
295
296 /**
297 * @brief Set minimap size scale
298 * @param scale Size multiplier (0.1f to 0.3f typical)
299 */
300 virtual void SetMinimapSize(float scale) override;
301
302 /**
303 * @brief Get minimap size scale
304 * @return Current size multiplier
305 */
306 virtual float GetMinimapSize() const override { return m_minimapSize; }
307
308 /**
309 * @brief Set minimap position
310 * @param position ImNodesMiniMapLocation enum value
311 */
312 virtual void SetMinimapPosition(int position) override;
313
314 /**
315 * @brief Get minimap position
316 * @return Current ImNodesMiniMapLocation value
317 */
318 virtual int GetMinimapPosition() const override { return m_minimapPosition; }
319
320 /**
321 * @brief Update minimap nodes (no-op for imnodes)
322 * @details ImNodes manages minimap data internally, so this is unused
323 */
324 virtual void UpdateMinimapNodes(
325 const std::vector<std::tuple<int, float, float, float, float>>& nodes,
326 float graphMinX, float graphMaxX, float graphMinY, float graphMaxY) override
327 {
328 // No-op: ImNodes::MiniMap() handles this internally
330 }
331
332 /**
333 * @brief Update minimap viewport (no-op for imnodes)
334 * @details ImNodes manages minimap viewport internally, so this is unused
335 */
337 float viewMinX, float viewMaxX, float viewMinY, float viewMaxY,
338 float graphMinX, float graphMaxX, float graphMinY, float graphMaxY) override
339 {
340 // No-op: ImNodes::MiniMap() handles this internally
343 }
344
345 private:
346 std::string m_name;
351
352 // Minimap configuration
353 bool m_minimapVisible = true;
354 float m_minimapSize = 0.15f;
356 };
357
358} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Standardized Canvas Editor interface for unified architecture.
GridStylePreset
Pre-configured grid styles matching professional editors.
Abstract interface for canvas editors with unified pan/zoom/grid management.
virtual void SetMinimapVisible(bool enabled) override
Enable/disable minimap rendering.
virtual void ResetView() override
Reset view to defaults (pan only, zoom already 1.0f)
virtual void ResetPan() override
Reset pan to origin.
virtual void SetMinimapPosition(int position) override
Set minimap position.
virtual void SetCanvasScreenPos(const ImVec2 &screenPos) override
Set canvas screen position (call each frame to update)
virtual bool IsPointInCanvas(const ImVec2 &screenPos) const override
Check if point is in canvas.
virtual void UpdateMinimapNodes(const std::vector< std::tuple< int, float, float, float, float > > &nodes, float graphMinX, float graphMaxX, float graphMinY, float graphMaxY) override
Update minimap nodes (no-op for imnodes)
virtual ImVec2 GetPan() const override
Get current pan offset.
virtual CanvasGridRenderer::GridConfig GetGridConfig() const override
Get current grid configuration.
virtual float GetMinimapSize() const override
Get minimap size scale.
virtual ImVec2 GetCanvasSize() const override
Get canvas size.
virtual ImVec2 GetZoomLimits() const override
Get zoom limits.
virtual ImVec2 GetCanvasScreenPos() const override
Get canvas screen position.
virtual bool IsMinimapVisible() const override
Check if minimap is visible.
virtual void PanBy(const ImVec2 &delta) override
Pan by delta.
virtual void ResetZoom() override
Reset zoom to 1.0x (no-op, already 1.0f)
virtual void SetGridVisible(bool enabled) override
Set grid visibility.
virtual void EndRender() override
End rendering cycle (calls ImNodes::EndNodeEditor)
virtual ~ImNodesCanvasEditor()=default
virtual void RenderGrid(CanvasGridRenderer::GridStylePreset preset) override
Render grid.
virtual void BeginRender() override
Begin rendering cycle (calls ImNodes::BeginNodeEditor)
virtual void SetMinimapSize(float scale) override
Set minimap size scale.
virtual void GetCanvasVisibleBounds(ImVec2 &outMin, ImVec2 &outMax) const override
Get canvas visible bounds in canvas space.
virtual ImVec2 CanvasToScreen(const ImVec2 &canvasPos) const override
Transform canvas space to screen space.
virtual void SetCanvasSize(const ImVec2 &size) override
Set canvas size (call each frame to update)
virtual int GetMinimapPosition() const override
Get minimap position.
virtual void SetZoom(float scale, const ImVec2 *zoomCenter=nullptr) override
Set zoom level (no-op for imnodes)
virtual ImVec2 GridToEditor(const ImVec2 &gridPos) const override
Transform grid space to editor space (adds pan)
virtual void RenderMinimap() override
Render minimap overlay.
virtual float GetZoom() const override
Get current zoom level.
virtual ImVec2 EditorToGrid(const ImVec2 &editorPos) const override
Transform editor space to grid space (removes pan)
ImNodesEditorContext * m_imnodesContext
virtual void ZoomBy(float factor, const ImVec2 *zoomCenter=nullptr) override
Zoom by multiplier (no-op for imnodes)
virtual bool IsCanvasHovered() const override
Check if canvas is hovered.
virtual ImVec2 ScreenToCanvas(const ImVec2 &screenPos) const override
Transform screen space to canvas space.
virtual const char * GetCanvasName() const override
Get canvas name.
virtual bool IsGridVisible() const override
Check if grid is visible.
virtual void SetPan(const ImVec2 &offset) override
Set pan offset.
virtual void UpdateMinimapViewport(float viewMinX, float viewMaxX, float viewMinY, float viewMaxY, float graphMinX, float graphMaxX, float graphMinY, float graphMaxY) override
Update minimap viewport (no-op for imnodes)
< Provides AssetID and INVALID_ASSET_ID
Configuration parameters for grid rendering.