Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
MinimapWidget.cpp
Go to the documentation of this file.
1/**
2 * @file MinimapWidget.cpp
3 * @brief Minimap widget implementation (Phase 7).
4 * @author Olympe Engine
5 * @date 2026-03-10
6 */
7
8#include "MinimapWidget.h"
9
10#include <cstddef>
11
12namespace Olympe {
13
14// ============================================================================
15// Singleton
16// ============================================================================
17
19{
20 static MinimapWidget s_Instance;
21 return s_Instance;
22}
23
24// ============================================================================
25// Construction
26// ============================================================================
27
29{
30 m_Viewport.x = 0.0f;
31 m_Viewport.y = 0.0f;
32 m_Viewport.w = 1.0f;
33 m_Viewport.h = 1.0f;
34}
35
36// ============================================================================
37// Helpers
38// ============================================================================
39
40namespace {
41
42/// Safely normalise a value within a range, clamped to [0,1].
43float Normalise(float value, float minVal, float maxVal)
44{
45 float range = maxVal - minVal;
46 if (range <= 0.0f)
47 return 0.0f;
48 float n = (value - minVal) / range;
49 if (n < 0.0f) n = 0.0f;
50 if (n > 1.0f) n = 1.0f;
51 return n;
52}
53
54} // anonymous namespace
55
56// ============================================================================
57// UpdateNodes
58// ============================================================================
59
60void MinimapWidget::UpdateNodes(const std::vector<MinimapNode>& nodes,
61 float graphMinX, float graphMinY,
62 float graphMaxX, float graphMaxY)
63{
64 m_MinimapNodes.clear();
65 m_MinimapNodes.reserve(nodes.size());
66
67 for (size_t i = 0; i < nodes.size(); ++i)
68 {
70 mn.id = nodes[i].id;
71 mn.x = Normalise(nodes[i].x, graphMinX, graphMaxX);
72 mn.y = Normalise(nodes[i].y, graphMinY, graphMaxY);
73 m_MinimapNodes.push_back(mn);
74 }
75}
76
77// ============================================================================
78// UpdateViewport
79// ============================================================================
80
82 float viewW, float viewH,
83 float graphMinX, float graphMinY,
84 float graphMaxX, float graphMaxY)
85{
86 float rangeX = graphMaxX - graphMinX;
87 float rangeY = graphMaxY - graphMinY;
88
89 m_Viewport.x = Normalise(viewX, graphMinX, graphMaxX);
90 m_Viewport.y = Normalise(viewY, graphMinY, graphMaxY);
91 m_Viewport.w = (rangeX > 0.0f) ? (viewW / rangeX) : 1.0f;
92 m_Viewport.h = (rangeY > 0.0f) ? (viewH / rangeY) : 1.0f;
93
94 // Clamp width/height so the viewport rect does not exceed 1.0
95 if (m_Viewport.w > 1.0f) m_Viewport.w = 1.0f;
96 if (m_Viewport.h > 1.0f) m_Viewport.h = 1.0f;
97}
98
99// ============================================================================
100// Accessors
101// ============================================================================
102
103const std::vector<MinimapNode>& MinimapWidget::GetMinimapNodes() const
104{
105 return m_MinimapNodes;
106}
107
109{
110 return m_Viewport;
111}
112
113// ============================================================================
114// OnDrag
115// ============================================================================
116
118 float graphW, float graphH,
119 float& outGraphDeltaX, float& outGraphDeltaY)
120{
121 // Map minimap pixel delta -> normalised delta -> graph-space delta
122 outGraphDeltaX = (WIDTH > 0.0f) ? (deltaX / WIDTH * graphW) : 0.0f;
123 outGraphDeltaY = (HEIGHT > 0.0f) ? (deltaY / HEIGHT * graphH) : 0.0f;
124}
125
126} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Data-only minimap widget for the VS graph editor (Phase 7).
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.
float Normalise(float value, float minVal, float maxVal)
Safely normalise a value within a range, clamped to [0,1].
< Provides AssetID and INVALID_ASSET_ID
A single node represented in the minimap.
int id
Corresponding node ID in the full graph.
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)