]> git.tdb.fi Git - libs/gui.git/blobdiff - source/inputhub.cpp
Add names for input devices
[libs/gui.git] / source / inputhub.cpp
index 27a340a134015433e19cace7ed65824f784558ef..1fa95d0fc3f41a3dfbf5c75b7636881dd4e1239e 100644 (file)
@@ -6,11 +6,17 @@ Distributed under the LGPL
 */
 
 #include <sigc++/bind.h>
+#include <msp/core/except.h>
 #include "inputhub.h"
 
 namespace Msp {
 namespace Input {
 
+Hub::Hub()
+{
+       name="Hub";
+}
+
 unsigned Hub::attach(Device &dev)
 {
        unsigned index=devices.size();
@@ -21,19 +27,29 @@ unsigned Hub::attach(Device &dev)
        return index;
 }
 
+std::string Hub::get_button_name(unsigned btn) const
+{
+       unsigned dev_index=btn>>12;
+       if(dev_index>devices.size())
+               throw InvalidParameterValue("Button does not exist");
+
+       const Device &dev=*devices[dev_index];
+       return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
+}
+
 void Hub::button_press(unsigned btn, unsigned index)
 {
-       set_button_state(index<<8 | btn&0xFF, true, true);
+       set_button_state(index<<12 | btn&0xFFF, true, true);
 }
 
 void Hub::button_release(unsigned btn, unsigned index)
 {
-       set_button_state(index<<8 | btn&0xFF, false, true);
+       set_button_state(index<<12 | btn&0xFFF, false, true);
 }
 
 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
 {
-       set_axis_value(index<<8 | axis&0xFF, value, true);
+       set_axis_value(index<<12 | axis&0xFFF, value, true);
 }
 
 } // namespace Input