+#include <sigc++/bind_return.h>
#include <msp/strings/lexicalcast.h>
#include "control.h"
#include "device.h"
{
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()
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;
}
}
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;
#include <stdexcept>
#include <sigc++/bind.h>
+#include <sigc++/bind_return.h>
#include <msp/core/hash.h>
#include <msp/core/maputils.h>
#include "hub.h"
++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
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;