]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/control.cpp
Normalize device axis ranges to [-1, 1]
[libs/gui.git] / source / input / control.cpp
index 8ddcdd772cf2af96cc7e7f51f42e978edebe87cd..ffa02932f7db9c3b3159c45ab589d2c2f434ae1e 100644 (file)
@@ -29,8 +29,10 @@ std::string ControlSource::str() const
 {
        if(type==BUTTON)
                return dev->get_button_name(index);
-       else if(type==AXIS_POS || type==AXIS_NEG)
-               return dev->get_axis_name(index);
+       else if(type==AXIS_POS)
+               return dev->get_axis_name(index)+" +";
+       else if(type==AXIS_NEG)
+               return dev->get_axis_name(index)+" -";
        else if(type==NONE)
                return "None";
 
@@ -54,36 +56,30 @@ Control::Control(Device &d, ControlSrcType t, unsigned i):
        connect_signals();
 }
 
-Control::Control(const Control &c):
-       trackable(c),
-       src(c.src),
-       capture_dev(0)
+void Control::capture(Device &d)
 {
-       connect_signals();
+       notify_callbacks();
+       capture_dev=&d;
+       capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
+       capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
 }
 
-Control &Control::operator=(const Control &c)
+void Control::cancel_capture()
 {
        notify_callbacks();
-       src=c.src;
        capture_dev=0;
        connect_signals();
-
-       return *this;
 }
 
-void Control::capture(Device &d)
+void Control::set_source(Device &d, ControlSrcType t, unsigned i)
 {
-       notify_callbacks();
-       capture_dev=&d;
-       capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
-       capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
+       set_source(ControlSource(d, t, i));
 }
 
-void Control::cancel_capture()
+void Control::set_source(const ControlSource &s)
 {
        notify_callbacks();
-       capture_dev=0;
+       src=s;
        connect_signals();
 }
 
@@ -134,9 +130,9 @@ void Control::axis_motion(unsigned i, float v, float r)
        if(capture_dev)
        {
                ControlSrcType type=NONE;
-               if(v<-src.dev->get_axis_threshold())
+               if(v<-0.9)
                        type=AXIS_NEG;
-               else if(v>src.dev->get_axis_threshold())
+               else if(v>0.9)
                        type=AXIS_POS;
 
                if(type!=NONE)