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

71 lines
2.2 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/input-events.hpp"
  25. #include "input/mapping.hpp"
  26. #include <memory>
  27. #include <vector>
  28. namespace input {
  29. /**
  30. * Listens for input events and generates corresponding input mappings.
  31. */
  32. class mapper
  33. {
  34. public:
  35. /**
  36. * Connects the input event signals of an event queue to the mapper.
  37. *
  38. * @param queue Event queue to connect.
  39. */
  40. void connect(::event::queue& queue);
  41. /**
  42. * Disconnects all input event signals from the mapper.
  43. */
  44. void disconnect();
  45. /// Returns the channel through which input mapped events are published.
  46. [[nodiscard]] inline ::event::channel<input_mapped_event>& get_input_mapped_channel() noexcept
  47. {
  48. return input_mapped_publisher.channel();
  49. }
  50. private:
  51. void handle_gamepad_axis_moved(const gamepad_axis_moved_event& event);
  52. void handle_gamepad_button_pressed(const gamepad_button_pressed_event& event);
  53. void handle_key_pressed(const key_pressed_event& event);
  54. void handle_mouse_button_pressed(const mouse_button_pressed_event& event);
  55. void handle_mouse_moved(const mouse_moved_event& event);
  56. void handle_mouse_scrolled(const mouse_scrolled_event& event);
  57. std::vector<std::shared_ptr<::event::subscription>> subscriptions;
  58. ::event::publisher<input_mapped_event> input_mapped_publisher;
  59. };
  60. } // namespace input
  61. #endif // ANTKEEPER_INPUT_MAPPER_HPP