Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
VisualScriptNodeRenderer.h
Go to the documentation of this file.
1/**
2 * @file VisualScriptNodeRenderer.h
3 * @brief Node style rendering helpers for VisualScriptEditorPanel (Phase 5).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * Provides stateless helpers for rendering VS node styles (colours, pin shapes,
9 * hover tooltips) on top of ImNodes.
10 *
11 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
12 */
13
14#pragma once
15
16#include <string>
17#include <vector>
18#include <utility>
19#include <unordered_set>
20#include "../TaskSystem/TaskGraphTypes.h"
21#include "../TaskSystem/TaskGraphTemplate.h"
22
23// Forward declarations (avoid pulling in heavy headers)
24struct ImVec2;
25
26namespace Olympe {
27
28// ============================================================================
29// Node visual style
30// ============================================================================
31
32/**
33 * @enum VSNodeStyle
34 * @brief Visual style category for a VS node.
35 */
36enum class VSNodeStyle {
37 EntryPoint, ///< Green — single "Out" exec pin
38 FlowControl, ///< Blue — Branch, Sequence, While, ForEach, DoOnce
39 Action, ///< Orange — AtomicTask
40 Data, ///< Purple — GetBBValue, SetBBValue, MathOp
41 SubGraph, ///< Teal — SubGraph call
42 Delay ///< Yellow — Delay timer
43};
44
45/**
46 * @brief Returns the VSNodeStyle appropriate for a given node type.
47 */
49
50/**
51 * @brief Returns the title-bar RGBA colour for a given style.
52 */
53unsigned int GetNodeTitleColor(VSNodeStyle style);
54
55/**
56 * @brief Returns the title-bar hovered RGBA colour.
57 */
58unsigned int GetNodeTitleHoveredColor(VSNodeStyle style);
59
60/**
61 * @brief Returns the RGBA colour for a data pin by variable type.
62 */
63unsigned int GetDataPinColor(VariableType type);
64
65/**
66 * @brief Returns a human-readable label for a TaskNodeType.
67 */
68const char* GetNodeTypeLabel(TaskNodeType type);
69
70/**
71 * @brief Returns a human-readable label for a VariableType.
72 */
73const char* GetVariableTypeLabel(VariableType type);
74
75// ============================================================================
76// VisualScriptNodeRenderer
77// ============================================================================
78
79/**
80 * @class VisualScriptNodeRenderer
81 * @brief Stateless helper class for rendering VS nodes via ImNodes.
82 *
83 * @details
84 * All methods are static — this class has no instance state. The renderer
85 * pushes/pops ImNodes colour styles and delegates actual node/pin calls to
86 * ImNodes directly.
87 */
89public:
90
91 /**
92 * @brief Renders a complete VS node (title + exec pins + data pins).
93 *
94 * Must be called inside an ImNodes::BeginNodeEditor() … EndNodeEditor() scope.
95 *
96 * @param nodeUID Global ImNodes node UID.
97 * @param nodeID Graph-local node ID (for breakpoint lookup).
98 * @param graphID Graph ID (for breakpoint lookup).
99 * @param nodeName Display name.
100 * @param type Node type (determines style).
101 * @param hasBreakpoint Whether a breakpoint is set on this node.
102 * @param isActive Whether this node is currently executing (debug).
103 * @param execInputPins Names of exec-in pins (usually just {"In"}).
104 * @param execOutputPins Names of exec-out pins (e.g. {"True","False"}).
105 * @param dataInputPins (name, type) pairs for data-in pins.
106 * @param dataOutputPins (name, type) pairs for data-out pins.
107 *
108 * @note Tooltip display is handled by the caller after EndNodeEditor()
109 * because ImNodes::IsNodeHovered() requires ImNodesScope_None.
110 */
111 static void RenderNode(
112 int nodeUID,
113 int nodeID,
114 int graphID,
115 const std::string& nodeName,
116 TaskNodeType type,
117 bool hasBreakpoint,
118 bool isActive,
119 const std::vector<std::string>& execInputPins,
120 const std::vector<std::string>& execOutputPins,
121 const std::vector<std::pair<std::string, VariableType>>& dataInputPins,
122 const std::vector<std::pair<std::string, VariableType>>& dataOutputPins,
123 const std::unordered_set<int>& connectedAttrIDs = {});
124
125 /**
126 * @brief Extended RenderNode with inline parameter display and optional Add[+]/Remove[-] callbacks.
127 *
128 * Displays key parameters inline in the node body (between title bar and pins).
129 * For VSSequence and Switch nodes, renders a [+] button below the last exec-out pin
130 * that invokes onAddPin(nodeID, onAddPinUserData).
131 * For each dynamic exec-out pin (all but the base pin), renders a [-] button inline
132 * that invokes onRemovePin(nodeID, dynamicPinIndex, onRemovePinUserData).
133 *
134 * @param nodeUID Global ImNodes node UID.
135 * @param nodeID Graph-local node ID.
136 * @param graphID Graph ID (breakpoint lookup).
137 * @param def Full node definition (for inline parameter display).
138 * @param hasBreakpoint Whether a breakpoint is set on this node.
139 * @param isActive Whether this node is executing (debug).
140 * @param execInputPins Names of exec-in pins.
141 * @param execOutputPins Names of exec-out pins (includes dynamic ones for VSSequence/Switch).
142 * @param dataInputPins (name, type) pairs for data-in pins.
143 * @param dataOutputPins (name, type) pairs for data-out pins.
144 * @param onAddPin Optional callback invoked when user clicks [+] on a VSSequence/Switch.
145 * Receives the nodeID and onAddPinUserData. Pass nullptr to disable.
146 * @param onAddPinUserData User data passed to onAddPin.
147 * @param onRemovePin Optional callback invoked when user clicks [-] on a dynamic pin.
148 * Receives nodeID, 0-based dynamic pin index, and onRemovePinUserData.
149 * Pass nullptr to disable.
150 * @param onRemovePinUserData User data passed to onRemovePin.
151 */
152 static void RenderNode(
153 int nodeUID,
154 int nodeID,
155 int graphID,
156 const TaskNodeDefinition& def,
157 bool hasBreakpoint,
158 bool isActive,
159 const std::vector<std::string>& execInputPins,
160 const std::vector<std::string>& execOutputPins,
161 const std::vector<std::pair<std::string, VariableType>>& dataInputPins,
162 const std::vector<std::pair<std::string, VariableType>>& dataOutputPins,
163 void (*onAddPin)(int nodeID, void* userData),
164 void* onAddPinUserData,
165 void (*onRemovePin)(int nodeID, int dynamicPinIndex, void* userData) = nullptr,
166 void* onRemovePinUserData = nullptr,
167 const std::unordered_set<int>& connectedAttrIDs = {});
168
169 /**
170 * @brief Renders a breakpoint indicator (red circle) next to a node.
171 *
172 * Must be called inside an ImNodes::BeginNodeEditor() … EndNodeEditor() scope,
173 * and after ImNodes::EndNode() so that GetNodeEditorSpacePos() is valid.
174 *
175 * @param nodeUID Global ImNodes node UID.
176 */
177 static void RenderBreakpointIndicator(int nodeUID);
178
179 /**
180 * @brief Renders a "currently executing" glow overlay around a node.
181 *
182 * @param nodeUID Global ImNodes node UID.
183 */
184 static void RenderActiveNodeGlow(int nodeUID);
185
186private:
188};
189
190} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Stateless helper class for rendering VS nodes via ImNodes.
static void RenderNode(int nodeUID, int nodeID, int graphID, const std::string &nodeName, TaskNodeType type, bool hasBreakpoint, bool isActive, const std::vector< std::string > &execInputPins, const std::vector< std::string > &execOutputPins, const std::vector< std::pair< std::string, VariableType > > &dataInputPins, const std::vector< std::pair< std::string, VariableType > > &dataOutputPins, const std::unordered_set< int > &connectedAttrIDs={})
Renders a complete VS node (title + exec pins + data pins).
static void RenderBreakpointIndicator(int nodeUID)
Renders a breakpoint indicator (red circle) next to a node.
static void RenderActiveNodeGlow(int nodeUID)
Renders a "currently executing" glow overlay around a node.
< Provides AssetID and INVALID_ASSET_ID
const char * GetNodeTypeLabel(TaskNodeType type)
Returns a human-readable label for a TaskNodeType.
VariableType
Type tags used by TaskValue to identify stored data.
VSNodeStyle
Visual style category for a VS node.
@ Action
Orange — AtomicTask.
@ FlowControl
Blue — Branch, Sequence, While, ForEach, DoOnce.
@ SubGraph
Teal — SubGraph call.
@ Delay
Yellow — Delay timer.
@ EntryPoint
Green — single "Out" exec pin.
unsigned int GetNodeTitleHoveredColor(VSNodeStyle style)
Returns the title-bar hovered RGBA colour.
unsigned int GetDataPinColor(VariableType type)
Returns the RGBA colour for a data pin by variable type.
VSNodeStyle GetNodeStyle(TaskNodeType type)
Returns the VSNodeStyle appropriate for a given node type.
const char * GetVariableTypeLabel(VariableType type)
Returns a human-readable label for a VariableType.
TaskNodeType
Identifies the role of a node in the task graph.
unsigned int GetNodeTitleColor(VSNodeStyle style)
Returns the title-bar RGBA colour for a given style.
Full description of a single node in the task graph.