]> git.tdb.fi Git - libs/gui.git/commitdiff
Add input hub
authorMikko Rasa <tdb@tdb.fi>
Mon, 27 Aug 2007 14:29:12 +0000 (14:29 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 27 Aug 2007 14:29:12 +0000 (14:29 +0000)
Connect Keyboard to key_release

source/inputhub.cpp [new file with mode: 0644]
source/inputhub.h
source/keyboard.cpp

diff --git a/source/inputhub.cpp b/source/inputhub.cpp
new file mode 100644 (file)
index 0000000..d2fc863
--- /dev/null
@@ -0,0 +1,33 @@
+#include <sigc++/bind.h>
+#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
index 1d4b465dfce5180c328a8b6d9658ddf7cf6a491b..b20fd43468fffc093d03e043bbc4d105d6fe60e3 100644 (file)
@@ -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<Device *> 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
index 4bc586ca3ff5deb0c61cccd4208e42aa8ac3e240..45ef0920448a12889a2ad9b1b7387c7b4c4987f3 100644 (file)
@@ -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)