ScummVM API documentation
inputengine.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on Broken Sword 2.5 engine
24  *
25  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26  *
27  * Licensed under GNU GPL v2
28  *
29  */
30 
31 /*
32  * BS_InputEngine
33  * -------------
34  * This is the input interface engine that contains all the methods that an
35  * input source must implement.
36  * All input engines must be derived from this class.
37  *
38  * Autor: Alex Arnst
39  */
40 
41 #ifndef SWORD25_INPUTENGINE_H
42 #define SWORD25_INPUTENGINE_H
43 
44 #include "common/keyboard.h"
45 
46 #include "sword25/kernel/common.h"
47 #include "sword25/kernel/service.h"
48 #include "sword25/kernel/persistable.h"
49 
50 namespace Sword25 {
51 
53 
54 class InputEngine : public Service, public Persistable {
55 public:
56  InputEngine(Kernel *pKernel);
57  ~InputEngine() override;
58 
59  // NOTE: These codes are registered in inputengine_script.cpp
60  // If you add or remove entries of this enum, you must also adjust
61  // the above file.
62  enum KEY_CODES {
63  KEY_BACKSPACE = Common::KEYCODE_BACKSPACE,
64  KEY_TAB = Common::KEYCODE_TAB,
65  KEY_CLEAR = Common::KEYCODE_CLEAR,
66  KEY_RETURN = Common::KEYCODE_RETURN,
67  KEY_PAUSE = Common::KEYCODE_PAUSE,
68  KEY_CAPSLOCK = Common::KEYCODE_CAPSLOCK,
69  KEY_ESCAPE = Common::KEYCODE_ESCAPE,
70  KEY_SPACE = Common::KEYCODE_SPACE,
71  KEY_PAGEUP = Common::KEYCODE_PAGEUP,
72  KEY_PAGEDOWN = Common::KEYCODE_PAGEDOWN,
73  KEY_END = Common::KEYCODE_END,
74  KEY_HOME = Common::KEYCODE_HOME,
75  KEY_LEFT = Common::KEYCODE_LEFT,
76  KEY_UP = Common::KEYCODE_UP,
77  KEY_RIGHT = Common::KEYCODE_RIGHT,
78  KEY_DOWN = Common::KEYCODE_DOWN,
79  KEY_PRINTSCREEN = Common::KEYCODE_PRINT,
80  KEY_INSERT = Common::KEYCODE_INSERT,
81  KEY_DELETE = Common::KEYCODE_DELETE,
82  KEY_0 = Common::KEYCODE_0,
83  KEY_1 = Common::KEYCODE_1,
84  KEY_2 = Common::KEYCODE_2,
85  KEY_3 = Common::KEYCODE_3,
86  KEY_4 = Common::KEYCODE_4,
87  KEY_5 = Common::KEYCODE_5,
88  KEY_6 = Common::KEYCODE_6,
89  KEY_7 = Common::KEYCODE_7,
90  KEY_8 = Common::KEYCODE_8,
91  KEY_9 = Common::KEYCODE_9,
92  KEY_A = Common::KEYCODE_a,
93  KEY_B = Common::KEYCODE_b,
94  KEY_C = Common::KEYCODE_c,
95  KEY_D = Common::KEYCODE_d,
96  KEY_E = Common::KEYCODE_e,
97  KEY_F = Common::KEYCODE_f,
98  KEY_G = Common::KEYCODE_g,
99  KEY_H = Common::KEYCODE_h,
100  KEY_I = Common::KEYCODE_i,
101  KEY_J = Common::KEYCODE_j,
102  KEY_K = Common::KEYCODE_k,
103  KEY_L = Common::KEYCODE_l,
104  KEY_M = Common::KEYCODE_m,
105  KEY_N = Common::KEYCODE_n,
106  KEY_O = Common::KEYCODE_o,
107  KEY_P = Common::KEYCODE_p,
108  KEY_Q = Common::KEYCODE_q,
109  KEY_R = Common::KEYCODE_r,
110  KEY_S = Common::KEYCODE_s,
111  KEY_T = Common::KEYCODE_t,
112  KEY_U = Common::KEYCODE_u,
113  KEY_V = Common::KEYCODE_v,
114  KEY_W = Common::KEYCODE_w,
115  KEY_X = Common::KEYCODE_x,
116  KEY_Y = Common::KEYCODE_y,
117  KEY_Z = Common::KEYCODE_z,
118  KEY_NUMPAD0 = Common::KEYCODE_KP0,
119  KEY_NUMPAD1 = Common::KEYCODE_KP1,
120  KEY_NUMPAD2 = Common::KEYCODE_KP2,
121  KEY_NUMPAD3 = Common::KEYCODE_KP3,
122  KEY_NUMPAD4 = Common::KEYCODE_KP4,
123  KEY_NUMPAD5 = Common::KEYCODE_KP5,
124  KEY_NUMPAD6 = Common::KEYCODE_KP6,
125  KEY_NUMPAD7 = Common::KEYCODE_KP7,
126  KEY_NUMPAD8 = Common::KEYCODE_KP8,
127  KEY_NUMPAD9 = Common::KEYCODE_KP9,
128  KEY_MULTIPLY = Common::KEYCODE_KP_MULTIPLY,
129  KEY_ADD = Common::KEYCODE_KP_PLUS,
130  KEY_SEPARATOR = Common::KEYCODE_EQUALS, // FIXME: This mapping is just a wild guess!!
131  KEY_SUBTRACT = Common::KEYCODE_KP_MINUS,
132  KEY_DECIMAL = Common::KEYCODE_KP_PERIOD,
133  KEY_DIVIDE = Common::KEYCODE_KP_DIVIDE,
134  KEY_F1 = Common::KEYCODE_F1,
135  KEY_F2 = Common::KEYCODE_F2,
136  KEY_F3 = Common::KEYCODE_F3,
137  KEY_F4 = Common::KEYCODE_F4,
138  KEY_F5 = Common::KEYCODE_F5,
139  KEY_F6 = Common::KEYCODE_F6,
140  KEY_F7 = Common::KEYCODE_F7,
141  KEY_F8 = Common::KEYCODE_F8,
142  KEY_F9 = Common::KEYCODE_F9,
143  KEY_F10 = Common::KEYCODE_F10,
144  KEY_F11 = Common::KEYCODE_F11,
145  KEY_F12 = Common::KEYCODE_F12,
146  KEY_NUMLOCK = Common::KEYCODE_NUMLOCK,
147  KEY_SCROLL = Common::KEYCODE_SCROLLOCK,
148  KEY_LSHIFT = Common::KEYCODE_LSHIFT,
149  KEY_RSHIFT = Common::KEYCODE_RSHIFT,
150  KEY_LCONTROL = Common::KEYCODE_LCTRL,
151  KEY_RCONTROL = Common::KEYCODE_RCTRL
152  };
153 
154  // NOTE: These codes are registered in inputengine_script.cpp
155  // If you add or remove entries of this enum, you must also adjust
156  // the above file.
157  enum KEY_COMMANDS {
158  KEY_COMMAND_ENTER = 1,
159  KEY_COMMAND_LEFT = 2,
160  KEY_COMMAND_RIGHT = 3,
161  KEY_COMMAND_HOME = 4,
162  KEY_COMMAND_END = 5,
163  KEY_COMMAND_BACKSPACE = 6,
164  KEY_COMMAND_TAB = 7,
165  KEY_COMMAND_INSERT = 8,
166  KEY_COMMAND_DELETE = 9
167  };
168 
172 
177  bool init();
178 
186  void update();
187 
191  bool isLeftMouseDown();
192 
196  bool isRightMouseDown();
197 
204  bool wasLeftMouseDown();
205 
212  bool wasRightMouseDown();
213 
217  bool isLeftDoubleClick();
218 
222  int getMouseX();
223 
227  int getMouseY();
228 
234  bool isKeyDown(uint keyCode);
235 
244  bool wasKeyDown(uint keyCode);
245 
246  typedef void (*CharacterCallback)(int command);
247 
259  void setCharacterCallback(CharacterCallback callback);
260 
261  typedef void (*CommandCallback)(int command);
262 
271  void setCommandCallback(CommandCallback callback);
272 
273  void reportCharacter(byte character);
274  void reportCommand(KEY_COMMANDS command);
275 
276  bool persist(OutputPersistenceBlock &writer) override;
277  bool unpersist(InputPersistenceBlock &reader) override;
278 
279 private:
280  bool registerScriptBindings();
281  void unregisterScriptBindings();
282 
283 private:
284  void testForLeftDoubleClick();
285  void alterKeyboardState(int keycode, byte newState);
286 
287  byte _keyboardState[2][512];
288  bool _leftMouseState[2];
289  bool _rightMouseState[2];
290  uint _currentState;
291  int _mouseX;
292  int _mouseY;
293  bool _leftMouseDown;
294  bool _rightMouseDown;
295  bool _leftDoubleClick;
296  uint _doubleClickTime;
297  int _doubleClickRectWidth;
298  int _doubleClickRectHeight;
299  uint _lastLeftClickTime;
300  int _lastLeftClickMouseX;
301  int _lastLeftClickMouseY;
302  CommandCallback _commandCallback;
303  CharacterCallback _characterCallback;
304 };
305 
306 } // End of namespace Sword25
307 
308 #endif
Definition: persistable.h:39
Definition: service.h:54
Definition: console.h:27
Definition: kernel.h:72
Definition: inputpersistenceblock.h:40
bool isKeyDown(uint keyCode)
void setCommandCallback(CommandCallback callback)
Class definitions.
Definition: inputengine.h:54
bool wasKeyDown(uint keyCode)
Definition: outputpersistenceblock.h:39
void setCharacterCallback(CharacterCallback callback)