Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
GraphComment.h
Go to the documentation of this file.
1/**
2 * @file GraphComment.h
3 * @brief Visual comment/annotation system for node graphs (Phase 9).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * GraphComment represents a coloured rectangular annotation that can be
9 * overlaid on the graph canvas. CommentManager manages the collection and
10 * provides serialisation helpers.
11 *
12 * No ImGui dependency — UI code reads the data and draws however it likes.
13 *
14 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
15 */
16
17#pragma once
18
19#include <string>
20#include <vector>
21
22#include "../third_party/nlohmann/json.hpp"
23
24namespace Olympe {
25
26// ============================================================================
27// GraphComment
28// ============================================================================
29
30/**
31 * @struct GraphComment
32 * @brief A rectangular comment box placed on the graph canvas.
33 */
35 int id = -1; ///< Unique comment ID (assigned by CommentManager)
36 std::string text; ///< Text content displayed inside the box
37 float posX = 0.0f; ///< Left edge in graph space
38 float posY = 0.0f; ///< Top edge in graph space
39 float width = 200.0f; ///< Box width in graph space
40 float height = 80.0f; ///< Box height in graph space
41 unsigned int color = 0xFFFFAA33u; ///< RGBA packed colour (default: amber)
42 float fontSize = 14.0f; ///< Font size in points
43 bool isVisible = true; ///< Whether the comment is drawn
44
45 nlohmann::json ToJson() const;
47};
48
49// ============================================================================
50// CommentManager
51// ============================================================================
52
53/**
54 * @class CommentManager
55 * @brief Singleton that owns all GraphComment instances for the active graph.
56 *
57 * Typical usage:
58 * @code
59 * auto& cm = CommentManager::Get();
60 * GraphComment c;
61 * c.text = "Patrol loop entry";
62 * c.posX = 100.0f; c.posY = 200.0f;
63 * int id = cm.AddComment(c);
64 * cm.RemoveComment(id);
65 * @endcode
66 */
68public:
69
70 // -----------------------------------------------------------------------
71 // Singleton access
72 // -----------------------------------------------------------------------
73
74 /** @brief Returns the single shared instance. */
75 static CommentManager& Get();
76
77 // -----------------------------------------------------------------------
78 // CRUD
79 // -----------------------------------------------------------------------
80
81 /**
82 * @brief Adds a comment and assigns it a unique ID.
83 * @return The assigned comment ID.
84 */
85 int AddComment(const GraphComment& comment);
86
87 /** @brief Removes the comment with the given ID. No-op if not found. */
88 void RemoveComment(int commentId);
89
90 /**
91 * @brief Returns a pointer to the comment with the given ID.
92 * @return Pointer, or nullptr if not found.
93 */
95
96 /** @brief Replaces the stored comment data for the given ID. */
97 void UpdateComment(int commentId, const GraphComment& comment);
98
99 /** @brief Returns the total number of comments managed. */
100 int GetCommentCount() const;
101
102 /** @brief Removes all comments and resets the ID counter. */
103 void Clear();
104
105 // -----------------------------------------------------------------------
106 // Serialisation
107 // -----------------------------------------------------------------------
108
109 void SaveToJson(nlohmann::json& j) const;
110 void LoadFromJson(const nlohmann::json& j);
111
112private:
113
115
116 std::vector<GraphComment> m_Comments;
118};
119
120} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton that owns all GraphComment instances for the active graph.
void SaveToJson(nlohmann::json &j) const
static CommentManager & Get()
Returns the single shared instance.
void LoadFromJson(const nlohmann::json &j)
void Clear()
Removes all comments and resets the ID counter.
GraphComment * GetComment(int commentId)
Returns a pointer to the comment with the given ID.
std::vector< GraphComment > m_Comments
int AddComment(const GraphComment &comment)
Adds a comment and assigns it a unique ID.
int GetCommentCount() const
Returns the total number of comments managed.
void UpdateComment(int commentId, const GraphComment &comment)
Replaces the stored comment data for the given ID.
void RemoveComment(int commentId)
Removes the comment with the given ID.
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
A rectangular comment box placed on the graph canvas.
static GraphComment FromJson(const nlohmann::json &j)
float posX
Left edge in graph space.
nlohmann::json ToJson() const
float fontSize
Font size in points.
float height
Box height in graph space.
unsigned int color
RGBA packed colour (default: amber)
std::string text
Text content displayed inside the box.
float width
Box width in graph space.
bool isVisible
Whether the comment is drawn.
float posY
Top edge in graph space.