VR-Engage  2.2
Loading...
Searching...
No Matches
hudItem.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file hudItem.h
7//! \brief Classes for representing and managing HUD (Heads-Up Display) items
8//! \ingroup vreCommonComponents
9
10#pragma once
11
13
14#include <string>
15
16namespace makVre
17{
18
19//! \brief Base class for all HUD (Heads-Up Display) items
20//!
21//! HudItem provides common functionality for all HUD elements, including positioning,
22//! alignment, visibility, and color. It also maintains a dirty flag system to track
23//! when properties have changed and rendering needs to be updated.
25{
26public:
27 //! \brief Enumeration of supported HUD item types
28 enum Type
29 {
30 //! \brief Invalid or uninitialized HUD item type
32
33 //! \brief Text-based HUD item
35
36 //! \brief Image-based HUD item
38 };
39
40 //! \brief Horizontal alignment options for HUD items
42 {
43 //! \brief Align to the left edge
45
46 //! \brief Align to the horizontal center
48
49 //! \brief Align to the right edge
51 };
52
53 //! \brief Vertical alignment options for HUD items
55 {
56 //! \brief Align to the top edge
58
59 //! \brief Align to the vertical middle
61
62 //! \brief Align to the bottom edge
64 };
65
66 //! \brief Constructor for HudItem
67 //!
68 //! Initializes the item with default values: centered position (0.5, 0.5),
69 //! white color (1,1,1,1), visibility enabled, and LEFT/TOP alignment
71
72 //! \brief Virtual destructor for HudItem
73 virtual ~HudItem();
74
75 //! \brief Gets the type of this HUD item
76 //! \return The HUD item type (TEXT, IMAGE, etc.)
77 virtual Type type() const;
78
79 //! \brief Gets the current dirty key value
80 //! \return Integer representing the current dirty state
81 //!
82 //! The dirty key is incremented whenever a property of the item is changed
83 virtual int dirtyKey() const;
84
85 //! \brief Forces the item to be marked as dirty
86 //!
87 //! Marks the item as needing a redraw by significantly incrementing the dirty key
88 virtual void makeDirty();
89
90 //! \brief Gets the current position of the HUD item
91 //! \param x Pointer to receive the x-coordinate (0.0 to 1.0)
92 //! \param y Pointer to receive the y-coordinate (0.0 to 1.0)
93 //!
94 //! Coordinates are in normalized screen space (0.0 to 1.0)
95 virtual void getPosition(float* x, float* y) const;
96
97 //! \brief Sets the position of the HUD item
98 //! \param x The x-coordinate in normalized screen space (0.0 to 1.0)
99 //! \param y The y-coordinate in normalized screen space (0.0 to 1.0)
100 //!
101 //! Updates the dirty key if the position changes
102 virtual void setPosition(float x, float y);
103
104 //! \brief Gets the current horizontal alignment
105 //! \return The horizontal alignment value (LEFT, CENTER, or RIGHT)
107
108 //! \brief Sets the horizontal alignment
109 //! \param align The horizontal alignment to use
110 //!
111 //! Updates the dirty key if the alignment changes
113
114 //! \brief Gets the current vertical alignment
115 //! \return The vertical alignment value (TOP, MIDDLE, or BOTTOM)
117
118 //! \brief Sets the vertical alignment
119 //! \param align The vertical alignment to use
120 //!
121 //! Updates the dirty key if the alignment changes
123
124 //! \brief Gets the x-coordinate of the item's position
125 //! \return The x-coordinate in normalized screen space (0.0 to 1.0)
126 virtual float getX() const;
127
128 //! \brief Gets the y-coordinate of the item's position
129 //! \return The y-coordinate in normalized screen space (0.0 to 1.0)
130 virtual float getY() const;
131
132 //! \brief Gets whether the HUD item is currently visible
133 //! \return True if the item is visible, false otherwise
134 virtual bool getVisible() const;
135
136 //! \brief Sets the visibility of the HUD item
137 //! \param visible True to make the item visible, false to hide it
138 //!
139 //! Updates the dirty key if the visibility changes
140 virtual void setVisible(bool visible);
141
142 //! \brief Gets the current color of the HUD item
143 //! \param r Pointer to receive the red component (0.0 to 1.0)
144 //! \param g Pointer to receive the green component (0.0 to 1.0)
145 //! \param b Pointer to receive the blue component (0.0 to 1.0)
146 //! \param a Pointer to receive the alpha component (0.0 to 1.0)
147 virtual void getColor(float* r, float* g, float* b, float* a) const;
148
149 //! \brief Sets the color of the HUD item
150 //! \param r The red component (0.0 to 1.0)
151 //! \param g The green component (0.0 to 1.0)
152 //! \param b The blue component (0.0 to 1.0)
153 //! \param a The alpha component (0.0 to 1.0)
154 //!
155 //! Updates the dirty key if the color changes
156 virtual void setColor(float r, float g, float b, float a);
157
158 //! \brief Gets the red component of the item's color
159 //! \return The red component value (0.0 to 1.0)
160 virtual float getRed() const;
161
162 //! \brief Gets the green component of the item's color
163 //! \return The green component value (0.0 to 1.0)
164 virtual float getGreen() const;
165
166 //! \brief Gets the blue component of the item's color
167 //! \return The blue component value (0.0 to 1.0)
168 virtual float getBlue() const;
169
170 //! \brief Gets the alpha component of the item's color
171 //! \return The alpha component value (0.0 to 1.0)
172 virtual float getAlpha() const;
173
174protected:
175 //! \brief The type of this HUD item
177
178 //! \brief Key that tracks whether the item needs to be redrawn
179 //!
180 //! Incremented whenever a property changes that affects rendering
182
183 //! \brief Position of the item in normalized screen space [x, y]
184 float myPosition[2];
185
186 //! \brief Horizontal alignment of the item
188
189 //! \brief Vertical alignment of the item
191
192 //! \brief Visibility flag for the item
194
195 //! \brief Color of the item [r, g, b, a] with components in range 0.0 to 1.0
196 float myColor[4];
197};
198
199//! \brief Text-based HUD item
200//!
201//! HudTextItem extends HudItem with text-specific properties including
202//! the text content, font path, and font size.
204{
205public:
206 //! \brief Constructor for HudTextItem
207 //!
208 //! Initializes the item as a TEXT type with default font size of 0.0
210
211 //! \brief Virtual destructor for HudTextItem
212 virtual ~HudTextItem() override;
213
214 //! \brief Gets the current text content
215 //! \return The current text string
216 virtual std::string getText() const;
217
218 //! \brief Sets the text content
219 //! \param text The new text string to display
220 //!
221 //! Updates the dirty key if the text changes
222 virtual void setText(const std::string& text);
223
224 //! \brief Gets the current font path
225 //! \return Path to the font file
226 virtual std::string getFontPath() const;
227
228 //! \brief Sets the font path
229 //! \param path Path to the font file to use
230 //!
231 //! Updates the dirty key if the font path changes
232 virtual void setFontPath(const std::string& path);
233
234 //! \brief Gets the current font size
235 //! \return The font size
236 virtual float getFontSize() const;
237
238 //! \brief Sets the font size
239 //! \param size The new font size to use
240 //!
241 //! Updates the dirty key if the font size changes
242 virtual void setFontSize(float size);
243
244protected:
245 //! \brief The text content to display
246 std::string myText;
247
248 //! \brief Path to the font file
249 std::string myFontPath;
250
251 //! \brief Font size for rendering
253};
254
255//! \brief Image-based HUD item
256//!
257//! HudImageItem extends HudItem with image-specific properties including
258//! the image path and size dimensions.
260{
261public:
262 //! \brief Constructor for HudImageItem
263 //!
264 //! Initializes the item as an IMAGE type
266
267 //! \brief Virtual destructor for HudImageItem
268 virtual ~HudImageItem() override;
269
270 //! \brief Gets the current image path
271 //! \return Path to the image file
272 virtual std::string getImagePath() const;
273
274 //! \brief Sets the image path
275 //! \param path Path to the image file to display
276 //!
277 //! Updates the dirty key if the image path changes
278 virtual void setImagePath(const std::string& path);
279
280 //! \brief Gets the current image size
281 //! \param w Pointer to receive the width
282 //! \param h Pointer to receive the height
283 virtual void getSize(float* w, float* h) const;
284
285 //! \brief Sets the image size
286 //! \param w The width of the image
287 //! \param h The height of the image
288 //!
289 //! Updates the dirty key if the size changes
290 virtual void setSize(float w, float h);
291
292 //! \brief Gets the width of the image
293 //! \return The current width
294 virtual float getWidth() const;
295
296 //! \brief Gets the height of the image
297 //! \return The current height
298 virtual float getHeight() const;
299
300protected:
301 //! \brief Path to the image file
302 std::string myImagePath;
303
304 //! \brief Size of the image [width, height]
305 float mySize[2];
306};
307
308} // namespace makVre
std::string myImagePath
Path to the image file.
Definition hudItem.h:302
virtual void setSize(float w, float h)
Sets the image size.
virtual float getWidth() const
Gets the width of the image.
virtual void setImagePath(const std::string &path)
Sets the image path.
virtual ~HudImageItem() override
Virtual destructor for HudImageItem.
HudImageItem()
Constructor for HudImageItem.
float mySize[2]
Size of the image [width, height].
Definition hudItem.h:305
virtual void getSize(float *w, float *h) const
Gets the current image size.
virtual float getHeight() const
Gets the height of the image.
virtual std::string getImagePath() const
Gets the current image path.
int myDirtyKey
Key that tracks whether the item needs to be redrawn.
Definition hudItem.h:181
virtual void setVisible(bool visible)
Sets the visibility of the HUD item.
virtual float getAlpha() const
Gets the alpha component of the item's color.
virtual void getPosition(float *x, float *y) const
Gets the current position of the HUD item.
virtual AlignHorizontal getHorizontalAlignment() const
Gets the current horizontal alignment.
Type myType
The type of this HUD item.
Definition hudItem.h:176
virtual void setPosition(float x, float y)
Sets the position of the HUD item.
float myPosition[2]
Position of the item in normalized screen space [x, y].
Definition hudItem.h:184
virtual AlignVertical getVerticalAlignment() const
Gets the current vertical alignment.
virtual void setColor(float r, float g, float b, float a)
Sets the color of the HUD item.
AlignHorizontal
Horizontal alignment options for HUD items.
Definition hudItem.h:42
@ LEFT
Align to the left edge.
Definition hudItem.h:44
@ RIGHT
Align to the right edge.
Definition hudItem.h:50
@ CENTER
Align to the horizontal center.
Definition hudItem.h:47
virtual int dirtyKey() const
Gets the current dirty key value.
virtual void getColor(float *r, float *g, float *b, float *a) const
Gets the current color of the HUD item.
AlignVertical myVerticalAlignment
Vertical alignment of the item.
Definition hudItem.h:190
virtual void setVerticalAlignment(AlignVertical align)
Sets the vertical alignment.
virtual float getGreen() const
Gets the green component of the item's color.
virtual bool getVisible() const
Gets whether the HUD item is currently visible.
float myColor[4]
Color of the item [r, g, b, a] with components in range 0.0 to 1.0.
Definition hudItem.h:196
Type
Enumeration of supported HUD item types.
Definition hudItem.h:29
@ TEXT
Text-based HUD item.
Definition hudItem.h:34
@ ILLEGAL_TYPE_UNDEFINED
Invalid or uninitialized HUD item type.
Definition hudItem.h:31
@ IMAGE
Image-based HUD item.
Definition hudItem.h:37
virtual Type type() const
Gets the type of this HUD item.
virtual void makeDirty()
Forces the item to be marked as dirty.
HudItem()
Constructor for HudItem.
virtual float getBlue() const
Gets the blue component of the item's color.
virtual float getRed() const
Gets the red component of the item's color.
AlignHorizontal myHorizontalAlignment
Horizontal alignment of the item.
Definition hudItem.h:187
virtual ~HudItem()
Virtual destructor for HudItem.
AlignVertical
Vertical alignment options for HUD items.
Definition hudItem.h:55
@ MIDDLE
Align to the vertical middle.
Definition hudItem.h:60
@ TOP
Align to the top edge.
Definition hudItem.h:57
@ BOTTOM
Align to the bottom edge.
Definition hudItem.h:63
virtual void setHorizontalAlignment(AlignHorizontal align)
Sets the horizontal alignment.
bool myVisible
Visibility flag for the item.
Definition hudItem.h:193
virtual float getX() const
Gets the x-coordinate of the item's position.
virtual float getY() const
Gets the y-coordinate of the item's position.
virtual void setText(const std::string &text)
Sets the text content.
std::string myText
The text content to display.
Definition hudItem.h:246
virtual void setFontPath(const std::string &path)
Sets the font path.
float myFontSize
Font size for rendering.
Definition hudItem.h:252
HudTextItem()
Constructor for HudTextItem.
virtual float getFontSize() const
Gets the current font size.
virtual std::string getText() const
Gets the current text content.
virtual ~HudTextItem() override
Virtual destructor for HudTextItem.
virtual std::string getFontPath() const
Gets the current font path.
virtual void setFontSize(float size)
Sets the font size.
std::string myFontPath
Path to the font file.
Definition hudItem.h:249
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Include export definitions for this library.
Definition glsVreMessageUtil.h:49