nomlib
Loading...
Searching...
No Matches
InputAction.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_ACTION_HPP
30#define NOMLIB_SYSTEM_INPUT_MAPPER_INPUT_ACTION_HPP
31
32#include "export.hpp"
33#include "nomlib/config.hpp"
34#include "nomlib/system/Event.hpp"
35#include "nomlib/system/GameController.hpp"
36
37namespace nom {
38
42class NOM_EXPORT InputAction
43{
44 public:
47
48 virtual ~InputAction();
49
54 virtual const Event& event( void ) const;
55
57 const nom::event_callback& callback( void ) const;
58
59 void set_callback(const nom::event_callback& delegate);
60
62 void operator()(const Event& evt) const;
63
67
68 private:
70 nom::event_callback callback_;
71};
72
74struct NOM_EXPORT KeyboardAction: public InputAction
75{
76 virtual ~KeyboardAction();
77
83 KeyboardAction(int32 sym, InputState state = InputState::PRESSED);
84
91 KeyboardAction(int32 sym, uint16 mod, InputState state = InputState::PRESSED);
92
99 KeyboardAction( int32 sym, uint16 mod, uint8 repeat,
100 InputState state = InputState::PRESSED );
101};
102
108struct NOM_EXPORT MouseButtonAction: public InputAction
109{
110 virtual ~MouseButtonAction();
111
119 MouseButtonAction(uint8 button, InputState state = InputState::PRESSED);
120
129 MouseButtonAction( uint8 button, uint8 clicks,
130 InputState state = InputState::PRESSED );
131};
132
133enum MouseWheelDirection: uint8
134{
135 MOUSE_WHEEL_INVALID = 0,
136 MOUSE_WHEEL_LEFT = 1,
137 MOUSE_WHEEL_RIGHT = 2,
138 MOUSE_WHEEL_UP = 4,
139 MOUSE_WHEEL_DOWN = 8,
140};
141
143struct NOM_EXPORT MouseWheelAction: public InputAction
144{
145 virtual ~MouseWheelAction();
146
150 MouseWheelAction(MouseWheelDirection dir);
151};
152
154struct NOM_EXPORT JoystickButtonAction: public InputAction
155{
156 virtual ~JoystickButtonAction();
157
166 JoystickButtonAction(JoystickID id, uint8 button, InputState state);
167};
168
170struct NOM_EXPORT JoystickAxisAction: public InputAction
171{
172 virtual ~JoystickAxisAction();
173
181 JoystickAxisAction(JoystickID id, uint8 axis);
182};
183
185struct NOM_EXPORT JoystickHatAction: public InputAction
186{
187 virtual ~JoystickHatAction();
188
197 JoystickHatAction(JoystickID id, uint8 hat, uint8 value);
198};
199
202{
204
214 InputState state = InputState::PRESSED );
215};
216
218struct NOM_EXPORT GameControllerAxisAction: public InputAction
219{
221
230};
231
232} // namespace nom
233
234#endif // include guard defined
Button
Game controller button definitions.
Axis
Game controller axis definitions.
Event event_
The event type and relevant input data; the criteria is used to match against user input.
const nom::event_callback & callback(void) const
Get the callback assigned to the input action.
void operator()(const Event &evt) const
C++ functor; execute the callback assigned for the input action.
virtual const Event & event(void) const
Get the underlying event associated with the input action.
nom::event_callback callback_
The delegate to call upon a successful action to event match.
InputAction()
Default constructor; constructs an invalid action state.
Event handling types.
Definition Event.hpp:458
GameControllerAxisAction(JoystickID id, GameController::Axis axis)
Constructor for initializing an object to a valid action state.
GameControllerButtonAction(JoystickID id, GameController::Button button, InputState state=InputState::PRESSED)
Constructor for initializing an object to a valid action state.
JoystickAxisAction(JoystickID id, uint8 axis)
Constructor for initializing an object to a valid action state.
JoystickButtonAction(JoystickID id, uint8 button, InputState state)
Constructor for initializing an object to a valid action state.
JoystickHatAction(JoystickID id, uint8 hat, uint8 value)
Constructor for initializing an object to a valid action state.
KeyboardAction(int32 sym, uint16 mod, InputState state=InputState::PRESSED)
Constructor for initializing an object to a valid action state.
KeyboardAction(int32 sym, InputState state=InputState::PRESSED)
Constructor for initializing an object to a valid action state.
KeyboardAction(int32 sym, uint16 mod, uint8 repeat, InputState state=InputState::PRESSED)
Constructor for initializing an object to a valid action state.
MouseButtonAction(uint8 button, InputState state=InputState::PRESSED)
Constructor for initializing an object to a valid action state.
MouseButtonAction(uint8 button, uint8 clicks, InputState state=InputState::PRESSED)
Constructor for initializing an object to a valid action state.
MouseWheelAction(MouseWheelDirection dir)
Construct a mouse wheel action.