Antkeeper  0.0.1
mouse.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_INPUT_MOUSE_HPP
21 #define ANTKEEPER_INPUT_MOUSE_HPP
22 
23 #include <engine/input/device.hpp>
27 #include <engine/math/vector.hpp>
28 #include <cstdint>
29 
30 namespace input {
31 
35 class mouse: public device
36 {
37 public:
43  void press(mouse_button button);
44 
50  void release(mouse_button button);
51 
59 
65  void scroll(const math::fvec2& velocity);
66 
68  [[nodiscard]] inline const math::vec2<std::int32_t>& get_position() const noexcept
69  {
70  return position;
71  }
72 
74  [[nodiscard]] inline ::event::channel<mouse_button_pressed_event>& get_button_pressed_channel() noexcept
75  {
76  return button_pressed_publisher.channel();
77  }
78 
80  [[nodiscard]] inline ::event::channel<mouse_button_released_event>& get_button_released_channel() noexcept
81  {
82  return button_released_publisher.channel();
83  }
84 
86  [[nodiscard]] inline ::event::channel<mouse_moved_event>& get_moved_channel() noexcept
87  {
88  return moved_publisher.channel();
89  }
90 
92  [[nodiscard]] inline ::event::channel<mouse_scrolled_event>& get_scrolled_channel() noexcept
93  {
94  return scrolled_publisher.channel();
95  }
96 
98  [[nodiscard]] inline constexpr device_type get_device_type() const noexcept override
99  {
100  return device_type::mouse;
101  }
102 
103 private:
104  math::vec2<std::int32_t> position{0, 0};
105 
106  ::event::publisher<mouse_button_pressed_event> button_pressed_publisher;
107  ::event::publisher<mouse_button_released_event> button_released_publisher;
109  ::event::publisher<mouse_scrolled_event> scrolled_publisher;
110 };
111 
112 } // namespace input
113 
114 #endif // ANTKEEPER_INPUT_MOUSE_HPP
Publishes messages to subscribers.
Definition: publisher.hpp:36
Abstract base class for virtual devices that generate input events.
Definition: device.hpp:36
A virtual mouse which generates mouse-related input events.
Definition: mouse.hpp:36
::event::channel< mouse_scrolled_event > & get_scrolled_channel() noexcept
Returns the channel through which mouse scrolled events are published.
Definition: mouse.hpp:92
const math::vec2< std::int32_t > & get_position() const noexcept
Returns the current mouse position, in pixels, relative to the window.
Definition: mouse.hpp:68
void move(const math::vec2< std::int32_t > &position, const math::vec2< std::int32_t > &difference)
Simulates mouse movement.
Definition: mouse.cpp:34
::event::channel< mouse_moved_event > & get_moved_channel() noexcept
Returns the channel through which mouse moved events are published.
Definition: mouse.hpp:86
void press(mouse_button button)
Simulates a mouse button press.
Definition: mouse.cpp:24
::event::channel< mouse_button_pressed_event > & get_button_pressed_channel() noexcept
Returns the channel through which mouse button pressed events are published.
Definition: mouse.hpp:74
void scroll(const math::fvec2 &velocity)
Simulates mouse scrolling.
Definition: mouse.cpp:40
constexpr device_type get_device_type() const noexcept override
Returns device_type::mouse.
Definition: mouse.hpp:98
void release(mouse_button button)
Simulates a mouse button release.
Definition: mouse.cpp:29
::event::channel< mouse_button_released_event > & get_button_released_channel() noexcept
Returns the channel through which mouse button released events are published.
Definition: mouse.hpp:80
constexpr int difference(T x, T y) noexcept
Returns the number of differing bits between two values, known as Hamming distance.
Definition: bit-math.hpp:280
Input devices, events, and mapping.
device_type
Input device types.
Definition: device-type.hpp:29
@ mouse
Mouse input device.
mouse_button
Mouse buttons.
n-dimensional vector.
Definition: vector.hpp:44