gfx.h
author Darkvater
Sat, 28 Jan 2006 11:18:09 +0000
changeset 2905 e0b7ecfcd0fd
parent 2649 7cd504bd4e51
child 3312 593789444b01
permissions -rw-r--r--
(svn r3460) - Fix: fix language errors and translate some missing string as far as my knowledge of those languages go (thx egladil for swedish)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2134
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2134
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#ifndef GFX_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
#define GFX_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 1991
diff changeset
     6
typedef byte Pixel;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
typedef struct ColorList {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
	byte unk0, unk1, unk2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
	byte window_color_1a, window_color_1b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
	byte window_color_bga, window_color_bgb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
	byte window_color_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
} ColorList;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
struct DrawPixelInfo {
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 1991
diff changeset
    16
	Pixel *dst_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
	int left, top, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
	int pitch;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
    19
	uint16 zoom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
typedef struct CursorVars {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	Point pos, size, offs, delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	Point draw_pos, draw_size;
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1829
diff changeset
    26
	CursorID sprite;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	int wheel; // mouse wheel movement
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1829
diff changeset
    29
	const CursorID *animate_list, *animate_cur;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	uint animate_timeout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	bool visible;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	bool dirty;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	bool fix_at;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
} CursorVars;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
void RedrawScreenRect(int left, int top, int right, int bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    40
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2187
diff changeset
    41
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2187
diff changeset
    42
// XXX doesn't really belong here, but the only
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2187
diff changeset
    43
// consumers always use it in conjunction with DoDrawString()
2407
983f1d8a0614 (svn r2933) Implement the non-breaking space
tron
parents: 2406
diff changeset
    44
#define UPARROW   "\x80"
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2187
diff changeset
    45
#define DOWNARROW "\xAA"
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2187
diff changeset
    46
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2187
diff changeset
    47
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    48
int DrawStringCentered(int x, int y, StringID str, uint16 color);
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2097
diff changeset
    49
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
2134
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
    50
int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    51
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    52
int DrawString(int x, int y, StringID str, uint16 color);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    53
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    54
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1093
diff changeset
    55
int DoDrawString(const char *string, int x, int y, uint16 color);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    56
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    57
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    58
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2097
diff changeset
    59
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    60
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    61
void DrawStringRightAligned(int x, int y, StringID str, uint16 color);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    62
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    63
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
    64
void GfxFillRect(int left, int top, int right, int bottom, int color);
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
    65
void GfxDrawLine(int left, int top, int right, int bottom, int color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
void DrawFrameRect(int left, int top, int right, int bottom, int color, int flags);
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2407
diff changeset
    67
uint16 GetDrawStringPlayerColor(PlayerID player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1093
diff changeset
    69
int GetStringWidth(const char *str);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    70
void LoadStringWidthTable(void);
2634
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2548
diff changeset
    71
void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2548
diff changeset
    72
void DrawStringMultiLine(int x, int y, StringID str, int maxw);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    73
void DrawDirtyBlocks(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
void SetDirtyBlocks(int left, int top, int right, int bottom);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    75
void MarkWholeScreenDirty(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    77
void GfxInitPalettes(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2436
diff changeset
    79
bool FillDrawPixelInfo(DrawPixelInfo* n, const DrawPixelInfo* o, int left, int top, int width, int height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
/* window.c */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
void SetMouseCursor(uint cursor);
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1829
diff changeset
    85
void SetAnimatedMouseCursor(const CursorID *table);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    86
void CursorTick(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    87
void DrawMouseCursor(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    88
void ScreenSizeChanged(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 657
diff changeset
    89
void UndrawMouseCursor(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
bool ChangeResInGame(int w, int h);
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1391
diff changeset
    91
void SortResolutions(int count);
1829
0b6de3b4458a (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1806
diff changeset
    92
void ToggleFullScreen(bool fs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
/* gfx.c */
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1350
diff changeset
    95
#define ASCII_LETTERSTART 32
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
VARDEF int _stringwidth_base;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
VARDEF byte _stringwidth_table[0x2A0];
1391
1325047def14 (svn r1895) - Fix: add assert for charwidth getter just in case
Darkvater
parents: 1390
diff changeset
    98
static inline byte GetCharacterWidth(uint key)
1325047def14 (svn r1895) - Fix: add assert for charwidth getter just in case
Darkvater
parents: 1390
diff changeset
    99
{
1325047def14 (svn r1895) - Fix: add assert for charwidth getter just in case
Darkvater
parents: 1390
diff changeset
   100
	assert(key >= ASCII_LETTERSTART && key - ASCII_LETTERSTART < lengthof(_stringwidth_table));
1325047def14 (svn r1895) - Fix: add assert for charwidth getter just in case
Darkvater
parents: 1390
diff changeset
   101
	return _stringwidth_table[key - ASCII_LETTERSTART];
1325047def14 (svn r1895) - Fix: add assert for charwidth getter just in case
Darkvater
parents: 1390
diff changeset
   102
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
VARDEF DrawPixelInfo _screen;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
VARDEF DrawPixelInfo *_cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
VARDEF ColorList _color_list[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
VARDEF CursorVars _cursor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
VARDEF int _pal_first_dirty;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
VARDEF int _pal_last_dirty;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   112
VARDEF bool _use_dos_palette;
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   113
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   114
typedef struct Colour {
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   115
	byte r;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   116
	byte g;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   117
	byte b;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   118
} Colour;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   119
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   120
extern Colour _cur_palette[256];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
657
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 614
diff changeset
   122
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 614
diff changeset
   123
typedef enum StringColorFlags {
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 614
diff changeset
   124
	IS_PALETTE_COLOR = 0x100, // color value is already a real palette color index, not an index of a StringColor
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 614
diff changeset
   125
} StringColorFlags;
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 614
diff changeset
   126
2649
7cd504bd4e51 (svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents: 2634
diff changeset
   127
#ifdef _DEBUG
7cd504bd4e51 (svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents: 2634
diff changeset
   128
extern bool _dbg_screen_rect;
7cd504bd4e51 (svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents: 2634
diff changeset
   129
#endif
7cd504bd4e51 (svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents: 2634
diff changeset
   130
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2407
diff changeset
   131
#endif /* GFX_H */