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