Antkeeper  0.0.1
mapping.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_MAPPING_HPP
21 #define ANTKEEPER_INPUT_MAPPING_HPP
22 
30 #include <cstdint>
31 
32 namespace input {
33 
34 class control;
35 class gamepad;
36 class keyboard;
37 class mouse;
38 
42 class mapping
43 {
44 public:
48  mapping() = default;
49 
51  virtual ~mapping() = default;
52 
54  [[nodiscard]] virtual constexpr mapping_type get_mapping_type() const noexcept = 0;
55 };
56 
61 {
62 public:
72  gamepad_axis_mapping() = default;
74 
76  [[nodiscard]] inline constexpr mapping_type get_mapping_type() const noexcept override
77  {
79  }
80 
83 
85  gamepad_axis axis{0};
86 
88  bool direction{false};
89 };
90 
95 {
96 public:
107 
109  [[nodiscard]] inline constexpr mapping_type get_mapping_type() const noexcept override
110  {
112  }
113 
116 
118  gamepad_button button{0};
119 };
120 
124 class key_mapping: public mapping
125 {
126 public:
136  key_mapping(input::keyboard* keyboard, input::scancode scancode, std::uint16_t modifiers = 0, bool repeat = false);
137  key_mapping() = default;
139 
141  [[nodiscard]] inline constexpr mapping_type get_mapping_type() const noexcept override
142  {
143  return mapping_type::key;
144  }
145 
148 
151 
153  std::uint16_t modifiers{0};
154 
156  bool repeat{false};
157 };
158 
163 {
164 public:
173  mouse_button_mapping() = default;
175 
177  [[nodiscard]] inline constexpr mapping_type get_mapping_type() const noexcept override
178  {
180  }
181 
183  input::mouse* mouse{nullptr};
184 
186  mouse_button button{0};
187 };
188 
193 {
194 public:
204  mouse_motion_mapping() = default;
206 
208  [[nodiscard]] inline constexpr mapping_type get_mapping_type() const noexcept override
209  {
211  }
212 
214  input::mouse* mouse{nullptr};
215 
218 
220  bool direction{false};
221 };
222 
227 {
228 public:
239  mouse_scroll_mapping() = default;
241 
243  [[nodiscard]] inline constexpr mapping_type get_mapping_type() const noexcept override
244  {
246  }
247 
249  input::mouse* mouse{nullptr};
250 
253 
255  bool direction{false};
256 };
257 
258 } // namespace input
259 
260 #endif // ANTKEEPER_INPUT_MAPPING_HPP
Maps a direction along a gamepad axis to a control input value.
Definition: mapping.hpp:61
constexpr mapping_type get_mapping_type() const noexcept override
Returns mapping_type::gamepad_axis.
Definition: mapping.hpp:76
gamepad_axis_mapping()=default
Constructs a gamepad axis mapping.
Maps a gamepad button to a control input value.
Definition: mapping.hpp:95
gamepad_button_mapping()=default
Constructs a gamepad button mapping.
constexpr mapping_type get_mapping_type() const noexcept override
Returns mapping_type::gamepad_button.
Definition: mapping.hpp:109
A virtual gamepad which generates gamepad-related input events.
Definition: gamepad.hpp:49
Maps a keyboard key to a control input value.
Definition: mapping.hpp:125
key_mapping()=default
Constructs a key mapping.
constexpr mapping_type get_mapping_type() const noexcept override
Returns mapping_type::key.
Definition: mapping.hpp:141
A virtual keyboard which generates keyboard-related input events.
Definition: keyboard.hpp:35
Abstract base class for input mappings.
Definition: mapping.hpp:43
virtual constexpr mapping_type get_mapping_type() const noexcept=0
Returns the input mapping type.
virtual ~mapping()=default
Destructs an input mapping.
mapping()=default
Constructs an input mapping.
Maps a mouse button to a control input value.
Definition: mapping.hpp:163
mouse_button_mapping()=default
Constructs a mouse button mapping.
constexpr mapping_type get_mapping_type() const noexcept override
Returns mapping_type::mouse_button.
Definition: mapping.hpp:177
Maps a direction along a mouse motion axis to a control input value.
Definition: mapping.hpp:193
constexpr mapping_type get_mapping_type() const noexcept override
Returns mapping_type::mouse_motion.
Definition: mapping.hpp:208
mouse_motion_mapping()=default
Constructs a mouse motion mapping.
Maps a direction along a mouse scroll axis to a control input value.
Definition: mapping.hpp:227
constexpr mapping_type get_mapping_type() const noexcept override
Returns mapping_type::mouse_scroll.
Definition: mapping.hpp:243
mouse_scroll_mapping()=default
Constructs a mouse scroll mapping.
A virtual mouse which generates mouse-related input events.
Definition: mouse.hpp:36
Input devices, events, and mapping.
mouse_motion_axis
Mouse motion axes.
mouse_scroll_axis
Mouse scroll axes.
gamepad_button
Gamepad buttons.
scancode
Keyboard scancodes.
Definition: scancode.hpp:33
@ keyboard
Keyboard input device.
@ mouse
Mouse input device.
@ gamepad
Gamepad input device.
mouse_button
Mouse buttons.
mapping_type
Input mapping types.
@ gamepad_axis
Gamepad axis mapping.
@ key
Key mapping.
@ mouse_button
Mouse button mapping.
@ mouse_scroll
Mouse scroll mapping.
@ mouse_motion
Mouse motion mapping.
@ gamepad_button
Gamepad button mapping.
gamepad_axis
Gamepad axes.