💿🐜 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.

329 lines
6.7 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_EVENT_HPP
  20. #define ANTKEEPER_INPUT_EVENT_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. * Input events.
  39. */
  40. namespace event {
  41. /**
  42. * Event generated when a control has been activated.
  43. */
  44. struct control_activated
  45. {
  46. /// Control that was activated.
  47. control* control;
  48. };
  49. /**
  50. * Event generated while a control is active.
  51. */
  52. struct control_active
  53. {
  54. /// Active control.
  55. control* control;
  56. /// Control input value.
  57. float input_value;
  58. };
  59. /**
  60. * Event generated when a control has been deactivated.
  61. */
  62. struct control_deactivated
  63. {
  64. /// Control that was deactivated.
  65. control* control;
  66. };
  67. /**
  68. * Event generated when an input mapping has been generated.
  69. */
  70. struct input_mapped
  71. {
  72. /// Input mapping that was generated.
  73. std::shared_ptr<mapping> mapping;
  74. };
  75. /**
  76. * Event generated when an input device has been connected.
  77. */
  78. struct device_connected
  79. {
  80. /// Device that was connected.
  81. device* device;
  82. };
  83. /**
  84. * Event generated when an input device has been disconnected.
  85. */
  86. struct device_disconnected
  87. {
  88. /// Device that was disconnected.
  89. device* device;
  90. };
  91. /**
  92. * Event generated when a gamepad button has been pressed.
  93. */
  94. struct gamepad_button_pressed
  95. {
  96. /// Gamepad that generated the event.
  97. gamepad* gamepad;
  98. /// Gamepad button being pressed.
  99. gamepad_button button;
  100. };
  101. /**
  102. * Event generated when a gamepad button has been released.
  103. */
  104. struct gamepad_button_released
  105. {
  106. /// Gamepad that generated the event.
  107. gamepad* gamepad;
  108. /// Gamepad button being released.
  109. gamepad_button button;
  110. };
  111. /**
  112. * Event generated when a gamepad axis has been moved.
  113. */
  114. struct gamepad_axis_moved
  115. {
  116. /// Gamepad that generated the event.
  117. gamepad* gamepad;
  118. /// Gamepad axis being moved.
  119. gamepad_axis axis;
  120. /// Position of the gamepad axis, on `[-1, 1]`.
  121. float position;
  122. };
  123. /**
  124. * Event generated when a keyboard key has been pressed.
  125. */
  126. struct key_pressed
  127. {
  128. /// Keyboard that generated the event.
  129. keyboard* keyboard;
  130. /// Scancode of the key being pressed.
  131. scancode scancode;
  132. /// `true` if the key press was generated by a key repeat, `false` otherwise.
  133. bool repeat;
  134. /// Bit mask containing the active modifier keys.
  135. std::uint16_t modifiers;
  136. };
  137. /**
  138. * Event generated when a keyboard key has been released.
  139. */
  140. struct key_released
  141. {
  142. /// Keyboard that generated the event.
  143. keyboard* keyboard;
  144. /// Scancode of the key being released.
  145. scancode scancode;
  146. /// `true` if the key release was generated by a key repeat, `false` otherwise.
  147. bool repeat;
  148. /// Bit mask containing the active modifier keys.
  149. std::uint16_t modifiers;
  150. };
  151. /**
  152. * Event generated when a mouse has been moved.
  153. */
  154. struct mouse_moved
  155. {
  156. /// Mouse that generated the event.
  157. mouse* mouse;
  158. /// Mouse position, in pixels, relative to the window.
  159. math::vector<std::int32_t, 2> position;
  160. /// Relative movement of the mouse, in pixels.
  161. math::vector<std::int32_t, 2> difference;
  162. };
  163. /**
  164. * Event generated when a mouse button has been pressed.
  165. */
  166. struct mouse_button_pressed
  167. {
  168. /// Mouse that generated the event.
  169. mouse* mouse;
  170. /// Mouse position, in pixels, relative to the window, when the button was pressed.
  171. math::vector<std::int32_t, 2> position;
  172. /// Mouse button being pressed.
  173. mouse_button button;
  174. };
  175. /**
  176. * Event generated when a mouse button has been released.
  177. */
  178. struct mouse_button_released
  179. {
  180. /// Mouse that generated the event.
  181. mouse* mouse;
  182. /// Mouse position, in pixels, relative to the window, when the button was released.
  183. math::vector<std::int32_t, 2> position;
  184. /// Mouse button being released.
  185. mouse_button button;
  186. };
  187. /**
  188. * Event generated when a mouse has been scrolled.
  189. */
  190. struct mouse_scrolled
  191. {
  192. /// Mouse that generated the event.
  193. mouse* mouse;
  194. /// Mouse position, in pixels, relative to the window, when the mouse was scrolled.
  195. math::vector<std::int32_t, 2> position;
  196. /// Scroll velocity.
  197. math::vector<float, 2> velocity;
  198. };
  199. /**
  200. * Event generated when a window has been requested to close.
  201. */
  202. struct window_closed
  203. {
  204. /// Pointer to the window that has been requested to close.
  205. void* window;
  206. };
  207. /**
  208. * Event generated when a window has gained or lost focus.
  209. */
  210. struct window_focus_changed
  211. {
  212. /// Pointer to the window that has gained or lost focus.
  213. void* window;
  214. /// `true` if the window is in focus, `false` otherwise.
  215. bool in_focus;
  216. };
  217. /**
  218. * Event generated when a window has been moved.
  219. */
  220. struct window_moved
  221. {
  222. /// Pointer to the window that has been moved.
  223. void* window;
  224. /// Position of the window, in pixels.
  225. math::vector<std::int32_t, 2> position;
  226. /// `true` if the window is maximized, `false` otherwise.
  227. bool maximized;
  228. /// `true` if the window is fullscreen, `false` otherwise.
  229. bool fullscreen;
  230. };
  231. /**
  232. * Event generated when a window has been maximized.
  233. */
  234. struct window_maximized
  235. {
  236. /// Pointer to the window that has been maximized.
  237. void* window;
  238. };
  239. /**
  240. * Event generated when a window has been minimized.
  241. */
  242. struct window_minimized
  243. {
  244. /// Pointer to the window that has been minimized.
  245. void* window;
  246. };
  247. /**
  248. * Event generated when a window has been restored.
  249. */
  250. struct window_restored
  251. {
  252. /// Pointer to the window that has been restored.
  253. void* window;
  254. };
  255. /**
  256. * Event generated when a window has been resized.
  257. */
  258. struct window_resized
  259. {
  260. /// Pointer to the window that has been resized.
  261. void* window;
  262. /// Window size, in display units.
  263. math::vector<std::int32_t, 2> size;
  264. /// `true` if the window is maximized, `false` otherwise.
  265. bool maximized;
  266. /// `true` if the window is fullscreen, `false` otherwise.
  267. bool fullscreen;
  268. /// Window viewport size, in pixels.
  269. math::vector<std::int32_t, 2> viewport_size;
  270. };
  271. } // namespace event
  272. } // namespace input
  273. #endif // ANTKEEPER_INPUT_EVENT_HPP