VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
annotationManager.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4//
5// DEVIATION: Rendering replaced with ImGui-based overlays instead of
6// SDL_RenderDebugText + CPU-rasterized bitmap textures. The manager
7// is now a lightweight annotation registry with screen-space hit testing.
8// All visual rendering is done externally via ImGuiOverlay.
9//
10#pragma once
11
12#include <string>
13#include <vector>
14
15#include "script.h"
16#include "scriptRegistry.h"
17#include "core/math/color.h"
18#include "core/math/vector3.h"
19
20namespace visutwin::canvas
21{
22 class Annotation;
23 class Entity;
24
30 {
32 float screenX = 0.0f;
33 float screenY = 0.0f;
34 bool visible = true; // false if behind camera or off-screen
35 };
36
57 {
58 public:
59 SCRIPT_NAME("annotationManager")
60
61 float hotspotSize() const { return _hotspotSize; }
62 void setHotspotSize(float value) { _hotspotSize = value; }
63
64 const Color& hotspotColor() const { return _hotspotColor; }
65 void setHotspotColor(const Color& value) { _hotspotColor = value; }
66
67 const Color& activeColor() const { return _activeColor; }
68 void setActiveColor(const Color& value) { _activeColor = value; }
69
70 const Color& hoverColor() const { return _hoverColor; }
71 void setHoverColor(const Color& value) { _hoverColor = value; }
72
73 float opacity() const { return _opacity; }
74 void setOpacity(float value) { _opacity = value; }
75
78 const std::vector<AnnotationScreenInfo>& screenInfos() const { return _screenInfos; }
79
81 Annotation* activeAnnotation() const { return _activeAnnotation; }
82
84 Annotation* hoveredAnnotation() const { return _hoveredAnnotation; }
85
86 void initialize() override;
87 void update(float dt) override;
88
90 void handleClick(float screenX, float screenY);
91
93 void updateHover(float mouseX, float mouseY);
94
95 private:
96 void registerAnnotation(Annotation* annotation);
97 void unregisterAnnotation(Annotation* annotation);
98
99 // Find camera entity in the scene graph (lazy, called from update)
100 void findCameraEntity();
101
102 // Compute screen position from world position
103 // Returns false if behind camera
104 bool worldToScreen(const Vector3& worldPos, float& screenX, float& screenY) const;
105
106 // Properties
107 float _hotspotSize = 25.0f;
108 Color _hotspotColor = Color(0.22f, 0.74f, 0.97f, 1.0f); // cyan-400
109 Color _activeColor = Color(0.40f, 0.91f, 0.98f, 1.0f); // cyan-300
110 Color _hoverColor = Color(1.0f, 0.4f, 0.0f, 1.0f); // orange
111 float _opacity = 1.0f;
112
113 Entity* _camera = nullptr;
114
115 // Registered annotations
116 std::vector<Annotation*> _annotations;
117
118 // Per-frame screen-space projection results
119 std::vector<AnnotationScreenInfo> _screenInfos;
120
121 // Interaction state
122 Annotation* _activeAnnotation = nullptr;
123 Annotation* _hoveredAnnotation = nullptr;
124 };
125}
126
Annotation * activeAnnotation() const
The currently selected (clicked) annotation, or nullptr.
const std::vector< AnnotationScreenInfo > & screenInfos() const
void handleClick(float screenX, float screenY)
Handle mouse click at screen coordinates — selects/deselects the nearest annotation.
void updateHover(float mouseX, float mouseY)
Update hover state based on mouse position (call each frame with current mouse pos).
void setHotspotColor(const Color &value)
void setActiveColor(const Color &value)
void setHoverColor(const Color &value)
Annotation * hoveredAnnotation() const
The currently hovered annotation (nearest to mouse within hotspot radius), or nullptr.
ECS entity — a GraphNode that hosts components defining its behavior.
Definition entity.h:32
#define SCRIPT_NAME(Name)
Definition script.h:10
#define REGISTER_SCRIPT(Type, Name)
RGBA color with floating-point components in [0, 1].
Definition color.h:18
3D vector for positions, directions, and normals with multi-backend SIMD acceleration.
Definition vector3.h:29