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