Antkeeper  0.0.1
mapper.hpp
Go to the documentation of this file.
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 
20 #ifndef ANTKEEPER_INPUT_MAPPER_HPP
21 #define ANTKEEPER_INPUT_MAPPER_HPP
22 
30 #include <memory>
31 #include <vector>
32 
33 namespace input {
34 
38 class mapper
39 {
40 public:
46  void connect(::event::dispatcher& dispatcher);
47 
51  void disconnect();
52 
54  [[nodiscard]] inline ::event::channel<gamepad_axis_mapped_event>& get_gamepad_axis_mapped_channel() noexcept
55  {
56  return gamepad_axis_mapped_publisher.channel();
57  }
58 
60  [[nodiscard]] inline ::event::channel<gamepad_button_mapped_event>& get_gamepad_button_mapped_channel() noexcept
61  {
62  return gamepad_button_mapped_publisher.channel();
63  }
64 
66  [[nodiscard]] inline ::event::channel<key_mapped_event>& get_key_mapped_channel() noexcept
67  {
68  return key_mapped_publisher.channel();
69  }
70 
72  [[nodiscard]] inline ::event::channel<mouse_button_mapped_event>& get_mouse_button_mapped_channel() noexcept
73  {
74  return mouse_button_mapped_publisher.channel();
75  }
76 
78  [[nodiscard]] inline ::event::channel<mouse_motion_mapped_event>& get_mouse_motion_mapped_channel() noexcept
79  {
80  return mouse_motion_mapped_publisher.channel();
81  }
82 
84  [[nodiscard]] inline ::event::channel<mouse_scroll_mapped_event>& get_mouse_scroll_mapped_channel() noexcept
85  {
86  return mouse_scroll_mapped_publisher.channel();
87  }
88 
89 private:
90  void handle_gamepad_axis_moved(const gamepad_axis_moved_event& event);
91  void handle_gamepad_button_pressed(const gamepad_button_pressed_event& event);
92  void handle_key_pressed(const key_pressed_event& event);
93  void handle_mouse_button_pressed(const mouse_button_pressed_event& event);
94  void handle_mouse_moved(const mouse_moved_event& event);
95  void handle_mouse_scrolled(const mouse_scrolled_event& event);
96 
97  std::vector<std::shared_ptr<::event::subscription>> subscriptions;
98  ::event::publisher<gamepad_axis_mapped_event> gamepad_axis_mapped_publisher;
99  ::event::publisher<gamepad_button_mapped_event> gamepad_button_mapped_publisher;
100  ::event::publisher<key_mapped_event> key_mapped_publisher;
101  ::event::publisher<mouse_button_mapped_event> mouse_button_mapped_publisher;
102  ::event::publisher<mouse_motion_mapped_event> mouse_motion_mapped_publisher;
103  ::event::publisher<mouse_scroll_mapped_event> mouse_scroll_mapped_publisher;
104 };
105 
106 } // namespace input
107 
108 #endif // ANTKEEPER_INPUT_MAPPER_HPP
Forwards messages from publishers to subscribers.
Definition: dispatcher.hpp:37
Publishes messages to subscribers.
Definition: publisher.hpp:36
Listens for input events and generates corresponding input mappings.
Definition: mapper.hpp:39
::event::channel< mouse_scroll_mapped_event > & get_mouse_scroll_mapped_channel() noexcept
Returns the channel through which mouse scroll mapped events are published.
Definition: mapper.hpp:84
::event::channel< key_mapped_event > & get_key_mapped_channel() noexcept
Returns the channel through which key mapped events are published.
Definition: mapper.hpp:66
void disconnect()
Disconnects all input event signals from the mapper.
Definition: mapper.cpp:35
::event::channel< mouse_button_mapped_event > & get_mouse_button_mapped_channel() noexcept
Returns the channel through which mouse button mapped events are published.
Definition: mapper.hpp:72
::event::channel< gamepad_button_mapped_event > & get_gamepad_button_mapped_channel() noexcept
Returns the channel through which gamepad button mapped events are published.
Definition: mapper.hpp:60
::event::channel< gamepad_axis_mapped_event > & get_gamepad_axis_mapped_channel() noexcept
Returns the channel through which gamepad axis mapped events are published.
Definition: mapper.hpp:54
void connect(::event::dispatcher &dispatcher)
Connects the input event signals of an event dispatcher to the mapper.
Definition: mapper.cpp:25
::event::channel< mouse_motion_mapped_event > & get_mouse_motion_mapped_channel() noexcept
Returns the channel through which mouse motion mapped events are published.
Definition: mapper.hpp:78
Publish-subscribe messaging.
Definition: channel.hpp:32
Input devices, events, and mapping.
Event generated when a gamepad axis has been moved.
Event generated when a gamepad button has been pressed.
Event generated when a keyboard key has been pressed.
Event generated when a mouse button has been pressed.
Event generated when a mouse has been moved.
Event generated when a mouse has been scrolled.