💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
5.2 KiB

  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. #ifndef ANTKEEPER_INPUT_INPUT_EVENTS_HPP
  20. #define ANTKEEPER_INPUT_INPUT_EVENTS_HPP
  21. #include "input/gamepad-axis.hpp"
  22. #include "input/gamepad-button.hpp"
  23. #include "input/mouse-motion-axis.hpp"
  24. #include "input/mouse-scroll-axis.hpp"
  25. #include "input/scancode.hpp"
  26. #include "input/mapping.hpp"
  27. #include "input/modifier-key.hpp"
  28. #include "math/vector.hpp"
  29. #include <cstdint>
  30. #include <memory>
  31. namespace input {
  32. class control;
  33. class device;
  34. class gamepad;
  35. class keyboard;
  36. class mouse;
  37. /**
  38. * Event generated when a control has been activated.
  39. */
  40. struct control_activated_event
  41. {
  42. /// Control that was activated.
  43. control* control;
  44. };
  45. /**
  46. * Event generated while a control is active.
  47. */
  48. struct control_active_event
  49. {
  50. /// Active control.
  51. control* control;
  52. /// Control input value.
  53. float input_value;
  54. };
  55. /**
  56. * Event generated when a control has been deactivated.
  57. */
  58. struct control_deactivated_event
  59. {
  60. /// Control that was deactivated.
  61. control* control;
  62. };
  63. /**
  64. * Event generated when an input mapping has been generated.
  65. */
  66. struct input_mapped_event
  67. {
  68. /// Input mapping that was generated.
  69. std::shared_ptr<mapping> mapping;
  70. };
  71. /**
  72. * Event generated when an input device has been connected.
  73. */
  74. struct device_connected_event
  75. {
  76. /// Device that was connected.
  77. device* device;
  78. };
  79. /**
  80. * Event generated when an input device has been disconnected.
  81. */
  82. struct device_disconnected_event
  83. {
  84. /// Device that was disconnected.
  85. device* device;
  86. };
  87. /**
  88. * Event generated when a gamepad button has been pressed.
  89. */
  90. struct gamepad_button_pressed_event
  91. {
  92. /// Gamepad that generated the event.
  93. gamepad* gamepad;
  94. /// Gamepad button being pressed.
  95. gamepad_button button;
  96. };
  97. /**
  98. * Event generated when a gamepad button has been released.
  99. */
  100. struct gamepad_button_released_event
  101. {
  102. /// Gamepad that generated the event.
  103. gamepad* gamepad;
  104. /// Gamepad button being released.
  105. gamepad_button button;
  106. };
  107. /**
  108. * Event generated when a gamepad axis has been moved.
  109. */
  110. struct gamepad_axis_moved_event
  111. {
  112. /// Gamepad that generated the event.
  113. gamepad* gamepad;
  114. /// Gamepad axis being moved.
  115. gamepad_axis axis;
  116. /// Position of the gamepad axis, on `[-1, 1]`.
  117. float position;
  118. };
  119. /**
  120. * Event generated when a keyboard key has been pressed.
  121. */
  122. struct key_pressed_event
  123. {
  124. /// Keyboard that generated the event.
  125. keyboard* keyboard;
  126. /// Scancode of the key being pressed.
  127. scancode scancode;
  128. /// `true` if the key press was generated by a key repeat, `false` otherwise.
  129. bool repeat;
  130. /// Bit mask containing the active modifier keys.
  131. std::uint16_t modifiers;
  132. };
  133. /**
  134. * Event generated when a keyboard key has been released.
  135. */
  136. struct key_released_event
  137. {
  138. /// Keyboard that generated the event.
  139. keyboard* keyboard;
  140. /// Scancode of the key being released.
  141. scancode scancode;
  142. /// `true` if the key release was generated by a key repeat, `false` otherwise.
  143. bool repeat;
  144. /// Bit mask containing the active modifier keys.
  145. std::uint16_t modifiers;
  146. };
  147. /**
  148. * Event generated when a mouse has been moved.
  149. */
  150. struct mouse_moved_event
  151. {
  152. /// Mouse that generated the event.
  153. mouse* mouse;
  154. /// Mouse position, in pixels, relative to the window.
  155. math::vector<std::int32_t, 2> position;
  156. /// Relative movement of the mouse, in pixels.
  157. math::vector<std::int32_t, 2> difference;
  158. };
  159. /**
  160. * Event generated when a mouse button has been pressed.
  161. */
  162. struct mouse_button_pressed_event
  163. {
  164. /// Mouse that generated the event.
  165. mouse* mouse;
  166. /// Mouse position, in pixels, relative to the window, when the button was pressed.
  167. math::vector<std::int32_t, 2> position;
  168. /// Mouse button being pressed.
  169. mouse_button button;
  170. };
  171. /**
  172. * Event generated when a mouse button has been released.
  173. */
  174. struct mouse_button_released_event
  175. {
  176. /// Mouse that generated the event.
  177. mouse* mouse;
  178. /// Mouse position, in pixels, relative to the window, when the button was released.
  179. math::vector<std::int32_t, 2> position;
  180. /// Mouse button being released.
  181. mouse_button button;
  182. };
  183. /**
  184. * Event generated when a mouse has been scrolled.
  185. */
  186. struct mouse_scrolled_event
  187. {
  188. /// Mouse that generated the event.
  189. mouse* mouse;
  190. /// Mouse position, in pixels, relative to the window, when the mouse was scrolled.
  191. math::vector<std::int32_t, 2> position;
  192. /// Scroll velocity.
  193. math::vector<float, 2> velocity;
  194. };
  195. /**
  196. * Event generated when the application has been requested to quit.
  197. */
  198. struct application_quit_event {};
  199. } // namespace input
  200. #endif // ANTKEEPER_INPUT_INPUT_EVENTS_HPP