ScummVM API documentation
virtual-keyboard.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#ifndef COMMON_VIRTUAL_KEYBOARD_H
23#define COMMON_VIRTUAL_KEYBOARD_H
24
25#include "common/scummsys.h"
26
27#ifdef ENABLE_VKEYBD
28
29class OSystem;
30
31#include "common/events.h"
32#include "common/hashmap.h"
33#include "common/hash-str.h"
34#include "common/keyboard.h"
35#include "common/list.h"
36#include "common/str.h"
37#include "common/fs.h"
38
39#include "backends/vkeybd/image-map.h"
40#include "graphics/surface.h"
41
42
43namespace Common {
44
45class Archive;
46
47class VirtualKeyboardGUI;
48class VirtualKeyboardParser;
49
56class VirtualKeyboard {
57protected:
58
63 enum VKEventType {
65 kVKEventKey,
67 kVKEventModifier,
69 kVKEventSwitchMode,
71 kVKEventSubmit,
73 kVKEventCancel,
75 kVKEventClear,
77 kVKEventMoveLeft,
79 kVKEventMoveRight,
81 kVKEventDelete
82 };
83
85 struct VKEvent {
86 String name;
87 VKEventType type;
95 void *data;
96
97 VKEvent() : data(0) {}
98 ~VKEvent() {
99 if (data)
100 free(data);
101 }
102 };
103
104 typedef HashMap<String, VKEvent *> VKEventMap;
105
109 struct Mode {
110 String name;
111 String resolution;
112 String bitmapName;
113 Graphics::Surface *image;
114 uint32 transparentColor;
115 ImageMap imageMap;
116 VKEventMap events;
117 Rect displayArea;
118 uint32 displayFontColor;
119
120 Mode() : image(0) {}
121 ~Mode() {
122 if (image) {
123 image->free();
124 delete image;
125 image = 0;
126 }
127 }
128 };
129
130 typedef HashMap<String, Mode, IgnoreCase_Hash, IgnoreCase_EqualTo> ModeMap;
131
132 enum HorizontalAlignment {
133 kAlignLeft,
134 kAlignCenter,
135 kAlignRight
136 };
137
138 enum VerticalAlignment {
139 kAlignTop,
140 kAlignMiddle,
141 kAlignBottom
142 };
143
144 struct VirtualKeyPress {
145 KeyState key;
147 uint strLen;
148 };
149
154 class KeyPressQueue {
155 public:
156 KeyPressQueue();
157 void toggleFlags(byte fl);
158 void clearFlags();
159 void insertKey(KeyState key);
160 void deleteKey();
161 void moveLeft();
162 void moveRight();
163 KeyState pop();
164 void clear();
165 bool empty();
166 String getString();
167 uint getInsertIndex();
168 bool hasStringChanged();
169
170 private:
171 byte _flags;
172 String _flagsStr;
173
174 typedef List<VirtualKeyPress> KeyPressList;
175 KeyPressList _keys;
176 String _keysStr;
177
178 bool _strChanged;
179
180 KeyPressList::iterator _keyPos;
181 uint _strPos;
182 };
183
184public:
185
186 VirtualKeyboard();
187
188 virtual ~VirtualKeyboard();
189
197 bool loadKeyboardPack(const String &packName);
198
204 void show();
205
211 void close(bool submit);
212
216 bool isDisplaying();
217
221 bool isLoaded() {
222 return _loaded;
223 }
224
225protected:
226
227 OSystem *_system;
228 DisposablePtr<Archive> _fileArchive;
229
230 friend class VirtualKeyboardGUI;
231 VirtualKeyboardGUI *_kbdGUI;
232
233 KeyPressQueue _keyQueue;
234
235 friend class VirtualKeyboardParser;
236 VirtualKeyboardParser *_parser;
237
238 void reset();
239 bool openPack(const String &packName, Archive *searchPath, DisposeAfterUse::Flag disposeSearchPath);
240 void deleteEvents();
241 bool checkModeResolutions();
242 void switchMode(Mode *newMode);
243 void switchMode(const String &newMode);
244 void initKeymap();
245 void handleMouseDown(int16 x, int16 y);
246 void handleMouseUp(int16 x, int16 y);
247 String findArea(int16 x, int16 y);
248 void processAreaClick(const String &area);
249
250 bool _loaded;
251
252 ModeMap _modes;
253 Mode *_initialMode;
254 Mode *_currentMode;
255
256 HorizontalAlignment _hAlignment;
257 VerticalAlignment _vAlignment;
258
259 String _areaDown;
260
261 bool _submitKeys;
262
263};
264
265} // End of namespace Common
266
267#endif // #ifdef ENABLE_VKEYBD
268
269#endif // #ifndef COMMON_VIRTUAL_KEYBOARD_H
Definition: system.h:166
Definition: algorithm.h:29
Definition: surface.h:67