1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
* BS_InputEngine
* -------------
* This is the input interface engine that contains all the methods that an
* input source must implement.
* All input engines must be derived from this class.
*
* Autor: Alex Arnst
*/
#ifndef SWORD25_INPUTENGINE_H
#define SWORD25_INPUTENGINE_H
/// Includes
#include "sword25/kernel/common.h"
#include "sword25/kernel/service.h"
#include "sword25/kernel/persistable.h"
namespace Sword25 {
/// Class definitions
class BS_InputEngine : public BS_Service, public BS_Persistable {
public:
BS_InputEngine(BS_Kernel* pKernel);
virtual ~BS_InputEngine(){};
// NOTE: These codes are registered in inputengine_script.cpp
// Any changes to these enums must also adjust the above file.
enum KEY_CODES {
KEY_BACKSPACE = 0x08,
KEY_TAB = 0x09,
KEY_CLEAR = 0x0C,
KEY_RETURN = 0x0D,
KEY_PAUSE = 0x13,
KEY_CAPSLOCK = 0x14,
KEY_ESCAPE = 0x1B,
KEY_SPACE = 0x20,
KEY_PAGEUP = 0x21,
KEY_PAGEDOWN = 0x22,
KEY_END = 0x23,
KEY_HOME = 0x24,
KEY_LEFT = 0x25,
KEY_UP = 0x26,
KEY_RIGHT = 0x27,
KEY_DOWN = 0x28,
KEY_PRINTSCREEN = 0x2C,
KEY_INSERT = 0x2D,
KEY_DELETE = 0x2E,
KEY_0 = 0x30,
KEY_1 = 0x31,
KEY_2 = 0x32,
KEY_3 = 0x33,
KEY_4 = 0x34,
KEY_5 = 0x35,
KEY_6 = 0x36,
KEY_7 = 0x37,
KEY_8 = 0x38,
KEY_9 = 0x39,
KEY_A = 0x41,
KEY_B = 0x42,
KEY_C = 0x43,
KEY_D = 0x44,
KEY_E = 0x45,
KEY_F = 0x46,
KEY_G = 0x47,
KEY_H = 0x48,
KEY_I = 0x49,
KEY_J = 0x4A,
KEY_K = 0x4B,
KEY_L = 0x4C,
KEY_M = 0x4D,
KEY_N = 0x4E,
KEY_O = 0x4F,
KEY_P = 0x50,
KEY_Q = 0x51,
KEY_R = 0x52,
KEY_S = 0x53,
KEY_T = 0x54,
KEY_U = 0x55,
KEY_V = 0x56,
KEY_W = 0x57,
KEY_X = 0x58,
KEY_Y = 0x59,
KEY_Z = 0x5A,
KEY_NUMPAD0 = 0x60,
KEY_NUMPAD1 = 0x61,
KEY_NUMPAD2 = 0x62,
KEY_NUMPAD3 = 0x63,
KEY_NUMPAD4 = 0x64,
KEY_NUMPAD5 = 0x65,
KEY_NUMPAD6 = 0x66,
KEY_NUMPAD7 = 0x67,
KEY_NUMPAD8 = 0x68,
KEY_NUMPAD9 = 0x69,
KEY_MULTIPLY = 0x6A,
KEY_ADD = 0x6B,
KEY_SEPARATOR = 0x6C,
KEY_SUBTRACT = 0x6D,
KEY_DECIMAL = 0x6E,
KEY_DIVIDE = 0x6F,
KEY_F1 = 0x70,
KEY_F2 = 0x71,
KEY_F3 = 0x72,
KEY_F4 = 0x73,
KEY_F5 = 0x74,
KEY_F6 = 0x75,
KEY_F7 = 0x76,
KEY_F8 = 0x77,
KEY_F9 = 0x78,
KEY_F10 = 0x79,
KEY_F11 = 0x7A,
KEY_F12 = 0x7B,
KEY_NUMLOCK = 0x90,
KEY_SCROLL = 0x91,
KEY_LSHIFT = 0xA0,
KEY_RSHIFT = 0xA1,
KEY_LCONTROL = 0xA2,
KEY_RCONTROL = 0xA3
};
// NOTE: These codes are registered in inputengine_script.cpp.
// Any changes to these enums must also adjust the above file.
enum KEY_COMMANDS {
KEY_COMMAND_ENTER = 1,
KEY_COMMAND_LEFT = 2,
KEY_COMMAND_RIGHT = 3,
KEY_COMMAND_HOME = 4,
KEY_COMMAND_END = 5,
KEY_COMMAND_BACKSPACE = 6,
KEY_COMMAND_TAB = 7,
KEY_COMMAND_INSERT = 8,
KEY_COMMAND_DELETE = 9
};
/// --------------------------------------------------------------
/// THESE METHODS MUST BE IMPLEMENTED BY THE INPUT ENGINE
/// --------------------------------------------------------------
/**
* Initialises the input engine
* @return Returns a true on success, otherwise false.
*/
virtual bool Init() = 0;
/**
* Performs a "tick" of the input engine.
*
* This method should be called once per frame. It can be used by implementations
* of the input engine that are not running in their own thread, or to perform
* additional administrative tasks that are needed.
*/
virtual void Update() = 0;
/**
* Returns true if the left mouse button is pressed
*/
virtual bool IsLeftMouseDown() = 0;
/**
* Returns true if the right mouse button is pressed.
*/
virtual bool IsRightMouseDown() = 0;
/**
* Returns true if the left mouse button was pressed and released.
*
* The difference between this and IsLeftMouseDown() is that this only returns
* true when the left mouse button is released.
*/
virtual bool WasLeftMouseDown() = 0;
/**
* Returns true if the right mouse button was pressed and released.
*
* The difference between this and IsRightMouseDown() is that this only returns
* true when the right mouse button is released.
*/
virtual bool WasRightMouseDown() = 0;
/**
* Returns true if the left mouse button double click was done
*/
virtual bool IsLeftDoubleClick() = 0;
/**
* Returns the X position of the cursor in pixels
*/
virtual int GetMouseX() = 0;
/**
* Returns the Y position of the cursor in pixels
*/
virtual int GetMouseY() = 0;
/**
* Sets the X position of the cursor in pixels
*/
virtual void SetMouseX(int PosX) = 0;
/**
* Sets the Y position of the cursor in pixels
*/
virtual void SetMouseY(int PosY) = 0;
/**
* Returns true if a given key was pressed
* @param KeyCode The key code to be checked
* @return Returns true if the given key is done, otherwise false.
*/
virtual bool IsKeyDown(unsigned int KeyCode) = 0;
/**
* Returns true if a certain key was pushed and released.
*
* The difference between IsKeyDown() is that this only returns true after the key
* has been released. This method facilitates the retrieval of keys, and reading
* strings that users type.
* @param KeyCode The key code to be checked
*/
virtual bool WasKeyDown(unsigned int KeyCode) = 0;
typedef void (*CharacterCallback)(unsigned char Character);
/**
* Registers a callback function for keyboard input.
*
* The callbacks that are registered with this function will be called whenever an
* input key is pressed. A letter entry is different from the query using the
* methods IsKeyDown () and WasKeyDown () in the sense that are treated instead
* of actual scan-coded letters. These were taken into account, among other things:
* the keyboard layout, the condition the Shift and Caps Lock keys and the repetition
* of longer holding the key.
* The input of strings by the user through use of callbacks should be implemented.
* @return Returns true if the function was registered, otherwise false.
*/
virtual bool RegisterCharacterCallback(CharacterCallback Callback) = 0;
/**
* De-registeres a previously registered callback function.
* @return Returns true if the function could be de-registered, otherwise false.
*/
virtual bool UnregisterCharacterCallback(CharacterCallback Callback) = 0;
typedef void (*CommandCallback)(KEY_COMMANDS Command);
/**
* Registers a callback function for the input of commands that can have influence on the string input
*
* The callbacks that are registered with this function will be called whenever the input service
* has a key that affects the character string input. This could be the following keys:
* Enter, End, Left, Right, ...
* The input of strings by the user through the use of callbacks should be implemented.
* @return Returns true if the function was registered, otherwise false.
*/
virtual bool RegisterCommandCallback(CommandCallback Callback) = 0;
/**
* Un-register a callback function for the input of commands that can have an influence on the string input.
* @return Returns true if the function could be de-registered, otherwise false.
*/
virtual bool UnregisterCommandCallback(CommandCallback Callback) = 0;
virtual void ReportCharacter(unsigned char Character) = 0;
virtual void ReportCommand(KEY_COMMANDS Command) = 0;
private:
bool _RegisterScriptBindings();
};
} // End of namespace Sword25
#endif
|