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
mouse_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/mouse_button_event.hpp"
24
25namespace utility::event
26{
27
28 MouseButtonEvent::Factory::~Factory(void) = default;
29
30 std::shared_ptr<Event> MouseButtonEvent::Factory::create(void) const
31 {
32 return std::make_unique<MouseButtonEvent>();
33 }
34
35 std::shared_ptr<MouseButtonEvent>
37 {
38 return std::make_unique<MouseButtonEvent>();
39 }
40
42
44
47 {
48 _position = position;
49 return *this;
50 }
51
53 MouseButtonEvent::getPosition(void) const noexcept
54 {
55 return _position;
56 }
57
59 {
60 _button = button;
61 return *this;
62 }
63
65 {
66 return _button;
67 }
68
69 MouseButtonEvent &MouseButtonEvent::setPressed(const bool pressed) noexcept
70 {
71 _pressed = pressed;
72 return *this;
73 }
74
75 bool MouseButtonEvent::isButtonPressed(void) const noexcept
76 {
77 return _pressed;
78 }
79
80 std::ostream &operator<<(std::ostream &stream,
81 const MouseButtonEvent::Button button)
82 {
83 switch (button) {
84 case MouseButtonEvent::Button::Unknown:
85 stream << "Unknown";
86 break;
87 case MouseButtonEvent::Button::Left:
88 stream << "Left";
89 break;
90 case MouseButtonEvent::Button::Right:
91 stream << "Right";
92 break;
93 case MouseButtonEvent::Button::Middle:
94 stream << "Middle";
95 break;
96 case MouseButtonEvent::Button::X1:
97 stream << "X1";
98 break;
99 case MouseButtonEvent::Button::X2:
100 stream << "X2";
101 break;
102 }
103 return stream;
104 }
105
106 std::ostream &operator<<(std::ostream &stream,
107 const MouseButtonEvent &mouseButtonEvent)
108 {
109 stream << "MouseButtonEvent("
110 << "Position: " << mouseButtonEvent.getPosition()
111 << ", Button: " << mouseButtonEvent.getButton()
112 << ", Pressed: " << std::boolalpha
113 << mouseButtonEvent.isButtonPressed() << ")";
114 return stream;
115 }
116
117} // namespace utility::event
std::shared_ptr< MouseButtonEvent > createTyped(void) const
Create a strongly-typed MouseButtonEvent.
std::shared_ptr< Event > create(void) const override
Create a MouseButtonEvent as a base Event pointer.
~MouseButtonEvent(void) override
Default destructor.
MouseButtonEvent & setPosition(const MousePosition &position) noexcept
Set the current mouse position.
bool isButtonPressed(void) const noexcept
Get the pressed state of the button.
MouseButtonEvent(void)
Default constructor.
Button getButton(void) const noexcept
Get the current mouse button.
MousePosition getPosition(void) const noexcept
Get the current mouse position.
MouseButtonEvent & setPressed(const bool pressed) noexcept
Set the pressed state of the button.
MouseButtonEvent & setButton(const Button button) noexcept
Set the state of a mouse button.
3D vector class inheriting from glm::vec3.
Definition vector.hpp:83