Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
IGraphRenderer.h
Go to the documentation of this file.
1/**
2 * @file IGraphRenderer.h
3 * @brief Abstract interface shared by all graph-renderer adapters.
4 * @author Olympe Engine
5 * @date 2026-03-11
6 *
7 * @details
8 * Every concrete renderer (VisualScript, BehaviorTree, AnimGraph …) that can
9 * live inside a TabManager tab must implement this interface.
10 *
11 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
12 */
13
14#pragma once
15
16#include <string>
17
18namespace Olympe {
19
20/**
21 * @class IGraphRenderer
22 * @brief Polymorphic interface for all graph editor renderers.
23 *
24 * Implementations are owned by TabManager via raw pointers (C++14 style).
25 * Lifetime: the owning EditorTab deletes the renderer when the tab is closed.
26 */
28{
29public:
30 virtual ~IGraphRenderer() {}
31
32 // ------------------------------------------------------------------
33 // Lifecycle
34 // ------------------------------------------------------------------
35
36 /** @brief Renders the graph canvas into the current ImGui child window. */
37 virtual void Render() = 0;
38
39 // ------------------------------------------------------------------
40 // File I/O
41 // ------------------------------------------------------------------
42
43 /**
44 * @brief Loads a graph from a file on disk.
45 * @param path Absolute or relative path to the .ats / .json file.
46 * @return true on success.
47 */
48 virtual bool Load(const std::string& path) = 0;
49
50 /**
51 * @brief Saves the current graph state to disk.
52 * @param path Destination path. If empty, save to the path passed to Load().
53 * @return true on success.
54 */
55 virtual bool Save(const std::string& path) = 0;
56
57 // ------------------------------------------------------------------
58 // State queries
59 // ------------------------------------------------------------------
60
61 /** @brief Returns true when the graph has unsaved changes. */
62 virtual bool IsDirty() const = 0;
63
64 /**
65 * @brief Returns the graph type string, e.g. "VisualScript", "BehaviorTree".
66 */
67 virtual std::string GetGraphType() const = 0;
68
69 /**
70 * @brief Returns the last path successfully loaded/saved, or empty string.
71 */
72 virtual std::string GetCurrentPath() const = 0;
73
74 // ------------------------------------------------------------------
75 // Canvas State Management (Phase 35.0 - Multi-Tab Fix)
76 // ------------------------------------------------------------------
77
78 /**
79 * @brief Save the current canvas viewport state (pan, zoom, etc.)
80 * Called when tab is deactivated.
81 * Used to preserve viewport when switching between multiple tabs.
82 */
83 virtual void SaveCanvasState() {}
84
85 /**
86 * @brief Restore previously saved canvas viewport state
87 * Called when tab is reactivated.
88 * Ensures smooth tab switching without losing layout.
89 */
90 virtual void RestoreCanvasState() {}
91
92 /**
93 * @brief Get canvas state as JSON string for persistence
94 * @return JSON representation of current canvas state
95 */
96 virtual std::string GetCanvasStateJSON() const
97 {
98 return ""; // Default: no persistent state
99 }
100
101 /**
102 * @brief Restore canvas state from JSON string
103 * @param json JSON representation of saved canvas state
104 */
105 virtual void SetCanvasStateJSON(const std::string& json)
106 {
107 (void)json; // Default: no-op
108 }
109};
110
111} // namespace Olympe
112
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Polymorphic interface for all graph editor renderers.
virtual std::string GetCurrentPath() const =0
Returns the last path successfully loaded/saved, or empty string.
virtual bool Load(const std::string &path)=0
Loads a graph from a file on disk.
virtual void RestoreCanvasState()
Restore previously saved canvas viewport state Called when tab is reactivated.
virtual bool IsDirty() const =0
Returns true when the graph has unsaved changes.
virtual void SetCanvasStateJSON(const std::string &json)
Restore canvas state from JSON string.
virtual void SaveCanvasState()
Save the current canvas viewport state (pan, zoom, etc.) Called when tab is deactivated.
virtual std::string GetCanvasStateJSON() const
Get canvas state as JSON string for persistence.
virtual void Render()=0
Renders the graph canvas into the current ImGui child window.
virtual std::string GetGraphType() const =0
Returns the graph type string, e.g.
virtual bool Save(const std::string &path)=0
Saves the current graph state to disk.
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json