2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2005-04-05 18:08:02 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-05 18:08:02 +00:00
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2005-04-05 18:08:02 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2005-04-09 19:19:54 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2005-04-05 18:08:02 +00:00
|
|
|
#ifndef GOB_UTIL_H
|
|
|
|
#define GOB_UTIL_H
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2011-08-31 11:41:43 +00:00
|
|
|
#include "common/str.h"
|
2007-06-23 17:00:27 +00:00
|
|
|
#include "common/keyboard.h"
|
2012-06-15 11:32:43 +00:00
|
|
|
#include "common/events.h"
|
2007-06-23 17:00:27 +00:00
|
|
|
|
2011-08-31 11:41:43 +00:00
|
|
|
namespace Common {
|
|
|
|
class SeekableReadStream;
|
|
|
|
}
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
namespace Gob {
|
|
|
|
|
2009-07-09 02:54:10 +00:00
|
|
|
class GobEngine;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
#define KEYBUFSIZE 16
|
|
|
|
|
2009-07-05 11:26:23 +00:00
|
|
|
enum MouseButtons {
|
|
|
|
kMouseButtonsNone = 0,
|
|
|
|
kMouseButtonsLeft = 1,
|
|
|
|
kMouseButtonsRight = 2,
|
|
|
|
kMouseButtonsBoth = 3,
|
|
|
|
kMouseButtonsAny = 4
|
|
|
|
};
|
|
|
|
|
2009-07-05 11:27:11 +00:00
|
|
|
enum Keys {
|
|
|
|
kKeyNone = 0x0000,
|
|
|
|
kKeyBackspace = 0x0E08,
|
|
|
|
kKeySpace = 0x3920,
|
|
|
|
kKeyReturn = 0x1C0D,
|
|
|
|
kKeyEscape = 0x011B,
|
|
|
|
kKeyDelete = 0x5300,
|
|
|
|
kKeyUp = 0x4800,
|
|
|
|
kKeyDown = 0x5000,
|
|
|
|
kKeyRight = 0x4D00,
|
|
|
|
kKeyLeft = 0x4B00,
|
|
|
|
kKeyF1 = 0x3B00,
|
|
|
|
kKeyF2 = 0x3C00,
|
|
|
|
kKeyF3 = 0x3D00,
|
|
|
|
kKeyF4 = 0x3E00,
|
|
|
|
kKeyF5 = 0x3F00,
|
|
|
|
kKeyF6 = 0x4000,
|
|
|
|
kKeyF7 = 0x4100,
|
|
|
|
kKeyF8 = 0x4200,
|
|
|
|
kKeyF9 = 0x4300,
|
|
|
|
kKeyF10 = 0x4400
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ShortKey {
|
|
|
|
kShortKeyUp = 0x0B,
|
|
|
|
kShortKeyDown = 0x0A,
|
|
|
|
kShortKeyRight = 0x09,
|
|
|
|
kShortKeyLeft = 0x08,
|
|
|
|
kShortKeyEscape = 0x1B,
|
|
|
|
kShortKeyBackspace = 0x19,
|
|
|
|
kShortKeyDelete = 0x1A
|
|
|
|
};
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
class Util {
|
|
|
|
public:
|
|
|
|
struct ListNode;
|
2006-01-29 02:27:10 +00:00
|
|
|
struct ListNode {
|
2006-01-03 23:14:39 +00:00
|
|
|
void *pData;
|
|
|
|
struct ListNode *pNext;
|
|
|
|
struct ListNode *pPrev;
|
|
|
|
ListNode() : pData(0), pNext(0), pPrev(0) {}
|
2006-01-29 02:27:10 +00:00
|
|
|
};
|
2006-01-03 23:14:39 +00:00
|
|
|
|
2006-01-29 02:27:10 +00:00
|
|
|
struct List {
|
2006-01-03 23:14:39 +00:00
|
|
|
ListNode *pHead;
|
|
|
|
ListNode *pTail;
|
|
|
|
List() : pHead(0), pTail(0) {}
|
2006-01-29 02:27:10 +00:00
|
|
|
};
|
2006-01-03 23:14:39 +00:00
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
uint32 getTimeKey();
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 getRandom(int16 max);
|
|
|
|
void beep(int16 freq);
|
|
|
|
|
2009-02-21 15:58:50 +00:00
|
|
|
void notifyPaused(uint32 duration);
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
void delay(uint16 msecs);
|
|
|
|
void longDelay(uint16 msecs);
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void initInput();
|
2007-04-13 07:48:26 +00:00
|
|
|
void processInput(bool scroll = false);
|
2009-11-02 21:54:57 +00:00
|
|
|
void clearKeyBuf();
|
|
|
|
int16 getKey();
|
|
|
|
int16 checkKey();
|
2009-06-06 19:06:47 +00:00
|
|
|
bool checkKey(int16 &key);
|
2011-09-03 15:21:25 +00:00
|
|
|
bool keyPressed();
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2012-06-15 11:32:43 +00:00
|
|
|
uint32 getKeyState() const;
|
|
|
|
|
2009-07-05 11:26:23 +00:00
|
|
|
void getMouseState(int16 *pX, int16 *pY, MouseButtons *pButtons);
|
2006-01-03 23:14:39 +00:00
|
|
|
void setMousePos(int16 x, int16 y);
|
2009-11-02 21:54:57 +00:00
|
|
|
void waitMouseUp();
|
|
|
|
void waitMouseDown();
|
2007-03-20 14:51:57 +00:00
|
|
|
void waitMouseRelease(char drawMouse);
|
2007-04-16 05:05:35 +00:00
|
|
|
void forceMouseUp(bool onlyWhenSynced = false);
|
2006-01-03 23:14:39 +00:00
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void clearPalette();
|
2008-02-29 22:24:52 +00:00
|
|
|
int16 getFrameRate();
|
2007-03-20 14:51:57 +00:00
|
|
|
void setFrameRate(int16 rate);
|
2009-06-14 12:19:42 +00:00
|
|
|
void notifyNewAnim();
|
2012-06-28 15:37:58 +00:00
|
|
|
void waitEndFrame(bool handleInput = true);
|
2007-03-20 14:51:57 +00:00
|
|
|
void setScrollOffset(int16 x = -1, int16 y = -1);
|
2006-01-03 23:14:39 +00:00
|
|
|
|
2006-01-29 19:18:15 +00:00
|
|
|
static void insertStr(const char *str1, char *str2, int16 pos);
|
|
|
|
static void cutFromStr(char *str, int16 from, int16 cutlen);
|
2009-07-05 11:26:42 +00:00
|
|
|
static void cleanupStr(char *str);
|
2007-04-28 21:16:13 +00:00
|
|
|
static void replaceChar(char *str, char c1, char c2);
|
2007-03-20 14:51:57 +00:00
|
|
|
|
|
|
|
static void listInsertFront(List *list, void *data);
|
|
|
|
static void listInsertBack(List *list, void *data);
|
|
|
|
static void listDropFront(List *list);
|
|
|
|
static void deleteList(List *list);
|
2006-01-03 23:14:39 +00:00
|
|
|
|
2011-01-29 22:50:11 +00:00
|
|
|
static char *setExtension(char *str, const char *ext);
|
|
|
|
static Common::String setExtension(const Common::String &str, const Common::String &ext);
|
|
|
|
|
2011-08-31 11:41:43 +00:00
|
|
|
/** Read a constant-length string out of a stream. */
|
|
|
|
static Common::String readString(Common::SeekableReadStream &stream, int n);
|
|
|
|
|
2012-07-07 17:14:06 +00:00
|
|
|
/** Convert a character in CP850 encoding to the equivalent lower case character. */
|
|
|
|
static char toCP850Lower(char cp850);
|
|
|
|
/** Convert a character in CP850 encoding to the equivalent upper case character. */
|
|
|
|
static char toCP850Upper(char cp850);
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
Util(GobEngine *vm);
|
|
|
|
|
|
|
|
protected:
|
2009-07-05 11:26:23 +00:00
|
|
|
MouseButtons _mouseButtons;
|
|
|
|
|
2007-06-23 17:00:27 +00:00
|
|
|
Common::KeyState _keyBuffer[KEYBUFSIZE];
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 _keyBufferHead;
|
|
|
|
int16 _keyBufferTail;
|
|
|
|
|
2007-04-13 19:55:09 +00:00
|
|
|
uint8 _fastMode;
|
|
|
|
|
2008-02-29 22:24:52 +00:00
|
|
|
int16 _frameRate;
|
2009-02-21 15:58:50 +00:00
|
|
|
int16 _frameWaitTime;
|
|
|
|
uint32 _startFrameTime;
|
2008-02-29 22:24:52 +00:00
|
|
|
|
2012-06-15 11:32:43 +00:00
|
|
|
uint32 _keyState;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
GobEngine *_vm;
|
|
|
|
|
|
|
|
bool keyBufferEmpty();
|
2007-06-23 17:00:27 +00:00
|
|
|
void addKeyToBuffer(const Common::KeyState &key);
|
|
|
|
bool getKeyFromBuffer(Common::KeyState &key);
|
|
|
|
int16 translateKey(const Common::KeyState &key);
|
2012-07-07 16:44:46 +00:00
|
|
|
int16 toCP850(uint16 latin1);
|
2006-01-03 23:14:39 +00:00
|
|
|
void checkJoystick();
|
2012-06-15 11:32:43 +00:00
|
|
|
|
|
|
|
void keyDown(const Common::Event &event);
|
|
|
|
void keyUp(const Common::Event &event);
|
2006-01-03 23:14:39 +00:00
|
|
|
};
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
} // End of namespace Gob
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
#endif // GOB_UTIL_H
|