Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Clipboard.h
Go to the documentation of this file.
1/**
2 * @file Clipboard.h
3 * @brief Node-graph clipboard: copy/paste selected nodes via ImGui system clipboard.
4 * @author Olympe Engine
5 * @date 2026-02-24
6 *
7 * @details
8 * NodeGraphClipboard serialises selected nodes (including their type, sub-type,
9 * parameters and relative positions) to a compact JSON string stored in the
10 * system clipboard via ImGui::SetClipboardText / ImGui::GetClipboardText.
11 *
12 * The JSON payload is prefixed with the marker OLYMPE_NG_CLIP: so that foreign
13 * clipboard contents are silently ignored on paste.
14 *
15 * Multi-node copy is supported: all currently selected nodes are written.
16 * On paste the nodes are positioned relative to the current mouse cursor
17 * position, preserving their layout offsets.
18 *
19 * Design notes
20 * ------------
21 * - The class is a singleton for convenience; each editor window uses the same
22 * shared clipboard.
23 * - No heap allocations are kept between Copy() and Paste() calls; the JSON is
24 * stored solely in the system clipboard string.
25 * - C++14 compliant - no C++17/20 features.
26 */
27
28#pragma once
29
30#include <string>
31#include <vector>
32#include "BTNodeGraphManager.h"
33
34namespace Olympe
35{
36
37/**
38 * @class NodeGraphClipboard
39 * @brief Singleton clipboard for node-graph copy / paste operations.
40 */
42{
43public:
44 /// Returns the singleton instance.
45 static NodeGraphClipboard& Get();
46
47 /**
48 * @brief Serialise currently selected nodes to JSON and write to the system
49 * clipboard.
50 *
51 * @param graph Active NodeGraph (source of node data and selection).
52 * @param graphID Active graph ID (used to resolve ImNodes global UIDs).
53 *
54 * If no nodes are selected the clipboard is left unchanged.
55 */
56 void CopySelectedNodes(NodeGraph* graph, int graphID);
57
58 /**
59 * @brief Read the system clipboard, deserialise nodes and create them in
60 * the active graph under the current mouse cursor.
61 *
62 * @param graph Active NodeGraph (destination).
63 * @param graphID Active graph ID used to set ImNodes node positions via
64 * ImNodes::SetNodeGridSpacePos immediately after creation.
65 * @param mousePosX Paste anchor X in canvas (grid) space.
66 * @param mousePosY Paste anchor Y in canvas (grid) space.
67 * @param snapToGrid When true, each pasted node position is snapped to the
68 * nearest grid cell of size @p snapGridSize.
69 * @param snapGridSize Grid cell size used when @p snapToGrid is true.
70 *
71 * If the clipboard does not contain a valid Olympe payload this is a no-op.
72 */
73 void PasteNodes(NodeGraph* graph, int graphID, float mousePosX, float mousePosY,
74 bool snapToGrid = false, float snapGridSize = 16.0f);
75
76private:
77 NodeGraphClipboard() = default;
78
79 /// Prefix that marks Olympe node-graph clipboard payloads.
80 static const char* k_ClipPrefix;
81};
82
83} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton clipboard for node-graph copy / paste operations.
Definition Clipboard.h:42
void PasteNodes(NodeGraph *graph, int graphID, float mousePosX, float mousePosY, bool snapToGrid=false, float snapGridSize=16.0f)
Read the system clipboard, deserialise nodes and create them in the active graph under the current mo...
static NodeGraphClipboard & Get()
Returns the singleton instance.
Definition Clipboard.cpp:60
void CopySelectedNodes(NodeGraph *graph, int graphID)
Serialise currently selected nodes to JSON and write to the system clipboard.
Definition Clipboard.cpp:70
static const char * k_ClipPrefix
Prefix that marks Olympe node-graph clipboard payloads.
Definition Clipboard.h:80
< Provides AssetID and INVALID_ASSET_ID