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

103 lines
3.0 KiB

/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_INPUT_MAPPER_HPP
#define ANTKEEPER_INPUT_MAPPER_HPP
#include "input/input-mapping.hpp"
#include "event/input-events.hpp"
#include "event/event-handler.hpp"
#include <functional>
class event_dispatcher;
/**
* An input mapper takes a control and listens to input events then generates corresponding input mappings which can be added to an input router.
*/
class input_mapper:
public event_handler<key_pressed_event>,
public event_handler<mouse_moved_event>,
public event_handler<mouse_wheel_scrolled_event>,
public event_handler<mouse_button_pressed_event>,
public event_handler<game_controller_axis_moved_event>,
public event_handler<game_controller_button_pressed_event>
{
public:
/**
* Creates an input mapper.
*/
input_mapper();
/**
* Destroys an input mapper.
*/
virtual ~input_mapper();
/**
* Sets the event dispatcher to which this input event router will subscribe itself.
*/
void set_event_dispatcher(event_dispatcher* event_dispatcher);
/**
* Sets the control for which input mappings will be generated.
*
* @param control ::control for which input mappings will be generated.
*/
void set_control(::control* control);
/**
* Sets the callback function to the input mappings generated by this input mapper.
*
* @param callback Callback function operates on an input mapping.
*/
void set_callback(std::function<void(const input_mapping&)> callback);
/**
* Enables or disables the input mapping generation.
*
* @param enabled Whether to enable input mapping generation or not.
*/
void set_enabled(bool enabled);
/**
* Returns true if input mapping generation is enabled.
*/
bool is_enabled() const;
private:
void handle_event(const key_pressed_event& event);
void handle_event(const mouse_moved_event& event);
void handle_event(const mouse_wheel_scrolled_event& event);
void handle_event(const mouse_button_pressed_event& event);
void handle_event(const game_controller_axis_moved_event& event);
void handle_event(const game_controller_button_pressed_event& event);
event_dispatcher* event_dispatcher;
::control* control;
std::function<void(const input_mapping&)> callback;
bool enabled;
};
inline bool input_mapper::is_enabled() const
{
return enabled;
}
#endif // ANTKEEPER_INPUT_MAPPER_HPP