X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Finput%2Fcontrol.cpp;h=3e2398d15860471dd8dc8eee9cad89ce1596e9c5;hb=7302a061c57602203895b616bf54d96269c677c6;hp=18c2ffd62a1d055394e3a2df1d5929d9dd1f227a;hpb=5ffc2443718f5514e4fe27d2aa4ac07022bc4917;p=libs%2Fgui.git diff --git a/source/input/control.cpp b/source/input/control.cpp index 18c2ffd..3e2398d 100644 --- a/source/input/control.cpp +++ b/source/input/control.cpp @@ -1,5 +1,6 @@ #include #include +#include "binarycontrol.h" #include "control.h" #include "device.h" @@ -36,21 +37,36 @@ std::string ControlSource::str() const Control::Control(): - capture_dev(0) + capture_dev(0), + activator(0), + origin(0), + rising_edge(false), + falling_edge(false) { } Control::Control(const ControlSource &s): src(s), - capture_dev(0) + capture_dev(0), + activator(0), + origin(0), + rising_edge(false), + falling_edge(false) { } Control::Control(Device &d, ControlSrcType t, unsigned i): src(d, t, i), - capture_dev(0) + capture_dev(0), + activator(0), + origin(0), + rising_edge(false), + falling_edge(false) { connect_signals(); } +Control::~Control() +{ } + void Control::capture(Device &d) { notify_callbacks(); @@ -78,6 +94,19 @@ void Control::set_source(const ControlSource &s) connect_signals(); } +void Control::set_activator(BinaryControl *ctrl) +{ + notify_callbacks(); + activator = ctrl; + connect_signals(); +} + +void Control::reset_edges() +{ + rising_edge = false; + falling_edge = false; +} + void Control::connect_signals() { switch(src.type) @@ -93,6 +122,9 @@ void Control::connect_signals() src.dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false)); break; } + + if(activator) + activator->signal_release.connect(sigc::mem_fun(this, &Control::deactivate)); } void Control::button_press(unsigned i) @@ -108,13 +140,13 @@ void Control::button_press(unsigned i) connect_signals(); signal_capture_complete.emit(); } - else if(src.type==BUTTON && i==src.index) + else if(src.type==BUTTON && i==src.index && (!activator || activator->get_state())) on_press(); } void Control::button_release(unsigned i) { - if(src.type==BUTTON && i==src.index) + if(src.type==BUTTON && i==src.index && (!activator || activator->get_state())) on_release(); } @@ -140,10 +172,24 @@ void Control::axis_motion(unsigned i, float v, float r) signal_capture_complete.emit(); } } - else if(src.type==AXIS_POS && i==src.index && v>=0) - on_motion(v, r); - else if(src.type==AXIS_NEG && i==src.index && v<=0) - on_motion(-v, -r); + else if(activator && !activator->get_state() && i==src.index) + origin = v; + else if(src.type==AXIS_POS && i==src.index && v>=origin) + on_motion(v-origin, r); + else if(src.type==AXIS_NEG && i==src.index && v<=origin) + on_motion(origin-v, -r); +} + +void Control::deactivate() +{ + if(src.type==BUTTON) + on_release(); + else if(src.type==AXIS_POS || src.type==AXIS_NEG) + { + float v = src.dev->get_axis_value(src.index); + on_motion(0, (src.type==AXIS_POS ? origin-v : v-origin)); + origin = v; + } } } // namespace Input