]> git.tdb.fi Git - libs/gui.git/blob - source/inputhub.cpp
Add a control layer suitable for games
[libs/gui.git] / source / inputhub.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 "inputhub.h"
10
11 namespace Msp {
12 namespace Input {
13
14 unsigned Hub::attach(Device &dev)
15 {
16         unsigned index=devices.size();
17         devices.push_back(&dev);
18         dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index));
19         dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index));
20         dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index));
21         return index;
22 }
23
24 void Hub::button_press(unsigned btn, unsigned index)
25 {
26         set_button_state(index<<8 | btn&0xFF, true, true);
27 }
28
29 void Hub::button_release(unsigned btn, unsigned index)
30 {
31         set_button_state(index<<8 | btn&0xFF, false, true);
32 }
33
34 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
35 {
36         set_axis_value(index<<8 | axis&0xFF, value, true);
37 }
38
39 } // namespace Input
40 } // namespace Msp