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 * @param color Optional color of the entry
62 * @param foregroundColor Optional text color of the entry; invalid uses the default
63 */
64 inline Entry(std::string name, std::string url, const RGBAColor& color = RGBAColor(false), const RGBAColor& foregroundColor = RGBAColor(false));
65
66 protected:
67
68 /// The name of the entry.
69 std::string name_;
70
71 /// The url of the entry.
72 std::string url_;
73
74 /// The optional color.
76
77 /// The optional text (foreground) color; invalid uses the default black/white.
79 };
80
81 /**
82 * Definition of a vector holding entries.
83 */
84 using Entries = std::vector<Entry>;
85
86 /**
87 * Definition of a pair combining a group section name and menu entries.
88 */
89 using Group = std::pair<std::string, Entries>;
90
91 /**
92 * Definition of a vector holding groups.
93 */
94 using Groups = std::vector<Group>;
95
96 protected:
97
98 /**
99 * This class contains the information necessary for one menu entry.
100 */
102 {
103 public:
104
105 /**
106 * Creates an new menu entry object.
107 * @param engine The rendering engine to be used
108 * @param textLineHeight The height of the text line, in meter, with range (0, infinity)
109 * @param name The text of the menu entry, must be valid
110 * @param url The optional URL connected with the menu entry
111 * @param isEntry True, if the entry is a menu entry; False, if the entry is a name of a group section
112 * @param color The color of an entry
113 * @param foregroundColor Optional text color of the entry; invalid uses the default
114 */
115 MenuEntry(Rendering::Engine& engine, const Scalar textLineHeight, const std::string& name, const std::string& url, bool isEntry, const RGBAColor& color = RGBAColor(0.0f, 0.0f, 0.0f, 0.0f), const RGBAColor& foregroundColor = RGBAColor(false));
116
117 /**
118 * Returns the extent of the actual text.
119 * @return The text's actual extent, in meter, with range [0, infinity)x[0, infinity)
120 */
121 inline Vector2 extent() const;
122
123 /**
124 * Returns the Transform node containing the Text node.
125 * @return The Transform node
126 */
127 inline const Rendering::TransformRef& transform() const;
128
129 /**
130 * Returns the name of this entry.
131 * @return The entry's name
132 */
133 inline const std::string& name() const;
134
135 /**
136 * Returns the optional URL of this entry.
137 * @return The entry's optional URL
138 */
139 inline const std::string& url() const;
140
141 /**
142 * Returns whether the entry is an actual menu entry of a group section.
143 * @return True, if the entry is a menu entry; False, if the entry is a name of a group section
144 */
145 inline bool isEntry() const;
146
147 protected:
148
149 /// The Text node rendering the text.
151
152 /// The Transform node containing the Text node.
154
155 /// The name of the menu entry.
156 std::string name_;
157
158 /// The optional URL of the menu entry.
159 std::string url_;
160
161 /// True, if the entry is a menu entry; False, if the entry is a name of a group section
162 bool isEntry_ = false;
163 };
164
165 /**
166 * Definition of a vector holding menu entries.
167 */
168 using MenuEntries = std::vector<MenuEntry>;
169
170 public:
171
172 /**
173 * Destructs a menu.
174 */
176
177 /**
178 * Sets all menu items.
179 * @param group The menu group containing all menu entries to set
180 * @param menuBackgroundColor The background color of a menu
181 * @param entryBackgroundColor The background color of individual entries
182 * @param entryHeight The height of each menu entry, in meter, with range (0, infinity)
183 * @param minWidth The minimal width of the menu, in meter, with range [0, infinity)
184 * @param minHeight The minimal height of the menu, in meter, with range [0, infinity)
185 * @return True, if succeeded
186 */
187 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));
188
189 /**
190 * Sets all menu items.
191 * @param groups The menu groups containing all menu entries to set
192 * @param menuBackgroundColor The background color of menu
193 * @param entryBackgroundColor The background color of individual entries
194 * @param entryHeight The height of each menu entry, in meter, with range (0, infinity)
195 * @param minWidth The minimal width of the menu, in meter, with range [0, infinity)
196 * @param minHeight The minimal height of the menu, in meter, with range [0, infinity)
197 * @return True, if succeeded
198 */
199 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));
200
201 /**
202 * Shows the menu at a specified location.
203 * @param base_T_menu The transformation between menu and world, or menu and device (if 'world_T_device' is defined), must be valid
204 * @param world_T_device The optional transformation between device and world, an invalid transformation to treat `base` as `world`
205 * @return True, if the menu was shown; False, if e.g., the menu is empty
206 */
207 bool show(const HomogenousMatrix4& base_T_menu, const HomogenousMatrix4& world_T_device = HomogenousMatrix4(false));
208
209 /**
210 * Hides the menu.
211 */
212 void hide();
213
214 /**
215 * Returns whether the menu is shown.
216 * @return True, if succeeded
217 */
218 inline bool isShown() const;
219
220 /**
221 * Returns the position of the menu
222 * @return The position of the menu in the coordinate system that was selected as base
223 * @sa show()
224 */
225 inline HomogenousMatrix4 base_T_menu() const;
226
227 /**
228 * Explicitly resets the entire menu without releasing any resources.
229 * @sa setMenuEntries()
230 */
231 void reset();
232
233 /**
234 * Explicitly releases the menu and all associated resources.
235 */
236 void release();
237
238 /**
239 * Returns whether this menu is valid (whether it has been initialized with a engine and framebuffer).
240 * @return True, if so
241 */
242 inline bool isValid() const;
243
244 /**
245 * Move operator.
246 * @param menu The menu object to be moved
247 * @return Reference to this object
248 */
250
251 protected:
252
253 /**
254 * Creates a new invalid menu object.
255 */
256 VRTableMenuBase() = default;
257
258 /**
259 * Default move constructor.
260 */
262
263 /**
264 * Creates a new valid menu object.
265 * @param engine The rendering engine which will be used to render the menu, must be valid
266 * @param framebuffer The framebuffer associated with the rendering engine to which the menu will be rendered
267 */
269
270 /**
271 * Disabled copy constructor.
272 */
274
275 /**
276 * Disabled copy operator.
277 * @return The reference to this object
278 */
280
281 protected:
282
283 /// The rendering engine.
285
286 /// The framebuffer in which the menu will be rendered.
288
289 /// The scene holding the group and highlight elements.
291
292 /// The group holding the menu.
294
295 /// The transformation for the selection pointer.
297
298 /// The transformation for the selection entry (the entry highlighting).
300
301 /// The width of the menu, in meter, with range (0, infinity)
302 Scalar menuWidth_ = 0;
303
304 /// The height of the menu, in meter, with range (0, infinity)
305 Scalar menuHeight_ = 0;
306
307 /// The height of each menu entry, in meter, with range (0, infinity)
308 Scalar entryHeight_ = Scalar(0.04);
309
310 /// The menu entries.
312
313 /// The transformation between the menu and a base coordinate system.
315
316 /// The transformation between menu and world (the center of the menu).
317 HomogenousMatrix4 world_T_menu_ = HomogenousMatrix4(false);
318
319 /// The names of the menu entries which is currently focused with the left and right controller, first left, second right.
320 std::string focusedEntryNames_[2];
321
322 /// The border around the menu entries.
323 static constexpr Scalar menuBorder_ = Scalar(0.05);
324
325 /// The offset in z-direction between background and menu entries in meter.
326 static constexpr Scalar entryOffsetZ_ = Scalar(0.001);
327};
328
329inline VRTableMenuBase::Entry::Entry(std::string name, std::string url, const RGBAColor& color, const RGBAColor& foregroundColor) :
330 name_(std::move(name)),
331 url_(std::move(url)),
332 color_(color),
333 foregroundColor_(foregroundColor)
334{
335 // nothing to do here
336}
337
339{
340 ocean_assert(text_);
341
342 return text_->size();
343}
344
346{
347 return transform_;
348}
349
350inline const std::string& VRTableMenuBase::MenuEntry::name() const
351{
352 return name_;
353}
354
355inline const std::string& VRTableMenuBase::MenuEntry::url() const
356{
357 return url_;
358}
359
361{
362 return isEntry_;
363}
364
365inline bool VRTableMenuBase::setMenuEntries(const Group& group, const RGBAColor& menuBackgroundColor, const RGBAColor& entryBackgroundColor, const Scalar entryHeight, const Scalar minWidth, const Scalar minHeight)
366{
367 const Groups groups(1, group);
368
369 return setMenuEntries(groups, menuBackgroundColor, entryBackgroundColor, entryHeight, minWidth, minHeight);
370}
371
372inline bool VRTableMenuBase::isShown() const
373{
374 return world_T_menu_.isValid() && !scene_.isNull() && scene_->visible();
375}
376
381
382inline bool VRTableMenuBase::isValid() const
383{
384 return engine_ && framebuffer_;
385}
386
387}
388
389}
390
391}
392
393}
394
395}
396
397#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
RGBAColor color_
The optional color.
Definition VRTableMenuBase.h:75
RGBAColor foregroundColor_
The optional text (foreground) color; invalid uses the default black/white.
Definition VRTableMenuBase.h:78
std::string name_
The name of the entry.
Definition VRTableMenuBase.h:69
Entry(std::string name, std::string url, const RGBAColor &color=RGBAColor(false), const RGBAColor &foregroundColor=RGBAColor(false))
Creates a new entry.
Definition VRTableMenuBase.h:329
std::string url_
The url of the entry.
Definition VRTableMenuBase.h:72
This class contains the information necessary for one menu entry.
Definition VRTableMenuBase.h:102
std::string url_
The optional URL of the menu entry.
Definition VRTableMenuBase.h:159
const std::string & url() const
Returns the optional URL of this entry.
Definition VRTableMenuBase.h:355
MenuEntry(Rendering::Engine &engine, const Scalar textLineHeight, const std::string &name, const std::string &url, bool isEntry, const RGBAColor &color=RGBAColor(0.0f, 0.0f, 0.0f, 0.0f), const RGBAColor &foregroundColor=RGBAColor(false))
Creates an new menu entry object.
bool isEntry() const
Returns whether the entry is an actual menu entry of a group section.
Definition VRTableMenuBase.h:360
const std::string & name() const
Returns the name of this entry.
Definition VRTableMenuBase.h:350
Rendering::TransformRef transform_
The Transform node containing the Text node.
Definition VRTableMenuBase.h:153
std::string name_
The name of the menu entry.
Definition VRTableMenuBase.h:156
const Rendering::TransformRef & transform() const
Returns the Transform node containing the Text node.
Definition VRTableMenuBase.h:345
Vector2 extent() const
Returns the extent of the actual text.
Definition VRTableMenuBase.h:338
Rendering::TextRef text_
The Text node rendering the text.
Definition VRTableMenuBase.h:150
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:287
std::vector< MenuEntry > MenuEntries
Definition of a vector holding menu entries.
Definition VRTableMenuBase.h:168
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:365
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:377
MenuEntries menuEntries_
The menu entries.
Definition VRTableMenuBase.h:311
HomogenousMatrix4 base_T_menu_
The transformation between the menu and a base coordinate system.
Definition VRTableMenuBase.h:314
HomogenousMatrix4 world_T_menu_
The transformation between menu and world (the center of the menu).
Definition VRTableMenuBase.h:317
void release()
Explicitly releases the menu and all associated resources.
std::pair< std::string, Entries > Group
Definition of a pair combining a group section name and menu entries.
Definition VRTableMenuBase.h:89
VRTableMenuBase & operator=(VRTableMenuBase &&menu)=default
Move operator.
Rendering::SceneRef scene_
The scene holding the group and highlight elements.
Definition VRTableMenuBase.h:290
Rendering::GroupRef menuGroup_
The group holding the menu.
Definition VRTableMenuBase.h:293
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:382
bool isShown() const
Returns whether the menu is shown.
Definition VRTableMenuBase.h:372
VRTableMenuBase()=default
Creates a new invalid menu object.
Rendering::TransformRef transformSelectionEntry_
The transformation for the selection entry (the entry highlighting).
Definition VRTableMenuBase.h:299
Rendering::TransformRef transformSelectionPointer_
The transformation for the selection pointer.
Definition VRTableMenuBase.h:296
std::vector< Entry > Entries
Definition of a vector holding entries.
Definition VRTableMenuBase.h:84
Rendering::EngineRef engine_
The rendering engine.
Definition VRTableMenuBase.h:284
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.
std::vector< Group > Groups
Definition of a vector holding groups.
Definition VRTableMenuBase.h:94
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