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

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