--- /dev/null
+#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
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
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)