/* * Copyright (C) 2020 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 ANTKEEER_INPUT_EVENT_ROUTER_HPP #define ANTKEEER_INPUT_EVENT_ROUTER_HPP #include "event/input-events.hpp" #include "event/event-handler.hpp" #include #include class control; class event_dispatcher; class input_mapping; class key_mapping; class mouse_motion_mapping; class mouse_wheel_mapping; class mouse_button_mapping; class game_controller_axis_mapping; class game_controller_button_mapping; enum class mouse_motion_axis; enum class mouse_wheel_axis; /** * Uses input mappings to route input events to controls. */ class input_event_router: public event_handler, public event_handler, public event_handler, public event_handler, public event_handler, public event_handler, public event_handler, public event_handler, public event_handler { public: /** * Creates an input router and subscribes it to the input events of the specified event dispatcher. */ input_event_router(); /** * Destroys an input router and unsubscribes it from input events. */ ~input_event_router(); /** * Adds an input mapping to the router. * * @param mapping Input mapping to add. */ void add_mapping(const input_mapping& mapping); /** * Removes all input mappings from the router that are associated with the specified control. * * @param control control with which associated input mappings should be removed. */ void remove_mappings(control* control); /** * Sets the event dispatcher to which this input event router will subscribe itself. */ void set_event_dispatcher(event_dispatcher* event_dispatcher); /** * Removes all input mappings from the router. */ void remove_mappings(); /// Returns a list of mappings for the specified control, or nullptr if the control is unmapped. const std::list* get_mappings(control* control) const; private: virtual void handle_event(const key_pressed_event& event); virtual void handle_event(const key_released_event& event); virtual void handle_event(const mouse_moved_event& event); virtual void handle_event(const mouse_wheel_scrolled_event& event); virtual void handle_event(const mouse_button_pressed_event& event); virtual void handle_event(const mouse_button_released_event& event); virtual void handle_event(const game_controller_axis_moved_event& event); virtual void handle_event(const game_controller_button_pressed_event& event); virtual void handle_event(const game_controller_button_released_event& event); event_dispatcher* event_dispatcher; std::map> controls; std::list key_mappings; std::list mouse_motion_mappings; std::list mouse_wheel_mappings; std::list mouse_button_mappings; std::list game_controller_axis_mappings; std::list game_controller_button_mappings; }; #endif // ANTKEEER_INPUT_EVENT_ROUTER_HPP