utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
hand_button_event.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "utility/event/hand_button_event.hpp"
24
25namespace utility::event
26{
27
29 const Button button) noexcept
30 {
31 switch (handType) {
32 case HandType::Left:
33 return button == Button::X || button == Button::Y
34 || button == Button::Menu;
35 case HandType::Right:
36 return button == Button::A || button == Button::B
37 || button == Button::System;
38 default:
39 return false;
40 }
41 }
42
43 HandButtonEvent::Factory::~Factory(void) = default;
44
45 std::shared_ptr<Event> HandButtonEvent::Factory::create(void) const
46 {
47 return std::make_unique<HandButtonEvent>();
48 }
49
50 std::shared_ptr<HandButtonEvent>
52 {
53 return std::make_unique<HandButtonEvent>();
54 }
55
57
59
61 {
62 _button = button;
63 return *this;
64 }
65
67 {
68 return _button;
69 }
70
72 {
73 return isButtonValidForHand(getHandType(), _button);
74 }
75
76 HandButtonEvent &HandButtonEvent::setTouched(const bool touched) noexcept
77 {
78 _isTouched = touched;
79 return *this;
80 }
81
82 bool HandButtonEvent::isTouched(void) const noexcept
83 {
84 return _isTouched;
85 }
86
88 HandButtonEvent::setButtonPressed(const bool clicked) noexcept
89 {
90 _isClicked = clicked;
91 return *this;
92 }
93
94 bool HandButtonEvent::isButtonPressed(void) const noexcept
95 {
96 return _isClicked;
97 }
98
99 std::ostream &operator<<(std::ostream &stream,
100 const HandButtonEvent::Button button)
101 {
102 switch (button) {
104 stream << "Unknown";
105 break;
107 stream << "A";
108 break;
110 stream << "B";
111 break;
113 stream << "X";
114 break;
116 stream << "Y";
117 break;
119 stream << "Menu";
120 break;
122 stream << "System";
123 break;
124 }
125 return stream;
126 }
127
128 std::ostream &operator<<(std::ostream &stream,
129 const HandButtonEvent &handButtonEvent)
130 {
131 stream << "HandButtonEvent("
132 << "HandType: " << handButtonEvent.getHandType() << ", "
133 << "Button: " << handButtonEvent.getButton() << ", "
134 << "Touched: "
135 << (handButtonEvent.isTouched() ? "true" : "false") << ", "
136 << "Clicked: "
137 << (handButtonEvent.isButtonPressed() ? "true" : "false") << ")";
138 return stream;
139 }
140} // namespace utility::event
std::shared_ptr< Event > create(void) const override
Create a HandButtonEvent as base Event pointer.
std::shared_ptr< HandButtonEvent > createTyped(void) const
Create a strongly-typed HandButtonEvent.
HandButtonEvent & setButtonPressed(const bool clicked) noexcept
Set clicked state.
bool isTouched(void) const noexcept
Get touched state.
static bool isButtonValidForHand(const HandType handType, const Button button) noexcept
Check whether a button is valid for a given hand path.
HandButtonEvent & setTouched(const bool touched) noexcept
Set touched state.
HandButtonEvent(void)
Default constructor.
~HandButtonEvent(void) override
Default destructor.
Button getButton(void) const noexcept
Get button value.
HandButtonEvent & setButton(const Button button) noexcept
Set button value.
bool isValidForCurrentHand(void) const noexcept
Check whether current hand/button combination is valid.
bool isButtonPressed(void) const noexcept
Get clicked state.
HandType
Hand types for hand events. Defines the type of hand involved in the event (e.g., left or right).
HandType getHandType(void) const noexcept
Get the type of hand involved in the event.