]> git.tdb.fi Git - libs/gui.git/blob - source/inputdevice.cpp
Initial revision
[libs/gui.git] / source / inputdevice.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 "inputdevice.h"
9
10 namespace Msp {
11 namespace Input {
12
13 bool Device::get_button_state(unsigned btn)
14 {
15         if(btn>buttons.size())
16                 return false;
17
18         return buttons[btn];
19 }
20
21 float Device::get_axis_value(unsigned axis)
22 {
23         if(axis>axes.size())
24                 return 0;
25
26         return axes[axis];
27 }
28
29 void Device::set_button_state(unsigned btn, bool state, bool event)
30 {
31         if(btn>=buttons.size())
32                 buttons.resize(btn+1, false);
33
34         if(state!=buttons[btn])
35         {
36                 buttons[btn]=state;
37
38                 if(event)
39                 {
40                         if(state)
41                                 signal_button_press.emit(btn);
42                         else
43                                 signal_button_release.emit(btn);
44                 }
45         }
46 }
47
48 void Device::set_axis_value(unsigned axis, float value, bool event)
49 {
50         if(axis>=axes.size())
51                 axes.resize(axis+1, 0);
52
53         if(value!=axes[axis])
54         {
55                 float old=axes[axis];
56                 axes[axis]=value;
57
58                 if(event)
59                         signal_axis_motion.emit(axis, value, value-old);
60         }
61 }
62
63 } // namespace Input
64 } // namespace Msp