Debian Codegraph @

src/io/controls.h

raw symbols SCIP
1
2 /**
3 *
4 * @file controls.h
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd August 2005: Created OpenJazz.h
10 * - 13th July 2009: Created controls.h from parts of OpenJazz.h
11 *
12 * @par Licence:
13 * Copyright (c) 2005-2012 AJ Thomson
14 * Copyright (c) 2015-2026 Carsten Teibes
15 *
16 * OpenJazz is distributed under the terms of
17 * the GNU General Public License, version 2.0
18 *
19 */
20
21 #ifndef OJ_CONTROLS_H
22 #define OJ_CONTROLS_H
23
24 #include "loop.h"
25 #include "OpenJazz.h"
26
27 // Constants
28
29 // Indexes for the keys / buttons / axes player controls arrays
30 #define C_UP 0
31 #define C_DOWN 1
32 #define C_LEFT 2
33 #define C_RIGHT 3
34 #define C_JUMP 4
35 #define C_SWIM 5
36 #define C_FIRE 6
37 #define C_CHANGE 7 /* Change weapon */
38 #define C_ENTER 8
39 #define C_ESCAPE 9
40 #define C_BLASTER 10
41 #define C_TOASTER 11
42 #define C_MISSILE 12
43 #define C_BOUNCER 13
44 #define C_TNT 14
45 #define C_STATS 15
46 #define C_PAUSE 16
47 #define C_YES 17
48 #define C_NO 18
49 // Size of those arrays
50 #define CONTROLS 19
51
52 // Time interval
53 #define T_KEY 200
54
55
56 // Class
57
58 union SDL_Event;
59
60 /// Keeps track of all control input
61 class Controls {
62
63 private:
64 typedef struct {
65
66 int key; ///< Keyboard key
67 bool pressed; ///< Whether or not the key is pressed
68
69 } Keys;
70
71 typedef struct {
72
73 int button; ///< Joystick button
74 bool pressed; ///< Whether or not the button is pressed
75
76 } Buttons;
77
78 typedef struct {
79
80 int axis; ///< Joystick axis
81 bool direction; ///< Axis direction
82 bool pressed; ///< Whether or not the axis is pressed in the given direction
83
84 } Axes;
85
86 typedef struct {
87
88 int hat; ///< Joystick hat
89 int direction; ///< Hat direction
90 bool pressed; ///< Whether or not the hat is pressed in the given direction
91
92 } Hats;
93
94 typedef struct {
95
96 unsigned int time; ///< The time from which the control will respond to being pressed
97 bool state; ///< Whether or not the control is being used
98
99 } ControlState;
100
101 Keys keys[CONTROLS];
102 Buttons buttons[CONTROLS];
103 Axes axes[CONTROLS];
104 Hats hats[CONTROLS];
105 ControlState controlstates[CONTROLS];
106
107 int cursorX; ///< X-coordinate of the cursor
108 int cursorY; ///< Y-coordinate of the cursor
109 bool cursorPressed; ///< Whether or not the cursor is being pressed
110 bool cursorReleased; ///< Whether or not the cursor has been released
111 int wheelUp; ///< How many times the wheel has been scrolled upwards
112 int wheelDown; ///< How many times the wheel has been scrolled downwards
113
114 void setCursor (int x, int y, bool pressed);
115
116 public:
117 Controls ();
118
119 void init();
120 void deinit();
121
122 void setKey (int control, int key);
123 void setButton (int control, int button);
124 void setAxis (int control, int axis, bool direction);
125 void setHat (int control, int hat, int direction);
126 int getKey (int control);
127 int getButton (int control);
128 int getAxis (int control);
129 int getAxisDirection (int control);
130 int getHat (int control);
131 int getHatDirection (int control);
132
133 int update (SDL_Event *event, LoopType type);
134 void loop ();
135
136 bool getState (int control);
137 bool release (int control);
138 bool getCursor (int& x, int& y);
139 bool wasCursorReleased ();
140
141 };
142
143
144 // Variable
145
146 EXTERN Controls controls;
147
148 #endif