]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/bindings.cpp
Use nullptr in place of 0 or NULL
[libs/gui.git] / source / input / bindings.cpp
index 85b59418a875b85b17b13ff3a58df1450ce4b004..291c8f152584b552acbf7228053fcb1ed765ee6b 100644 (file)
@@ -1,5 +1,6 @@
-#include <msp/strings/format.h>
 #include "bindings.h"
+#include <algorithm>
+#include <msp/strings/format.h>
 #include "controlscheme.h"
 
 using namespace std;
@@ -11,14 +12,14 @@ vector<Device *> Bindings::resolve_devices(Device &dev) const
 {
        vector<Device *> resolved_devs;
        resolved_devs.reserve(devices.size());
-       for(vector<DeviceRef>::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<Device *> Bindings::resolve_devices(Device &dev) const
 bool Bindings::is_compatible(Device &dev) const
 {
        vector<Device *> resolved_devs = resolve_devices(dev);
-       for(vector<Device *>::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<Device *> resolved_devs = resolve_devices(dev);
        bool applied = false;
-       for(vector<Binding>::const_iterator i=bindings.begin(); i!=bindings.end(); ++i)
+       for(const Binding &b: bindings)
        {
-               Control *ctrl = control_scheme.find(i->control);
-               Device *bdev = (i->device<resolved_devs.size() ? resolved_devs[i->device] : 0);
+               Control *ctrl = control_scheme.find(b.control);
+               Device *bdev = (b.device<resolved_devs.size() ? resolved_devs[b.device] : nullptr);
                if(ctrl && bdev)
                {
-                       ctrl->set_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)