|
VR-Engage
2.2
|
DtMenu provides the foundation for all menus in VR-Engage. It manages a collection of menu elements, handles selection state, scrolling, input processing, and visual presentation. The menu system supports various types including static menus, quick context-sensitive menus, and specialized input menus.
Menus can be hierarchical, with parent-child relationships, and support both keyboard/mouse and VR controller input. They can dynamically update their content based on player state and context.
#include <actionMenu.h>
Classes | |
| struct | Item |
Public Types | |
| enum | Type { STATIC , QUICK } |
Public Member Functions | |
| DtMenu (DtMenuManager &mgr) | |
| virtual | ~DtMenu () |
| virtual const std::string & | name () |
| virtual void | setName (const std::string &name) |
| virtual void | setPosition (float x, float y) |
| virtual float | x () const |
| virtual float | y () const |
| virtual void | setSize (float x, float y) |
| virtual float | width () const |
| virtual float | height () const |
| virtual void | setActive (bool active, bool saveSelection=false, bool closeOnElementSelected=false) |
| virtual bool | isActive () const |
| virtual bool | isEmpty () const |
| virtual void | tick (double dt) |
| virtual void | activateInputLogic () |
| virtual void | deactivateInputLogic () |
| virtual const std::string & | title () const |
| virtual void | setTitle (const std::string &title) |
| virtual const std::string & | titleAttribute () const |
| void | setTitleAttribute (const std::string &titleAttribute) |
| virtual void | setShowTitle (bool show) |
| virtual void | addElement (DtMenuElement *element) |
| virtual DtMenuElement * | removeElement (DtMenuElement *element) |
| virtual DtMenuElement * | removeElement (const std::string &name) |
| virtual DtMenuElement * | findElement (const std::string &name) |
| virtual std::vector< DtMenuElement * > | elements () |
| virtual bool | selectElement (int index) |
| virtual void | selectElementByOnScreenIndex (int index) |
| virtual bool | selectElement (const std::string &name) |
| virtual void | selectNext (float val=1) |
| virtual void | selectPrevious (float val=1) |
| virtual DtMenuElement * | selectedElement () |
| virtual int | selectedElementIndex () const |
| virtual void | clearSelected () |
| virtual bool | scrollToItem (int index) |
| virtual void | scrollDown () |
| virtual void | scrollUp () |
| virtual void | scroll (float val) |
| virtual void | pageUp (float val=1) |
| virtual void | pageDown (float val=1) |
| virtual void | updateElements () |
| virtual void | updateVisuals () |
| virtual void | addElementGenerator (DtMenuAttributeObserver *generator) |
| virtual void | setParent (const std::string &name) |
| virtual void | setInheritParentPosition (bool set) |
| virtual void | setInheritParentSize (bool set) |
| virtual const std::string & | parent () const |
| virtual void | closeMenu (float val=1) |
| virtual void | select (float val=1) |
| virtual void | selectItem (float val, unsigned int num) |
| virtual void | select1 (float val) |
| virtual void | select2 (float val) |
| virtual void | select3 (float val) |
| virtual void | select4 (float val) |
| virtual void | select5 (float val) |
| virtual void | select6 (float val) |
| virtual void | select7 (float val) |
| virtual void | select8 (float val) |
| virtual void | select9 (float val) |
| virtual void | select10 (float val) |
| virtual void | back (float val=1) |
| virtual const DtMenuDisplayConditions & | displayConditions () const |
| virtual DtMenuDisplayConditions & | displayConditions () |
| virtual bool | containsEnabledDuplicate (DtMenuElement *element) |
| virtual DtMenuManager & | manager () |
| void | setType (Type type) |
| Type | type () |
| virtual void | clearElements () |
| void | triggerActionFromQML (int index) |
Protected Types | |
| enum | Layers { HIDDEN , BACKGROUND , GRAPHIC , LABEL } |
Protected Member Functions | |
| virtual DtVreMessageResult | handlePlayerControlsState (DtVreMessage *msg) |
| virtual DtVreMessageResult | handleMenuInputMessage (DtVreMessage *msg) |
| virtual bool | scrollToItem (int index, bool doUpdate) |
| virtual void | updateImguiUI () |
Protected Attributes | |
| DtMenuManager & | myManager |
| std::string | myName |
| std::string | myTitleString |
| std::string | myTitleAttribute |
| std::string | myParent |
| DtMenuDisplayConditions | myDisplayConditions |
| Type | myType |
| float | myX |
| float | myY |
| float | myWidth |
| float | myHeight |
| bool | myIsActive |
| bool | myShowTitle |
| bool | myNeedParentSize |
| bool | myNeedParentPosition |
| bool | myShouldShowNumbers |
| std::vector< Item * > | myItems |
| std::vector< Item * > | myEnabledItems |
| Item * | mySelectedItem |
| Item * | mySavedSelection |
| Item | myScrollUp |
| Item | myScrollDown |
| bool | myCanScrollUp |
| bool | myCanScrollDown |
| int | myScrollOffset |
| int | myVisibleScrollItems |
| double | myActionFlash |
| bool | myCloseOnSelection |
| int | myLineHeight |
| DtMenuAttributeObserver * | myElementGenerator |
| DtInputLogic | myInputLogic |
| enum makVre::DtMenu::Type |
Menu type enumeration.
Defines the types of menus supported by the system:
| Enumerator | |
|---|---|
| STATIC | Standard persistent menu. |
| QUICK | Context-sensitive temporary menu. |
|
protected |
Enumeration of display layers for menu rendering.
Defines the different visual layers used when rendering the menu, with later layers drawn on top of earlier ones. This allows proper layering of menu components for a cohesive visual appearance.
| Enumerator | |
|---|---|
| HIDDEN | Layer for hidden elements (not displayed) |
| BACKGROUND | Background layer (drawn first) |
| GRAPHIC | Graphic elements layer (drawn second) |
| LABEL | Text labels layer (drawn on top) |
| makVre::DtMenu::DtMenu | ( | DtMenuManager & | mgr | ) |
Constructor.
| mgr | Reference to the menu manager |
Creates a new menu associated with the specified menu manager. The menu starts with no elements and is inactive (not displayed).
|
virtual |
Virtual destructor.
Ensures proper cleanup of all menu resources and derived menu classes.
|
virtual |
Gets the menu's identifier name.
Returns the user-supplied name of the menu. This name is used to identify and look up the menu in the menu manager registry.
Referenced by findElement(), removeElement(), selectElement(), setName(), and setParent().
|
virtual |
Sets the menu's identifier name.
| name | The name to assign to this menu |
Sets the user-supplied name of the menu. This name is used to identify and look up the menu in the menu manager registry.
References name().
|
virtual |
|
inlinevirtual |
Gets the menu's horizontal position.
Returns the current horizontal position of the menu.
References myX.
Referenced by setPosition(), and setSize().
|
inlinevirtual |
Gets the menu's vertical position.
Returns the current vertical position of the menu.
References myY.
Referenced by setPosition(), and setSize().
|
virtual |
|
inlinevirtual |
Gets the menu's width.
Returns the current width of the menu.
References myWidth.
|
inlinevirtual |
Gets the menu's height.
Returns the current height of the menu.
References myHeight.
|
virtual |
Sets the active state of the menu.
| active | True to activate (show) the menu, false to deactivate (hide) |
| saveSelection | If true, preserve selection from last time the menu was open |
| closeOnElementSelected | If true, close menu when an element is selected |
Controls whether the menu is visible and interactive. When activated, the menu will either restore its previous selection (if saveSelection is true) or select the first valid element. If closeOnElementSelected is true, the menu will automatically close after an element is selected or if there are no valid selections available.
Reimplemented in makVre::DtActionInputMenu.
|
virtual |
Checks if the menu is currently active.
Determines whether the menu is currently visible and interactive.
|
virtual |
Checks if the menu has any elements.
Determines whether the menu contains any elements.
|
virtual |
Updates the menu's state and visuals.
| dt | Time elapsed since the last update in seconds |
Called once per frame to update the menu's state and refresh its visual representation. This handles animation, scrolling, and display updates.
|
virtual |
Initializes the input handling logic for the menu.
Sets up the input logic system for this menu, mapping input events (keyboard, mouse, controller buttons, etc.) to menu action handlers. This establishes all the input handlers needed for navigating and interacting with the menu, such as selection, scrolling, and item activation.
This is automatically called when the menu becomes active.
Reimplemented in makVre::DtActionInputMenu.
|
virtual |
Shuts down the input handling logic for the menu.
Deactivates the input logic system for this menu, removing all input handlers and cleaning up resources. This prevents the menu from responding to input events when it's no longer active.
This is automatically called when the menu becomes inactive.
|
inlinevirtual |
Gets the menu title text.
Returns the title text displayed at the top of the menu.
References myTitleString.
Referenced by setTitle().
|
virtual |
Sets the menu title text.
| title | The title text to display |
Sets the title text to be displayed at the top of the menu. This is typically shown in a header area above the menu elements.
References title().
|
inlinevirtual |
Gets the menu title text.
Returns the title text displayed at the top of the menu.
References myTitleAttribute.
Referenced by setTitleAttribute().
| void makVre::DtMenu::setTitleAttribute | ( | const std::string & | titleAttribute | ) |
Sets the menu title text.
| title | The title text to display |
Sets the title text to be displayed at the top of the menu. This is typically shown in a header area above the menu elements.
Sets the attribute path used for the menu title
| titleAttribute | The attribute path to use for dynamically updating the menu title |
References titleAttribute().
|
virtual |
Sets whether to show the menu title.
| show | True to show the title, false to hide it |
Controls the visibility of the menu title. When enabled, the title is displayed at the top of the menu. When disabled, no title is shown.
|
virtual |
Adds an element to the menu.
| element | Pointer to the menu element to add |
Adds the specified element to this menu. If there is no currently selected element, the new element will become the selected element if it is enabled. The menu takes ownership of the element and will delete it when the menu is destroyed or when the element is removed.
|
virtual |
Removes an element from the menu by pointer.
| element | Pointer to the element to remove |
Removes the specified element from the menu. If the removed element was the currently selected element, the selection will be updated to the nearest valid element. The caller becomes responsible for deleting the returned element to avoid memory leaks.
|
virtual |
Removes an element from the menu by name.
| name | Name of the element to remove |
Removes the element with the specified name from the menu. If the removed element was the currently selected element, the selection will be updated to the nearest valid element. The caller becomes responsible for deleting the returned element to avoid memory leaks.
References name().
|
virtual |
Finds a menu element by name.
| name | Name of the element to find |
Searches for and returns the menu element with the specified name. Returns NULL if no element with that name exists in the menu.
References name().
|
virtual |
Gets all elements in the menu.
Returns a vector containing pointers to all elements in the menu. The elements remain owned by the menu; the caller should not delete them.
|
virtual |
Selects a menu element by index.
| index | Zero-based index of the element to select |
Attempts to select the element at the specified index. If the requested element is not enabled or does not exist, it will try to select the next enabled element. Returns true if the selection successfully changed to a valid element, false if the selection remained unchanged or no valid selection was possible.
|
virtual |
Selects a menu element by its on-screen index.
| index | On-screen index of the element to select (as displayed to the user) |
Selects the element with the specified on-screen index. On-screen indices are only assigned to visible and enabled elements, and are used for keyboard shortcuts (e.g., pressing 1-9 to select menu items 1-9).
|
virtual |
Selects a menu element by name.
| name | Name of the element to select |
Attempts to select the element with the specified name. Returns true if the element was found and successfully selected, false if the element was not found or could not be selected (e.g., because it is disabled).
References name().
|
virtual |
Selects the next enabled element in the menu.
| val | Input value (typically 1.0 for full activation) |
Moves the selection to the next enabled element in the menu. If already at the last element, the selection will not change. The val parameter supports analog inputs (like joysticks) that may not be fully activated.
|
virtual |
Selects the previous enabled element in the menu.
| val | Input value (typically 1.0 for full activation) |
Moves the selection to the previous enabled element in the menu. If already at the first element, the selection will not change. The val parameter supports analog inputs (like joysticks) that may not be fully activated.
|
virtual |
Gets the currently selected menu element.
Returns a pointer to the currently selected menu element. Returns nullptr if no element is currently selected, which can happen if the menu is empty or if no elements are enabled.
|
inlinevirtual |
Gets the index of the currently selected element.
Returns the index of the currently selected menu element in the list of enabled elements. Returns -1 if no element is currently selected, which can happen if the menu is empty or if no elements are enabled.
References mySelectedItem.
|
virtual |
Clears the current selection.
Removes the current element selection, leaving no element selected. This is useful when you want to reset the menu state or when no element should be highlighted.
|
inlinevirtual |
Scrolls the menu to show a specific item.
| index | Index of the item to scroll to |
Adjusts the menu scroll position to ensure the element at the specified index is visible. This automatically updates the menu visuals. Returns true if the scroll was successful, false otherwise.
References scrollToItem().
Referenced by scrollToItem().
|
virtual |
Scrolls the menu down one item.
Scrolls the menu down by one item, showing the next set of elements if the menu contains more elements than can be displayed at once.
|
virtual |
Scrolls the menu up one item.
Scrolls the menu up by one item, showing the previous set of elements if the menu has been scrolled down.
|
virtual |
Scrolls the menu by a variable amount.
| val | Amount to scroll, positive for down, negative for up |
Scrolls the menu by the specified amount. Positive values scroll down, negative values scroll up. The val parameter supports analog inputs (like joysticks) for variable-speed scrolling.
|
virtual |
Scrolls the menu up by a page.
| val | Input value (typically 1.0 for full page) |
Scrolls the menu up by one page (the number of visible elements). The val parameter supports analog inputs for partial page scrolling.
|
virtual |
Scrolls the menu down by a page.
| val | Input value (typically 1.0 for full page) |
Scrolls the menu down by one page (the number of visible elements). The val parameter supports analog inputs for partial page scrolling.
|
virtual |
Updates the enabled element list.
Refreshes the internal list of enabled elements based on the current state of all menu elements. This rebuilds the myEnabledItems list, recalculating which elements are visible and enabled based on their display conditions. Called automatically when menu state changes affect element visibility.
|
virtual |
Updates the visual representation of the menu.
Refreshes the visual display of the menu based on the current state. This updates element positions, scrolling state, and visual properties. Called automatically when the menu's state changes in a way that affects its visual appearance.
|
virtual |
Adds a dynamic element generator to the menu.
| generator | Pointer to the attribute observer that generates elements |
Sets an attribute observer that will dynamically generate menu elements based on attribute values. This allows menus to automatically update their contents when attributes change. The menu takes ownership of the generator and will delete it when the menu is destroyed.
|
virtual |
Sets the parent menu by name.
| name | Name of the parent menu |
Establishes a parent-child relationship between menus. When this menu is closed, the parent menu will be reopened if it exists. This creates a hierarchical menu structure for navigation.
References name().
|
virtual |
Sets whether to inherit position from parent menu.
| set | True to inherit parent position, false to use own position |
When set to true, this menu will adopt the same position as its parent menu. This is useful for submenus that should appear in the same location as their parent menu for visual continuity.
|
virtual |
Sets whether to inherit size from parent menu.
| set | True to inherit parent size, false to use own size |
When set to true, this menu will adopt the same size as its parent menu. This is useful for submenus that should maintain the same dimensions as their parent menu for visual consistency.
|
virtual |
Gets the name of the parent menu.
Returns the name of this menu's parent menu. Returns an empty string if this menu has no parent.
|
virtual |
Closes the menu.
| val | Input value (typically 1.0 for full activation) |
Closes this menu, deactivating it and hiding it from view. If the menu has a parent, the parent menu will be activated. The val parameter supports analog inputs for partial activation.
|
virtual |
Selects the currently highlighted menu element.
| val | Input value (typically 1.0 for full activation) |
Executes the action associated with the currently selected menu element. For action elements, this will trigger the action. For menu elements, this will open the submenu. The val parameter supports analog inputs for partial activation.
Reimplemented in makVre::DtActionInputMenu.
|
virtual |
Selects a menu item by number with analog input support.
| val | Input value (typically 1.0 for full activation) |
| num | Index of the item to select (1-based) |
General handler for numerical item selection. This allows selecting a menu item by its displayed number. The val parameter supports analog inputs for partial activation.
|
virtual |
Selects the first menu item.
| val | Input value (typically 1.0 for full activation) |
Selects the first visible menu item. The val parameter supports analog inputs for partial activation.
|
virtual |
Selects the second menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the third menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the fourth menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the fifth menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the sixth menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the seventh menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the eighth menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the ninth menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Selects the tenth menu item.
| val | Input value (typically 1.0 for full activation) |
|
virtual |
Navigates back to the parent menu.
| val | Input value (typically 1.0 for full activation) |
Closes this menu and returns to the parent menu if one exists. Equivalent to pressing the Back button or Escape key. The val parameter supports analog inputs for partial activation.
|
virtual |
Gets the display conditions for this menu (const version)
Returns a constant reference to the conditions that determine when this menu should be displayed. These include context-sensitive conditions like player posture.
|
virtual |
Gets the display conditions for this menu (mutable version)
Returns a mutable reference to the conditions that determine when this menu should be displayed. These can be modified to change when the menu is available to the player.
|
virtual |
Checks if a duplicate element exists in the enabled list.
| element | Pointer to the element to check for duplicates |
Determines whether another enabled element with the same label as the specified element already exists in the menu. This is used to prevent duplicate entries in dynamically generated menus.
|
inlinevirtual |
Gets the menu manager for this menu.
Returns a reference to the menu manager that controls this menu. The menu manager handles menu registration, parent-child relationships, and other menu system functionality.
References myManager.
|
inline |
|
inline |
|
virtual |
Removes all elements from the menu.
Clears the menu by removing and deleting all its elements. This resets the menu to an empty state, removing all options.
| void makVre::DtMenu::triggerActionFromQML | ( | int | index | ) |
Triggers an action from QML interface.
| index | Index of the element to trigger |
Executes the action associated with the element at the specified index. This is used for integration with QML-based user interfaces, allowing QML components to trigger menu actions.
|
protectedvirtual |
Handles player controls state change messages.
| msg | Pointer to the message to handle |
Processes messages about changes in player controls state. When controls are disabled, this automatically closes the menu to prevent interaction when the player cannot control the menu.
|
protectedvirtual |
Handles menu input messages from VR controllers.
| msg | Pointer to the message to handle |
Processes input messages specifically designed for VR control of menus. This provides a bridge for VR controller input to interact with menus until a more integrated VR input system is implemented.
|
protectedvirtual |
Internal implementation of scrollToItem.
| index | Index of the item to scroll to |
| doUpdate | Whether to update the visual display after scrolling |
Adjusts the scroll position to ensure the element at the specified index is visible. The doUpdate parameter controls whether the menu visuals are immediately updated after scrolling, which is useful for batch operations where multiple scrolls might occur before the final update.
|
protectedvirtual |
Updates the ImGui-based user interface.
Refreshes the menu's user interface components using the ImGui framework. This handles the rendering of the menu background, elements, scrollbars, and other visual components. Called internally by the tick method when the menu needs to be visually updated.
|
protected |
Reference to the menu manager.
Reference to the menu manager that controls this menu. The menu manager handles menu registration, parent-child relationships, and other menu system functionality.
Referenced by manager().
|
protected |
Name identifier for this menu.
Unique name that identifies this menu in the menu system. Used for menu lookup and parent-child relationships.
|
protected |
Title text displayed at the top of the menu.
Text shown in the menu's title bar, describing the menu's purpose.
Referenced by title().
|
protected |
Title attribute for the menu.
The attribute name to get the title's text from.
Referenced by titleAttribute().
|
protected |
Name of the parent menu.
Name of this menu's parent menu. When this menu is closed, the parent menu will be activated if it exists. Empty string indicates no parent.
|
protected |
Display conditions for this menu.
Conditions that determine when this menu should be displayed, such as player posture requirements.
|
protected |
|
protected |
Position and size of the menu in pixels.
Coordinates and dimensions that define the menu's location and size on the screen. The position (myX, myY) represents the top-left corner of the menu rectangle.
Referenced by x().
|
protected |
Referenced by y().
|
protected |
Referenced by width().
|
protected |
Referenced by height().
|
protected |
Active state of the menu.
Indicates whether the menu is currently active (visible and interactive).
|
protected |
Whether to show the menu title.
Controls visibility of the title bar at the top of the menu.
|
protected |
Whether to inherit size from parent menu.
When true, this menu adopts the same size as its parent menu.
|
protected |
Whether to inherit position from parent menu.
When true, this menu appears at the same position as its parent menu.
|
protected |
Whether to show numerical indices for menu items.
When true, menu elements are displayed with numerical indices (1, 2, 3...) that can be used for keyboard shortcuts. Input menus typically disable this.
|
protected |
List of all menu items, owned by this menu.
Vector of all menu items, including both enabled and disabled ones. The menu owns these items and is responsible for deleting them.
|
protected |
List of currently enabled menu items.
Vector of pointers to enabled menu items only. These are not owned by this vector, but are references to items in myItems. This list is rebuilt whenever element states change, and is used for display and selection.
|
protected |
Pointer to the currently selected item.
Points to the item that is currently selected in the menu. This is a reference to an item in myEnabledItems. Null if no item is selected.
Referenced by selectedElementIndex().
|
protected |
Pointer to the saved selection for menu reopening.
When a menu is closed with saveSelection=true, this stores the last selected item so it can be restored when the menu is reopened.
|
protected |
Special items for scroll indicators.
Items representing the scroll up and scroll down indicators that appear at the top and bottom of the menu when not all items can be displayed at once.
|
protected |
|
protected |
Whether the menu can scroll upward.
Indicates if there are additional items above the currently visible ones.
|
protected |
Whether the menu can scroll downward.
Indicates if there are additional items below the currently visible ones.
|
protected |
Current scroll position in the menu.
Index of the first visible item in the list of enabled items.
|
protected |
Number of items that can be displayed at once.
Maximum number of menu elements that can be displayed simultaneously based on menu height and element height.
|
protected |
Timer for action selection flash effect.
Used to create a visual flash effect when an action is selected. Counts down from a positive value to zero.
|
protected |
Whether to close the menu after an element is selected.
When true, the menu automatically closes after an element is selected. This is commonly used for context menus and quick menus.
|
protected |
Height of each menu element line in pixels.
Used for layout calculations and determining how many elements can be displayed at once.
|
protected |
Element generator for dynamic menu content.
Observer that dynamically generates menu elements based on attribute values. This allows the menu to update its content automatically when relevant attributes change.
|
protected |
Input logic for menu interaction.
Handles input event processing for menu navigation and selection. Maps input events to menu actions like selection, scrolling, and activation.