Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
CanvasMinimapRenderer.h
Go to the documentation of this file.
1/**
2 * @file CanvasMinimapRenderer.h
3 * @brief Centralized minimap rendering helper for all canvas types
4 * @author Olympe Engine
5 * @date 2026-03-15
6 *
7 * @details
8 * Unified minimap renderer supporting:
9 * - ImNodes native MiniMap (BehaviorTree, VisualScript)
10 * - Custom minimap rendering (EntityPrefab, future custom canvases)
11 *
12 * This class handles:
13 * - Normalised coordinate computation (0..1 range)
14 * - Minimap visibility, size, and position control
15 * - Integration with ImGui for rendering
16 *
17 * C++14 compliant.
18 */
19
20#pragma once
21
22#include "../../third_party/imgui/imgui.h"
23#include "../../third_party/imnodes/imnodes.h"
24#include <vector>
25#include <tuple>
26#include <utility>
27
28namespace Olympe
29{
30 /**
31 * @struct MinimapNode
32 * @brief Node representation in minimap (normalised coordinates)
33 */
35 {
36 int nodeId; ///< Original graph node ID
37 float normX; ///< Normalised X position [0..1]
38 float normY; ///< Normalised Y position [0..1]
39 float normW; ///< Normalised width [0..1]
40 float normH; ///< Normalised height [0..1]
41 };
42
43 /**
44 * @struct MinimapViewportData
45 * @brief Viewport region in normalised coordinates
46 */
48 {
49 float x; ///< Left edge [0..1]
50 float y; ///< Top edge [0..1]
51 float w; ///< Width [0..1]
52 float h; ///< Height [0..1]
53 };
54
55 /**
56 * @enum MinimapPosition
57 * @brief Screen corner positions for minimap overlay
58 */
59 enum class MinimapPosition
60 {
61 TopLeft = 0,
62 TopRight = 1,
63 BottomLeft = 2,
64 BottomRight = 3
65 };
66
67 /**
68 * @class CanvasMinimapRenderer
69 * @brief Unified minimap renderer for standardized appearance
70 *
71 * Typical usage:
72 * @code
73 * CanvasMinimapRenderer minimap;
74 * minimap.SetSize(0.15f); // 15% of canvas
75 * minimap.SetPosition(MinimapPosition::TopRight);
76 *
77 * // Before rendering:
78 * minimap.UpdateNodes(nodesList, graphMinX, graphMaxX, graphMinY, graphMaxY);
79 * minimap.UpdateViewport(viewX, viewY, viewW, viewH, graphBounds);
80 *
81 * // During render:
82 * if (minimap.IsVisible())
83 * {
84 * minimap.RenderCustom(drawList, canvasScreenPos, canvasSize);
85 * // OR for ImNodes:
86 * minimap.RenderImNodes();
87 * }
88 * @endcode
89 */
91 {
92 public:
93 // Default dimensions
94 static constexpr float DEFAULT_WIDTH = 200.0f;
95 static constexpr float DEFAULT_HEIGHT = 150.0f;
96
98 virtual ~CanvasMinimapRenderer() = default;
99
100 // ====================================================================
101 // Configuration
102 // ====================================================================
103
104 /**
105 * @brief Set minimap visibility
106 */
107 void SetVisible(bool visible);
108
109 /**
110 * @brief Check if minimap should be rendered
111 */
112 bool IsVisible() const;
113
114 /**
115 * @brief Set minimap size as ratio of canvas (0.05 - 0.5)
116 */
117 void SetSize(float ratio);
118
119 /**
120 * @brief Get current size ratio
121 */
122 float GetSize() const;
123
124 /**
125 * @brief Set minimap corner position
126 */
128
129 /**
130 * @brief Get current position
131 */
133
134 // ====================================================================
135 // Data Updates
136 // ====================================================================
137
138 /**
139 * @brief Update node positions from raw graph data
140 * @param nodes Vector of (nodeId, posX, posY, width, height) tuples
141 * @param graphMinX Graph bounds left edge
142 * @param graphMaxX Graph bounds right edge
143 * @param graphMinY Graph bounds top edge
144 * @param graphMaxY Graph bounds bottom edge
145 */
146 void UpdateNodes(
147 const std::vector<std::tuple<int, float, float, float, float>>& nodes,
148 float graphMinX, float graphMaxX, float graphMinY, float graphMaxY
149 );
150
151 /**
152 * @brief Update visible viewport
153 * @param viewMinX Left edge of visible area (graph space)
154 * @param viewMaxX Right edge of visible area (graph space)
155 * @param viewMinY Top edge of visible area (graph space)
156 * @param viewMaxY Bottom edge of visible area (graph space)
157 * @param graphMinX Graph bounds left edge
158 * @param graphMaxX Graph bounds right edge
159 * @param graphMinY Graph bounds top edge
160 * @param graphMaxY Graph bounds bottom edge
161 */
162 void UpdateViewport(
163 float viewMinX, float viewMaxX, float viewMinY, float viewMaxY,
164 float graphMinX, float graphMaxX, float graphMinY, float graphMaxY
165 );
166
167 // ====================================================================
168 // Rendering
169 // ====================================================================
170
171 /**
172 * @brief Render minimap using ImNodes native API
173 * @details Must be called BEFORE ImNodes::EndNodeEditor()
174 */
175 void RenderImNodes() const;
176
177 /**
178 * @brief Render minimap using custom ImGui drawing
179 * @param canvasScreenPos Top-left of canvas on screen
180 * @param canvasSize Canvas dimensions in screen pixels
181 */
182 void RenderCustom(const ImVec2& canvasScreenPos, const ImVec2& canvasSize) const;
183
184 // ====================================================================
185 // Data Access
186 // ====================================================================
187
188 /**
189 * @brief Get normalised node positions for custom rendering
190 */
191 const std::vector<MinimapNodeData>& GetNormalisedNodes() const;
192
193 /**
194 * @brief Get normalised viewport rectangle for custom rendering
195 */
197
198 // ====================================================================
199 // Colors (customizable for different canvas types)
200 // ====================================================================
201
202 /**
203 * @brief Set minimap background color (RGBA)
204 */
205 void SetBackgroundColor(ImU32 color);
206
207 /**
208 * @brief Set minimap node color (RGBA)
209 */
210 void SetNodeColor(ImU32 color);
211
212 /**
213 * @brief Set minimap viewport rectangle color (RGBA)
214 */
215 void SetViewportColor(ImU32 color);
216
217 private:
218
219 // Normalisation helper
220 static float NormaliseCoord(float value, float minVal, float maxVal);
221
222 // Configuration
224 float m_sizeRatio; ///< 0.05 - 0.5 ratio of canvas
226
227 // Normalised data
228 std::vector<MinimapNodeData> m_normalisedNodes;
230
231 // Colors
235 };
236
237} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Unified minimap renderer for standardized appearance.
void SetPosition(MinimapPosition pos)
Set minimap corner position.
virtual ~CanvasMinimapRenderer()=default
void SetViewportColor(ImU32 color)
Set minimap viewport rectangle color (RGBA)
void RenderImNodes() const
Render minimap using ImNodes native API.
void SetNodeColor(ImU32 color)
Set minimap node color (RGBA)
void SetBackgroundColor(ImU32 color)
Set minimap background color (RGBA)
float GetSize() const
Get current size ratio.
std::vector< MinimapNodeData > m_normalisedNodes
void RenderCustom(const ImVec2 &canvasScreenPos, const ImVec2 &canvasSize) const
Render minimap using custom ImGui drawing.
MinimapPosition GetPosition() const
Get current position.
bool IsVisible() const
Check if minimap should be rendered.
static float NormaliseCoord(float value, float minVal, float maxVal)
float m_sizeRatio
0.05 - 0.5 ratio of canvas
void SetSize(float ratio)
Set minimap size as ratio of canvas (0.05 - 0.5)
const MinimapViewportData & GetNormalisedViewport() const
Get normalised viewport rectangle for custom rendering.
static constexpr float DEFAULT_WIDTH
const std::vector< MinimapNodeData > & GetNormalisedNodes() const
Get normalised node positions for custom rendering.
void SetVisible(bool visible)
Set minimap visibility.
void UpdateViewport(float viewMinX, float viewMaxX, float viewMinY, float viewMaxY, float graphMinX, float graphMaxX, float graphMinY, float graphMaxY)
Update visible viewport.
void UpdateNodes(const std::vector< std::tuple< int, float, float, float, float > > &nodes, float graphMinX, float graphMaxX, float graphMinY, float graphMaxY)
Update node positions from raw graph data.
static constexpr float DEFAULT_HEIGHT
< Provides AssetID and INVALID_ASSET_ID
MinimapPosition
Screen corner positions for minimap overlay.
float normW
Normalised width [0..1].
float normX
Normalised X position [0..1].
float normH
Normalised height [0..1].
float normY
Normalised Y position [0..1].
int nodeId
Original graph node ID.
Viewport region in normalised coordinates.