]> git.tdb.fi Git - libs/gui.git/commitdiff
Allow event handling to be interrupted
authorMikko Rasa <tdb@tdb.fi>
Sun, 24 Mar 2013 15:06:09 +0000 (17:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 24 Mar 2013 15:06:09 +0000 (17:06 +0200)
source/input/control.cpp
source/input/device.h
source/input/hub.cpp
source/input/keyboard.h

index f3f1919d45815535561932e99c7d23b29b59b16d..18c2ffd62a1d055394e3a2df1d5929d9dd1f227a 100644 (file)
@@ -1,3 +1,4 @@
+#include <sigc++/bind_return.h>
 #include <msp/strings/lexicalcast.h>
 #include "control.h"
 #include "device.h"
@@ -54,8 +55,8 @@ void Control::capture(Device &d)
 {
        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));
+       capture_dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
+       capture_dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
 }
 
 void Control::cancel_capture()
@@ -84,12 +85,12 @@ void Control::connect_signals()
        case NONE:
                break;
        case BUTTON:
-               src.dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
-               src.dev->signal_button_release.connect(sigc::mem_fun(this, &Control::button_release));
+               src.dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
+               src.dev->signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_release), false));
                break;
        case AXIS_POS:
        case AXIS_NEG:
-               src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
+               src.dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
                break;
        }
 }
index 3338137eb51e46e50528cf51af02c73beb31ce50..6a436ab2d8a62f0318b893aefca0ac0b068592b1 100644 (file)
@@ -12,13 +12,30 @@ namespace Input {
 Base class for input devices.  Input devices have two types of controls:
 buttons and axes.  Buttons are either on or off.  Axes have a floating point
 value in the range [-1, 1].
+
+Event handlers return a boolean indicating whether the event is considered
+processed.  If a handler returns true, no further handlers are invoked.
 */
 class Device
 {
+protected:
+       struct EventAccumulator
+       {
+               typedef void result_type;
+
+               template<typename Iter>
+               result_type operator()(Iter begin, Iter end) const
+               {
+                       for(Iter i=begin; i!=end; ++i)
+                               if(*i)
+                                       return;
+               }
+       };
+
 public:
-       sigc::signal<void, unsigned> signal_button_press;
-       sigc::signal<void, unsigned> signal_button_release;
-       sigc::signal<void, unsigned, float, float> signal_axis_motion;
+       sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_press;
+       sigc::signal<bool, unsigned>::accumulated<EventAccumulator> signal_button_release;
+       sigc::signal<bool, unsigned, float, float>::accumulated<EventAccumulator> signal_axis_motion;
 
 protected:
        std::string name;
index 4a2d5533aafeb36bea172bee347e0bd4d25ae184..13c88d63b18b32cb064c6feb5ef3b94ab4f43ab9 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdexcept>
 #include <sigc++/bind.h>
+#include <sigc++/bind_return.h>
 #include <msp/core/hash.h>
 #include <msp/core/maputils.h>
 #include "hub.h"
@@ -21,9 +22,9 @@ void Hub::attach(Device &dev)
                ++tag;
 
        devices[tag] = &dev;
-       dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), tag));
-       dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), tag));
-       dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), tag));
+       dev.signal_button_press.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_press), tag), false));
+       dev.signal_button_release.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_release), tag), false));
+       dev.signal_axis_motion.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), tag), false));
 }
 
 std::string Hub::get_button_name(unsigned btn) const
index 822de31df55403e6ebc1211b402af297722b4822..babdf9ac97dfcc283877b19e00f2ec26e7261652 100644 (file)
@@ -15,7 +15,7 @@ are translated to platform-independent values.  See keys.h for a list.
 class Keyboard: public Device
 {
 public:
-       sigc::signal<void, StringCodec::unichar> signal_character;
+       sigc::signal<bool, StringCodec::unichar>::accumulated<EventAccumulator> signal_character;
 
 private:
        Graphics::Window &window;