forked from pioneerspacesim/pioneer
/
KeyBindings.h
96 lines (73 loc) · 2.01 KB
/
KeyBindings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright © 2008-2012 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#ifndef KEYBINDINGS_H
#define KEYBINDINGS_H
#include "libs.h"
namespace KeyBindings {
enum Type {
KEYBOARD_KEY,
JOYSTICK_BUTTON,
JOYSTICK_HAT
};
struct KeyBinding {
Type type;
union {
struct {
SDLKey key;
SDLMod mod;
} keyboard;
struct {
Uint8 joystick;
Uint8 button;
} joystickButton;
struct {
Uint8 joystick;
Uint8 hat;
Uint8 direction;
} joystickHat;
} u;
std::string Description() const;
bool Matches(const SDL_keysym *sym) const;
static KeyBinding keyboardBinding(SDLKey key, SDLMod mod);
};
struct KeyAction {
KeyBinding binding;
sigc::signal<void> onPress;
sigc::signal<void> onRelease;
bool IsActive() const;
void CheckSDLEventAndDispatch(const SDL_Event *event);
};
enum AxisDirection {
POSITIVE,
NEGATIVE
};
struct AxisBinding {
Uint8 joystick;
Uint8 axis;
AxisDirection direction;
AxisBinding();
AxisBinding(Uint8 joystick, Uint8 axis, AxisDirection direction);
float GetValue();
std::string Description() const;
};
struct BindingPrototype {
const char *label, *function;
KeyAction *kb;
AxisBinding *ab;
};
void InitBindings();
void UpdateBindings();
bool KeyBindingFromString(const std::string &str, KeyBinding *kb);
KeyBinding KeyBindingFromString(const std::string &str);
std::string KeyBindingToString(const KeyBinding &kb);
bool AxisBindingFromString(const std::string &str, AxisBinding *ab);
AxisBinding AxisBindingFromString(const std::string &str);
std::string AxisBindingToString(const AxisBinding &ab);
void DispatchSDLEvent(const SDL_Event *event);
#define KEY_BINDING(name,a,b,c) extern KeyAction name;
#define AXIS_BINDING(name,a,b,c) extern AxisBinding name;
#include "KeyBindings.inc.h"
#define BINDING_PAGE(name) extern const BindingPrototype BINDING_PROTOS_ ## name[];
#include "KeyBindings.inc.h"
} // namespace KeyBindings
#endif /* KEYBINDINGS_H */