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

108 lines
3.9 KiB

  1. /*
  2. * Copyright (C) 2023 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_MAPPER_HPP
  20. #define ANTKEEPER_INPUT_MAPPER_HPP
  21. #include "event/subscription.hpp"
  22. #include "event/queue.hpp"
  23. #include "event/publisher.hpp"
  24. #include "input/gamepad-events.hpp"
  25. #include "input/keyboard-events.hpp"
  26. #include "input/mouse-events.hpp"
  27. #include "input/mapping-events.hpp"
  28. #include <memory>
  29. #include <vector>
  30. namespace input {
  31. /**
  32. * Listens for input events and generates corresponding input mappings.
  33. */
  34. class mapper
  35. {
  36. public:
  37. /**
  38. * Connects the input event signals of an event queue to the mapper.
  39. *
  40. * @param queue Event queue to connect.
  41. */
  42. void connect(::event::queue& queue);
  43. /**
  44. * Disconnects all input event signals from the mapper.
  45. */
  46. void disconnect();
  47. /// Returns the channel through which gamepad axis mapped events are published.
  48. [[nodiscard]] inline ::event::channel<gamepad_axis_mapped_event>& get_gamepad_axis_mapped_channel() noexcept
  49. {
  50. return gamepad_axis_mapped_publisher.channel();
  51. }
  52. /// Returns the channel through which gamepad button mapped events are published.
  53. [[nodiscard]] inline ::event::channel<gamepad_button_mapped_event>& get_gamepad_button_mapped_channel() noexcept
  54. {
  55. return gamepad_button_mapped_publisher.channel();
  56. }
  57. /// Returns the channel through which key mapped events are published.
  58. [[nodiscard]] inline ::event::channel<key_mapped_event>& get_key_mapped_channel() noexcept
  59. {
  60. return key_mapped_publisher.channel();
  61. }
  62. /// Returns the channel through which mouse button mapped events are published.
  63. [[nodiscard]] inline ::event::channel<mouse_button_mapped_event>& get_mouse_button_mapped_channel() noexcept
  64. {
  65. return mouse_button_mapped_publisher.channel();
  66. }
  67. /// Returns the channel through which mouse motion mapped events are published.
  68. [[nodiscard]] inline ::event::channel<mouse_motion_mapped_event>& get_mouse_motion_mapped_channel() noexcept
  69. {
  70. return mouse_motion_mapped_publisher.channel();
  71. }
  72. /// Returns the channel through which mouse scroll mapped events are published.
  73. [[nodiscard]] inline ::event::channel<mouse_scroll_mapped_event>& get_mouse_scroll_mapped_channel() noexcept
  74. {
  75. return mouse_scroll_mapped_publisher.channel();
  76. }
  77. private:
  78. void handle_gamepad_axis_moved(const gamepad_axis_moved_event& event);
  79. void handle_gamepad_button_pressed(const gamepad_button_pressed_event& event);
  80. void handle_key_pressed(const key_pressed_event& event);
  81. void handle_mouse_button_pressed(const mouse_button_pressed_event& event);
  82. void handle_mouse_moved(const mouse_moved_event& event);
  83. void handle_mouse_scrolled(const mouse_scrolled_event& event);
  84. std::vector<std::shared_ptr<::event::subscription>> subscriptions;
  85. ::event::publisher<gamepad_axis_mapped_event> gamepad_axis_mapped_publisher;
  86. ::event::publisher<gamepad_button_mapped_event> gamepad_button_mapped_publisher;
  87. ::event::publisher<key_mapped_event> key_mapped_publisher;
  88. ::event::publisher<mouse_button_mapped_event> mouse_button_mapped_publisher;
  89. ::event::publisher<mouse_motion_mapped_event> mouse_motion_mapped_publisher;
  90. ::event::publisher<mouse_scroll_mapped_event> mouse_scroll_mapped_publisher;
  91. };
  92. } // namespace input
  93. #endif // ANTKEEPER_INPUT_MAPPER_HPP