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 
35 namespace Common {
36  class SeekableReadStream;
37 }
38 
39 namespace Gob {
40 
41 class GobEngine;
42 
43 #define KEYBUFSIZE 16
44 
45 enum MouseButtons {
46  kMouseButtonsNone = 0,
47  kMouseButtonsLeft = 1,
48  kMouseButtonsRight = 2,
49  kMouseButtonsBoth = 3,
50  kMouseButtonsAny = 4
51 };
52 
53 enum 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 
76 enum ShortKey {
77  kShortKeyUp = 0x0B,
78  kShortKeyDown = 0x0A,
79  kShortKeyRight = 0x09,
80  kShortKeyLeft = 0x08,
81  kShortKeyEscape = 0x1B,
82  kShortKeyBackspace = 0x19,
83  kShortKeyDelete = 0x1A
84 };
85 
86 class Util {
87 public:
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 
128  void clearPalette();
129  int16 getFrameRate();
130  void setFrameRate(int16 rate);
131  void notifyNewAnim();
132  void waitEndFrame(bool handleInput = true);
133  void setScrollOffset(int16 x = -1, int16 y = -1);
134 
135  static void insertStr(const char *str1, char *str2, int16 pos);
136  static void cutFromStr(char *str, int16 from, int16 cutlen);
137  static void cleanupStr(char *str);
138  static void replaceChar(char *str, char c1, char c2);
139 
140  static void listInsertFront(List *list, void *data);
141  static void listInsertBack(List *list, void *data);
142  static void listDropFront(List *list);
143  static void deleteList(List *list);
144 
145  //static char *setExtension(char *str, const char *ext);
146  static Common::String setExtension(const Common::String &str, const Common::String &ext);
147 
149  static Common::String readString(Common::SeekableReadStream &stream, int n);
150 
152  static char toCP850Lower(char cp850);
154  static char toCP850Upper(char cp850);
155 
156  Util(GobEngine *vm);
157 
158 protected:
159  MouseButtons _mouseButtons;
160 
161  Common::KeyState _keyBuffer[KEYBUFSIZE];
162  int16 _keyBufferHead;
163  int16 _keyBufferTail;
164 
165  uint8 _fastMode;
166 
167  int16 _frameRate;
168  int16 _frameWaitTime;
169  uint32 _startFrameTime;
170 
171  uint32 _keyState;
172 
173  GobEngine *_vm;
174 
175  bool keyBufferEmpty();
176  void addKeyToBuffer(const Common::KeyState &key);
177  bool getKeyFromBuffer(Common::KeyState &key);
178  int16 translateKey(const Common::KeyState &key);
179  int16 toCP850(uint16 latin1);
180  void checkJoystick();
181 
182  void keyDown(const Common::Event &event);
183  void keyUp(const Common::Event &event);
184 };
185 
186 } // End of namespace Gob
187 
188 #endif // GOB_UTIL_H
Definition: gob.h:163
Definition: str.h:59
Definition: util.h:89
Definition: stream.h:745
Definition: anifile.h:40
Definition: double_serialization.h:36
Definition: events.h:199
Definition: algorithm.h:29
Definition: keyboard.h:294
Definition: util.h:96