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#ifndef HEADER_SUPERTUX_CONTROL_CONTROLLER_HPP
18#define HEADER_SUPERTUX_CONTROL_CONTROLLER_HPP
19
20#include <iosfwd>
21#include <boost/optional.hpp>
22
23enum class Control {
24 LEFT = 0,
25 RIGHT,
26 UP,
27 DOWN,
28
29 JUMP,
30 ACTION,
31
32 START,
33 ESCAPE,
34 MENU_SELECT,
35 MENU_SELECT_SPACE,
36 MENU_BACK,
37 REMOVE,
38
39 CHEAT_MENU,
40 DEBUG_MENU,
41 CONSOLE,
42
43 PEEK_LEFT,
44 PEEK_RIGHT,
45 PEEK_UP,
46 PEEK_DOWN,
47
48 CONTROLCOUNT
49};
50
51std::ostream& operator<<(std::ostream& os, Control control);
52
53std::string Control_to_string(Control control);
54boost::optional<Control> Control_from_string(const std::string& text);
55
56class Controller
57{
58public:
59 Controller();
60 virtual ~Controller();
61
62 virtual void update();
63
64 void set_control(Control control, bool value);
65
66 /** returns true if the control is pressed down */
67 bool hold(Control control) const;
68
69 /** returns true if the control has just been pressed down this frame */
70 bool pressed(Control control) const;
71
72 /** returns true if the control has just been released this frame */
73 bool released(Control control) const;
74
75 void reset();
76
77protected:
78 /** current control status */
79 bool m_controls[static_cast<int>(Control::CONTROLCOUNT)];
80
81 /** control status at last frame */
82 bool m_old_controls[static_cast<int>(Control::CONTROLCOUNT)];
83
84private:
85 Controller(const Controller&) = delete;
86 Controller& operator=(const Controller&) = delete;
87};
88
89#endif
90
91/* EOF */
92