]> git.tdb.fi Git - libs/gui.git/blobdiff - source/inputhub.cpp
Add input hub
[libs/gui.git] / source / inputhub.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