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 
232  void setMouseX(int posX);
233 
237  void setMouseY(int posY);
238 
244  bool isKeyDown(uint keyCode);
245 
254  bool wasKeyDown(uint keyCode);
255 
256  typedef void (*CharacterCallback)(int command);
257 
269  void setCharacterCallback(CharacterCallback callback);
270 
271  typedef void (*CommandCallback)(int command);
272 
281  void setCommandCallback(CommandCallback callback);
282 
283  void reportCharacter(byte character);
284  void reportCommand(KEY_COMMANDS command);
285 
286  bool persist(OutputPersistenceBlock &writer) override;
287  bool unpersist(InputPersistenceBlock &reader) override;
288 
289 private:
290  bool registerScriptBindings();
291  void unregisterScriptBindings();
292 
293 private:
294  void testForLeftDoubleClick();
295  void alterKeyboardState(int keycode, byte newState);
296 
297  byte _keyboardState[2][512];
298  bool _leftMouseState[2];
299  bool _rightMouseState[2];
300  uint _currentState;
301  int _mouseX;
302  int _mouseY;
303  bool _leftMouseDown;
304  bool _rightMouseDown;
305  bool _leftDoubleClick;
306  uint _doubleClickTime;
307  int _doubleClickRectWidth;
308  int _doubleClickRectHeight;
309  uint _lastLeftClickTime;
310  int _lastLeftClickMouseX;
311  int _lastLeftClickMouseY;
312  CommandCallback _commandCallback;
313  CharacterCallback _characterCallback;
314 };
315 
316 } // End of namespace Sword25
317 
318 #endif
void setMouseY(int posY)
Definition: persistable.h:39
Definition: service.h:54
Definition: console.h:27
Definition: kernel.h:72
void setMouseX(int posX)
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)