From: Mikko Rasa Date: Mon, 27 Aug 2007 14:29:12 +0000 (+0000) Subject: Add input hub X-Git-Tag: 0.9~22 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4d297f94791ef51e574c1345e8dcc5a15aee2149;p=libs%2Fgui.git Add input hub Connect Keyboard to key_release --- diff --git a/source/inputhub.cpp b/source/inputhub.cpp new file mode 100644 index 0000000..d2fc863 --- /dev/null +++ b/source/inputhub.cpp @@ -0,0 +1,33 @@ +#include +#include "inputhub.h" + +namespace Msp { +namespace Input { + +unsigned Hub::attach(Device &dev) +{ + unsigned index=devices.size(); + devices.push_back(&dev); + dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index)); + dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index)); + dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index)); + return index; +} + +void Hub::button_press(unsigned btn, unsigned index) +{ + set_button_state(index<<8 | btn&0xFF, true, true); +} + +void Hub::button_release(unsigned btn, unsigned index) +{ + set_button_state(index<<8 | btn&0xFF, false, true); +} + +void Hub::axis_motion(unsigned axis, float value, float, unsigned index) +{ + set_axis_value(index<<8 | axis&0xFF, value, true); +} + +} // namespace Input +} // namespace Msp diff --git a/source/inputhub.h b/source/inputhub.h index 1d4b465..b20fd43 100644 --- a/source/inputhub.h +++ b/source/inputhub.h @@ -13,8 +13,28 @@ Distributed under the LGPL namespace Msp { namespace Input { +/** +The Hub device collects events from multiple input devices and presents an +aggregate of them. Button and axis numbers are mapped to unique values. +*/ class Hub: public Device { +protected: + std::vector devices; + +public: + /** + Attaches an input device to the hub. + + @param dev Device to attach + + @return Index of the device within the hub + */ + unsigned attach(Device &dev); +protected: + void button_press(unsigned, unsigned); + void button_release(unsigned, unsigned); + void axis_motion(unsigned, float, float, unsigned); }; } // namespace Input diff --git a/source/keyboard.cpp b/source/keyboard.cpp index 4bc586c..45ef092 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -16,6 +16,7 @@ Keyboard::Keyboard(Window &window) buttons.resize(256, false); window.signal_key_press.connect(sigc::mem_fun(this, &Keyboard::key_press)); + window.signal_key_release.connect(sigc::mem_fun(this, &Keyboard::key_release)); } void Keyboard::key_press(unsigned key, unsigned, unsigned)