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