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