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

202 lines
5.3 KiB

  1. /*
  2. * Copyright (C) 2021 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_MAPPING_HPP
  20. #define ANTKEEPER_INPUT_MAPPING_HPP
  21. namespace input {
  22. enum class mouse_motion_axis;
  23. enum class mouse_wheel_axis;
  24. enum class scancode;
  25. enum class game_controller_axis;
  26. enum class game_controller_button;
  27. class control;
  28. class keyboard;
  29. class mouse;
  30. class game_controller;
  31. /**
  32. * Enumerates the supported types of control mappings.
  33. */
  34. enum class mapping_type
  35. {
  36. key,
  37. mouse_motion,
  38. mouse_wheel,
  39. mouse_button,
  40. game_controller_axis,
  41. game_controller_button
  42. };
  43. /**
  44. * Abstract base class for input mappings.
  45. */
  46. class mapping
  47. {
  48. public:
  49. mapping() = default;
  50. mapping(input::control* control);
  51. virtual ~mapping() = default;
  52. /// Returns this control mapping's type.
  53. virtual mapping_type get_type() const = 0;
  54. control* control;
  55. };
  56. /**
  57. * A mapping between a control and a keyboard key.
  58. */
  59. class key_mapping: public mapping
  60. {
  61. public:
  62. key_mapping() = default;
  63. key_mapping(const key_mapping& mapping);
  64. key_mapping(input::control* control, input::keyboard* keyboard, scancode scancode);
  65. virtual ~key_mapping() = default;
  66. key_mapping& operator=(const key_mapping& mapping);
  67. virtual mapping_type get_type() const;
  68. input::keyboard* keyboard;
  69. scancode scancode;
  70. };
  71. inline mapping_type key_mapping::get_type() const
  72. {
  73. return mapping_type::key;
  74. }
  75. /**
  76. * A mapping between a control and a mouse motion axis.
  77. */
  78. class mouse_motion_mapping: public mapping
  79. {
  80. public:
  81. mouse_motion_mapping() = default;
  82. mouse_motion_mapping(const mouse_motion_mapping& mapping);
  83. mouse_motion_mapping(input::control* control, input::mouse* mouse, mouse_motion_axis axis);
  84. virtual ~mouse_motion_mapping() = default;
  85. mouse_motion_mapping& operator=(const mouse_motion_mapping& mapping);
  86. virtual mapping_type get_type() const;
  87. input::mouse* mouse;
  88. mouse_motion_axis axis;
  89. };
  90. inline mapping_type mouse_motion_mapping::get_type() const
  91. {
  92. return mapping_type::mouse_motion;
  93. }
  94. /**
  95. * A mapping between a control and a mouse wheel axis.
  96. */
  97. class mouse_wheel_mapping: public mapping
  98. {
  99. public:
  100. mouse_wheel_mapping() = default;
  101. mouse_wheel_mapping(const mouse_wheel_mapping& mapping);
  102. mouse_wheel_mapping(input::control* control, input::mouse* mouse, mouse_wheel_axis axis);
  103. virtual ~mouse_wheel_mapping() = default;
  104. mouse_wheel_mapping& operator=(const mouse_wheel_mapping& mapping);
  105. virtual mapping_type get_type() const;
  106. input::mouse* mouse;
  107. mouse_wheel_axis axis;
  108. };
  109. inline mapping_type mouse_wheel_mapping::get_type() const
  110. {
  111. return mapping_type::mouse_wheel;
  112. }
  113. /**
  114. * A mapping between a control and a mouse button.
  115. */
  116. class mouse_button_mapping: public mapping
  117. {
  118. public:
  119. mouse_button_mapping() = default;
  120. mouse_button_mapping(const mouse_button_mapping& mapping);
  121. mouse_button_mapping(input::control* control, input::mouse* mouse, int button);
  122. virtual ~mouse_button_mapping() = default;
  123. mouse_button_mapping& operator=(const mouse_button_mapping& mapping);
  124. virtual mapping_type get_type() const;
  125. input::mouse* mouse;
  126. int button;
  127. };
  128. inline mapping_type mouse_button_mapping::get_type() const
  129. {
  130. return mapping_type::mouse_button;
  131. }
  132. /**
  133. * A mapping between a control and a game controller axis.
  134. */
  135. class game_controller_axis_mapping: public mapping
  136. {
  137. public:
  138. game_controller_axis_mapping() = default;
  139. game_controller_axis_mapping(const game_controller_axis_mapping& mapping);
  140. game_controller_axis_mapping(input::control* control, game_controller* controller, game_controller_axis axis, bool negative);
  141. virtual ~game_controller_axis_mapping() = default;
  142. game_controller_axis_mapping& operator=(const game_controller_axis_mapping& mapping);
  143. virtual mapping_type get_type() const;
  144. game_controller* controller;
  145. game_controller_axis axis;
  146. bool negative;
  147. };
  148. inline mapping_type game_controller_axis_mapping::get_type() const
  149. {
  150. return mapping_type::game_controller_axis;
  151. }
  152. /**
  153. * A mapping between a control and a game controller button.
  154. *
  155. * @ingroup input.
  156. */
  157. class game_controller_button_mapping: public mapping
  158. {
  159. public:
  160. game_controller_button_mapping() = default;
  161. game_controller_button_mapping(const game_controller_button_mapping& mapping);
  162. game_controller_button_mapping(input::control* control, game_controller* controller, game_controller_button button);
  163. virtual ~game_controller_button_mapping() = default;
  164. game_controller_button_mapping& operator=(const game_controller_button_mapping& mapping);
  165. virtual mapping_type get_type() const;
  166. game_controller* controller;
  167. game_controller_button button;
  168. };
  169. inline mapping_type game_controller_button_mapping::get_type() const
  170. {
  171. return mapping_type::game_controller_button;
  172. }
  173. } // namespace input
  174. #endif // ANTKEEPER_INPUT_MAPPING_HPP