ScummVM API documentation
util.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 * This file is dual-licensed.
22 * In addition to the GPLv3 license mentioned above, this code is also
23 * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24 * full text of the license.
25 *
26 */
27
28#ifndef GOB_UTIL_H
29#define GOB_UTIL_H
30
31#include "common/str.h"
32#include "common/keyboard.h"
33#include "common/events.h"
34
35namespace Common {
36 class SeekableReadStream;
37}
38
39namespace Gob {
40
41class GobEngine;
42
43#define KEYBUFSIZE 16
44
45enum MouseButtons {
46 kMouseButtonsNone = 0,
47 kMouseButtonsLeft = 1,
48 kMouseButtonsRight = 2,
49 kMouseButtonsBoth = 3,
50 kMouseButtonsAny = 4
51};
52
53enum Keys {
54 kKeyNone = 0x0000,
55 kKeyBackspace = 0x0E08,
56 kKeySpace = 0x3920,
57 kKeyReturn = 0x1C0D,
58 kKeyEscape = 0x011B,
59 kKeyDelete = 0x5300,
60 kKeyUp = 0x4800,
61 kKeyDown = 0x5000,
62 kKeyRight = 0x4D00,
63 kKeyLeft = 0x4B00,
64 kKeyF1 = 0x3B00,
65 kKeyF2 = 0x3C00,
66 kKeyF3 = 0x3D00,
67 kKeyF4 = 0x3E00,
68 kKeyF5 = 0x3F00,
69 kKeyF6 = 0x4000,
70 kKeyF7 = 0x4100,
71 kKeyF8 = 0x4200,
72 kKeyF9 = 0x4300,
73 kKeyF10 = 0x4400
74};
75
76enum ShortKey {
77 kShortKeyUp = 0x0B,
78 kShortKeyDown = 0x0A,
79 kShortKeyRight = 0x09,
80 kShortKeyLeft = 0x08,
81 kShortKeyEscape = 0x1B,
82 kShortKeyBackspace = 0x19,
83 kShortKeyDelete = 0x1A
84};
85
86class Util {
87public:
88 struct ListNode;
89 struct ListNode {
90 void *pData;
91 struct ListNode *pNext;
92 struct ListNode *pPrev;
93 ListNode() : pData(0), pNext(0), pPrev(0) {}
94 };
95
96 struct List {
97 ListNode *pHead;
98 ListNode *pTail;
99 List() : pHead(0), pTail(0) {}
100 };
101
102 uint32 getTimeKey();
103 int16 getRandom(int16 max);
104 void beep(int16 freq);
105
106 void notifyPaused(uint32 duration);
107
108 void delay(uint16 msecs);
109 void longDelay(uint16 msecs);
110
111 void initInput();
112 void processInput(bool scroll = false);
113 void clearKeyBuf();
114 int16 getKey();
115 int16 checkKey();
116 bool checkKey(int16 &key);
117 bool keyPressed();
118
119 uint32 getKeyState() const;
120
121 void getMouseState(int16 *pX, int16 *pY, MouseButtons *pButtons);
122 void setMousePos(int16 x, int16 y);
123 void waitMouseUp();
124 void waitMouseDown();
125 void waitMouseRelease(char drawMouse);
126 void forceMouseUp(bool onlyWhenSynced = false);
127 void forceMouseButtonsSync();
128
129 void clearPalette();
130 int16 getFrameRate();
131 void setFrameRate(int16 rate);
132 void notifyNewAnim();
133 void waitEndFrame(bool handleInput = true);
134 void setScrollOffset(int16 x = -1, int16 y = -1);
135
136 static void insertStr(const char *str1, char *str2, int16 pos);
137 static void cutFromStr(char *str, int16 from, int16 cutlen);
138 static void cleanupStr(char *str);
139 static void replaceChar(char *str, char c1, char c2);
140
141 static void listInsertFront(List *list, void *data);
142 static void listInsertBack(List *list, void *data);
143 static void listDropFront(List *list);
144 static void deleteList(List *list);
145
146 //static char *setExtension(char *str, const char *ext);
147 static Common::String setExtension(const Common::String &str, const Common::String &ext);
148
151
153 static char toCP850Lower(char cp850);
155 static char toCP850Upper(char cp850);
156
157 Util(GobEngine *vm);
158
159protected:
160 MouseButtons _mouseButtons;
161
162 Common::KeyState _keyBuffer[KEYBUFSIZE];
163 int16 _keyBufferHead;
164 int16 _keyBufferTail;
165
166 uint8 _fastMode;
167
168 int16 _frameRate;
169 int16 _frameWaitTime;
170 uint32 _startFrameTime;
171
172 uint32 _keyState;
173
174 GobEngine *_vm;
175
176 bool keyBufferEmpty();
177 void addKeyToBuffer(const Common::KeyState &key);
178 bool getKeyFromBuffer(Common::KeyState &key);
179 int16 translateKey(const Common::KeyState &key);
180 int16 toCP850(uint16 latin1);
181 void checkJoystick();
182
183 void keyDown(const Common::Event &event);
184 void keyUp(const Common::Event &event);
185};
186
187} // End of namespace Gob
188
189#endif // GOB_UTIL_H
Definition: stream.h:745
Definition: str.h:59
Definition: gob.h:166
Definition: util.h:86
static Common::String readString(Common::SeekableReadStream &stream, int n)
static char toCP850Upper(char cp850)
static char toCP850Lower(char cp850)
Definition: algorithm.h:29
Definition: events.h:218
Definition: keyboard.h:294
Definition: util.h:96
Definition: util.h:89