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

95 lines
2.1 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. #include "game-controller.hpp"
  20. #include "event/input-events.hpp"
  21. #include "event/event-dispatcher.hpp"
  22. #include <cmath>
  23. namespace input {
  24. game_controller::game_controller():
  25. connected(true)
  26. {}
  27. void game_controller::press(game_controller_button button)
  28. {
  29. if (!device::event_dispatcher)
  30. {
  31. return;
  32. }
  33. game_controller_button_pressed_event event;
  34. event.controller = this;
  35. event.button = button;
  36. device::event_dispatcher->queue(event);
  37. }
  38. void game_controller::release(game_controller_button button)
  39. {
  40. if (!device::event_dispatcher)
  41. {
  42. return;
  43. }
  44. game_controller_button_released_event event;
  45. event.controller = this;
  46. event.button = button;
  47. device::event_dispatcher->queue(event);
  48. }
  49. void game_controller::move(game_controller_axis axis, float value)
  50. {
  51. if (!device::event_dispatcher)
  52. {
  53. return;
  54. }
  55. game_controller_axis_moved_event event;
  56. event.controller = this;
  57. event.axis = axis;
  58. event.value = value;
  59. device::event_dispatcher->queue(event);
  60. }
  61. void game_controller::connect(bool reconnected)
  62. {
  63. connected = true;
  64. game_controller_connected_event event;
  65. event.controller = this;
  66. event.reconnected = reconnected;
  67. device::event_dispatcher->queue(event);
  68. }
  69. void game_controller::disconnect()
  70. {
  71. connected = false;
  72. game_controller_disconnected_event event;
  73. event.controller = this;
  74. device::event_dispatcher->queue(event);
  75. }
  76. } // namespace input