Merge button and stick input gracefully in GameControllerManager
[supertux.git] / src / control / controller.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "control/controller.hpp"
18
19 const char* Controller::controlNames[] = {
20   "left",
21   "right",
22   "up",
23   "down",
24   "jump",
25   "action",
26   "pause-menu",
27   "menu-select",
28   "menu-back",
29   "console",
30   "peek-left",
31   "peek-right",
32   "peek-up",
33   "peek-down",
34   0
35 };
36
37 Controller::Controller()
38 {
39   reset();
40 }
41
42 Controller::~Controller()
43 {}
44
45 void
46 Controller::reset()
47 {
48   for(int i = 0; i < CONTROLCOUNT; ++i) {
49     controls[i] = false;
50     oldControls[i] = false;
51   }
52 }
53
54 void
55 Controller::set_control(Control control, bool value)
56 {
57   controls[control] = value;
58 }
59
60 bool
61 Controller::hold(Control control)
62 {
63   return controls[control];
64 }
65
66 bool
67 Controller::pressed(Control control)
68 {
69   return !oldControls[control] && controls[control];
70 }
71
72 bool
73 Controller::released(Control control)
74 {
75   return oldControls[control] && !controls[control];
76 }
77
78 void
79 Controller::update()
80 {
81   for(int i = 0; i < CONTROLCOUNT; ++i)
82     oldControls[i] = controls[i];
83 }
84
85 /* EOF */