1 #include <msp/strings/format.h>
3 #include "controlscheme.h"
10 vector<Device *> Bindings::resolve_devices(Device &dev) const
12 vector<Device *> resolved_devs;
13 resolved_devs.reserve(devices.size());
14 for(vector<DeviceRef>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
16 if(i->type!=UNSPECIFIED)
17 resolved_devs.push_back(dev.find_subdevice(i->type));
18 else if(!i->name.empty())
19 resolved_devs.push_back(dev.find_subdevice(i->name));
21 resolved_devs.push_back(0);
26 bool Bindings::is_compatible(Device &dev) const
28 vector<Device *> resolved_devs = resolve_devices(dev);
29 for(vector<Device *>::const_iterator i=resolved_devs.begin(); i!=resolved_devs.end(); ++i)
35 bool Bindings::apply_to(ControlScheme &control_scheme, Device &dev)
37 vector<Device *> resolved_devs = resolve_devices(dev);
39 for(vector<Binding>::const_iterator i=bindings.begin(); i!=bindings.end(); ++i)
41 Control *ctrl = control_scheme.find(i->control);
42 Device *bdev = (i->device<resolved_devs.size() ? resolved_devs[i->device] : 0);
45 ctrl->set_source(*bdev, i->type, i->index);
54 DataFile::Loader::ActionMap Bindings::Loader::shared_actions;
56 Bindings::Loader::Loader(Bindings &b):
57 ObjectLoader<Bindings>(b)
59 set_actions(shared_actions);
62 void Bindings::Loader::init_actions()
64 add("binding", &Loader::binding);
65 add("device", &Loader::device_type);
66 add("device", &Loader::device_name);
69 void Bindings::Loader::binding(const string &c)
74 obj.bindings.push_back(bind);
77 void Bindings::Loader::device_type(DeviceType t)
81 obj.devices.push_back(dev);
84 void Bindings::Loader::device_name(const string &n)
88 obj.devices.push_back(dev);
92 DataFile::Loader::ActionMap Bindings::Binding::Loader::shared_actions;
94 Bindings::Binding::Loader::Loader(Binding &b):
95 ObjectLoader<Binding>(b)
97 set_actions(shared_actions);
100 void Bindings::Binding::Loader::init_actions()
102 add("axis", &Loader::axis);
103 add("button", &Loader::button);
104 add("device", &Binding::device);
105 add("key", &Loader::key);
106 add("mouse_axis", &Loader::mouse_axis);
107 add("mouse_button", &Loader::mouse_button);
110 void Bindings::Binding::Loader::axis(unsigned a, AxisSide s)
112 obj.type = (s==NEGATIVE ? AXIS_NEG : AXIS_POS);
116 void Bindings::Binding::Loader::button(unsigned b)
123 void operator>>(const LexicalConverter &conv, Bindings::AxisSide &side)
125 if(conv.get()=="POSITIVE")
126 side = Bindings::POSITIVE;
127 else if(conv.get()=="NEGATIVE")
128 side = Bindings::NEGATIVE;
130 throw lexical_error(format("conversion of '%s' to AxisSide", conv.get()));
133 void operator<<(LexicalConverter &conv, Bindings::AxisSide side)
137 case Bindings::POSITIVE: conv.result("POSITIVE"); break;
138 case Bindings::NEGATIVE: conv.result("NEGATIVE"); break;
139 default: conv.result(format("AxisSide(%#x)", static_cast<int>(side)));