Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
CanvasGridRenderer.h
Go to the documentation of this file.
1#pragma once
2
3#include "../../third_party/imgui/imgui.h"
4
5namespace Olympe
6{
7 /**
8 * @class CanvasGridRenderer
9 * @brief Shared utility for rendering grid backgrounds on any canvas editor
10 * @details Provides configurable grid rendering with support for:
11 * - Major and minor grid lines
12 * - Zoom-aware scaling
13 * - Pan offset handling
14 * - Customizable colors and spacing
15 * - Professional grid styles (VisualScript, Compact, Spacious)
16 * - C++14 compatible
17 */
19 {
20 public:
21 /**
22 * @enum GridStylePreset
23 * @brief Pre-configured grid styles matching professional editors
24 */
26 {
27 Style_VisualScript, // Dark blue bg, subtle gray grid (imnodes professional default)
28 Style_Compact, // Tight grid for dense layouts
29 Style_Spacious, // Wide grid for spacious layouts
30 };
31
32 /**
33 * @struct GridConfig
34 * @brief Configuration parameters for grid rendering
35 */
37 {
38 // Canvas positioning
39 ImVec2 canvasPos; // Top-left screen position of canvas
40 ImVec2 canvasSize; // Width and height of canvas area
41
42 // Canvas transformation
43 float zoom = 1.0f; // Canvas zoom level (1.0 = 100%)
44 float offsetX = 0.0f; // Pan offset X (canvas space)
45 float offsetY = 0.0f; // Pan offset Y (canvas space)
46
47 // Grid parameters
48 float majorSpacing = 24.0f; // Distance between major grid lines (canvas units)
49 float minorDivisor = 1.0f; // Minor lines = majorSpacing / minorDivisor
50
51 // Colors (ImVec4: r, g, b, a)
52 ImVec4 backgroundColor = ImVec4(0.157f, 0.157f, 0.196f, 0.784f); // (40,40,50,200) - Dark blue
53 ImVec4 majorLineColor = ImVec4(0.941f, 0.941f, 0.941f, 0.235f); // (240,240,240,60)
54 ImVec4 minorLineColor = ImVec4(0.784f, 0.784f, 0.784f, 0.157f); // (200,200,200,40)
55
56 // Line weights
57 float majorLineThickness = 1.0f; // Major line thickness in pixels
58 float minorLineThickness = 0.5f; // Minor line thickness in pixels
59 };
60
61 /**
62 * @brief Get pre-configured grid style (VisualScript/Compact/Spacious)
63 * @param preset The style preset to use
64 * @return GridConfig initialized with preset values
65 */
67
68 /**
69 * @brief Render a grid on the given ImDrawList
70 * @param drawList ImGui draw list to render to
71 * @param config Grid configuration parameters
72 */
73 static void RenderGrid(ImDrawList* drawList, const GridConfig& config);
74
75 /**
76 * @brief Convenience overload using ImGui's current context
77 * @param config Grid configuration parameters
78 */
79 static void RenderGrid(const GridConfig& config);
80 };
81}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Shared utility for rendering grid backgrounds on any canvas editor.
static GridConfig GetStylePreset(GridStylePreset preset)
Get pre-configured grid style (VisualScript/Compact/Spacious)
static void RenderGrid(ImDrawList *drawList, const GridConfig &config)
Render a grid on the given ImDrawList.
GridStylePreset
Pre-configured grid styles matching professional editors.
< Provides AssetID and INVALID_ASSET_ID
Configuration parameters for grid rendering.