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