VR-Engage  2.2
Loading...
Searching...
No Matches
actionMenu.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file actionMenu.h
7//! \brief Defines the core menu class for VR-Engage
8//!
9//! This file contains the DtMenu class which provides the foundation for all
10//! interactive menus in VR-Engage. It manages menu elements, selection state,
11//! scrolling, input handling, and visual presentation. The menu system supports
12//! various menu types including static menus, quick menus, and input menus for
13//! both normal and VR display modes.
14
15#pragma once
16
20
22
23#include <vector>
24#include <string>
25
26namespace makVrv
27{
28class DtDe;
29class DtQuadProxy;
30class DtTextProxy;
31class DtOverlayRenderer;
32class DtOsgChannel;
33} // namespace makVrv
34
35namespace makVre
36{
37class DtMenuManager;
38class DtMenuAttributeBinder;
40class DtMenuCursor;
41class DtQmlActionMenu;
42//! \brief Structure holding conditions for menu display
43//!
44//! DtMenuDisplayConditions contains the criteria that determine when a menu
45//! should be displayed. This includes contextual conditions such as player
46//! posture (standing, prone, etc.) which can affect menu availability.
48{
49 //! \brief Required player posture for menu display
50 //!
51 //! The posture the player must be in for this menu to be displayed.
52 //! Empty string means any posture is acceptable.
53 std::string myPosture;
54};
55
56//! \brief Core class for all interactive menus in VR-Engage
57//!
58//! DtMenu provides the foundation for all menus in VR-Engage. It manages a collection
59//! of menu elements, handles selection state, scrolling, input processing, and
60//! visual presentation. The menu system supports various types including static
61//! menus, quick context-sensitive menus, and specialized input menus.
62//!
63//! Menus can be hierarchical, with parent-child relationships, and support both
64//! keyboard/mouse and VR controller input. They can dynamically update their content
65//! based on player state and context.
67{
68public:
69 //! \brief Constructor
70 //! \param mgr Reference to the menu manager
71 //!
72 //! Creates a new menu associated with the specified menu manager.
73 //! The menu starts with no elements and is inactive (not displayed).
75
76 //! \brief Virtual destructor
77 //!
78 //! Ensures proper cleanup of all menu resources and derived menu classes.
79 virtual ~DtMenu();
80
81 //! \brief Gets the menu's identifier name
82 //! \return Reference to the menu's name string
83 //!
84 //! Returns the user-supplied name of the menu. This name is used to
85 //! identify and look up the menu in the menu manager registry.
86 virtual const std::string& name();
87
88 //! \brief Sets the menu's identifier name
89 //! \param name The name to assign to this menu
90 //!
91 //! Sets the user-supplied name of the menu. This name is used to
92 //! identify and look up the menu in the menu manager registry.
93 virtual void setName(const std::string& name);
94
95 //! \brief Sets the position of the menu
96 //! \param x Horizontal position in pixels from the left edge
97 //! \param y Vertical position in pixels from the top edge
98 //!
99 //! Sets the position of the menu on the screen in pixel coordinates.
100 //! The position represents the top-left corner of the menu.
101 virtual void setPosition(float x, float y);
102
103 //! \brief Gets the menu's horizontal position
104 //! \return Horizontal position in pixels
105 //!
106 //! Returns the current horizontal position of the menu.
107 virtual float x() const { return myX; }
108
109 //! \brief Gets the menu's vertical position
110 //! \return Vertical position in pixels
111 //!
112 //! Returns the current vertical position of the menu.
113 virtual float y() const { return myY; }
114
115 //! \brief Sets the size of the menu
116 //! \param x Width in pixels
117 //! \param y Height in pixels
118 //!
119 //! Sets the size of the menu in pixel dimensions.
120 virtual void setSize(float x, float y);
121
122 //! \brief Gets the menu's width
123 //! \return Width in pixels
124 //!
125 //! Returns the current width of the menu.
126 virtual float width() const { return myWidth; }
127
128 //! \brief Gets the menu's height
129 //! \return Height in pixels
130 //!
131 //! Returns the current height of the menu.
132 virtual float height() const { return myHeight; }
133
134 //! \brief Sets the active state of the menu
135 //! \param active True to activate (show) the menu, false to deactivate (hide)
136 //! \param saveSelection If true, preserve selection from last time the menu was open
137 //! \param closeOnElementSelected If true, close menu when an element is selected
138 //!
139 //! Controls whether the menu is visible and interactive. When activated, the menu will
140 //! either restore its previous selection (if saveSelection is true) or select the first
141 //! valid element. If closeOnElementSelected is true, the menu will automatically close
142 //! after an element is selected or if there are no valid selections available.
143 virtual void setActive(bool active, bool saveSelection = false, bool closeOnElementSelected = false);
144
145 //! \brief Checks if the menu is currently active
146 //! \return True if the menu is active (visible), false otherwise
147 //!
148 //! Determines whether the menu is currently visible and interactive.
149 virtual bool isActive() const;
150
151 //! \brief Checks if the menu has any elements
152 //! \return True if the menu has no elements, false if it has at least one
153 //!
154 //! Determines whether the menu contains any elements.
155 virtual bool isEmpty() const;
156
157 //! \brief Updates the menu's state and visuals
158 //! \param dt Time elapsed since the last update in seconds
159 //!
160 //! Called once per frame to update the menu's state and refresh its visual
161 //! representation. This handles animation, scrolling, and display updates.
162 virtual void tick(double dt);
163
164 //! \brief Initializes the input handling logic for the menu
165 //!
166 //! Sets up the input logic system for this menu, mapping input events (keyboard,
167 //! mouse, controller buttons, etc.) to menu action handlers. This establishes
168 //! all the input handlers needed for navigating and interacting with the menu,
169 //! such as selection, scrolling, and item activation.
170 //!
171 //! This is automatically called when the menu becomes active.
172 virtual void activateInputLogic();
173
174 //! \brief Shuts down the input handling logic for the menu
175 //!
176 //! Deactivates the input logic system for this menu, removing all input handlers
177 //! and cleaning up resources. This prevents the menu from responding to input
178 //! events when it's no longer active.
179 //!
180 //! This is automatically called when the menu becomes inactive.
181 virtual void deactivateInputLogic();
182
183 //! \brief Gets the menu title text
184 //! \return Reference to the title string
185 //!
186 //! Returns the title text displayed at the top of the menu.
187 virtual const std::string& title() const { return myTitleString; }
188
189 //! \brief Sets the menu title text
190 //! \param title The title text to display
191 //!
192 //! Sets the title text to be displayed at the top of the menu.
193 //! This is typically shown in a header area above the menu elements.
194 virtual void setTitle(const std::string& title);
195
196 //! \brief Gets the menu title text
197 //! \return Reference to the title string
198 //!
199 //! Returns the title text displayed at the top of the menu.
200 virtual const std::string& titleAttribute() const { return myTitleAttribute; }
201
202 //! \brief Sets the menu title text
203 //! \param title The title text to display
204 //!
205 //! Sets the title text to be displayed at the top of the menu.
206 //! This is typically shown in a header area above the menu elements.
207 //! \brief Sets the attribute path used for the menu title
208 //! \param titleAttribute The attribute path to use for dynamically updating the menu title
209 void setTitleAttribute(const std::string& titleAttribute);
210
211 //! \brief Sets whether to show the menu title
212 //! \param show True to show the title, false to hide it
213 //!
214 //! Controls the visibility of the menu title. When enabled, the title
215 //! is displayed at the top of the menu. When disabled, no title is shown.
216 virtual void setShowTitle(bool show);
217
218 //! \brief Adds an element to the menu
219 //! \param element Pointer to the menu element to add
220 //!
221 //! Adds the specified element to this menu. If there is no currently
222 //! selected element, the new element will become the selected element
223 //! if it is enabled. The menu takes ownership of the element and will
224 //! delete it when the menu is destroyed or when the element is removed.
225 virtual void addElement(DtMenuElement* element);
226
227 //! \brief Removes an element from the menu by pointer
228 //! \param element Pointer to the element to remove
229 //! \return Pointer to the removed element, or NULL if not found
230 //!
231 //! Removes the specified element from the menu. If the removed element
232 //! was the currently selected element, the selection will be updated to
233 //! the nearest valid element. The caller becomes responsible for deleting
234 //! the returned element to avoid memory leaks.
236
237 //! \brief Removes an element from the menu by name
238 //! \param name Name of the element to remove
239 //! \return Pointer to the removed element, or NULL if not found
240 //!
241 //! Removes the element with the specified name from the menu. If the
242 //! removed element was the currently selected element, the selection
243 //! will be updated to the nearest valid element. The caller becomes
244 //! responsible for deleting the returned element to avoid memory leaks.
245 virtual DtMenuElement* removeElement(const std::string& name);
246
247 //! \brief Finds a menu element by name
248 //! \param name Name of the element to find
249 //! \return Pointer to the found element, or NULL if not found
250 //!
251 //! Searches for and returns the menu element with the specified name.
252 //! Returns NULL if no element with that name exists in the menu.
253 virtual DtMenuElement* findElement(const std::string& name);
254
255 //! \brief Gets all elements in the menu
256 //! \return Vector of pointers to all menu elements
257 //!
258 //! Returns a vector containing pointers to all elements in the menu.
259 //! The elements remain owned by the menu; the caller should not delete them.
260 virtual std::vector<DtMenuElement*> elements();
261
262 //! \brief Selects a menu element by index
263 //! \param index Zero-based index of the element to select
264 //! \return True if selection was changed to a valid element, false otherwise
265 //!
266 //! Attempts to select the element at the specified index. If the requested
267 //! element is not enabled or does not exist, it will try to select the next
268 //! enabled element. Returns true if the selection successfully changed to
269 //! a valid element, false if the selection remained unchanged or no valid
270 //! selection was possible.
271 virtual bool selectElement(int index);
272
273 //! \brief Selects a menu element by its on-screen index
274 //! \param index On-screen index of the element to select (as displayed to the user)
275 //!
276 //! Selects the element with the specified on-screen index. On-screen indices
277 //! are only assigned to visible and enabled elements, and are used for keyboard
278 //! shortcuts (e.g., pressing 1-9 to select menu items 1-9).
279 virtual void selectElementByOnScreenIndex(int index);
280
281 //! \brief Selects a menu element by name
282 //! \param name Name of the element to select
283 //! \return True if the element was found and selected, false otherwise
284 //!
285 //! Attempts to select the element with the specified name. Returns true if
286 //! the element was found and successfully selected, false if the element
287 //! was not found or could not be selected (e.g., because it is disabled).
288 virtual bool selectElement(const std::string& name);
289
290 //! \brief Selects the next enabled element in the menu
291 //! \param val Input value (typically 1.0 for full activation)
292 //!
293 //! Moves the selection to the next enabled element in the menu. If already
294 //! at the last element, the selection will not change. The val parameter
295 //! supports analog inputs (like joysticks) that may not be fully activated.
296 virtual void selectNext(float val = 1);
297
298 //! \brief Selects the previous enabled element in the menu
299 //! \param val Input value (typically 1.0 for full activation)
300 //!
301 //! Moves the selection to the previous enabled element in the menu. If already
302 //! at the first element, the selection will not change. The val parameter
303 //! supports analog inputs (like joysticks) that may not be fully activated.
304 virtual void selectPrevious(float val = 1);
305
306 //! \brief Gets the currently selected menu element
307 //! \return Pointer to the selected element, or nullptr if no element is selected
308 //!
309 //! Returns a pointer to the currently selected menu element. Returns nullptr
310 //! if no element is currently selected, which can happen if the menu is empty
311 //! or if no elements are enabled.
313
314 //! \brief Gets the index of the currently selected element
315 //! \return Index of the selected element, or -1 if no element is selected
316 //!
317 //! Returns the index of the currently selected menu element in the list of
318 //! enabled elements. Returns -1 if no element is currently selected, which can
319 //! happen if the menu is empty or if no elements are enabled.
320 virtual int selectedElementIndex() const { return mySelectedItem ? mySelectedItem->enabledIndex : -1; }
321
322 //! \brief Clears the current selection
323 //!
324 //! Removes the current element selection, leaving no element selected.
325 //! This is useful when you want to reset the menu state or when no
326 //! element should be highlighted.
327 virtual void clearSelected();
328
329 //! \brief Scrolls the menu to show a specific item
330 //! \param index Index of the item to scroll to
331 //! \return True if successful, false otherwise
332 //!
333 //! Adjusts the menu scroll position to ensure the element at the specified
334 //! index is visible. This automatically updates the menu visuals.
335 //! Returns true if the scroll was successful, false otherwise.
336 virtual bool scrollToItem(int index) { return scrollToItem(index, true); }
337
338 //! \brief Scrolls the menu down one item
339 //!
340 //! Scrolls the menu down by one item, showing the next set of elements
341 //! if the menu contains more elements than can be displayed at once.
342 virtual void scrollDown();
343
344 //! \brief Scrolls the menu up one item
345 //!
346 //! Scrolls the menu up by one item, showing the previous set of elements
347 //! if the menu has been scrolled down.
348 virtual void scrollUp();
349
350 //! \brief Scrolls the menu by a variable amount
351 //! \param val Amount to scroll, positive for down, negative for up
352 //!
353 //! Scrolls the menu by the specified amount. Positive values scroll down,
354 //! negative values scroll up. The val parameter supports analog inputs
355 //! (like joysticks) for variable-speed scrolling.
356 virtual void scroll(float val);
357
358 //! \brief Scrolls the menu up by a page
359 //! \param val Input value (typically 1.0 for full page)
360 //!
361 //! Scrolls the menu up by one page (the number of visible elements).
362 //! The val parameter supports analog inputs for partial page scrolling.
363 virtual void pageUp(float val = 1);
364
365 //! \brief Scrolls the menu down by a page
366 //! \param val Input value (typically 1.0 for full page)
367 //!
368 //! Scrolls the menu down by one page (the number of visible elements).
369 //! The val parameter supports analog inputs for partial page scrolling.
370 virtual void pageDown(float val = 1);
371 //! \brief Updates the enabled element list
372 //!
373 //! Refreshes the internal list of enabled elements based on the current state
374 //! of all menu elements. This rebuilds the myEnabledItems list, recalculating
375 //! which elements are visible and enabled based on their display conditions.
376 //! Called automatically when menu state changes affect element visibility.
377 virtual void updateElements();
378
379 //! \brief Updates the visual representation of the menu
380 //!
381 //! Refreshes the visual display of the menu based on the current state.
382 //! This updates element positions, scrolling state, and visual properties.
383 //! Called automatically when the menu's state changes in a way that affects
384 //! its visual appearance.
385 virtual void updateVisuals();
386
387 //! \brief Adds a dynamic element generator to the menu
388 //! \param generator Pointer to the attribute observer that generates elements
389 //!
390 //! Sets an attribute observer that will dynamically generate menu elements
391 //! based on attribute values. This allows menus to automatically update
392 //! their contents when attributes change. The menu takes ownership of the
393 //! generator and will delete it when the menu is destroyed.
395
396 //! \brief Sets the parent menu by name
397 //! \param name Name of the parent menu
398 //!
399 //! Establishes a parent-child relationship between menus. When this menu
400 //! is closed, the parent menu will be reopened if it exists. This creates
401 //! a hierarchical menu structure for navigation.
402 virtual void setParent(const std::string& name);
403
404 //! \brief Sets whether to inherit position from parent menu
405 //! \param set True to inherit parent position, false to use own position
406 //!
407 //! When set to true, this menu will adopt the same position as its parent
408 //! menu. This is useful for submenus that should appear in the same location
409 //! as their parent menu for visual continuity.
410 virtual void setInheritParentPosition(bool set);
411
412 //! \brief Sets whether to inherit size from parent menu
413 //! \param set True to inherit parent size, false to use own size
414 //!
415 //! When set to true, this menu will adopt the same size as its parent
416 //! menu. This is useful for submenus that should maintain the same
417 //! dimensions as their parent menu for visual consistency.
418 virtual void setInheritParentSize(bool set);
419
420 //! \brief Gets the name of the parent menu
421 //! \return Reference to the parent menu name string
422 //!
423 //! Returns the name of this menu's parent menu. Returns an empty string
424 //! if this menu has no parent.
425 virtual const std::string& parent() const;
426
427 //! \brief Closes the menu
428 //! \param val Input value (typically 1.0 for full activation)
429 //!
430 //! Closes this menu, deactivating it and hiding it from view. If the menu
431 //! has a parent, the parent menu will be activated. The val parameter
432 //! supports analog inputs for partial activation.
433 virtual void closeMenu(float val = 1);
434
435 //! \brief Selects the currently highlighted menu element
436 //! \param val Input value (typically 1.0 for full activation)
437 //!
438 //! Executes the action associated with the currently selected menu element.
439 //! For action elements, this will trigger the action. For menu elements, this
440 //! will open the submenu. The val parameter supports analog inputs for
441 //! partial activation.
442 virtual void select(float val = 1);
443
444 //! \brief Selects a menu item by number with analog input support
445 //! \param val Input value (typically 1.0 for full activation)
446 //! \param num Index of the item to select (1-based)
447 //!
448 //! General handler for numerical item selection. This allows selecting
449 //! a menu item by its displayed number. The val parameter supports analog
450 //! inputs for partial activation.
451 virtual void selectItem(float val, unsigned int num);
452
453 //! \brief Selects the first menu item
454 //! \param val Input value (typically 1.0 for full activation)
455 //!
456 //! Selects the first visible menu item. The val parameter supports
457 //! analog inputs for partial activation.
458 virtual void select1(float val);
459
460 //! \brief Selects the second menu item
461 //! \param val Input value (typically 1.0 for full activation)
462 virtual void select2(float val);
463
464 //! \brief Selects the third menu item
465 //! \param val Input value (typically 1.0 for full activation)
466 virtual void select3(float val);
467
468 //! \brief Selects the fourth menu item
469 //! \param val Input value (typically 1.0 for full activation)
470 virtual void select4(float val);
471
472 //! \brief Selects the fifth menu item
473 //! \param val Input value (typically 1.0 for full activation)
474 virtual void select5(float val);
475
476 //! \brief Selects the sixth menu item
477 //! \param val Input value (typically 1.0 for full activation)
478 virtual void select6(float val);
479
480 //! \brief Selects the seventh menu item
481 //! \param val Input value (typically 1.0 for full activation)
482 virtual void select7(float val);
483
484 //! \brief Selects the eighth menu item
485 //! \param val Input value (typically 1.0 for full activation)
486 virtual void select8(float val);
487
488 //! \brief Selects the ninth menu item
489 //! \param val Input value (typically 1.0 for full activation)
490 virtual void select9(float val);
491
492 //! \brief Selects the tenth menu item
493 //! \param val Input value (typically 1.0 for full activation)
494 virtual void select10(float val);
495
496 //! \brief Navigates back to the parent menu
497 //! \param val Input value (typically 1.0 for full activation)
498 //!
499 //! Closes this menu and returns to the parent menu if one exists.
500 //! Equivalent to pressing the Back button or Escape key. The val parameter
501 //! supports analog inputs for partial activation.
502 virtual void back(float val = 1);
503
504 //! \brief Gets the display conditions for this menu (const version)
505 //! \return Constant reference to the menu's display conditions
506 //!
507 //! Returns a constant reference to the conditions that determine when
508 //! this menu should be displayed. These include context-sensitive
509 //! conditions like player posture.
511
512 //! \brief Gets the display conditions for this menu (mutable version)
513 //! \return Mutable reference to the menu's display conditions
514 //!
515 //! Returns a mutable reference to the conditions that determine when
516 //! this menu should be displayed. These can be modified to change when
517 //! the menu is available to the player.
519
520 //! \brief Checks if a duplicate element exists in the enabled list
521 //! \param element Pointer to the element to check for duplicates
522 //! \return True if a duplicate exists, false otherwise
523 //!
524 //! Determines whether another enabled element with the same label as the
525 //! specified element already exists in the menu. This is used to prevent
526 //! duplicate entries in dynamically generated menus.
528
529 //! \brief Gets the menu manager for this menu
530 //! \return Reference to the menu manager
531 //!
532 //! Returns a reference to the menu manager that controls this menu.
533 //! The menu manager handles menu registration, parent-child relationships,
534 //! and other menu system functionality.
535 virtual DtMenuManager& manager() { return myManager; }
536
537 //! \brief Menu type enumeration
538 //!
539 //! Defines the types of menus supported by the system:
540 //! - STATIC: Standard menu that persists until explicitly closed
541 //! - QUICK: Context-sensitive menu that appears temporarily based on proximity or other triggers
542 enum Type
543 {
544 STATIC, //!< Standard persistent menu
545 QUICK, //!< Context-sensitive temporary menu
546 };
547
548 //! \brief Sets the menu type
549 //! \param type Type of menu to set
550 //!
551 //! Sets the type of this menu, which affects its behavior and appearance.
553
554 //! \brief Gets the menu type
555 //! \return Current menu type
556 //!
557 //! Returns the current type of this menu.
558 Type type() { return myType; }
559
560 //! \brief Removes all elements from the menu
561 //!
562 //! Clears the menu by removing and deleting all its elements.
563 //! This resets the menu to an empty state, removing all options.
564 virtual void clearElements();
565
566 //! \brief Triggers an action from QML interface
567 //! \param index Index of the element to trigger
568 //!
569 //! Executes the action associated with the element at the specified index.
570 //! This is used for integration with QML-based user interfaces, allowing
571 //! QML components to trigger menu actions.
572 void triggerActionFromQML(int index);
573
574protected:
575 //! \brief Handles player controls state change messages
576 //! \param msg Pointer to the message to handle
577 //! \return Message handling result
578 //!
579 //! Processes messages about changes in player controls state. When controls
580 //! are disabled, this automatically closes the menu to prevent interaction
581 //! when the player cannot control the menu.
583
584 //! \brief Handles menu input messages from VR controllers
585 //! \param msg Pointer to the message to handle
586 //! \return Message handling result
587 //!
588 //! Processes input messages specifically designed for VR control of menus.
589 //! This provides a bridge for VR controller input to interact with menus
590 //! until a more integrated VR input system is implemented.
592
593 //! \brief Internal implementation of scrollToItem
594 //! \param index Index of the item to scroll to
595 //! \param doUpdate Whether to update the visual display after scrolling
596 //! \return True if scroll was successful, false otherwise
597 //!
598 //! Adjusts the scroll position to ensure the element at the specified index
599 //! is visible. The doUpdate parameter controls whether the menu visuals are
600 //! immediately updated after scrolling, which is useful for batch operations
601 //! where multiple scrolls might occur before the final update.
602 virtual bool scrollToItem(int index, bool doUpdate);
603
604 //! \brief Updates the ImGui-based user interface
605 //!
606 //! Refreshes the menu's user interface components using the ImGui framework.
607 //! This handles the rendering of the menu background, elements, scrollbars,
608 //! and other visual components. Called internally by the tick method when
609 //! the menu needs to be visually updated.
610 virtual void updateImguiUI();
611
612 //! \brief Enumeration of display layers for menu rendering
613 //!
614 //! Defines the different visual layers used when rendering the menu, with
615 //! later layers drawn on top of earlier ones. This allows proper layering
616 //! of menu components for a cohesive visual appearance.
618 {
619 HIDDEN, //!< Layer for hidden elements (not displayed)
620 BACKGROUND, //!< Background layer (drawn first)
621 GRAPHIC, //!< Graphic elements layer (drawn second)
622 LABEL //!< Text labels layer (drawn on top)
623 };
624
625 //! \brief Reference to the menu manager
626 //!
627 //! Reference to the menu manager that controls this menu. The menu manager
628 //! handles menu registration, parent-child relationships, and other menu
629 //! system functionality.
631
632 //! \brief Name identifier for this menu
633 //!
634 //! Unique name that identifies this menu in the menu system. Used for
635 //! menu lookup and parent-child relationships.
636 std::string myName;
637
638 //! \brief Title text displayed at the top of the menu
639 //!
640 //! Text shown in the menu's title bar, describing the menu's purpose.
641 std::string myTitleString;
642
643 //! \brief Title attribute for the menu
644 //!
645 //! The attribute name to get the title's text from.
646 std::string myTitleAttribute;
647
648 //! \brief Name of the parent menu
649 //!
650 //! Name of this menu's parent menu. When this menu is closed, the parent
651 //! menu will be activated if it exists. Empty string indicates no parent.
652 std::string myParent;
653
654 //! \brief Display conditions for this menu
655 //!
656 //! Conditions that determine when this menu should be displayed, such as
657 //! player posture requirements.
659
660 //! \brief Type of this menu (STATIC or QUICK)
661 //!
662 //! Determines the menu's behavior and appearance. STATIC menus persist until
663 //! explicitly closed, while QUICK menus are context-sensitive and temporary.
665
666 //! \brief Position and size of the menu in pixels
667 //!
668 //! Coordinates and dimensions that define the menu's location and size
669 //! on the screen. The position (myX, myY) represents the top-left corner
670 //! of the menu rectangle.
672
673 //! \brief Active state of the menu
674 //!
675 //! Indicates whether the menu is currently active (visible and interactive).
677
678 //! \brief Whether to show the menu title
679 //!
680 //! Controls visibility of the title bar at the top of the menu.
682
683 //! \brief Whether to inherit size from parent menu
684 //!
685 //! When true, this menu adopts the same size as its parent menu.
687
688 //! \brief Whether to inherit position from parent menu
689 //!
690 //! When true, this menu appears at the same position as its parent menu.
692
693 //! \brief Whether to show numerical indices for menu items
694 //!
695 //! When true, menu elements are displayed with numerical indices (1, 2, 3...)
696 //! that can be used for keyboard shortcuts. Input menus typically disable this.
698
699 //! \brief Internal structure for managing menu elements
700 //!
701 //! Item wraps a menu element with additional state information needed for
702 //! menu management, such as enabled index and ownership tracking. The Item
703 //! structure takes ownership of the contained element and deletes it when
704 //! the Item is destroyed.
705 struct Item
706 {
707 //! \brief Constructor
708 //! \param _element Pointer to the menu element to wrap
709 //!
710 //! Creates a new Item wrapping the specified menu element.
712 : element(_element)
713 {
714 }
715
716 //! \brief Destructor
717 //!
718 //! Deletes the wrapped menu element, ensuring proper cleanup.
720 {
721 delete element;
722 element = nullptr;
723 }
724
725 //! \brief Pointer to the wrapped menu element
727
728 //! \brief Index of this element in the enabled elements list
729 //!
730 //! This is used to track the element's position in the visible menu.
731 //! Only enabled elements are given an index for selection purposes.
733
734 //! \brief Checks if the wrapped element is currently enabled
735 //! \return True if the element is enabled, false otherwise
736 bool isEnabled() { return element->isEnabled(); }
737 };
738
739 //! \brief List of all menu items, owned by this menu
740 //!
741 //! Vector of all menu items, including both enabled and disabled ones.
742 //! The menu owns these items and is responsible for deleting them.
743 std::vector<Item*> myItems;
744
745 //! \brief List of currently enabled menu items
746 //!
747 //! Vector of pointers to enabled menu items only. These are not owned by
748 //! this vector, but are references to items in myItems. This list is
749 //! rebuilt whenever element states change, and is used for display and selection.
750 std::vector<Item*> myEnabledItems;
751
752 //! \brief Pointer to the currently selected item
753 //!
754 //! Points to the item that is currently selected in the menu. This is
755 //! a reference to an item in myEnabledItems. Null if no item is selected.
757
758 //! \brief Pointer to the saved selection for menu reopening
759 //!
760 //! When a menu is closed with saveSelection=true, this stores the last
761 //! selected item so it can be restored when the menu is reopened.
763
764 //! \brief Special items for scroll indicators
765 //!
766 //! Items representing the scroll up and scroll down indicators that
767 //! appear at the top and bottom of the menu when not all items can be
768 //! displayed at once.
771
772 //! \brief Whether the menu can scroll upward
773 //!
774 //! Indicates if there are additional items above the currently visible ones.
776
777 //! \brief Whether the menu can scroll downward
778 //!
779 //! Indicates if there are additional items below the currently visible ones.
781
782 //! \brief Current scroll position in the menu
783 //!
784 //! Index of the first visible item in the list of enabled items.
786
787 //! \brief Number of items that can be displayed at once
788 //!
789 //! Maximum number of menu elements that can be displayed simultaneously
790 //! based on menu height and element height.
792
793 //! \brief Timer for action selection flash effect
794 //!
795 //! Used to create a visual flash effect when an action is selected.
796 //! Counts down from a positive value to zero.
798
799 //! \brief Whether to close the menu after an element is selected
800 //!
801 //! When true, the menu automatically closes after an element is selected.
802 //! This is commonly used for context menus and quick menus.
804
805 //! \brief Height of each menu element line in pixels
806 //!
807 //! Used for layout calculations and determining how many elements can
808 //! be displayed at once.
810
811 //! \brief Element generator for dynamic menu content
812 //!
813 //! Observer that dynamically generates menu elements based on attribute
814 //! values. This allows the menu to update its content automatically when
815 //! relevant attributes change.
817
818 //! \brief Input logic for menu interaction
819 //!
820 //! Handles input event processing for menu navigation and selection.
821 //! Maps input events to menu actions like selection, scrolling, and activation.
823};
824
825} // namespace makVre
Defines the menu element classes for interactive menus.
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:35
Generates menu elements from a list of attributes.
Definition actionMenuElement.h:325
Class for managing menu cursor visualization.
Definition actionMenuManager.h:60
Menu element class for interactive menus.
Definition actionMenuElement.h:40
virtual void selectElementByOnScreenIndex(int index)
Selects a menu element by its on-screen index.
bool myShowTitle
Whether to show the menu title.
Definition actionMenu.h:681
virtual void selectItem(float val, unsigned int num)
Selects a menu item by number with analog input support.
virtual void activateInputLogic()
Initializes the input handling logic for the menu.
bool myIsActive
Active state of the menu.
Definition actionMenu.h:676
virtual bool scrollToItem(int index)
Scrolls the menu to show a specific item.
Definition actionMenu.h:336
virtual void setTitle(const std::string &title)
Sets the menu title text.
virtual void closeMenu(float val=1)
Closes the menu.
virtual void setActive(bool active, bool saveSelection=false, bool closeOnElementSelected=false)
Sets the active state of the menu.
virtual void tick(double dt)
Updates the menu's state and visuals.
virtual float height() const
Gets the menu's height.
Definition actionMenu.h:132
virtual void addElementGenerator(DtMenuAttributeObserver *generator)
Adds a dynamic element generator to the menu.
virtual void select4(float val)
Selects the fourth menu item.
virtual void setName(const std::string &name)
Sets the menu's identifier name.
virtual void deactivateInputLogic()
Shuts down the input handling logic for the menu.
virtual DtMenuElement * selectedElement()
Gets the currently selected menu element.
virtual const std::string & titleAttribute() const
Gets the menu title text.
Definition actionMenu.h:200
virtual void selectPrevious(float val=1)
Selects the previous enabled element in the menu.
virtual void back(float val=1)
Navigates back to the parent menu.
Item myScrollUp
Special items for scroll indicators.
Definition actionMenu.h:769
std::vector< Item * > myEnabledItems
List of currently enabled menu items.
Definition actionMenu.h:750
virtual void select8(float val)
Selects the eighth menu item.
virtual float y() const
Gets the menu's vertical position.
Definition actionMenu.h:113
virtual void setSize(float x, float y)
Sets the size of the menu.
virtual void selectNext(float val=1)
Selects the next enabled element in the menu.
bool myNeedParentSize
Whether to inherit size from parent menu.
Definition actionMenu.h:686
std::string myTitleAttribute
Title attribute for the menu.
Definition actionMenu.h:646
virtual DtVreMessageResult handleMenuInputMessage(DtVreMessage *msg)
Handles menu input messages from VR controllers.
virtual void select10(float val)
Selects the tenth menu item.
virtual DtMenuElement * removeElement(const std::string &name)
Removes an element from the menu by name.
DtMenu(DtMenuManager &mgr)
Constructor.
virtual void setParent(const std::string &name)
Sets the parent menu by name.
virtual DtMenuManager & manager()
Gets the menu manager for this menu.
Definition actionMenu.h:535
virtual int selectedElementIndex() const
Gets the index of the currently selected element.
Definition actionMenu.h:320
float myWidth
Definition actionMenu.h:671
DtInputLogic myInputLogic
Input logic for menu interaction.
Definition actionMenu.h:822
virtual void scrollDown()
Scrolls the menu down one item.
virtual void addElement(DtMenuElement *element)
Adds an element to the menu.
int myVisibleScrollItems
Number of items that can be displayed at once.
Definition actionMenu.h:791
virtual DtVreMessageResult handlePlayerControlsState(DtVreMessage *msg)
Handles player controls state change messages.
Type type()
Gets the menu type.
Definition actionMenu.h:558
virtual ~DtMenu()
Virtual destructor.
virtual bool containsEnabledDuplicate(DtMenuElement *element)
Checks if a duplicate element exists in the enabled list.
bool myCloseOnSelection
Whether to close the menu after an element is selected.
Definition actionMenu.h:803
virtual bool selectElement(const std::string &name)
Selects a menu element by name.
bool myCanScrollUp
Whether the menu can scroll upward.
Definition actionMenu.h:775
virtual std::vector< DtMenuElement * > elements()
Gets all elements in the menu.
virtual void updateElements()
Updates the enabled element list.
DtMenuDisplayConditions myDisplayConditions
Display conditions for this menu.
Definition actionMenu.h:658
void setType(Type type)
Sets the menu type.
Definition actionMenu.h:552
DtMenuManager & myManager
Reference to the menu manager.
Definition actionMenu.h:630
virtual float width() const
Gets the menu's width.
Definition actionMenu.h:126
virtual void pageDown(float val=1)
Scrolls the menu down by a page.
virtual bool selectElement(int index)
Selects a menu element by index.
virtual void pageUp(float val=1)
Scrolls the menu up by a page.
virtual void scrollUp()
Scrolls the menu up one item.
virtual void select7(float val)
Selects the seventh menu item.
std::string myParent
Name of the parent menu.
Definition actionMenu.h:652
int myLineHeight
Height of each menu element line in pixels.
Definition actionMenu.h:809
virtual void scroll(float val)
Scrolls the menu by a variable amount.
Layers
Enumeration of display layers for menu rendering.
Definition actionMenu.h:618
@ GRAPHIC
Graphic elements layer (drawn second)
Definition actionMenu.h:621
@ BACKGROUND
Background layer (drawn first)
Definition actionMenu.h:620
@ HIDDEN
Layer for hidden elements (not displayed)
Definition actionMenu.h:619
@ LABEL
Text labels layer (drawn on top)
Definition actionMenu.h:622
virtual DtMenuElement * findElement(const std::string &name)
Finds a menu element by name.
std::string myTitleString
Title text displayed at the top of the menu.
Definition actionMenu.h:641
Item * mySavedSelection
Pointer to the saved selection for menu reopening.
Definition actionMenu.h:762
virtual bool isActive() const
Checks if the menu is currently active.
virtual void select6(float val)
Selects the sixth menu item.
bool myNeedParentPosition
Whether to inherit position from parent menu.
Definition actionMenu.h:691
virtual void select1(float val)
Selects the first menu item.
virtual void select2(float val)
Selects the second menu item.
Item myScrollDown
Definition actionMenu.h:770
virtual void clearElements()
Removes all elements from the menu.
virtual const std::string & parent() const
Gets the name of the parent menu.
virtual DtMenuElement * removeElement(DtMenuElement *element)
Removes an element from the menu by pointer.
virtual float x() const
Gets the menu's horizontal position.
Definition actionMenu.h:107
virtual void clearSelected()
Clears the current selection.
virtual void setInheritParentSize(bool set)
Sets whether to inherit size from parent menu.
std::vector< Item * > myItems
List of all menu items, owned by this menu.
Definition actionMenu.h:743
virtual void select5(float val)
Selects the fifth menu item.
virtual const std::string & name()
Gets the menu's identifier name.
float myX
Position and size of the menu in pixels.
Definition actionMenu.h:671
virtual void setPosition(float x, float y)
Sets the position of the menu.
virtual void select(float val=1)
Selects the currently highlighted menu element.
bool myCanScrollDown
Whether the menu can scroll downward.
Definition actionMenu.h:780
virtual void updateVisuals()
Updates the visual representation of the menu.
virtual bool scrollToItem(int index, bool doUpdate)
Internal implementation of scrollToItem.
Item * mySelectedItem
Pointer to the currently selected item.
Definition actionMenu.h:756
Type myType
Type of this menu (STATIC or QUICK)
Definition actionMenu.h:664
float myY
Definition actionMenu.h:671
int myScrollOffset
Current scroll position in the menu.
Definition actionMenu.h:785
void setTitleAttribute(const std::string &titleAttribute)
Sets the menu title text.
virtual DtMenuDisplayConditions & displayConditions()
Gets the display conditions for this menu (mutable version)
void triggerActionFromQML(int index)
Triggers an action from QML interface.
double myActionFlash
Timer for action selection flash effect.
Definition actionMenu.h:797
virtual void updateImguiUI()
Updates the ImGui-based user interface.
virtual void select3(float val)
Selects the third menu item.
virtual void select9(float val)
Selects the ninth menu item.
virtual bool isEmpty() const
Checks if the menu has any elements.
virtual void setShowTitle(bool show)
Sets whether to show the menu title.
virtual void setInheritParentPosition(bool set)
Sets whether to inherit position from parent menu.
float myHeight
Definition actionMenu.h:671
bool myShouldShowNumbers
Whether to show numerical indices for menu items.
Definition actionMenu.h:697
std::string myName
Name identifier for this menu.
Definition actionMenu.h:636
virtual const std::string & title() const
Gets the menu title text.
Definition actionMenu.h:187
virtual const DtMenuDisplayConditions & displayConditions() const
Gets the display conditions for this menu (const version)
DtMenuAttributeObserver * myElementGenerator
Element generator for dynamic menu content.
Definition actionMenu.h:816
Type
Menu type enumeration.
Definition actionMenu.h:543
@ STATIC
Standard persistent menu.
Definition actionMenu.h:544
@ QUICK
Context-sensitive temporary menu.
Definition actionMenu.h:545
Central manager for all menus in VR-Engage.
Definition actionMenuManager.h:111
QML-based action menu interface for VR-Engage.
Definition qmlActionMenu.h:32
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Defines the DtInputLogic class for handling input in VR-Engage.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Internal structure for managing menu elements.
Definition actionMenu.h:706
Item(DtMenuElement *_element)
Constructor.
Definition actionMenu.h:711
bool isEnabled()
Checks if the wrapped element is currently enabled.
Definition actionMenu.h:736
int enabledIndex
Index of this element in the enabled elements list.
Definition actionMenu.h:732
DtMenuElement * element
Pointer to the wrapped menu element.
Definition actionMenu.h:726
~Item()
Destructor.
Definition actionMenu.h:719
Structure holding conditions for menu display.
Definition actionMenu.h:48
std::string myPosture
Required player posture for menu display.
Definition actionMenu.h:53
Defines the base class for all VREngage messages.