Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
MinimapWidget.h
Go to the documentation of this file.
1/**
2 * @file MinimapWidget.h
3 * @brief Data-only minimap widget for the VS graph editor (Phase 7).
4 * @author Olympe Engine
5 * @date 2026-03-10
6 *
7 * @details
8 * MinimapWidget converts absolute graph-space positions into normalised 0..1
9 * coordinates suitable for rendering a miniature overview of the canvas. It
10 * also tracks the visible viewport rectangle and handles drag events.
11 *
12 * No ImGui dependency — the UI layer calls UpdateNodes(), UpdateViewport(), and
13 * GetMinimapNodes() each frame and renders the result using whatever draw calls
14 * it likes.
15 *
16 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
17 */
18
19#pragma once
20
21#include <vector>
22
23namespace Olympe {
24
25// ============================================================================
26// Supporting types
27// ============================================================================
28
29/**
30 * @struct MinimapNode
31 * @brief A single node represented in the minimap.
32 */
34 float x; ///< Normalised x position [0..1] in graph space
35 float y; ///< Normalised y position [0..1] in graph space
36 int id; ///< Corresponding node ID in the full graph
37};
38
39/**
40 * @struct MinimapViewport
41 * @brief Normalised rectangle [0..1] representing the visible portion of the graph.
42 */
44 float x; ///< Left edge (normalised)
45 float y; ///< Top edge (normalised)
46 float w; ///< Width (normalised)
47 float h; ///< Height (normalised)
48};
49
50// ============================================================================
51// MinimapWidget
52// ============================================================================
53
54/**
55 * @class MinimapWidget
56 * @brief Singleton that maintains normalised minimap state.
57 *
58 * Typical usage:
59 * @code
60 * auto& mm = MinimapWidget::Get();
61 * mm.UpdateNodes(graphNodes, minX, minY, maxX, maxY);
62 * mm.UpdateViewport(scrollX, scrollY, viewW, viewH, minX, minY, maxX, maxY);
63 * const auto& pts = mm.GetMinimapNodes();
64 * const auto& vp = mm.GetViewport();
65 * // ... render pts and vp rectangle ...
66 * @endcode
67 */
69public:
70
71 /// Width of the minimap panel in screen pixels.
72 static constexpr float WIDTH = 200.0f;
73 /// Height of the minimap panel in screen pixels.
74 static constexpr float HEIGHT = 150.0f;
75
76 // -----------------------------------------------------------------------
77 // Singleton access
78 // -----------------------------------------------------------------------
79
80 /**
81 * @brief Returns the single shared instance.
82 */
83 static MinimapWidget& Get();
84
85 // -----------------------------------------------------------------------
86 // Update
87 // -----------------------------------------------------------------------
88
89 /**
90 * @brief Recomputes normalised node positions from graph-space coordinates.
91 *
92 * @param nodes Nodes to display (absolute graph-space positions).
93 * @param graphMinX Leftmost graph boundary.
94 * @param graphMinY Topmost graph boundary.
95 * @param graphMaxX Rightmost graph boundary.
96 * @param graphMaxY Bottommost graph boundary.
97 */
98 void UpdateNodes(const std::vector<MinimapNode>& nodes,
99 float graphMinX, float graphMinY,
100 float graphMaxX, float graphMaxY);
101
102 /**
103 * @brief Recomputes the normalised viewport rectangle.
104 *
105 * @param viewX Current scroll / pan X in graph space.
106 * @param viewY Current scroll / pan Y in graph space.
107 * @param viewW Viewport width in graph space.
108 * @param viewH Viewport height in graph space.
109 * @param graphMinX Leftmost graph boundary.
110 * @param graphMinY Topmost graph boundary.
111 * @param graphMaxX Rightmost graph boundary.
112 * @param graphMaxY Bottommost graph boundary.
113 */
114 void UpdateViewport(float viewX, float viewY,
115 float viewW, float viewH,
116 float graphMinX, float graphMinY,
117 float graphMaxX, float graphMaxY);
118
119 // -----------------------------------------------------------------------
120 // Accessors
121 // -----------------------------------------------------------------------
122
123 /**
124 * @brief Returns the last computed set of normalised minimap node positions.
125 */
126 const std::vector<MinimapNode>& GetMinimapNodes() const;
127
128 /**
129 * @brief Returns the last computed normalised viewport rectangle.
130 */
131 const MinimapViewport& GetViewport() const;
132
133 // -----------------------------------------------------------------------
134 // Interaction
135 // -----------------------------------------------------------------------
136
137 /**
138 * @brief Converts a drag delta on the minimap into a graph-space delta.
139 *
140 * @param deltaX Drag delta in minimap pixel space (x).
141 * @param deltaY Drag delta in minimap pixel space (y).
142 * @param graphW Full graph width in graph space.
143 * @param graphH Full graph height in graph space.
144 * @param outGraphDeltaX Resulting graph-space x delta.
145 * @param outGraphDeltaY Resulting graph-space y delta.
146 */
147 void OnDrag(float deltaX, float deltaY,
148 float graphW, float graphH,
149 float& outGraphDeltaX, float& outGraphDeltaY);
150
151private:
152
154
155 std::vector<MinimapNode> m_MinimapNodes;
157};
158
159} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton that maintains normalised minimap state.
void UpdateNodes(const std::vector< MinimapNode > &nodes, float graphMinX, float graphMinY, float graphMaxX, float graphMaxY)
Recomputes normalised node positions from graph-space coordinates.
void OnDrag(float deltaX, float deltaY, float graphW, float graphH, float &outGraphDeltaX, float &outGraphDeltaY)
Converts a drag delta on the minimap into a graph-space delta.
const std::vector< MinimapNode > & GetMinimapNodes() const
Returns the last computed set of normalised minimap node positions.
static constexpr float HEIGHT
Height of the minimap panel in screen pixels.
MinimapViewport m_Viewport
std::vector< MinimapNode > m_MinimapNodes
const MinimapViewport & GetViewport() const
Returns the last computed normalised viewport rectangle.
void UpdateViewport(float viewX, float viewY, float viewW, float viewH, float graphMinX, float graphMinY, float graphMaxX, float graphMaxY)
Recomputes the normalised viewport rectangle.
static constexpr float WIDTH
Width of the minimap panel in screen pixels.
static MinimapWidget & Get()
Returns the single shared instance.
< Provides AssetID and INVALID_ASSET_ID
A single node represented in the minimap.
int id
Corresponding node ID in the full graph.
float x
Normalised x position [0..1] in graph space.
float y
Normalised y position [0..1] in graph space.
Normalised rectangle [0..1] representing the visible portion of the graph.
float w
Width (normalised)
float h
Height (normalised)
float y
Top edge (normalised)
float x
Left edge (normalised)