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

120 lines
2.7 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_GAME_CONTROLLER_HPP
  20. #define ANTKEEPER_INPUT_GAME_CONTROLLER_HPP
  21. #include "device.hpp"
  22. namespace input {
  23. enum class game_controller_button
  24. {
  25. a,
  26. b,
  27. x,
  28. y,
  29. back,
  30. guide,
  31. start,
  32. left_stick,
  33. right_stick,
  34. left_shoulder,
  35. right_shoulder,
  36. dpad_up,
  37. dpad_down,
  38. dpad_left,
  39. dpad_right
  40. };
  41. enum class game_controller_axis
  42. {
  43. left_x,
  44. left_y,
  45. right_x,
  46. right_y,
  47. left_trigger,
  48. right_trigger,
  49. };
  50. /**
  51. * A virtual game controller which can generate game controller-related input events and pass them to an event dispatcher.
  52. *
  53. * @ingroup input
  54. */
  55. class game_controller: public device
  56. {
  57. public:
  58. /**
  59. * Creates a game controller input device.
  60. */
  61. game_controller();
  62. /// Destroys a game controller input device.
  63. virtual ~game_controller() = default;
  64. /**
  65. * Simulates a game controller button press.
  66. *
  67. * @param button Index of the pressed button.
  68. */
  69. void press(game_controller_button button);
  70. /**
  71. * Simulates a game controller button release.
  72. *
  73. * @param button Index of the released button.
  74. */
  75. void release(game_controller_button button);
  76. /**
  77. * Simulates a game controller axis movement.
  78. *
  79. * @param axis Index of the moved axis.
  80. * @param negative Whether the movement was negative or positive.
  81. * @param value Normalized degree of movement.
  82. */
  83. void move(game_controller_axis axis, float value);
  84. /**
  85. * Simulates a game controller being connected.
  86. *
  87. * @param reconnected `true` if the controller is being reconnected, or `false` if the controller is being connected for the first time.
  88. */
  89. void connect(bool reconnnected);
  90. /// Simulates a game controller being disconnected.
  91. void disconnect();
  92. /// Returns `true` if the controller is currently connected.
  93. bool is_connected() const;
  94. private:
  95. bool connected;
  96. };
  97. inline bool game_controller::is_connected() const
  98. {
  99. return connected;
  100. }
  101. } // namespace input
  102. #endif // ANTKEEPER_INPUT_GAME_CONTROLLER_HPP