Olympe Engine
2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Source
NodeGraphCore
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
24
namespace
Olympe
{
25
26
// ============================================================================
27
// GraphComment
28
// ============================================================================
29
30
/**
31
* @struct GraphComment
32
* @brief A rectangular comment box placed on the graph canvas.
33
*/
34
struct
GraphComment
{
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
;
46
static
GraphComment
FromJson
(
const
nlohmann::json
&
j
);
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
*/
67
class
CommentManager
{
68
public
:
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
*/
94
GraphComment
*
GetComment
(
int
commentId
);
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
112
private
:
113
114
CommentManager
();
115
116
std::vector<GraphComment>
m_Comments
;
117
int
m_NextCommentId
;
118
};
119
120
}
// namespace Olympe
GetComponentTypeID_Static
ComponentTypeID GetComponentTypeID_Static()
Definition
ECS_Entity.h:56
Olympe::CommentManager
Singleton that owns all GraphComment instances for the active graph.
Definition
GraphComment.h:67
Olympe::CommentManager::SaveToJson
void SaveToJson(nlohmann::json &j) const
Definition
GraphComment.cpp:149
Olympe::CommentManager::Get
static CommentManager & Get()
Returns the single shared instance.
Definition
GraphComment.cpp:73
Olympe::CommentManager::CommentManager
CommentManager()
Definition
GraphComment.cpp:79
Olympe::CommentManager::m_NextCommentId
int m_NextCommentId
Definition
GraphComment.h:117
Olympe::CommentManager::LoadFromJson
void LoadFromJson(const nlohmann::json &j)
Definition
GraphComment.cpp:157
Olympe::CommentManager::Clear
void Clear()
Removes all comments and resets the ID counter.
Definition
GraphComment.cpp:139
Olympe::CommentManager::GetComment
GraphComment * GetComment(int commentId)
Returns a pointer to the comment with the given ID.
Definition
GraphComment.cpp:108
Olympe::CommentManager::m_Comments
std::vector< GraphComment > m_Comments
Definition
GraphComment.h:116
Olympe::CommentManager::AddComment
int AddComment(const GraphComment &comment)
Adds a comment and assigns it a unique ID.
Definition
GraphComment.cpp:88
Olympe::CommentManager::GetCommentCount
int GetCommentCount() const
Returns the total number of comments managed.
Definition
GraphComment.cpp:134
Olympe::CommentManager::UpdateComment
void UpdateComment(int commentId, const GraphComment &comment)
Replaces the stored comment data for the given ID.
Definition
GraphComment.cpp:118
Olympe::CommentManager::RemoveComment
void RemoveComment(int commentId)
Removes the comment with the given ID.
Definition
GraphComment.cpp:96
Olympe
< Provides AssetID and INVALID_ASSET_ID
Definition
BTEditorCommand.cpp:16
nlohmann::json
nlohmann::json json
Definition
ParameterSchema.h:23
Olympe::GraphComment
A rectangular comment box placed on the graph canvas.
Definition
GraphComment.h:34
Olympe::GraphComment::FromJson
static GraphComment FromJson(const nlohmann::json &j)
Definition
GraphComment.cpp:35
Olympe::GraphComment::posX
float posX
Left edge in graph space.
Definition
GraphComment.h:37
Olympe::GraphComment::ToJson
nlohmann::json ToJson() const
Definition
GraphComment.cpp:20
Olympe::GraphComment::fontSize
float fontSize
Font size in points.
Definition
GraphComment.h:42
Olympe::GraphComment::height
float height
Box height in graph space.
Definition
GraphComment.h:40
Olympe::GraphComment::color
unsigned int color
RGBA packed colour (default: amber)
Definition
GraphComment.h:41
Olympe::GraphComment::text
std::string text
Text content displayed inside the box.
Definition
GraphComment.h:36
Olympe::GraphComment::width
float width
Box width in graph space.
Definition
GraphComment.h:39
Olympe::GraphComment::isVisible
bool isVisible
Whether the comment is drawn.
Definition
GraphComment.h:43
Olympe::GraphComment::posY
float posY
Top edge in graph space.
Definition
GraphComment.h:38
Generated on Mon Apr 13 2026 08:15:20 for Olympe Engine by
1.9.8