]> git.tdb.fi Git - libs/gui.git/blob - source/input/bindings.h
Add decorations for things which should be exported from the library
[libs/gui.git] / source / input / bindings.h
1 #ifndef MSP_INPUT_BINDINGS_H_
2 #define MSP_INPUT_BINDINGS_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include <msp/graphics/mspgui_api.h>
6 #include <msp/strings/lexicalcast.h>
7 #include "control.h"
8 #include "device.h"
9 #include "keys.h"
10
11 namespace Msp {
12 namespace Input {
13
14 class ControlScheme;
15
16 class MSPGUI_API Bindings
17 {
18 public:
19         class MSPGUI_API Loader: public DataFile::ObjectLoader<Bindings>
20         {
21         private:
22                 static ActionMap shared_actions;
23
24         public:
25                 Loader(Bindings &);
26
27         private:
28                 void init_actions() override;
29
30                 void binding(const std::string &);
31                 void device_type(DeviceType);
32                 void device_name(const std::string &);
33         };
34
35         struct DeviceRef
36         {
37                 DeviceType type = UNSPECIFIED;
38                 std::string name;
39         };
40
41 private:
42         enum AxisSide
43         {
44                 POSITIVE,
45                 NEGATIVE
46         };
47
48         friend void operator>>(const LexicalConverter &, AxisSide &);
49         friend void operator<<(LexicalConverter &, AxisSide);
50
51 public:
52         struct Binding
53         {
54                 class Loader: public DataFile::ObjectLoader<Binding>
55                 {
56                 private:
57                         static ActionMap shared_actions;
58
59                 public:
60                         Loader(Binding &);
61
62                 private:
63                         void init_actions() override;
64
65                         void axis(unsigned, AxisSide);
66                         void button(unsigned);
67                         void key(Key k) { button(k); }
68                         void mouse_axis(MouseAxis a, AxisSide s) { axis(a, s); }
69                         void mouse_button(MouseButton b) { button(b); }
70                 };
71
72                 std::string control;
73                 unsigned device = 0;
74                 ControlSrcType type = NO_SOURCE;
75                 unsigned index = 0;
76         };
77
78 private:
79         std::vector<DeviceRef> devices;
80         std::vector<Binding> bindings;
81
82 public:
83         const std::vector<DeviceRef> &get_devices() const { return devices; }
84         std::vector<Device *> resolve_devices(Device &) const;
85         bool is_compatible(Device &) const;
86         const std::vector<Binding> &get_bindings() const { return bindings; }
87
88         bool apply_to(ControlScheme &, Device &);
89 };
90
91 } // namespace Input
92 } // namespace Msp
93
94 #endif