]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/hub.cpp
Consistently label the graphics part as graphics
[libs/gui.git] / source / input / hub.cpp
index 51b971748170c60599a09c65afe687c2238e2645..cbf9f78a689e083d79057945ba84eb218aba3685 100644 (file)
@@ -1,25 +1,20 @@
-/* $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 "hub.h"
 
+using namespace std;
+
 namespace Msp {
 namespace Input {
 
 Hub::Hub()
 {
-       name="Hub";
+       name = "Hub";
 }
 
 unsigned 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));
@@ -29,27 +24,37 @@ unsigned Hub::attach(Device &dev)
 
 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");
+       unsigned dev_index = btn>>12;
+       if(dev_index>=devices.size())
+               throw invalid_argument("Hub::get_button_name");
 
-       const Device &dev=*devices[dev_index];
+       const Device &dev = *devices[dev_index];
        return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
 }
 
+std::string Hub::get_axis_name(unsigned axis) const
+{
+       unsigned dev_index = axis>>12;
+       if(dev_index>=devices.size())
+               throw invalid_argument("Hub::get_axis_name");
+
+       const Device &dev = *devices[dev_index];
+       return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF);
+}
+
 void Hub::button_press(unsigned btn, unsigned index)
 {
-       set_button_state(index<<12 | btn&0xFFF, true, true);
+       set_button_state((index<<12) | (btn&0xFFF), true, true);
 }
 
 void Hub::button_release(unsigned btn, unsigned index)
 {
-       set_button_state(index<<12 | btn&0xFFF, 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<<12 | axis&0xFFF, value, true);
+       set_axis_value((index<<12) | (axis&0xFFF), value, true);
 }
 
 } // namespace Input