2005-07-24 14:12:37 +00:00
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/** @file gfx.h */
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
#ifndef GFX_H
|
|
|
|
|
#define GFX_H
|
|
|
|
|
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
|
|
|
|
enum WindowKeyCodes {
|
|
|
|
|
WKC_SHIFT = 0x8000,
|
|
|
|
|
WKC_CTRL = 0x4000,
|
|
|
|
|
WKC_ALT = 0x2000,
|
|
|
|
|
WKC_META = 0x1000,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* Special ones */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_NONE = 0,
|
|
|
|
|
WKC_ESC = 1,
|
|
|
|
|
WKC_BACKSPACE = 2,
|
|
|
|
|
WKC_INSERT = 3,
|
|
|
|
|
WKC_DELETE = 4,
|
|
|
|
|
|
|
|
|
|
WKC_PAGEUP = 5,
|
|
|
|
|
WKC_PAGEDOWN = 6,
|
|
|
|
|
WKC_END = 7,
|
|
|
|
|
WKC_HOME = 8,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* Arrow keys */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_LEFT = 9,
|
|
|
|
|
WKC_UP = 10,
|
|
|
|
|
WKC_RIGHT = 11,
|
|
|
|
|
WKC_DOWN = 12,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* Return & tab */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_RETURN = 13,
|
|
|
|
|
WKC_TAB = 14,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* Numerical keyboard */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_NUM_0 = 16,
|
|
|
|
|
WKC_NUM_1 = 17,
|
|
|
|
|
WKC_NUM_2 = 18,
|
|
|
|
|
WKC_NUM_3 = 19,
|
|
|
|
|
WKC_NUM_4 = 20,
|
|
|
|
|
WKC_NUM_5 = 21,
|
|
|
|
|
WKC_NUM_6 = 22,
|
|
|
|
|
WKC_NUM_7 = 23,
|
|
|
|
|
WKC_NUM_8 = 24,
|
|
|
|
|
WKC_NUM_9 = 25,
|
|
|
|
|
WKC_NUM_DIV = 26,
|
|
|
|
|
WKC_NUM_MUL = 27,
|
|
|
|
|
WKC_NUM_MINUS = 28,
|
|
|
|
|
WKC_NUM_PLUS = 29,
|
|
|
|
|
WKC_NUM_ENTER = 30,
|
|
|
|
|
WKC_NUM_DECIMAL = 31,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* Space */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_SPACE = 32,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* Function keys */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_F1 = 33,
|
|
|
|
|
WKC_F2 = 34,
|
|
|
|
|
WKC_F3 = 35,
|
|
|
|
|
WKC_F4 = 36,
|
|
|
|
|
WKC_F5 = 37,
|
|
|
|
|
WKC_F6 = 38,
|
|
|
|
|
WKC_F7 = 39,
|
|
|
|
|
WKC_F8 = 40,
|
|
|
|
|
WKC_F9 = 41,
|
|
|
|
|
WKC_F10 = 42,
|
|
|
|
|
WKC_F11 = 43,
|
|
|
|
|
WKC_F12 = 44,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* backquote is the key left of "1"
|
|
|
|
|
* we only store this key here, no matter what character is really mapped to it
|
|
|
|
|
* on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and <EFBFBD>) */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
WKC_BACKQUOTE = 45,
|
|
|
|
|
WKC_PAUSE = 46,
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* 0-9 are mapped to 48-57
|
|
|
|
|
* A-Z are mapped to 65-90
|
|
|
|
|
* a-z are mapped to 97-122 */
|
2007-01-13 14:43:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum GameModes {
|
|
|
|
|
GM_MENU,
|
|
|
|
|
GM_NORMAL,
|
|
|
|
|
GM_EDITOR
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void GameLoop(void);
|
|
|
|
|
|
|
|
|
|
void CreateConsole(void);
|
|
|
|
|
|
|
|
|
|
typedef int32 CursorID;
|
|
|
|
|
typedef byte Pixel;
|
|
|
|
|
|
|
|
|
|
typedef struct Point {
|
|
|
|
|
int x,y;
|
|
|
|
|
} Point;
|
|
|
|
|
|
|
|
|
|
typedef struct Rect {
|
|
|
|
|
int left,top,right,bottom;
|
|
|
|
|
} Rect;
|
|
|
|
|
|
2007-02-24 15:05:14 +00:00
|
|
|
|
/** A single sprite of a list of animated cursors */
|
|
|
|
|
struct AnimCursor {
|
2007-02-24 22:35:42 +00:00
|
|
|
|
static const CursorID LAST = MAX_UVALUE(CursorID);
|
2007-02-24 15:05:14 +00:00
|
|
|
|
CursorID sprite; ///< Must be set to LAST_ANIM when it is the last sprite of the loop
|
|
|
|
|
byte display_time; ///< Amount of ticks this sprite will be shown
|
|
|
|
|
};
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
|
|
|
|
typedef struct CursorVars {
|
|
|
|
|
Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement
|
|
|
|
|
Point draw_pos, draw_size; ///< position and size bounding-box for drawing
|
2007-01-14 19:57:49 +00:00
|
|
|
|
SpriteID sprite; ///< current image of cursor
|
|
|
|
|
SpriteID pal;
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
|
|
|
|
int wheel; ///< mouse wheel movement
|
2007-02-24 15:05:14 +00:00
|
|
|
|
const AnimCursor *animate_list; ///< in case of animated cursor, list of frames
|
|
|
|
|
const AnimCursor *animate_cur; ///< in case of animated cursor, current frame
|
|
|
|
|
uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
|
|
|
|
bool visible; ///< cursor is visible
|
|
|
|
|
bool dirty; ///< the rect occupied by the mouse is dirty (redraw)
|
|
|
|
|
bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling)
|
|
|
|
|
bool in_window; ///< mouse inside this window, determines drawing logic
|
|
|
|
|
} CursorVars;
|
|
|
|
|
|
|
|
|
|
typedef struct DrawPixelInfo {
|
|
|
|
|
Pixel *dst_ptr;
|
|
|
|
|
int left, top, width, height;
|
|
|
|
|
int pitch;
|
|
|
|
|
uint16 zoom;
|
|
|
|
|
} DrawPixelInfo;
|
|
|
|
|
|
|
|
|
|
typedef struct Colour {
|
|
|
|
|
byte r;
|
|
|
|
|
byte g;
|
|
|
|
|
byte b;
|
|
|
|
|
} Colour;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
extern byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down
|
2007-01-13 14:43:46 +00:00
|
|
|
|
extern bool _fullscreen;
|
|
|
|
|
extern CursorVars _cursor;
|
2007-03-01 01:24:44 +00:00
|
|
|
|
extern bool _ctrl_pressed; ///< Is Ctrl pressed?
|
|
|
|
|
extern bool _shift_pressed; ///< Is Shift pressed?
|
2007-01-13 14:43:46 +00:00
|
|
|
|
extern byte _fast_forward;
|
|
|
|
|
|
|
|
|
|
extern bool _left_button_down;
|
|
|
|
|
extern bool _left_button_clicked;
|
|
|
|
|
extern bool _right_button_down;
|
|
|
|
|
extern bool _right_button_clicked;
|
|
|
|
|
|
|
|
|
|
extern DrawPixelInfo _screen;
|
|
|
|
|
extern bool _exit_game;
|
|
|
|
|
extern bool _networking; ///< are we in networking mode?
|
|
|
|
|
extern byte _game_mode;
|
|
|
|
|
extern byte _pause;
|
|
|
|
|
|
|
|
|
|
extern int _pal_first_dirty;
|
|
|
|
|
extern int _pal_last_dirty;
|
|
|
|
|
extern int _num_resolutions;
|
|
|
|
|
extern uint16 _resolutions[32][2];
|
|
|
|
|
extern uint16 _cur_resolution[2];
|
|
|
|
|
extern Colour _cur_palette[256];
|
|
|
|
|
|
|
|
|
|
void HandleKeypress(uint32 key);
|
|
|
|
|
void HandleMouseEvents(void);
|
|
|
|
|
void CSleep(int milliseconds);
|
|
|
|
|
void UpdateWindows(void);
|
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
uint32 InteractiveRandom(void); //< Used for random sequences that are not the same on the other end of the multiplayer link
|
2007-01-13 14:43:46 +00:00
|
|
|
|
uint InteractiveRandomRange(uint max);
|
|
|
|
|
void DrawTextMessage(void);
|
|
|
|
|
void DrawMouseCursor(void);
|
|
|
|
|
void ScreenSizeChanged(void);
|
|
|
|
|
void HandleExitGameRequest(void);
|
|
|
|
|
void GameSizeChanged(void);
|
|
|
|
|
void UndrawMouseCursor(void);
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
|
#include "helpers.hpp"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
2006-05-09 13:23:04 +00:00
|
|
|
|
typedef enum FontSizes {
|
|
|
|
|
FS_NORMAL,
|
|
|
|
|
FS_SMALL,
|
|
|
|
|
FS_LARGE,
|
|
|
|
|
FS_END,
|
|
|
|
|
} FontSize;
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
|
DECLARE_POSTFIX_INCREMENT(FontSize);
|
2006-05-09 13:23:04 +00:00
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
void RedrawScreenRect(int left, int top, int right, int bottom);
|
|
|
|
|
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
|
2005-09-10 07:38:03 +00:00
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* XXX doesn't really belong here, but the only
|
|
|
|
|
* consumers always use it in conjunction with DoDrawString() */
|
2006-11-16 22:05:33 +00:00
|
|
|
|
#define UPARROW "\xEE\x8A\x80"
|
|
|
|
|
#define DOWNARROW "\xEE\x8A\xAA"
|
2005-09-10 07:38:03 +00:00
|
|
|
|
|
|
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
|
int DrawStringCentered(int x, int y, StringID str, uint16 color);
|
2005-07-17 19:23:18 +00:00
|
|
|
|
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
|
2005-07-19 22:12:04 +00:00
|
|
|
|
int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
|
|
|
|
|
int DrawString(int x, int y, StringID str, uint16 color);
|
|
|
|
|
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
|
|
|
|
|
|
2005-02-06 18:30:45 +00:00
|
|
|
|
int DoDrawString(const char *string, int x, int y, uint16 color);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
|
|
|
|
|
|
|
|
|
|
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
|
2005-07-17 19:23:18 +00:00
|
|
|
|
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
|
2006-08-20 10:50:23 +00:00
|
|
|
|
int DrawStringRightAligned(int x, int y, StringID str, uint16 color);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
|
2006-08-20 10:50:23 +00:00
|
|
|
|
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
|
void GfxFillRect(int left, int top, int right, int bottom, int color);
|
|
|
|
|
void GfxDrawLine(int left, int top, int right, int bottom, int color);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
2006-09-16 13:20:14 +00:00
|
|
|
|
BoundingRect GetStringBoundingBox(const char *str);
|
2006-10-27 09:55:38 +00:00
|
|
|
|
uint32 FormatStringLinebreaks(char *str, int maxw);
|
2005-01-22 20:23:18 +00:00
|
|
|
|
void LoadStringWidthTable(void);
|
2005-11-13 21:16:34 +00:00
|
|
|
|
void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
|
2006-10-23 18:13:24 +00:00
|
|
|
|
uint DrawStringMultiLine(int x, int y, StringID str, int maxw);
|
2005-01-22 20:23:18 +00:00
|
|
|
|
void DrawDirtyBlocks(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
void SetDirtyBlocks(int left, int top, int right, int bottom);
|
2005-01-22 20:23:18 +00:00
|
|
|
|
void MarkWholeScreenDirty(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
|
void GfxInitPalettes(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
2006-08-28 07:33:51 +00:00
|
|
|
|
bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int height);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* window.cpp */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
|
void SetMouseCursor(CursorID cursor);
|
2007-01-14 19:57:49 +00:00
|
|
|
|
void SetMouseCursor(SpriteID sprite, SpriteID pal);
|
2007-02-24 15:05:14 +00:00
|
|
|
|
void SetAnimatedMouseCursor(const AnimCursor *table);
|
2005-01-22 20:23:18 +00:00
|
|
|
|
void CursorTick(void);
|
|
|
|
|
void DrawMouseCursor(void);
|
|
|
|
|
void ScreenSizeChanged(void);
|
|
|
|
|
void UndrawMouseCursor(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
bool ChangeResInGame(int w, int h);
|
2005-05-14 21:01:57 +00:00
|
|
|
|
void SortResolutions(int count);
|
2007-02-05 21:16:56 +00:00
|
|
|
|
void ToggleFullScreen(bool fs);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
|
/* gfx.cpp */
|
2005-02-21 18:59:54 +00:00
|
|
|
|
#define ASCII_LETTERSTART 32
|
2006-05-09 13:23:04 +00:00
|
|
|
|
extern FontSize _cur_fontsize;
|
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
|
byte GetCharacterWidth(FontSize size, uint32 key);
|
2006-05-09 13:23:04 +00:00
|
|
|
|
|
|
|
|
|
static inline byte GetCharacterHeight(FontSize size)
|
2005-02-21 19:14:16 +00:00
|
|
|
|
{
|
2006-05-09 13:23:04 +00:00
|
|
|
|
switch (size) {
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
|
case FS_NORMAL: return 10;
|
|
|
|
|
case FS_SMALL: return 6;
|
|
|
|
|
case FS_LARGE: return 18;
|
|
|
|
|
}
|
2005-02-21 19:14:16 +00:00
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
|
VARDEF DrawPixelInfo *_cur_dpi;
|
|
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
|
enum {
|
|
|
|
|
COLOUR_DARK_BLUE,
|
|
|
|
|
COLOUR_PALE_GREEN,
|
|
|
|
|
COLOUR_PINK,
|
|
|
|
|
COLOUR_YELLOW,
|
|
|
|
|
COLOUR_RED,
|
|
|
|
|
COLOUR_LIGHT_BLUE,
|
|
|
|
|
COLOUR_GREEN,
|
|
|
|
|
COLOUR_DARK_GREEN,
|
|
|
|
|
COLOUR_BLUE,
|
|
|
|
|
COLOUR_CREAM,
|
|
|
|
|
COLOUR_MAUVE,
|
|
|
|
|
COLOUR_PURPLE,
|
|
|
|
|
COLOUR_ORANGE,
|
|
|
|
|
COLOUR_BROWN,
|
|
|
|
|
COLOUR_GREY,
|
|
|
|
|
COLOUR_WHITE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* All 16 colour gradients
|
|
|
|
|
* 8 colours per gradient from darkest (0) to lightest (7)
|
|
|
|
|
*/
|
|
|
|
|
VARDEF byte _colour_gradient[16][8];
|
|
|
|
|
|
2004-12-12 20:36:24 +00:00
|
|
|
|
VARDEF bool _use_dos_palette;
|
|
|
|
|
|
2004-12-14 20:54:01 +00:00
|
|
|
|
typedef enum StringColorFlags {
|
2007-03-01 01:24:44 +00:00
|
|
|
|
IS_PALETTE_COLOR = 0x100, ///< color value is already a real palette color index, not an index of a StringColor
|
2004-12-14 20:54:01 +00:00
|
|
|
|
} StringColorFlags;
|
|
|
|
|
|
2007-01-13 14:43:46 +00:00
|
|
|
|
|
2005-11-16 08:35:26 +00:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
extern bool _dbg_screen_rect;
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
|
#endif /* GFX_H */
|