/* * Copyright (C) 2023 Christopher J. Howard * * This file is part of Antkeeper source code. * * Antkeeper source code is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Antkeeper source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Antkeeper source code. If not, see . */ #ifndef ANTKEEPER_INPUT_MAPPER_HPP #define ANTKEEPER_INPUT_MAPPER_HPP #include "event/subscription.hpp" #include "event/queue.hpp" #include "event/publisher.hpp" #include "input/gamepad-events.hpp" #include "input/keyboard-events.hpp" #include "input/mouse-events.hpp" #include "input/mapping-events.hpp" #include #include namespace input { /** * Listens for input events and generates corresponding input mappings. */ class mapper { public: /** * Connects the input event signals of an event queue to the mapper. * * @param queue Event queue to connect. */ void connect(::event::queue& queue); /** * Disconnects all input event signals from the mapper. */ void disconnect(); /// Returns the channel through which gamepad axis mapped events are published. [[nodiscard]] inline ::event::channel& get_gamepad_axis_mapped_channel() noexcept { return gamepad_axis_mapped_publisher.channel(); } /// Returns the channel through which gamepad button mapped events are published. [[nodiscard]] inline ::event::channel& get_gamepad_button_mapped_channel() noexcept { return gamepad_button_mapped_publisher.channel(); } /// Returns the channel through which key mapped events are published. [[nodiscard]] inline ::event::channel& get_key_mapped_channel() noexcept { return key_mapped_publisher.channel(); } /// Returns the channel through which mouse button mapped events are published. [[nodiscard]] inline ::event::channel& get_mouse_button_mapped_channel() noexcept { return mouse_button_mapped_publisher.channel(); } /// Returns the channel through which mouse motion mapped events are published. [[nodiscard]] inline ::event::channel& get_mouse_motion_mapped_channel() noexcept { return mouse_motion_mapped_publisher.channel(); } /// Returns the channel through which mouse scroll mapped events are published. [[nodiscard]] inline ::event::channel& get_mouse_scroll_mapped_channel() noexcept { return mouse_scroll_mapped_publisher.channel(); } private: void handle_gamepad_axis_moved(const gamepad_axis_moved_event& event); void handle_gamepad_button_pressed(const gamepad_button_pressed_event& event); void handle_key_pressed(const key_pressed_event& event); void handle_mouse_button_pressed(const mouse_button_pressed_event& event); void handle_mouse_moved(const mouse_moved_event& event); void handle_mouse_scrolled(const mouse_scrolled_event& event); std::vector> subscriptions; ::event::publisher gamepad_axis_mapped_publisher; ::event::publisher gamepad_button_mapped_publisher; ::event::publisher key_mapped_publisher; ::event::publisher mouse_button_mapped_publisher; ::event::publisher mouse_motion_mapped_publisher; ::event::publisher mouse_scroll_mapped_publisher; }; } // namespace input #endif // ANTKEEPER_INPUT_MAPPER_HPP