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

198 lines
5.4 KiB

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