Ocean
Loading...
Searching...
No Matches
VRTableMenuBase.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_TABLE_MENU_BASE_H
9#define META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_TABLE_MENU_BASE_H
10
12
15
21
22namespace Ocean
23{
24
25namespace Platform
26{
27
28namespace Meta
29{
30
31namespace Quest
32{
33
34namespace Application
35{
36
37/**
38 * The class implements the base class for a simple table-based menu for VR application.
39 * The menu is composed of sections and menu entries.<br>
40 * Based on controller tracking, the menu entries can be selected.<br>
41 * Use the derived classes OpenXR::VRTableMenu or VrApi::VRTableMenu.
42 * @ingroup platformmetaquestapplication
43 */
44class OCEAN_PLATFORM_META_QUEST_APPLICATION_EXPORT VRTableMenuBase
45{
46 public:
47
48 /**
49 * This class holds the information of a user-defined menu entry.
50 */
51 class Entry
52 {
53 friend class VRTableMenuBase;
54
55 public:
56
57 /**
58 * Creates a new entry.
59 * @param name The name of the entry (the text of the entry), must be valid
60 * @param url The url of the entry which is necessary to identify the individual entries
61 */
62 inline Entry(std::string name, std::string url);
63
64 protected:
65
66 /// The name of the entry.
67 std::string name_;
68
69 /// The url of the entry.
70 std::string url_;
71 };
72
73 /**
74 * Definition of a vector holding entries.
75 */
76 typedef std::vector<Entry> Entries;
77
78 /**
79 * Definition of a pair combining a group section name and menu entries.
80 */
81 typedef std::pair<std::string, Entries> Group;
82
83 /**
84 * Definition of a vector holding groups.
85 */
86 typedef std::vector<Group> Groups;
87
88 protected:
89
90 /**
91 * This class contains the information necessary for one menu entry.
92 */
94 {
95 public:
96
97 /**
98 * Creates an new menu entry object.
99 * @param engine The rendering engine to be used
100 * @param textLineHeight The height of the text line, in meter, with range (0, infinity)
101 * @param name The text of the menu entry, must be valid
102 * @param url The optional URL connected with the menu entry
103 * @param isEntry True, if the entry is a menu entry; False, if the entry is a name of a group section
104 * @param backgroundColor The background color of an entry
105 */
106 MenuEntry(Rendering::Engine& engine, const Scalar textLineHeight, const std::string& name, const std::string& url, bool isEntry, const RGBAColor& backgroundColor = RGBAColor(0.0f, 0.0f, 0.0f, 0.0f));
107
108 /**
109 * Returns the extent of the actual text.
110 * @return The text's actual extent, in meter, with range [0, infinity)x[0, infinity)
111 */
112 inline Vector2 extent() const;
113
114 /**
115 * Returns the Transform node containing the Text node.
116 * @return The Transform node
117 */
118 inline const Rendering::TransformRef& transform() const;
119
120 /**
121 * Returns the name of this entry.
122 * @return The entry's name
123 */
124 inline const std::string& name() const;
125
126 /**
127 * Returns the optional URL of this entry.
128 * @return The entry's optional URL
129 */
130 inline const std::string& url() const;
131
132 /**
133 * Returns whether the entry is an actual menu entry of a group section.
134 * @return True, if the entry is a menu entry; False, if the entry is a name of a group section
135 */
136 inline bool isEntry() const;
137
138 protected:
139
140 /// The Text node rendering the text.
142
143 /// The Transform node containing the Text node.
145
146 /// The name of the menu entry.
147 std::string name_;
148
149 /// The optional URL of the menu entry.
150 std::string url_;
151
152 /// True, if the entry is a menu entry; False, if the entry is a name of a group section
153 bool isEntry_ = false;
154 };
155
156 /**
157 * Definition of a vector holding menu entries.
158 */
159 typedef std::vector<MenuEntry> MenuEntries;
160
161 public:
162
163 /**
164 * Destructs a menu.
165 */
167
168 /**
169 * Sets all menu items.
170 * @param group The menu group containing all menu entries to set
171 * @param menuBackgroundColor The background color of a menu
172 * @param entryBackgroundColor The background color of individual entries
173 * @param entryHeight The height of each menu entry, in meter, with range (0, infinity)
174 * @param minWidth The minimal width of the menu, in meter, with range [0, infinity)
175 * @param minHeight The minimal height of the menu, in meter, with range [0, infinity)
176 * @return True, if succeeded
177 */
178 inline bool setMenuEntries(const Group& group, const RGBAColor& menuBackgroundColor = RGBAColor(1.0f, 1.0f, 1.0f), const RGBAColor& entryBackgroundColor = RGBAColor(0.0f, 0.0f, 0.0f, 0.0f), const Scalar entryHeight = Scalar(0.04), const Scalar minWidth = Scalar(1), const Scalar minHeight = Scalar(0.5));
179
180 /**
181 * Sets all menu items.
182 * @param groups The menu groups containing all menu entries to set
183 * @param menuBackgroundColor The background color of menu
184 * @param entryBackgroundColor The background color of individual entries
185 * @param entryHeight The height of each menu entry, in meter, with range (0, infinity)
186 * @param minWidth The minimal width of the menu, in meter, with range [0, infinity)
187 * @param minHeight The minimal height of the menu, in meter, with range [0, infinity)
188 * @return True, if succeeded
189 */
190 bool setMenuEntries(const Groups& groups, const RGBAColor& menuBackgroundColor = RGBAColor(1.0f, 1.0f, 1.0f), const RGBAColor& entryBackgroundColor = RGBAColor(0.0f, 0.0f, 0.0f, 0.0f), const Scalar entryHeight = Scalar(0.04), const Scalar minWidth = Scalar(1), const Scalar minHeight = Scalar(0.5));
191
192 /**
193 * Shows the menu at a specified location.
194 * @param base_T_menu The transformation between menu and world, or menu and device (if 'world_T_device' is defined), must be valid
195 * @param world_T_device The optional transformation between device and world, an invalid transformation to treat `base` as `world`
196 * @return True, if the menu was shown; False, if e.g., the menu is empty
197 */
198 bool show(const HomogenousMatrix4& base_T_menu, const HomogenousMatrix4& world_T_device = HomogenousMatrix4(false));
199
200 /**
201 * Hides the menu.
202 */
203 void hide();
204
205 /**
206 * Returns whether the menu is shown.
207 * @return True, if succeeded
208 */
209 inline bool isShown() const;
210
211 /**
212 * Returns the position of the menu
213 * @return The position of the menu in the coordinate system that was selected as base
214 * @sa show()
215 */
216 inline HomogenousMatrix4 base_T_menu() const;
217
218 /**
219 * Explicitly resets the entire menu without releasing any resources.
220 * @sa setMenuEntries()
221 */
222 void reset();
223
224 /**
225 * Explicitly releases the menu and all associated resources.
226 */
227 void release();
228
229 /**
230 * Returns whether this menu is valid (whether it has been initialized with a engine and framebuffer).
231 * @return True, if so
232 */
233 inline bool isValid() const;
234
235 /**
236 * Move operator.
237 * @param menu The menu object to be moved
238 * @return Reference to this object
239 */
241
242 protected:
243
244 /**
245 * Creates a new invalid menu object.
246 */
247 VRTableMenuBase() = default;
248
249 /**
250 * Default move constructor.
251 */
253
254 /**
255 * Creates a new valid menu object.
256 * @param engine The rendering engine which will be used to render the menu, must be valid
257 * @param framebuffer The framebuffer associated with the rendering engine to which the menu will be rendered
258 */
260
261 /**
262 * Disabled copy constructor.
263 */
265
266 /**
267 * Disabled copy operator.
268 * @return The reference to this object
269 */
271
272 protected:
273
274 /// The rendering engine.
276
277 /// The framebuffer in which the menu will be rendered.
279
280 /// The scene holding the group and highlight elements.
282
283 /// The group holding the menu.
285
286 /// The transformation for the selection pointer.
288
289 /// The transformation for the selection entry (the entry highlighting).
291
292 /// The width of the menu, in meter, with range (0, infinity)
293 Scalar menuWidth_ = 0;
294
295 /// The height of the menu, in meter, with range (0, infinity)
296 Scalar menuHeight_ = 0;
297
298 /// The height of each menu entry, in meter, with range (0, infinity)
299 Scalar entryHeight_ = Scalar(0.04);
300
301 /// The menu entries.
303
304 /// The transformation between the menu and a base coordinate system.
306
307 /// The transformation between menu and world (the center of the menu).
308 HomogenousMatrix4 world_T_menu_ = HomogenousMatrix4(false);
309
310 /// The names of the menu entries which is currently focused with the left and right controller, first left, second right.
311 std::string focusedEntryNames_[2];
312
313 /// The border around the menu entries.
314 static constexpr Scalar menuBorder_ = Scalar(0.05);
315
316 /// The offset in z-direction between background and menu entries in meter.
317 static constexpr Scalar entryOffsetZ_ = Scalar(0.001);
318};
319
320inline VRTableMenuBase::Entry::Entry(std::string name, std::string url) :
321 name_(std::move(name)),
322 url_(std::move(url))
323{
324 // nothing to do here
325}
326
328{
329 ocean_assert(text_);
330
331 return text_->size();
332}
333
335{
336 return transform_;
337}
338
339inline const std::string& VRTableMenuBase::MenuEntry::name() const
340{
341 return name_;
342}
343
344inline const std::string& VRTableMenuBase::MenuEntry::url() const
345{
346 return url_;
347}
348
350{
351 return isEntry_;
352}
353
354inline bool VRTableMenuBase::setMenuEntries(const Group& group, const RGBAColor& menuBackgroundColor, const RGBAColor& entryBackgroundColor, const Scalar entryHeight, const Scalar minWidth, const Scalar minHeight)
355{
356 const Groups groups(1, group);
357
358 return setMenuEntries(groups, menuBackgroundColor, entryBackgroundColor, entryHeight, minWidth, minHeight);
359}
360
361inline bool VRTableMenuBase::isShown() const
362{
363 return world_T_menu_.isValid() && !scene_.isNull() && scene_->visible();
364}
365
370
371inline bool VRTableMenuBase::isValid() const
372{
373 return engine_ && framebuffer_;
374}
375
376}
377
378}
379
380}
381
382}
383
384}
385
386#endif // META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_TABLE_MENU_BASE_H
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
bool isNull() const
Returns whether this object reference holds no internal object.
Definition base/ObjectRef.h:390
This class holds the information of a user-defined menu entry.
Definition VRTableMenuBase.h:52
std::string name_
The name of the entry.
Definition VRTableMenuBase.h:67
Entry(std::string name, std::string url)
Creates a new entry.
Definition VRTableMenuBase.h:320
std::string url_
The url of the entry.
Definition VRTableMenuBase.h:70
This class contains the information necessary for one menu entry.
Definition VRTableMenuBase.h:94
std::string url_
The optional URL of the menu entry.
Definition VRTableMenuBase.h:150
const std::string & url() const
Returns the optional URL of this entry.
Definition VRTableMenuBase.h:344
bool isEntry() const
Returns whether the entry is an actual menu entry of a group section.
Definition VRTableMenuBase.h:349
const std::string & name() const
Returns the name of this entry.
Definition VRTableMenuBase.h:339
Rendering::TransformRef transform_
The Transform node containing the Text node.
Definition VRTableMenuBase.h:144
std::string name_
The name of the menu entry.
Definition VRTableMenuBase.h:147
MenuEntry(Rendering::Engine &engine, const Scalar textLineHeight, const std::string &name, const std::string &url, bool isEntry, const RGBAColor &backgroundColor=RGBAColor(0.0f, 0.0f, 0.0f, 0.0f))
Creates an new menu entry object.
const Rendering::TransformRef & transform() const
Returns the Transform node containing the Text node.
Definition VRTableMenuBase.h:334
Vector2 extent() const
Returns the extent of the actual text.
Definition VRTableMenuBase.h:327
Rendering::TextRef text_
The Text node rendering the text.
Definition VRTableMenuBase.h:141
The class implements the base class for a simple table-based menu for VR application.
Definition VRTableMenuBase.h:45
Rendering::FramebufferRef framebuffer_
The framebuffer in which the menu will be rendered.
Definition VRTableMenuBase.h:278
bool setMenuEntries(const Group &group, const RGBAColor &menuBackgroundColor=RGBAColor(1.0f, 1.0f, 1.0f), const RGBAColor &entryBackgroundColor=RGBAColor(0.0f, 0.0f, 0.0f, 0.0f), const Scalar entryHeight=Scalar(0.04), const Scalar minWidth=Scalar(1), const Scalar minHeight=Scalar(0.5))
Sets all menu items.
Definition VRTableMenuBase.h:354
VRTableMenuBase & operator=(const VRTableMenuBase &)=delete
Disabled copy operator.
VRTableMenuBase(const Rendering::EngineRef &engine, const Rendering::FramebufferRef &framebuffer)
Creates a new valid menu object.
VRTableMenuBase(const VRTableMenuBase &)=delete
Disabled copy constructor.
HomogenousMatrix4 base_T_menu() const
Returns the position of the menu.
Definition VRTableMenuBase.h:366
MenuEntries menuEntries_
The menu entries.
Definition VRTableMenuBase.h:302
HomogenousMatrix4 base_T_menu_
The transformation between the menu and a base coordinate system.
Definition VRTableMenuBase.h:305
HomogenousMatrix4 world_T_menu_
The transformation between menu and world (the center of the menu).
Definition VRTableMenuBase.h:308
void release()
Explicitly releases the menu and all associated resources.
VRTableMenuBase & operator=(VRTableMenuBase &&menu)=default
Move operator.
std::pair< std::string, Entries > Group
Definition of a pair combining a group section name and menu entries.
Definition VRTableMenuBase.h:81
Rendering::SceneRef scene_
The scene holding the group and highlight elements.
Definition VRTableMenuBase.h:281
Rendering::GroupRef menuGroup_
The group holding the menu.
Definition VRTableMenuBase.h:284
bool show(const HomogenousMatrix4 &base_T_menu, const HomogenousMatrix4 &world_T_device=HomogenousMatrix4(false))
Shows the menu at a specified location.
VRTableMenuBase(VRTableMenuBase &&)=default
Default move constructor.
bool isValid() const
Returns whether this menu is valid (whether it has been initialized with a engine and framebuffer).
Definition VRTableMenuBase.h:371
std::vector< Entry > Entries
Definition of a vector holding entries.
Definition VRTableMenuBase.h:76
std::vector< MenuEntry > MenuEntries
Definition of a vector holding menu entries.
Definition VRTableMenuBase.h:159
bool isShown() const
Returns whether the menu is shown.
Definition VRTableMenuBase.h:361
VRTableMenuBase()=default
Creates a new invalid menu object.
std::vector< Group > Groups
Definition of a vector holding groups.
Definition VRTableMenuBase.h:86
Rendering::TransformRef transformSelectionEntry_
The transformation for the selection entry (the entry highlighting).
Definition VRTableMenuBase.h:290
Rendering::TransformRef transformSelectionPointer_
The transformation for the selection pointer.
Definition VRTableMenuBase.h:287
Rendering::EngineRef engine_
The rendering engine.
Definition VRTableMenuBase.h:275
void reset()
Explicitly resets the entire menu without releasing any resources.
bool setMenuEntries(const Groups &groups, const RGBAColor &menuBackgroundColor=RGBAColor(1.0f, 1.0f, 1.0f), const RGBAColor &entryBackgroundColor=RGBAColor(0.0f, 0.0f, 0.0f, 0.0f), const Scalar entryHeight=Scalar(0.04), const Scalar minWidth=Scalar(1), const Scalar minHeight=Scalar(0.5))
Sets all menu items.
This class implements a color defined by red, green, blue and alpha parameters.
Definition RGBAColor.h:41
This class is the base class for all rendering engines like.
Definition Engine.h:46
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15