X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fdevice.h;h=7df388b18c34f5f0d2dc1001ac61e27ae5b9afa8;hb=f9ebab54c3debe98e108790be9c21f43f4de116f;hp=d1c96f23be04e890d56755bc2ef55b4043c5aa8b;hpb=999ca92aa9ee10585c0b2094d84364159253982f;p=libs%2Fgui.git diff --git a/source/input/device.h b/source/input/device.h index d1c96f2..7df388b 100644 --- a/source/input/device.h +++ b/source/input/device.h @@ -1,12 +1,5 @@ -/* $Id$ - -This file is part of libmspgbase -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifndef MSP_GBASE_INPUTDEVICE_H_ -#define MSP_GBASE_INPUTDEVICE_H_ +#ifndef MSP_INPUT_INPUTDEVICE_H_ +#define MSP_INPUT_INPUTDEVICE_H_ #include #include @@ -17,30 +10,45 @@ 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, with range depending on the device. +buttons and axes. Buttons are either on or off. Axes have a floating point +value nominally 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; - std::vector buttons; + std::vector buttons; std::vector axes; - float axis_threshold; - float axis_dead_zone; - Device() { } + Device(); public: - virtual ~Device() { } + virtual ~Device(); + const std::string &get_name() const { return name; } - bool get_button_state(unsigned) const; + bool get_button_state(unsigned) const; float get_axis_value(unsigned) const; - float get_axis_threshold() const { return axis_threshold; } virtual std::string get_button_name(unsigned) const; virtual std::string get_axis_name(unsigned) const;