X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fbindings.cpp;h=291c8f152584b552acbf7228053fcb1ed765ee6b;hb=11ab96ba152e389814543a6398e2cd6f17a31092;hp=85b59418a875b85b17b13ff3a58df1450ce4b004;hpb=7302a061c57602203895b616bf54d96269c677c6;p=libs%2Fgui.git diff --git a/source/input/bindings.cpp b/source/input/bindings.cpp index 85b5941..291c8f1 100644 --- a/source/input/bindings.cpp +++ b/source/input/bindings.cpp @@ -1,5 +1,6 @@ -#include #include "bindings.h" +#include +#include #include "controlscheme.h" using namespace std; @@ -11,14 +12,14 @@ vector Bindings::resolve_devices(Device &dev) const { vector resolved_devs; resolved_devs.reserve(devices.size()); - for(vector::const_iterator i=devices.begin(); i!=devices.end(); ++i) + for(const DeviceRef &d: devices) { - if(i->type!=UNSPECIFIED) - resolved_devs.push_back(dev.find_subdevice(i->type)); - else if(!i->name.empty()) - resolved_devs.push_back(dev.find_subdevice(i->name)); + if(d.type!=UNSPECIFIED) + resolved_devs.push_back(dev.find_subdevice(d.type)); + else if(!d.name.empty()) + resolved_devs.push_back(dev.find_subdevice(d.name)); else - resolved_devs.push_back(0); + resolved_devs.push_back(nullptr); } return resolved_devs; } @@ -26,23 +27,20 @@ vector Bindings::resolve_devices(Device &dev) const bool Bindings::is_compatible(Device &dev) const { vector resolved_devs = resolve_devices(dev); - for(vector::const_iterator i=resolved_devs.begin(); i!=resolved_devs.end(); ++i) - if(!*i) - return false; - return true; + return all_of(resolved_devs.begin(), resolved_devs.end(), [](Device *d) -> bool { return d; }); } bool Bindings::apply_to(ControlScheme &control_scheme, Device &dev) { vector resolved_devs = resolve_devices(dev); bool applied = false; - for(vector::const_iterator i=bindings.begin(); i!=bindings.end(); ++i) + for(const Binding &b: bindings) { - Control *ctrl = control_scheme.find(i->control); - Device *bdev = (i->devicedevice] : 0); + Control *ctrl = control_scheme.find(b.control); + Device *bdev = (b.deviceset_source(*bdev, i->type, i->index); + ctrl->set_source(*bdev, b.type, b.index); applied = true; } } @@ -103,6 +101,8 @@ void Bindings::Binding::Loader::init_actions() add("button", &Loader::button); add("device", &Binding::device); add("key", &Loader::key); + add("mouse_axis", &Loader::mouse_axis); + add("mouse_button", &Loader::mouse_button); } void Bindings::Binding::Loader::axis(unsigned a, AxisSide s)