From 5ffc2443718f5514e4fe27d2aa4ac07022bc4917 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 24 Mar 2013 17:06:09 +0200 Subject: [PATCH] Allow event handling to be interrupted --- source/input/control.cpp | 11 ++++++----- source/input/device.h | 23 ++++++++++++++++++++--- source/input/hub.cpp | 7 ++++--- source/input/keyboard.h | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/source/input/control.cpp b/source/input/control.cpp index f3f1919..18c2ffd 100644 --- a/source/input/control.cpp +++ b/source/input/control.cpp @@ -1,3 +1,4 @@ +#include #include #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; } } diff --git a/source/input/device.h b/source/input/device.h index 3338137..6a436ab 100644 --- a/source/input/device.h +++ b/source/input/device.h @@ -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 + result_type operator()(Iter begin, Iter end) const + { + for(Iter i=begin; i!=end; ++i) + if(*i) + return; + } + }; + public: - sigc::signal signal_button_press; - sigc::signal signal_button_release; - sigc::signal signal_axis_motion; + sigc::signal::accumulated signal_button_press; + sigc::signal::accumulated signal_button_release; + sigc::signal::accumulated signal_axis_motion; protected: std::string name; diff --git a/source/input/hub.cpp b/source/input/hub.cpp index 4a2d553..13c88d6 100644 --- a/source/input/hub.cpp +++ b/source/input/hub.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #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 diff --git a/source/input/keyboard.h b/source/input/keyboard.h index 822de31..babdf9a 100644 --- a/source/input/keyboard.h +++ b/source/input/keyboard.h @@ -15,7 +15,7 @@ are translated to platform-independent values. See keys.h for a list. class Keyboard: public Device { public: - sigc::signal signal_character; + sigc::signal::accumulated signal_character; private: Graphics::Window &window; -- 2.45.2