]> git.tdb.fi Git - libs/gui.git/blob - source/input/hub.cpp
51b971748170c60599a09c65afe687c2238e2645
[libs/gui.git] / source / input / hub.cpp
1 /* $Id$
2
3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <sigc++/bind.h>
9 #include <msp/core/except.h>
10 #include "hub.h"
11
12 namespace Msp {
13 namespace Input {
14
15 Hub::Hub()
16 {
17         name="Hub";
18 }
19
20 unsigned Hub::attach(Device &dev)
21 {
22         unsigned index=devices.size();
23         devices.push_back(&dev);
24         dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index));
25         dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index));
26         dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index));
27         return index;
28 }
29
30 std::string Hub::get_button_name(unsigned btn) const
31 {
32         unsigned dev_index=btn>>12;
33         if(dev_index>devices.size())
34                 throw InvalidParameterValue("Button does not exist");
35
36         const Device &dev=*devices[dev_index];
37         return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
38 }
39
40 void Hub::button_press(unsigned btn, unsigned index)
41 {
42         set_button_state(index<<12 | btn&0xFFF, true, true);
43 }
44
45 void Hub::button_release(unsigned btn, unsigned index)
46 {
47         set_button_state(index<<12 | btn&0xFFF, false, true);
48 }
49
50 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
51 {
52         set_axis_value(index<<12 | axis&0xFFF, value, true);
53 }
54
55 } // namespace Input
56 } // namespace Msp