nomlib
Loading...
Searching...
No Matches
InputStateMapper.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SYSTEM_INPUT_MAPPER_INPUT_STATE_MAPPER_HPP
30#define NOMLIB_SYSTEM_INPUT_MAPPER_INPUT_STATE_MAPPER_HPP
31
32#include <map>
33
34#include "nomlib/config.hpp"
35#include "nomlib/system/InputMapper/InputActionMapper.hpp"
36
37namespace nom {
38
39// Forward declarations
40struct Event;
41class EventHandler;
42class InputAction;
43
45{
46 bool active;
47 InputActionMapper::ActionMap actions;
48};
49
54{
55 public:
56 typedef InputStateMapper SelfType;
57 typedef std::pair<std::string, InputActionState> Pair;
58 typedef std::map<std::string, InputActionState> InputStateMap;
59
62
65
69 bool active( const std::string& key ) const;
70
80 bool insert( const std::string& key, const InputActionMapper& map, bool active );
81
85 bool erase(const std::string& key);
86
90 bool activate( const std::string& key );
91
95 bool disable( const std::string& key );
96
98 void disable( void );
99
104 bool activate_only( const std::string& key );
105
107 void clear( void );
108
112 void dump();
113
121 void set_event_handler(EventHandler& evt_handler);
122
123 private:
125 void on_event(const Event& ev);
126
129 bool on_key_press(const InputAction& mapping, const Event& ev);
130
133 bool on_mouse_button( const InputAction& mapping, const Event& ev );
134
137 bool on_mouse_wheel( const InputAction& mapping, const Event& ev );
138
141 bool on_joystick_button(const InputAction& mapping, const Event& ev);
142
145 bool on_joystick_axis(const InputAction& mapping, const Event& ev);
146
147 bool on_joystick_hat(const InputAction& mapping, const Event& ev);
148
151 bool
152 on_game_controller_button(const InputAction& mapping, const Event& ev);
153
156 bool
157 on_game_controller_axis(const InputAction& mapping, const Event& ev);
158
159 // Non-owned pointer
160 EventHandler* event_handler_ = nullptr;
161
162 InputStateMap states_;
163};
164
165} // namespace nom
166
167#endif // include guard defined
Event handling abstraction.
Base class for mapping an action to an input device.
High-level API for associating names with input actions.
void disable(void)
Disable all input states.
void set_event_handler(EventHandler &evt_handler)
Install the event handler used by the interface.
bool on_joystick_button(const InputAction &mapping, const Event &ev)
Internal event handler for matching a joystick button action to a joystick button event.
void clear(void)
Empty the container of input states.
bool on_game_controller_button(const InputAction &mapping, const Event &ev)
Internal event handler for matching a game controller button action to an equivalent event.
bool insert(const std::string &key, const InputActionMapper &map, bool active)
Add action mappings to an input state.
InputStateMapper(void)
Default constructor.
bool erase(const std::string &key)
Remove a state.
bool on_mouse_button(const InputAction &mapping, const Event &ev)
Internal event handler for matching a mouse button action to a mouse button event.
bool on_joystick_axis(const InputAction &mapping, const Event &ev)
Internal event handler for matching a joystick axis action to a joystick axis event.
bool on_mouse_wheel(const InputAction &mapping, const Event &ev)
Internal event handler for matching a mouse wheel action to a mouse wheel event.
bool activate_only(const std::string &key)
Enable only a particular state.
bool on_game_controller_axis(const InputAction &mapping, const Event &ev)
Internal event handler for matching a game controller axis action to an equivalent event.
bool on_key_press(const InputAction &mapping, const Event &ev)
Internal event handler for matching a keyboard action to a keyboard event.
bool activate(const std::string &key)
Activate a state.
bool disable(const std::string &key)
Disable a state.
~InputStateMapper(void)
Destructor.
void dump()
Diagnostic output.
void on_event(const Event &ev)
Internal event handler for triggering mapped action states.
bool active(const std::string &key) const
Obtain active state status.
Event handling types.
Definition Event.hpp:457