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