VR-Engage  2.2
Loading...
Searching...
No Matches
overlayComponent.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file overlayComponent.h
7//! \brief Component for creating and managing HUD elements in overlay channels
8//! \ingroup vreCommonComponents
9
10
11#pragma once
12
14
17
18#include <string>
19#include <vector>
20
21namespace makVre
22{
24{
25//! \ingroup RoleConfigParams
26//! \defgroup OverlayComponentRoleParams Overlay Component Role Parameters
27//! \roleInherits{PlayerComponentRoleParams}
28//! Configuration Options for overlay component role.
29//! @{
30
31//! \vreRoleParam{channelName,string,"Channel 1",overlayComponent,Name of the render channel where the overlay should be displayed.}
32constexpr const char* channelName = "channelName";
33
34//! \vreRoleParam{elements,table,"",overlayComponent,Table defining the HUD elements to be created and displayed in the overlay.}
35constexpr const char* elements = "elements";
36
37//! \vreRoleParam{windowName,string,"Window 1",overlayComponent,Name of the window where the overlay should be rendered.}
38constexpr const char* windowName = "windowName";
39
40//! @}
41} // namespace OverlayComponentConfig
42
43//! \brief Type identifier for DtOverlayComponent component
44constexpr const char* DtOverlayComponentType = "DtOverlayComponent";
45
46//! \brief Base component for creating and managing 2D HUD overlays
47//!
48//! DtOverlayComponent provides functionality for creating and managing 2D HUD elements
49//! including text, lines, and textured quads. The component can render these elements
50//! on top of the 3D scene and dynamically update text content based on state attributes.
51//! Elements are defined in the component's configuration and can be resized or repositioned
52//! when the display resolution changes.
54{
55public:
56 //! \brief Constructor for DtOverlayComponent
57 //!
58 //! Initializes the overlay component with the specified class name
60
61 //! \brief Virtual destructor for DtOverlayComponent
62 virtual ~DtOverlayComponent() override;
63
64 //! \brief Initializes the overlay component
65 //! \param player Pointer to the player station this component belongs to
66 //! \param config Configuration table containing overlay settings and element definitions
67 //! \return True if initialization succeeded, false otherwise
68 //!
69 //! Creates the VRV overlay in the appropriate window/channel and builds the
70 //! defined HUD elements from the configuration
72
73 //! \brief Performs post-initialization after all components are initialized
74 //! \return True if post-initialization succeeded, false otherwise
75 //!
76 //! Resolves initial text values by substituting state attribute values
77 virtual bool postInitialize() override;
78
79 //! \brief Called every frame to update the overlay
80 //! \param dt Delta time since the last frame in seconds
81 //!
82 //! Updates text elements with current state attribute values
83 virtual void tick(double dt) override;
84
85 //! \brief Shuts down the overlay component
86 //!
87 //! Destroys all created elements and the overlay itself
88 virtual void shutdown() override;
89
90 //! \brief Finds a text element by its name
91 //! \param name Name of the text element to find
92 //! \return Pointer to the text proxy if found, nullptr otherwise
93 //!
94 //! Searches through the text elements for one with the specified name
95 virtual makVrv::DtTextProxy* findTextByName(const std::string& name);
96
97 //! \brief Sets the visibility of a text element
98 //! \param name Name of the text element to modify
99 //! \param isVisible True to show the text, false to hide it
100 //!
101 //! Changes the visibility of a named text element by setting its group
102 virtual void setTextVisible(const std::string& name, bool isVisible);
103
104 //! \brief Sets the group for all overlay elements
105 //! \param group Group number to assign to all elements
106 //!
107 //! Changes the visibility group of all text, line, and quad elements
108 //! (group 0 is typically used to hide elements, group 1 to show them)
109 virtual void setAllElementGroups(int group);
110
111 //! \brief Returns the component type identifier
112 //! \return The component type string
113 virtual const char* type() const override;
114
115protected:
116 //! \brief Updates text elements with current state attribute values
117 //!
118 //! Processes all text strings, replacing state attribute references like $(attributeName)
119 //! with their current values from the player attribute store
120 virtual void resolveTexts();
121 //! \brief Converts a state attribute to a string representation
122 //! \param attrName Name of the attribute to retrieve
123 //! \param mappings Optional value mappings to translate numeric values to strings
124 //! \return String representation of the attribute value
125 //!
126 //! Retrieves a state attribute and converts it to a string, applying any mappings if provided
127 virtual std::string getAttributeAsString(const std::string& attrName, const std::vector<std::string>& mappings);
128 //! \brief Handles overlay resize events
129 //!
130 //! Called when the window or overlay is resized to rebuild all elements
131 //! with the new screen dimensions
132 virtual void handleOverlayResized();
133 //! \brief Destroys all overlay elements
134 //!
135 //! Removes and deletes all text, line, and quad elements from the overlay
136 virtual void destroyElements();
137 //! \brief Builds overlay elements from a configuration table
138 //! \param elements Configuration table containing element definitions
139 //!
140 //! Creates text, line, and quad elements based on the provided configuration
141 virtual void buildElements(DtInitTable& elements);
142
143 //! \brief Pointer to the VRV overlay that contains all HUD elements
145
146 //! \brief Structure representing a text element in the overlay
147 struct Text
148 {
149 //! \brief Name identifier for the text element
150 std::string myName;
151
152 //! \brief Original text string with attribute references
153 std::string myTextString;
154
155 //! \brief Pointer to the text proxy in the overlay
156 makVrv::DtTextProxy* myText;
157
158 //! \brief Value mappings for translating numeric values to strings
159 std::vector<std::string> myValueMapping;
160 };
161
162 //! \brief Collection of text elements in the overlay
163 std::vector<Text> myTexts;
164
165 //! \brief Collection of line elements in the overlay
166 std::vector<makVrv::DtLineSegment*> myLines;
167
168 //! \brief Collection of quad elements in the overlay
169 std::vector<makVrv::DtQuadProxy*> myQuads;
170
171 //! \brief Configuration table containing element definitions
173};
174} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
DtOverlayComponent()
Constructor for DtOverlayComponent.
virtual void resolveTexts()
Updates text elements with current state attribute values.
virtual void setTextVisible(const std::string &name, bool isVisible)
Sets the visibility of a text element.
virtual void setAllElementGroups(int group)
Sets the group for all overlay elements.
virtual void shutdown() override
Shuts down the overlay component.
DtVrvOverlay * myOverlay
Pointer to the VRV overlay that contains all HUD elements.
Definition overlayComponent.h:144
virtual makVrv::DtTextProxy * findTextByName(const std::string &name)
Finds a text element by its name.
virtual const char * type() const override
Returns the component type identifier.
std::vector< makVrv::DtLineSegment * > myLines
Collection of line elements in the overlay.
Definition overlayComponent.h:166
virtual std::string getAttributeAsString(const std::string &attrName, const std::vector< std::string > &mappings)
Converts a state attribute to a string representation.
virtual ~DtOverlayComponent() override
Virtual destructor for DtOverlayComponent.
virtual void handleOverlayResized()
Handles overlay resize events.
virtual void destroyElements()
Destroys all overlay elements.
virtual void buildElements(DtInitTable &elements)
Builds overlay elements from a configuration table.
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the overlay component.
std::vector< Text > myTexts
Collection of text elements in the overlay.
Definition overlayComponent.h:163
DtInitTable myElementConfig
Configuration table containing element definitions.
Definition overlayComponent.h:172
virtual void tick(double dt) override
Called every frame to update the overlay.
std::vector< makVrv::DtQuadProxy * > myQuads
Collection of quad elements in the overlay.
Definition overlayComponent.h:169
virtual DtPlayerStation & player()
Gets the player station.
virtual const std::string & name()
Gets the component name.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Class for creating and managing 2D overlays on a 3D scene.
Definition vrvOverlay.h:79
constexpr const char * windowName
Definition overlayComponent.h:38
constexpr const char * channelName
Definition overlayComponent.h:32
constexpr const char * elements
Definition overlayComponent.h:35
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition overlayComponent.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtOverlayComponentType
Type identifier for DtOverlayComponent component.
Definition overlayComponent.h:44
Defines the DtPlayerComponent base class for VR-Engage role components.
Structure representing a text element in the overlay.
Definition overlayComponent.h:148
std::string myTextString
Original text string with attribute references.
Definition overlayComponent.h:153
makVrv::DtTextProxy * myText
Pointer to the text proxy in the overlay.
Definition overlayComponent.h:156
std::string myName
Name identifier for the text element.
Definition overlayComponent.h:150
std::vector< std::string > myValueMapping
Value mappings for translating numeric values to strings.
Definition overlayComponent.h:159
Provides a 2D overlay rendering system for VRV-based applications.