]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/hub.cpp
Go back to using vector to store devices in a Hub
[libs/gui.git] / source / input / hub.cpp
index 0bc818f1adac6e28fdda21a9afdfd639dc8dada3..635ea8a6c935fe9485fee30c87dc55386a3f56ed 100644 (file)
@@ -1,65 +1,65 @@
-/* $Id$
-
-This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <stdexcept>
 #include <sigc++/bind.h>
-#include <msp/core/except.h>
+#include <sigc++/bind_return.h>
+#include <msp/core/hash.h>
+#include <msp/core/maputils.h>
 #include "hub.h"
 
+using namespace std;
+
 namespace Msp {
 namespace Input {
 
 Hub::Hub()
 {
-       name="Hub";
+       name = "Hub";
 }
 
-unsigned Hub::attach(Device &dev)
+void Hub::attach(Device &dev)
 {
-       unsigned index=devices.size();
+       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;
+       dev.signal_button_press.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index), false));
+       dev.signal_button_release.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index), false));
+       dev.signal_axis_motion.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index), false));
 }
 
 std::string Hub::get_button_name(unsigned btn) const
 {
-       unsigned dev_index=btn>>12;
+       unsigned dev_index = btn>>8;
        if(dev_index>=devices.size())
-               throw InvalidParameterValue("Button does not exist");
+               throw out_of_range("Hub::get_button_name");
 
-       const Device &dev=*devices[dev_index];
-       return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
+       const Device &dev = *devices[dev_index];
+       return dev.get_name()+": "+dev.get_button_name(btn&0xFF);
 }
 
 std::string Hub::get_axis_name(unsigned axis) const
 {
-       unsigned dev_index=axis>>12;
+       unsigned dev_index = axis>>8;
        if(dev_index>=devices.size())
-               throw InvalidParameterValue("Axis does not exist");
+               throw out_of_range("Hub::get_axis_name");
 
-       const Device &dev=*devices[dev_index];
-       return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF);
+       const Device &dev = *devices[dev_index];
+       return dev.get_name()+": "+dev.get_axis_name(axis&0xFF);
 }
 
 void Hub::button_press(unsigned btn, unsigned index)
 {
-       set_button_state((index<<12) | (btn&0xFFF), true, true);
+       if(btn<0x100)
+               set_button_state((index<<8) | btn, true, true);
 }
 
 void Hub::button_release(unsigned btn, unsigned index)
 {
-       set_button_state((index<<12) | (btn&0xFFF), false, true);
+       if(btn<0x100)
+               set_button_state((index<<8) | btn, false, true);
 }
 
 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
 {
-       set_axis_value((index<<12) | (axis&0xFFF), value, true);
+       if(axis<0x100)
+               set_axis_value((index<<8) | axis, value, true);
 }
 
 } // namespace Input