author | tron |
Mon, 28 Aug 2006 07:33:51 +0000 | |
changeset 4429 | b4eb6d97996f |
parent 4428 | 6d9fab57f2af |
child 4437 | 49e79e135539 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1829
diff
changeset
|
4 |
#include "openttd.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
5 |
#include "functions.h" |
4428
6d9fab57f2af
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4425
diff
changeset
|
6 |
#include "macros.h" |
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
7 |
#include "spritecache.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1130
diff
changeset
|
8 |
#include "strings.h" |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
9 |
#include "string.h" |
0 | 10 |
#include "gfx.h" |
11 |
#include "table/palettes.h" |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
12 |
#include "table/sprites.h" |
0 | 13 |
#include "hal.h" |
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2134
diff
changeset
|
14 |
#include "variables.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
15 |
#include "genworld.h" |
0 | 16 |
|
2649
1392cd1a60cc
(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:
2645
diff
changeset
|
17 |
#ifdef _DEBUG |
1392cd1a60cc
(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:
2645
diff
changeset
|
18 |
bool _dbg_screen_rect; |
1392cd1a60cc
(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:
2645
diff
changeset
|
19 |
#endif |
1392cd1a60cc
(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:
2645
diff
changeset
|
20 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
21 |
Colour _cur_palette[256]; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
22 |
byte _stringwidth_table[FS_END][224]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
23 |
|
1357 | 24 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, int mode); |
0 | 25 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
26 |
FontSize _cur_fontsize; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
27 |
static FontSize _last_fontsize; |
2062 | 28 |
static Pixel _cursor_backup[64 * 64]; |
0 | 29 |
static Rect _invalid_rect; |
1357 | 30 |
static const byte *_color_remap_ptr; |
0 | 31 |
static byte _string_colorremap[3]; |
32 |
||
2010 | 33 |
#define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH / 64) |
0 | 34 |
static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8]; |
35 |
||
36 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
37 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
38 |
void memcpy_pitch(void *d, void *s, int w, int h, int spitch, int dpitch) |
0 | 39 |
{ |
40 |
byte *dp = (byte*)d; |
|
41 |
byte *sp = (byte*)s; |
|
42 |
||
43 |
assert(h >= 0); |
|
1056
24579058c082
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
44 |
for (; h != 0; --h) { |
0 | 45 |
memcpy(dp, sp, w); |
46 |
dp += dpitch; |
|
47 |
sp += spitch; |
|
1056
24579058c082
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
48 |
} |
0 | 49 |
} |
50 |
||
51 |
||
2010 | 52 |
void GfxScroll(int left, int top, int width, int height, int xo, int yo) |
53 |
{ |
|
2062 | 54 |
const Pixel *src; |
55 |
Pixel *dst; |
|
0 | 56 |
int p; |
57 |
int ht; |
|
58 |
||
2010 | 59 |
if (xo == 0 && yo == 0) return; |
0 | 60 |
|
2010 | 61 |
if (_cursor.visible) UndrawMouseCursor(); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
62 |
UndrawTextMessage(); |
0 | 63 |
|
64 |
p = _screen.pitch; |
|
65 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
66 |
if (yo > 0) { |
0 | 67 |
// Calculate pointers |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
68 |
dst = _screen.dst_ptr + (top + height - 1) * p + left; |
0 | 69 |
src = dst - yo * p; |
70 |
||
71 |
// Decrease height and increase top |
|
72 |
top += yo; |
|
73 |
height -= yo; |
|
74 |
assert(height > 0); |
|
75 |
||
76 |
// Adjust left & width |
|
77 |
if (xo >= 0) { |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
78 |
dst += xo; |
0 | 79 |
left += xo; |
80 |
width -= xo; |
|
81 |
} else { |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
82 |
src -= xo; |
0 | 83 |
width += xo; |
84 |
} |
|
85 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
86 |
for (ht = height; ht > 0; --ht) { |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
87 |
memcpy(dst, src, width); |
0 | 88 |
src -= p; |
89 |
dst -= p; |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
90 |
} |
0 | 91 |
} else { |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
92 |
// Calculate pointers |
0 | 93 |
dst = _screen.dst_ptr + top * p + left; |
94 |
src = dst - yo * p; |
|
95 |
||
96 |
// Decrese height. (yo is <=0). |
|
97 |
height += yo; |
|
98 |
assert(height > 0); |
|
99 |
||
100 |
// Adjust left & width |
|
101 |
if (xo >= 0) { |
|
102 |
dst += xo; |
|
103 |
left += xo; |
|
104 |
width -= xo; |
|
105 |
} else { |
|
106 |
src -= xo; |
|
107 |
width += xo; |
|
108 |
} |
|
109 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
110 |
// the y-displacement may be 0 therefore we have to use memmove, |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
111 |
// because source and destination may overlap |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
112 |
for (ht = height; ht > 0; --ht) { |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
113 |
memmove(dst, src, width); |
0 | 114 |
src += p; |
115 |
dst += p; |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
116 |
} |
0 | 117 |
} |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
118 |
// This part of the screen is now dirty. |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
119 |
_video_driver->make_dirty(left, top, width, height); |
0 | 120 |
} |
121 |
||
122 |
||
2010 | 123 |
void GfxFillRect(int left, int top, int right, int bottom, int color) |
124 |
{ |
|
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
125 |
const DrawPixelInfo* dpi = _cur_dpi; |
2062 | 126 |
Pixel *dst; |
332 | 127 |
const int otop = top; |
128 |
const int oleft = left; |
|
0 | 129 |
|
2010 | 130 |
if (dpi->zoom != 0) return; |
131 |
if (left > right || top > bottom) return; |
|
132 |
if (right < dpi->left || left >= dpi->left + dpi->width) return; |
|
133 |
if (bottom < dpi->top || top >= dpi->top + dpi->height) return; |
|
0 | 134 |
|
135 |
if ( (left -= dpi->left) < 0) left = 0; |
|
136 |
right = right - dpi->left + 1; |
|
2010 | 137 |
if (right > dpi->width) right = dpi->width; |
0 | 138 |
right -= left; |
139 |
assert(right > 0); |
|
140 |
||
141 |
if ( (top -= dpi->top) < 0) top = 0; |
|
142 |
bottom = bottom - dpi->top + 1; |
|
2010 | 143 |
if (bottom > dpi->height) bottom = dpi->height; |
0 | 144 |
bottom -= top; |
145 |
assert(bottom > 0); |
|
146 |
||
147 |
dst = dpi->dst_ptr + top * dpi->pitch + left; |
|
148 |
||
2218
2132596a35c0
(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents:
2204
diff
changeset
|
149 |
if (!(color & PALETTE_MODIFIER_GREYOUT)) { |
2132596a35c0
(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents:
2204
diff
changeset
|
150 |
if (!(color & USE_COLORTABLE)) { |
0 | 151 |
do { |
152 |
memset(dst, color, right); |
|
153 |
dst += dpi->pitch; |
|
154 |
} while (--bottom); |
|
155 |
} else { |
|
156 |
/* use colortable mode */ |
|
2218
2132596a35c0
(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents:
2204
diff
changeset
|
157 |
const byte* ctab = GetNonSprite(color & COLORTABLE_MASK) + 1; |
1357 | 158 |
|
0 | 159 |
do { |
160 |
int i; |
|
2005 | 161 |
for (i = 0; i != right; i++) dst[i] = ctab[dst[i]]; |
0 | 162 |
dst += dpi->pitch; |
163 |
} while (--bottom); |
|
164 |
} |
|
165 |
} else { |
|
332 | 166 |
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; |
0 | 167 |
do { |
168 |
int i; |
|
2005 | 169 |
for (i = (bo ^= 1); i < right; i += 2) dst[i] = (byte)color; |
0 | 170 |
dst += dpi->pitch; |
332 | 171 |
} while (--bottom > 0); |
0 | 172 |
} |
173 |
} |
|
174 |
||
410 | 175 |
static void GfxSetPixel(int x, int y, int color) |
0 | 176 |
{ |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
177 |
const DrawPixelInfo* dpi = _cur_dpi; |
0 | 178 |
if ((x-=dpi->left) < 0 || x>=dpi->width || (y-=dpi->top)<0 || y>=dpi->height) |
179 |
return; |
|
2010 | 180 |
dpi->dst_ptr[y * dpi->pitch + x] = color; |
0 | 181 |
} |
182 |
||
183 |
void GfxDrawLine(int x, int y, int x2, int y2, int color) |
|
184 |
{ |
|
185 |
int dy; |
|
186 |
int dx; |
|
2010 | 187 |
int stepx; |
188 |
int stepy; |
|
0 | 189 |
int frac; |
190 |
||
191 |
// Check clipping first |
|
192 |
{ |
|
193 |
DrawPixelInfo *dpi = _cur_dpi; |
|
194 |
int t; |
|
195 |
||
2010 | 196 |
if (x < dpi->left && x2 < dpi->left) return; |
0 | 197 |
|
2010 | 198 |
if (y < dpi->top && y2 < dpi->top) return; |
0 | 199 |
|
200 |
t = dpi->left + dpi->width; |
|
2010 | 201 |
if (x > t && x2 > t) return; |
0 | 202 |
|
203 |
t = dpi->top + dpi->height; |
|
2010 | 204 |
if (y > t && y2 > t) return; |
0 | 205 |
} |
206 |
||
207 |
dy = (y2 - y) * 2; |
|
2010 | 208 |
if (dy < 0) { |
209 |
dy = -dy; |
|
210 |
stepy = -1; |
|
211 |
} else { |
|
212 |
stepy = 1; |
|
213 |
} |
|
0 | 214 |
|
215 |
dx = (x2 - x) * 2; |
|
2010 | 216 |
if (dx < 0) { |
217 |
dx = -dx; |
|
218 |
stepx = -1; |
|
219 |
} else { |
|
220 |
stepx = 1; |
|
221 |
} |
|
0 | 222 |
|
223 |
GfxSetPixel(x, y, color); |
|
224 |
if (dx > dy) { |
|
225 |
frac = dy - (dx >> 1); |
|
226 |
while (x != x2) { |
|
227 |
if (frac >= 0) { |
|
228 |
y += stepy; |
|
229 |
frac -= dx; |
|
230 |
} |
|
231 |
x += stepx; |
|
232 |
frac += dy; |
|
233 |
GfxSetPixel(x, y, color); |
|
234 |
} |
|
235 |
} else { |
|
236 |
frac = dx - (dy >> 1); |
|
237 |
while (y != y2) { |
|
238 |
if (frac >= 0) { |
|
239 |
x += stepx; |
|
240 |
frac -= dy; |
|
241 |
} |
|
242 |
y += stepy; |
|
243 |
frac += dx; |
|
244 |
GfxSetPixel(x, y, color); |
|
245 |
} |
|
246 |
} |
|
247 |
} |
|
248 |
||
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
249 |
|
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
250 |
static inline SpriteID GetFontBase(FontSize size) |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
251 |
{ |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
252 |
switch (size) { |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
253 |
default: NOT_REACHED(); |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
254 |
case FS_NORMAL: return SPR_ASCII_SPACE; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
255 |
case FS_SMALL: return SPR_ASCII_SPACE_SMALL; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
256 |
case FS_LARGE: return SPR_ASCII_SPACE_BIG; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
257 |
} |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
258 |
} |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
259 |
|
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
260 |
|
0 | 261 |
// ASSIGNMENT OF ASCII LETTERS < 32 |
262 |
// 0 - end of string |
|
263 |
// 1 - SETX <BYTE> |
|
264 |
// 2 - SETXY <BYTE> <BYTE> |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
265 |
// 3-7 - |
0 | 266 |
// 8 - TINYFONT |
267 |
// 9 - BIGFONT |
|
268 |
// 10 - newline |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
269 |
// 11-14 - |
0 | 270 |
// 15-31 - 17 colors |
271 |
||
272 |
||
273 |
enum { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4314
diff
changeset
|
274 |
ASCII_SETX = 1, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4314
diff
changeset
|
275 |
ASCII_SETXY = 2, |
0 | 276 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4314
diff
changeset
|
277 |
ASCII_TINYFONT = 8, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4314
diff
changeset
|
278 |
ASCII_BIGFONT = 9, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4314
diff
changeset
|
279 |
ASCII_NL = 10, |
0 | 280 |
|
281 |
ASCII_COLORSTART = 15, |
|
282 |
}; |
|
283 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
284 |
/** Truncate a given string to a maximum width if neccessary. |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
285 |
* If the string is truncated, add three dots ('...') to show this. |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
286 |
* @param *dest string that is checked and possibly truncated |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
287 |
* @param maxw maximum width in pixels of the string |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
288 |
* @return new width of (truncated) string */ |
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
289 |
static int TruncateString(char *str, int maxw) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
290 |
{ |
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
291 |
int w = 0; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
292 |
FontSize size = _cur_fontsize; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
293 |
int ddd, ddd_w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
294 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
295 |
byte c; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
296 |
char *ddd_pos; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
297 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
298 |
ddd_w = ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
299 |
|
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
300 |
for (ddd_pos = str; (c = *str++) != '\0'; ) { |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
301 |
if (c >= ASCII_LETTERSTART) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
302 |
w += GetCharacterWidth(size, c); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
303 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
304 |
if (w >= maxw) { |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
305 |
// string got too big... insert dotdotdot |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
306 |
ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
307 |
ddd_pos[3] = 0; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
308 |
return ddd_w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
309 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
310 |
} else { |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
311 |
if (c == ASCII_SETX) str++; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
312 |
else if (c == ASCII_SETXY) str += 2; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
313 |
else if (c == ASCII_TINYFONT) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
314 |
size = FS_SMALL; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
315 |
ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
316 |
} else if (c == ASCII_BIGFONT) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
317 |
size = FS_LARGE; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
318 |
ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
319 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
320 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
321 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
322 |
// Remember the last position where three dots fit. |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
323 |
if (w + ddd < maxw) { |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
324 |
ddd_w = w + ddd; |
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
325 |
ddd_pos = str; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
326 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
327 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
328 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
329 |
return w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
330 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
331 |
|
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
332 |
static inline int TruncateStringID(StringID src, char *dest, int maxw) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
333 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
334 |
GetString(dest, src); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
335 |
return TruncateString(dest, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
336 |
} |
0 | 337 |
|
338 |
/* returns right coordinate */ |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
339 |
int DrawString(int x, int y, StringID str, uint16 color) |
0 | 340 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
341 |
char buffer[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
342 |
|
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
343 |
GetString(buffer, str); |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
344 |
return DoDrawString(buffer, x, y, color); |
0 | 345 |
} |
346 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
347 |
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
348 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
349 |
char buffer[512]; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
350 |
TruncateStringID(str, buffer, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
351 |
return DoDrawString(buffer, x, y, color); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
352 |
} |
0 | 353 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
354 |
|
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
355 |
int DrawStringRightAligned(int x, int y, StringID str, uint16 color) |
0 | 356 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
357 |
char buffer[512]; |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
358 |
int w; |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
359 |
|
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
360 |
GetString(buffer, str); |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
361 |
w = GetStringWidth(buffer); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
362 |
DoDrawString(buffer, x - w, y, color); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
363 |
|
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
364 |
return w; |
0 | 365 |
} |
366 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
367 |
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
368 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
369 |
char buffer[512]; |
0 | 370 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
371 |
TruncateStringID(str, buffer, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
372 |
DoDrawString(buffer, x - GetStringWidth(buffer), y, color); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
373 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
374 |
|
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
375 |
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color) |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
376 |
{ |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
377 |
int w = DrawStringRightAligned(x, y, str, color); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
378 |
GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
379 |
} |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
380 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
381 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
382 |
int DrawStringCentered(int x, int y, StringID str, uint16 color) |
0 | 383 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
384 |
char buffer[512]; |
0 | 385 |
int w; |
386 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
387 |
GetString(buffer, str); |
0 | 388 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
389 |
w = GetStringWidth(buffer); |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
390 |
DoDrawString(buffer, x - w / 2, y, color); |
0 | 391 |
|
392 |
return w; |
|
393 |
} |
|
394 |
||
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
395 |
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
396 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
397 |
char buffer[512]; |
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
398 |
int w = TruncateStringID(str, buffer, xr - xl); |
be2f07df0dfa
(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:
2107
diff
changeset
|
399 |
return DoDrawString(buffer, (xl + xr - w) / 2, y, color); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
400 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
401 |
|
2134 | 402 |
int DoDrawStringCentered(int x, int y, const char *str, uint16 color) |
403 |
{ |
|
404 |
int w = GetStringWidth(str); |
|
405 |
DoDrawString(str, x - w / 2, y, color); |
|
406 |
return w; |
|
407 |
} |
|
408 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
409 |
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color) |
0 | 410 |
{ |
411 |
int w = DrawStringCentered(x, y, str, color); |
|
2010 | 412 |
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]); |
0 | 413 |
} |
414 |
||
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
415 |
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
416 |
{ |
2113
be2f07df0dfa
(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:
2107
diff
changeset
|
417 |
int w = DrawStringCenteredTruncated(xl, xr, y, str, color); |
be2f07df0dfa
(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:
2107
diff
changeset
|
418 |
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
419 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
420 |
|
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
421 |
static uint32 FormatStringLinebreaks(char *str, int maxw) |
1095 | 422 |
{ |
0 | 423 |
int num = 0; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
424 |
FontSize size = _cur_fontsize; |
0 | 425 |
int w; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
426 |
char *last_space; |
0 | 427 |
byte c; |
428 |
||
2952 | 429 |
for (;;) { |
0 | 430 |
w = 0; |
431 |
last_space = NULL; |
|
432 |
||
2952 | 433 |
for (;;) { |
0 | 434 |
c = *str++; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
435 |
if (c == ASCII_LETTERSTART) last_space = str; |
0 | 436 |
|
437 |
if (c >= ASCII_LETTERSTART) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
438 |
w += GetCharacterWidth(size, c); |
0 | 439 |
if (w > maxw) { |
440 |
str = last_space; |
|
441 |
if (str == NULL) |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
442 |
return num + (size << 16); |
0 | 443 |
break; |
444 |
} |
|
445 |
} else { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
446 |
if (c == 0) return num + (size << 16); |
0 | 447 |
if (c == ASCII_NL) break; |
448 |
||
449 |
if (c == ASCII_SETX) str++; |
|
450 |
else if (c == ASCII_SETXY) str += 2; |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
451 |
else if (c == ASCII_TINYFONT) size = FS_SMALL; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
452 |
else if (c == ASCII_BIGFONT) size = FS_LARGE; |
0 | 453 |
} |
454 |
} |
|
455 |
||
456 |
num++; |
|
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
457 |
str[-1] = '\0'; |
0 | 458 |
} |
459 |
} |
|
460 |
||
2634
0df9396b0067
(svn r3176) Use proper types, not some variants of int
tron
parents:
2631
diff
changeset
|
461 |
void DrawStringMultiCenter(int x, int y, StringID str, int maxw) |
0 | 462 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
463 |
char buffer[512]; |
0 | 464 |
uint32 tmp; |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
465 |
int num, w, mt; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
466 |
const char *src; |
0 | 467 |
byte c; |
468 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
469 |
GetString(buffer, str); |
0 | 470 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
471 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 472 |
num = GB(tmp, 0, 16); |
0 | 473 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
474 |
mt = GetCharacterHeight(GB(tmp, 16, 16)); |
0 | 475 |
|
476 |
y -= (mt >> 1) * num; |
|
477 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
478 |
src = buffer; |
0 | 479 |
|
2952 | 480 |
for (;;) { |
0 | 481 |
w = GetStringWidth(src); |
482 |
DoDrawString(src, x - (w>>1), y, 0xFE); |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
483 |
_cur_fontsize = _last_fontsize; |
0 | 484 |
|
2952 | 485 |
for (;;) { |
0 | 486 |
c = *src++; |
487 |
if (c == 0) { |
|
488 |
y += mt; |
|
489 |
if (--num < 0) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
490 |
_cur_fontsize = FS_NORMAL; |
0 | 491 |
return; |
492 |
} |
|
493 |
break; |
|
494 |
} else if (c == ASCII_SETX) { |
|
495 |
src++; |
|
496 |
} else if (c == ASCII_SETXY) { |
|
497 |
src+=2; |
|
498 |
} |
|
499 |
} |
|
500 |
} |
|
501 |
} |
|
502 |
||
2634
0df9396b0067
(svn r3176) Use proper types, not some variants of int
tron
parents:
2631
diff
changeset
|
503 |
void DrawStringMultiLine(int x, int y, StringID str, int maxw) |
2010 | 504 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
505 |
char buffer[512]; |
0 | 506 |
uint32 tmp; |
2753 | 507 |
int num, mt; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
508 |
const char *src; |
0 | 509 |
byte c; |
510 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
511 |
GetString(buffer, str); |
0 | 512 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
513 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 514 |
num = GB(tmp, 0, 16); |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
515 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
516 |
mt = GetCharacterHeight(GB(tmp, 16, 16)); |
0 | 517 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
518 |
src = buffer; |
0 | 519 |
|
2952 | 520 |
for (;;) { |
0 | 521 |
DoDrawString(src, x, y, 0xFE); |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
522 |
_cur_fontsize = _last_fontsize; |
0 | 523 |
|
2952 | 524 |
for (;;) { |
0 | 525 |
c = *src++; |
526 |
if (c == 0) { |
|
527 |
y += mt; |
|
528 |
if (--num < 0) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
529 |
_cur_fontsize = FS_NORMAL; |
0 | 530 |
return; |
531 |
} |
|
532 |
break; |
|
533 |
} else if (c == ASCII_SETX) { |
|
534 |
src++; |
|
535 |
} else if (c == ASCII_SETXY) { |
|
536 |
src+=2; |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
||
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
542 |
int GetStringWidth(const char *str) |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
543 |
{ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
544 |
FontSize size = _cur_fontsize; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
545 |
int w = 0; |
0 | 546 |
byte c; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
547 |
for (c = *str; c != '\0'; c = *(++str)) { |
0 | 548 |
if (c >= ASCII_LETTERSTART) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
549 |
w += GetCharacterWidth(size, c); |
0 | 550 |
} else { |
551 |
if (c == ASCII_SETX) str++; |
|
552 |
else if (c == ASCII_SETXY) str += 2; |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
553 |
else if (c == ASCII_TINYFONT) size = FS_SMALL; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
554 |
else if (c == ASCII_BIGFONT) size = FS_LARGE; |
0 | 555 |
} |
556 |
} |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
557 |
return w; |
0 | 558 |
} |
559 |
||
2010 | 560 |
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, int flags) |
561 |
{ |
|
0 | 562 |
byte color_2 = _color_list[ctab].window_color_1a; |
563 |
byte color_interior = _color_list[ctab].window_color_bga; |
|
564 |
byte color_3 = _color_list[ctab].window_color_bgb; |
|
565 |
byte color = _color_list[ctab].window_color_2; |
|
566 |
||
2025 | 567 |
if (!(flags & 0x8)) { |
0 | 568 |
if (!(flags & 0x20)) { |
2010 | 569 |
GfxFillRect(left, top, left, bottom - 1, color); |
570 |
GfxFillRect(left + 1, top, right - 1, top, color); |
|
571 |
GfxFillRect(right, top, right, bottom - 1, color_2); |
|
0 | 572 |
GfxFillRect(left, bottom, right, bottom, color_2); |
573 |
if (!(flags & 0x10)) { |
|
2010 | 574 |
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, color_interior); |
0 | 575 |
} |
576 |
} else { |
|
577 |
GfxFillRect(left, top, left, bottom, color_2); |
|
2010 | 578 |
GfxFillRect(left + 1, top, right, top, color_2); |
579 |
GfxFillRect(right, top + 1, right, bottom - 1, color); |
|
580 |
GfxFillRect(left + 1, bottom, right, bottom, color); |
|
0 | 581 |
if (!(flags & 0x10)) { |
2010 | 582 |
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, |
583 |
flags & 0x40 ? color_interior : color_3); |
|
0 | 584 |
} |
585 |
} |
|
586 |
} else if (flags & 0x1) { |
|
587 |
// transparency |
|
2218
2132596a35c0
(svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents:
2204
diff
changeset
|
588 |
GfxFillRect(left, top, right, bottom, 0x322 | USE_COLORTABLE); |
0 | 589 |
} else { |
590 |
GfxFillRect(left, top, right, bottom, color_interior); |
|
591 |
} |
|
592 |
} |
|
593 |
||
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
594 |
int DoDrawString(const char *string, int x, int y, uint16 real_color) |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
595 |
{ |
0 | 596 |
DrawPixelInfo *dpi = _cur_dpi; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
597 |
FontSize size = _cur_fontsize; |
509
3217af6d2d6a
(svn r819) Code cleanup: colors for langfile strings are now taken from a color table instead of a sprite
dominik
parents:
461
diff
changeset
|
598 |
byte c; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
599 |
byte color; |
0 | 600 |
int xo = x, yo = y; |
601 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
602 |
color = real_color & 0xFF; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
603 |
|
0 | 604 |
if (color != 0xFE) { |
605 |
if (x >= dpi->left + dpi->width || |
|
606 |
x + _screen.width*2 <= dpi->left || |
|
607 |
y >= dpi->top + dpi->height || |
|
608 |
y + _screen.height <= dpi->top) |
|
609 |
return x; |
|
610 |
||
611 |
if (color != 0xFF) { |
|
612 |
switch_color:; |
|
657
d4d36b4853ec
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
613 |
if (real_color & IS_PALETTE_COLOR) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
614 |
_string_colorremap[1] = color; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
615 |
_string_colorremap[2] = 215; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
616 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
617 |
_string_colorremap[1] = _string_colormap[color].text; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
618 |
_string_colorremap[2] = _string_colormap[color].shadow; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
619 |
} |
0 | 620 |
_color_remap_ptr = _string_colorremap; |
621 |
} |
|
622 |
} |
|
623 |
||
624 |
check_bounds: |
|
625 |
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) { |
|
626 |
skip_char:; |
|
2952 | 627 |
for (;;) { |
0 | 628 |
c = *string++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
629 |
if (c < ASCII_LETTERSTART) goto skip_cont; |
0 | 630 |
} |
631 |
} |
|
632 |
||
2952 | 633 |
for (;;) { |
0 | 634 |
c = *string++; |
635 |
skip_cont:; |
|
636 |
if (c == 0) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
637 |
_last_fontsize = size; |
0 | 638 |
return x; |
639 |
} |
|
640 |
if (c >= ASCII_LETTERSTART) { |
|
641 |
if (x >= dpi->left + dpi->width) goto skip_char; |
|
642 |
if (x + 26 >= dpi->left) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
643 |
GfxMainBlitter(GetSprite(GetFontBase(size) + c - ASCII_LETTERSTART), x, y, 1); |
0 | 644 |
} |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
645 |
x += GetCharacterWidth(size, c); |
0 | 646 |
} else if (c == ASCII_NL) { // newline = {} |
647 |
x = xo; |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
648 |
y += GetCharacterHeight(size); |
0 | 649 |
goto check_bounds; |
650 |
} else if (c >= ASCII_COLORSTART) { // change color? |
|
651 |
color = (byte)(c - ASCII_COLORSTART); |
|
652 |
goto switch_color; |
|
653 |
} else if (c == ASCII_SETX) { // {SETX} |
|
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
654 |
x = xo + (byte)*string++; |
0 | 655 |
} else if (c == ASCII_SETXY) {// {SETXY} |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
656 |
x = xo + (byte)*string++; |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
657 |
y = yo + (byte)*string++; |
0 | 658 |
} else if (c == ASCII_TINYFONT) { // {TINYFONT} |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
659 |
size = FS_SMALL; |
0 | 660 |
} else if (c == ASCII_BIGFONT) { // {BIGFONT} |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
661 |
size = FS_LARGE; |
0 | 662 |
} else { |
663 |
printf("Unknown string command character %d\n", c); |
|
664 |
} |
|
665 |
} |
|
666 |
} |
|
667 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
668 |
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
669 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
670 |
char buffer[512]; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
671 |
ttd_strlcpy(buffer, str, sizeof(buffer)); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
672 |
TruncateString(buffer, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
673 |
return DoDrawString(buffer, x, y, color); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
674 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
675 |
|
2010 | 676 |
void DrawSprite(uint32 img, int x, int y) |
677 |
{ |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
678 |
if (img & PALETTE_MODIFIER_COLOR) { |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
679 |
_color_remap_ptr = GetNonSprite(GB(img, PALETTE_SPRITE_START, PALETTE_SPRITE_WIDTH)) + 1; |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
680 |
GfxMainBlitter(GetSprite(img & SPRITE_MASK), x, y, 1); |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
681 |
} else if (img & PALETTE_MODIFIER_TRANSPARENT) { |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
682 |
_color_remap_ptr = GetNonSprite(GB(img, PALETTE_SPRITE_START, PALETTE_SPRITE_WIDTH)) + 1; |
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
683 |
GfxMainBlitter(GetSprite(img & SPRITE_MASK), x, y, 2); |
0 | 684 |
} else { |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
685 |
GfxMainBlitter(GetSprite(img & SPRITE_MASK), x, y, 0); |
0 | 686 |
} |
687 |
} |
|
688 |
||
689 |
typedef struct BlitterParams { |
|
690 |
int start_x, start_y; |
|
4171 | 691 |
const byte *sprite; |
692 |
const byte *sprite_org; |
|
2062 | 693 |
Pixel *dst; |
0 | 694 |
int mode; |
695 |
int width, height; |
|
2010 | 696 |
int width_org; |
697 |
int height_org; |
|
0 | 698 |
int pitch; |
699 |
byte info; |
|
700 |
} BlitterParams; |
|
701 |
||
702 |
static void GfxBlitTileZoomIn(BlitterParams *bp) |
|
703 |
{ |
|
4171 | 704 |
const byte *src_o = bp->sprite; |
705 |
const byte *src; |
|
0 | 706 |
int num, skip; |
707 |
byte done; |
|
2062 | 708 |
Pixel *dst; |
4171 | 709 |
const byte *ctab; |
0 | 710 |
|
711 |
if (bp->mode & 1) { |
|
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
712 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
713 |
|
0 | 714 |
do { |
715 |
do { |
|
716 |
done = src_o[0]; |
|
717 |
num = done & 0x7F; |
|
718 |
skip = src_o[1]; |
|
719 |
src = src_o + 2; |
|
720 |
src_o += num + 2; |
|
721 |
||
722 |
dst = bp->dst; |
|
723 |
||
724 |
if ( (skip -= bp->start_x) > 0) { |
|
725 |
dst += skip; |
|
726 |
} else { |
|
727 |
src -= skip; |
|
728 |
num += skip; |
|
2010 | 729 |
if (num <= 0) continue; |
0 | 730 |
skip = 0; |
731 |
} |
|
732 |
||
733 |
skip = skip + num - bp->width; |
|
734 |
if (skip > 0) { |
|
735 |
num -= skip; |
|
2010 | 736 |
if (num <= 0) continue; |
0 | 737 |
} |
738 |
||
739 |
ctab = _color_remap_ptr; |
|
740 |
||
1997 | 741 |
for (; num >= 4; num -=4) { |
0 | 742 |
dst[3] = ctab[src[3]]; |
743 |
dst[2] = ctab[src[2]]; |
|
744 |
dst[1] = ctab[src[1]]; |
|
745 |
dst[0] = ctab[src[0]]; |
|
746 |
dst += 4; |
|
747 |
src += 4; |
|
748 |
} |
|
1997 | 749 |
for (; num != 0; num--) *dst++ = ctab[*src++]; |
0 | 750 |
} while (!(done & 0x80)); |
751 |
||
752 |
bp->dst += bp->pitch; |
|
2010 | 753 |
} while (--bp->height != 0); |
0 | 754 |
} else if (bp->mode & 2) { |
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
755 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
0 | 756 |
do { |
757 |
do { |
|
758 |
done = src_o[0]; |
|
759 |
num = done & 0x7F; |
|
760 |
skip = src_o[1]; |
|
761 |
src_o += num + 2; |
|
762 |
||
763 |
dst = bp->dst; |
|
764 |
||
765 |
if ( (skip -= bp->start_x) > 0) { |
|
766 |
dst += skip; |
|
767 |
} else { |
|
768 |
num += skip; |
|
2010 | 769 |
if (num <= 0) continue; |
0 | 770 |
skip = 0; |
771 |
} |
|
772 |
||
773 |
skip = skip + num - bp->width; |
|
774 |
if (skip > 0) { |
|
775 |
num -= skip; |
|
2010 | 776 |
if (num <= 0) continue; |
0 | 777 |
} |
778 |
||
779 |
ctab = _color_remap_ptr; |
|
1997 | 780 |
for (; num != 0; num--) { |
0 | 781 |
*dst = ctab[*dst]; |
782 |
dst++; |
|
783 |
} |
|
784 |
} while (!(done & 0x80)); |
|
785 |
||
786 |
bp->dst += bp->pitch; |
|
2010 | 787 |
} while (--bp->height != 0); |
0 | 788 |
} else { |
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
789 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
0 | 790 |
do { |
791 |
do { |
|
792 |
done = src_o[0]; |
|
793 |
num = done & 0x7F; |
|
794 |
skip = src_o[1]; |
|
795 |
src = src_o + 2; |
|
796 |
src_o += num + 2; |
|
797 |
||
798 |
dst = bp->dst; |
|
799 |
||
800 |
if ( (skip -= bp->start_x) > 0) { |
|
801 |
dst += skip; |
|
802 |
} else { |
|
803 |
src -= skip; |
|
804 |
num += skip; |
|
2010 | 805 |
if (num <= 0) continue; |
0 | 806 |
skip = 0; |
807 |
} |
|
808 |
||
809 |
skip = skip + num - bp->width; |
|
810 |
if (skip > 0) { |
|
811 |
num -= skip; |
|
2010 | 812 |
if (num <= 0) continue; |
0 | 813 |
} |
814 |
#if defined(_WIN32) |
|
815 |
if (num & 1) *dst++ = *src++; |
|
816 |
if (num & 2) { *(uint16*)dst = *(uint16*)src; dst += 2; src += 2; } |
|
817 |
if (num >>= 2) { |
|
818 |
do { |
|
819 |
*(uint32*)dst = *(uint32*)src; |
|
820 |
dst += 4; |
|
821 |
src += 4; |
|
2010 | 822 |
} while (--num != 0); |
0 | 823 |
} |
824 |
#else |
|
825 |
memcpy(dst, src, num); |
|
826 |
#endif |
|
827 |
} while (!(done & 0x80)); |
|
828 |
||
829 |
bp->dst += bp->pitch; |
|
2010 | 830 |
} while (--bp->height != 0); |
0 | 831 |
} |
832 |
} |
|
833 |
||
834 |
static void GfxBlitZoomInUncomp(BlitterParams *bp) |
|
835 |
{ |
|
1357 | 836 |
const byte *src = bp->sprite; |
2062 | 837 |
Pixel *dst = bp->dst; |
0 | 838 |
int height = bp->height; |
839 |
int width = bp->width; |
|
840 |
int i; |
|
841 |
||
842 |
assert(height > 0); |
|
843 |
assert(width > 0); |
|
844 |
||
845 |
if (bp->mode & 1) { |
|
846 |
if (bp->info & 1) { |
|
1357 | 847 |
const byte *ctab = _color_remap_ptr; |
0 | 848 |
|
849 |
do { |
|
1996 | 850 |
for (i = 0; i != width; i++) { |
851 |
byte b = ctab[src[i]]; |
|
852 |
||
853 |
if (b != 0) dst[i] = b; |
|
0 | 854 |
} |
855 |
src += bp->width_org; |
|
856 |
dst += bp->pitch; |
|
2010 | 857 |
} while (--height != 0); |
0 | 858 |
} |
859 |
} else if (bp->mode & 2) { |
|
860 |
if (bp->info & 1) { |
|
1357 | 861 |
const byte *ctab = _color_remap_ptr; |
862 |
||
0 | 863 |
do { |
1996 | 864 |
for (i = 0; i != width; i++) |
865 |
if (src[i] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 866 |
src += bp->width_org; |
867 |
dst += bp->pitch; |
|
2010 | 868 |
} while (--height != 0); |
0 | 869 |
} |
870 |
} else { |
|
871 |
if (!(bp->info & 1)) { |
|
872 |
do { |
|
873 |
memcpy(dst, src, width); |
|
874 |
src += bp->width_org; |
|
875 |
dst += bp->pitch; |
|
2010 | 876 |
} while (--height != 0); |
0 | 877 |
} else { |
878 |
do { |
|
879 |
int n = width; |
|
2004 | 880 |
|
881 |
for (; n >= 4; n -= 4) { |
|
1996 | 882 |
if (src[0] != 0) dst[0] = src[0]; |
883 |
if (src[1] != 0) dst[1] = src[1]; |
|
884 |
if (src[2] != 0) dst[2] = src[2]; |
|
885 |
if (src[3] != 0) dst[3] = src[3]; |
|
0 | 886 |
|
887 |
dst += 4; |
|
888 |
src += 4; |
|
889 |
} |
|
890 |
||
2004 | 891 |
for (; n != 0; n--) { |
1996 | 892 |
if (src[0] != 0) dst[0] = src[0]; |
0 | 893 |
src++; |
894 |
dst++; |
|
895 |
} |
|
896 |
||
897 |
src += bp->width_org - width; |
|
898 |
dst += bp->pitch - width; |
|
2010 | 899 |
} while (--height != 0); |
0 | 900 |
} |
901 |
} |
|
902 |
} |
|
903 |
||
904 |
static void GfxBlitTileZoomMedium(BlitterParams *bp) |
|
905 |
{ |
|
4171 | 906 |
const byte *src_o = bp->sprite; |
907 |
const byte *src; |
|
0 | 908 |
int num, skip; |
909 |
byte done; |
|
2062 | 910 |
Pixel *dst; |
4171 | 911 |
const byte *ctab; |
0 | 912 |
|
913 |
if (bp->mode & 1) { |
|
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
914 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
0 | 915 |
do { |
916 |
do { |
|
917 |
done = src_o[0]; |
|
918 |
num = done & 0x7F; |
|
919 |
skip = src_o[1]; |
|
920 |
src = src_o + 2; |
|
921 |
src_o += num + 2; |
|
922 |
||
923 |
dst = bp->dst; |
|
924 |
||
925 |
if (skip & 1) { |
|
926 |
skip++; |
|
927 |
src++; |
|
2004 | 928 |
if (--num == 0) continue; |
0 | 929 |
} |
930 |
||
931 |
if ( (skip -= bp->start_x) > 0) { |
|
932 |
dst += skip >> 1; |
|
933 |
} else { |
|
934 |
src -= skip; |
|
935 |
num += skip; |
|
2010 | 936 |
if (num <= 0) continue; |
0 | 937 |
skip = 0; |
938 |
} |
|
939 |
||
940 |
skip = skip + num - bp->width; |
|
941 |
if (skip > 0) { |
|
942 |
num -= skip; |
|
2010 | 943 |
if (num <= 0) continue; |
0 | 944 |
} |
945 |
||
946 |
ctab = _color_remap_ptr; |
|
947 |
num = (num + 1) >> 1; |
|
1997 | 948 |
for (; num != 0; num--) { |
0 | 949 |
*dst = ctab[*src]; |
950 |
dst++; |
|
1997 | 951 |
src += 2; |
0 | 952 |
} |
953 |
} while (!(done & 0x80)); |
|
954 |
bp->dst += bp->pitch; |
|
2004 | 955 |
if (--bp->height == 0) return; |
0 | 956 |
|
957 |
do { |
|
958 |
done = src_o[0]; |
|
959 |
src_o += (done & 0x7F) + 2; |
|
960 |
} while (!(done & 0x80)); |
|
2010 | 961 |
} while (--bp->height != 0); |
0 | 962 |
} else if (bp->mode & 2) { |
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
963 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
0 | 964 |
do { |
965 |
do { |
|
966 |
done = src_o[0]; |
|
967 |
num = done & 0x7F; |
|
968 |
skip = src_o[1]; |
|
969 |
src_o += num + 2; |
|
970 |
||
971 |
dst = bp->dst; |
|
972 |
||
973 |
if (skip & 1) { |
|
974 |
skip++; |
|
2004 | 975 |
if (--num == 0) continue; |
0 | 976 |
} |
977 |
||
978 |
if ( (skip -= bp->start_x) > 0) { |
|
979 |
dst += skip >> 1; |
|
980 |
} else { |
|
981 |
num += skip; |
|
2010 | 982 |
if (num <= 0) continue; |
0 | 983 |
skip = 0; |
984 |
} |
|
985 |
||
986 |
skip = skip + num - bp->width; |
|
987 |
if (skip > 0) { |
|
988 |
num -= skip; |
|
2010 | 989 |
if (num <= 0) continue; |
0 | 990 |
} |
991 |
||
992 |
ctab = _color_remap_ptr; |
|
993 |
num = (num + 1) >> 1; |
|
1997 | 994 |
for (; num != 0; num--) { |
0 | 995 |
*dst = ctab[*dst]; |
996 |
dst++; |
|
997 |
} |
|
998 |
} while (!(done & 0x80)); |
|
999 |
bp->dst += bp->pitch; |
|
2004 | 1000 |
if (--bp->height == 0) return; |
0 | 1001 |
|
1002 |
do { |
|
1003 |
done = src_o[0]; |
|
1004 |
src_o += (done & 0x7F) + 2; |
|
1005 |
} while (!(done & 0x80)); |
|
2010 | 1006 |
} while (--bp->height != 0); |
0 | 1007 |
} else { |
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
1008 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
0 | 1009 |
do { |
1010 |
do { |
|
1011 |
done = src_o[0]; |
|
1012 |
num = done & 0x7F; |
|
1013 |
skip = src_o[1]; |
|
1014 |
src = src_o + 2; |
|
1015 |
src_o += num + 2; |
|
1016 |
||
1017 |
dst = bp->dst; |
|
1018 |
||
1019 |
if (skip & 1) { |
|
1020 |
skip++; |
|
1021 |
src++; |
|
2004 | 1022 |
if (--num == 0) continue; |
0 | 1023 |
} |
1024 |
||
1025 |
if ( (skip -= bp->start_x) > 0) { |
|
1026 |
dst += skip >> 1; |
|
1027 |
} else { |
|
1028 |
src -= skip; |
|
1029 |
num += skip; |
|
2010 | 1030 |
if (num <= 0) continue; |
0 | 1031 |
skip = 0; |
1032 |
} |
|
1033 |
||
1034 |
skip = skip + num - bp->width; |
|
1035 |
if (skip > 0) { |
|
1036 |
num -= skip; |
|
2010 | 1037 |
if (num <= 0) continue; |
0 | 1038 |
} |
1039 |
||
1040 |
num = (num + 1) >> 1; |
|
1041 |
||
1997 | 1042 |
for (; num != 0; num--) { |
0 | 1043 |
*dst = *src; |
1044 |
dst++; |
|
1997 | 1045 |
src += 2; |
0 | 1046 |
} |
1047 |
||
1048 |
} while (!(done & 0x80)); |
|
1049 |
||
1050 |
bp->dst += bp->pitch; |
|
2004 | 1051 |
if (--bp->height == 0) return; |
0 | 1052 |
|
1053 |
do { |
|
1054 |
done = src_o[0]; |
|
1055 |
src_o += (done & 0x7F) + 2; |
|
1056 |
} while (!(done & 0x80)); |
|
2010 | 1057 |
} while (--bp->height != 0); |
0 | 1058 |
} |
1059 |
} |
|
1060 |
||
1061 |
static void GfxBlitZoomMediumUncomp(BlitterParams *bp) |
|
1062 |
{ |
|
1357 | 1063 |
const byte *src = bp->sprite; |
2062 | 1064 |
Pixel *dst = bp->dst; |
0 | 1065 |
int height = bp->height; |
1066 |
int width = bp->width; |
|
1067 |
int i; |
|
1068 |
||
1069 |
assert(height > 0); |
|
1070 |
assert(width > 0); |
|
1071 |
||
1072 |
if (bp->mode & 1) { |
|
1073 |
if (bp->info & 1) { |
|
1357 | 1074 |
const byte *ctab = _color_remap_ptr; |
1075 |
||
1996 | 1076 |
for (height >>= 1; height != 0; height--) { |
1077 |
for (i = 0; i != width >> 1; i++) { |
|
1078 |
byte b = ctab[src[i * 2]]; |
|
1079 |
||
1080 |
if (b != 0) dst[i] = b; |
|
1081 |
} |
|
0 | 1082 |
src += bp->width_org * 2; |
1083 |
dst += bp->pitch; |
|
1996 | 1084 |
} |
0 | 1085 |
} |
1086 |
} else if (bp->mode & 2) { |
|
1087 |
if (bp->info & 1) { |
|
1357 | 1088 |
const byte *ctab = _color_remap_ptr; |
1089 |
||
1996 | 1090 |
for (height >>= 1; height != 0; height--) { |
1091 |
for (i = 0; i != width >> 1; i++) |
|
1092 |
if (src[i * 2] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 1093 |
src += bp->width_org * 2; |
1094 |
dst += bp->pitch; |
|
1996 | 1095 |
} |
0 | 1096 |
} |
1097 |
} else { |
|
1098 |
if (bp->info & 1) { |
|
1996 | 1099 |
for (height >>= 1; height != 0; height--) { |
1100 |
for (i = 0; i != width >> 1; i++) |
|
1101 |
if (src[i * 2] != 0) dst[i] = src[i * 2]; |
|
0 | 1102 |
src += bp->width_org * 2; |
1103 |
dst += bp->pitch; |
|
1996 | 1104 |
} |
0 | 1105 |
} |
1106 |
} |
|
1107 |
} |
|
1108 |
||
1109 |
static void GfxBlitTileZoomOut(BlitterParams *bp) |
|
1110 |
{ |
|
4171 | 1111 |
const byte *src_o = bp->sprite; |
1112 |
const byte *src; |
|
0 | 1113 |
int num, skip; |
1114 |
byte done; |
|
2062 | 1115 |
Pixel *dst; |
4171 | 1116 |
const byte *ctab; |
0 | 1117 |
|
1118 |
if (bp->mode & 1) { |
|
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
1119 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
2952 | 1120 |
for (;;) { |
0 | 1121 |
do { |
1122 |
done = src_o[0]; |
|
1123 |
num = done & 0x7F; |
|
1124 |
skip = src_o[1]; |
|
1125 |
src = src_o + 2; |
|
1126 |
src_o += num + 2; |
|
1127 |
||
1128 |
dst = bp->dst; |
|
1129 |
||
1130 |
if (skip & 1) { |
|
1131 |
skip++; |
|
1132 |
src++; |
|
2004 | 1133 |
if (--num == 0) continue; |
0 | 1134 |
} |
1135 |
||
1136 |
if (skip & 2) { |
|
2004 | 1137 |
skip += 2; |
1138 |
src += 2; |
|
1139 |
num -= 2; |
|
1140 |
if (num <= 0) continue; |
|
0 | 1141 |
} |
1142 |
||
1143 |
if ( (skip -= bp->start_x) > 0) { |
|
1144 |
dst += skip >> 2; |
|
1145 |
} else { |
|
1146 |
src -= skip; |
|
1147 |
num += skip; |
|
2004 | 1148 |
if (num <= 0) continue; |
0 | 1149 |
skip = 0; |
1150 |
} |
|
1151 |
||
1152 |
skip = skip + num - bp->width; |
|
1153 |
if (skip > 0) { |
|
1154 |
num -= skip; |
|
2004 | 1155 |
if (num <= 0) continue; |
0 | 1156 |
} |
1157 |
||
1158 |
ctab = _color_remap_ptr; |
|
1159 |
num = (num + 3) >> 2; |
|
1997 | 1160 |
for (; num != 0; num--) { |
0 | 1161 |
*dst = ctab[*src]; |
1162 |
dst++; |
|
1997 | 1163 |
src += 4; |
0 | 1164 |
} |
1165 |
} while (!(done & 0x80)); |
|
1166 |
bp->dst += bp->pitch; |
|
2004 | 1167 |
if (--bp->height == 0) return; |
0 | 1168 |
|
1169 |
do { |
|
1170 |
done = src_o[0]; |
|
1171 |
src_o += (done & 0x7F) + 2; |
|
1172 |
} while (!(done & 0x80)); |
|
2004 | 1173 |
if (--bp->height == 0) return; |
0 | 1174 |
|
1175 |
do { |
|
1176 |
done = src_o[0]; |
|
1177 |
src_o += (done & 0x7F) + 2; |
|
1178 |
} while (!(done & 0x80)); |
|
2004 | 1179 |
if (--bp->height == 0) return; |
0 | 1180 |
|
1181 |
do { |
|
1182 |
done = src_o[0]; |
|
1183 |
src_o += (done & 0x7F) + 2; |
|
1184 |
} while (!(done & 0x80)); |
|
2004 | 1185 |
if (--bp->height == 0) return; |
0 | 1186 |
} |
1187 |
} else if (bp->mode & 2) { |
|
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
1188 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
2952 | 1189 |
for (;;) { |
0 | 1190 |
do { |
1191 |
done = src_o[0]; |
|
1192 |
num = done & 0x7F; |
|
1193 |
skip = src_o[1]; |
|
1194 |
src_o += num + 2; |
|
1195 |
||
1196 |
dst = bp->dst; |
|
1197 |
||
1198 |
if (skip & 1) { |
|
1199 |
skip++; |
|
2004 | 1200 |
if (--num == 0) continue; |
0 | 1201 |
} |
1202 |
||
1203 |
if (skip & 2) { |
|
2004 | 1204 |
skip += 2; |
1205 |
num -= 2; |
|
1206 |
if (num <= 0) continue; |
|
0 | 1207 |
} |
1208 |
||
1209 |
if ( (skip -= bp->start_x) > 0) { |
|
1210 |
dst += skip >> 2; |
|
1211 |
} else { |
|
1212 |
num += skip; |
|
2004 | 1213 |
if (num <= 0) continue; |
0 | 1214 |
skip = 0; |
1215 |
} |
|
1216 |
||
1217 |
skip = skip + num - bp->width; |
|
1218 |
if (skip > 0) { |
|
1219 |
num -= skip; |
|
2004 | 1220 |
if (num <= 0) continue; |
0 | 1221 |
} |
1222 |
||
1223 |
ctab = _color_remap_ptr; |
|
1224 |
num = (num + 3) >> 2; |
|
1997 | 1225 |
for (; num != 0; num--) { |
0 | 1226 |
*dst = ctab[*dst]; |
1227 |
dst++; |
|
1228 |
} |
|
1229 |
||
1230 |
} while (!(done & 0x80)); |
|
1231 |
bp->dst += bp->pitch; |
|
2004 | 1232 |
if (--bp->height == 0) return; |
0 | 1233 |
|
1234 |
do { |
|
1235 |
done = src_o[0]; |
|
1236 |
src_o += (done & 0x7F) + 2; |
|
1237 |
} while (!(done & 0x80)); |
|
2004 | 1238 |
if (--bp->height == 0) return; |
0 | 1239 |
|
1240 |
do { |
|
1241 |
done = src_o[0]; |
|
1242 |
src_o += (done & 0x7F) + 2; |
|
1243 |
} while (!(done & 0x80)); |
|
2004 | 1244 |
if (--bp->height == 0) return; |
0 | 1245 |
|
1246 |
do { |
|
1247 |
done = src_o[0]; |
|
1248 |
src_o += (done & 0x7F) + 2; |
|
1249 |
} while (!(done & 0x80)); |
|
2004 | 1250 |
if (--bp->height == 0) return; |
0 | 1251 |
} |
1252 |
} else { |
|
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2952
diff
changeset
|
1253 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
2952 | 1254 |
for (;;) { |
0 | 1255 |
do { |
1256 |
done = src_o[0]; |
|
1257 |
num = done & 0x7F; |
|
1258 |
skip = src_o[1]; |
|
1259 |
src = src_o + 2; |
|
1260 |
src_o += num + 2; |
|
1261 |
||
1262 |
dst = bp->dst; |
|
1263 |
||
1264 |
if (skip & 1) { |
|
1265 |
skip++; |
|
1266 |
src++; |
|
2004 | 1267 |
if (--num == 0) continue; |
0 | 1268 |
} |
1269 |
||
1270 |
if (skip & 2) { |
|
2004 | 1271 |
skip += 2; |
1272 |
src += 2; |
|
1273 |
num -= 2; |
|
1274 |
if (num <= 0) continue; |
|
0 | 1275 |
} |
1276 |
||
1277 |
if ( (skip -= bp->start_x) > 0) { |
|
1278 |
dst += skip >> 2; |
|
1279 |
} else { |
|
1280 |
src -= skip; |
|
1281 |
num += skip; |
|
2004 | 1282 |
if (num <= 0) continue; |
0 | 1283 |
skip = 0; |
1284 |
} |
|
1285 |
||
1286 |
skip = skip + num - bp->width; |
|
1287 |
if (skip > 0) { |
|
1288 |
num -= skip; |
|
2004 | 1289 |
if (num <= 0) continue; |
0 | 1290 |
} |
1291 |
||
1292 |
num = (num + 3) >> 2; |
|
1293 |
||
1997 | 1294 |
for (; num != 0; num--) { |
0 | 1295 |
*dst = *src; |
1296 |
dst++; |
|
1997 | 1297 |
src += 4; |
0 | 1298 |
} |
1299 |
} while (!(done & 0x80)); |
|
1300 |
||
1301 |
bp->dst += bp->pitch; |
|
2004 | 1302 |
if (--bp->height == 0) return; |
0 | 1303 |
|
1304 |
do { |
|
1305 |
done = src_o[0]; |
|
1306 |
src_o += (done & 0x7F) + 2; |
|
1307 |
} while (!(done & 0x80)); |
|
2004 | 1308 |
if (--bp->height == 0) return; |
0 | 1309 |
|
1310 |
do { |
|
1311 |
done = src_o[0]; |
|
1312 |
src_o += (done & 0x7F) + 2; |
|
1313 |
} while (!(done & 0x80)); |
|
2004 | 1314 |
if (--bp->height == 0) return; |
0 | 1315 |
|
1316 |
do { |
|
1317 |
done = src_o[0]; |
|
1318 |
src_o += (done & 0x7F) + 2; |
|
1319 |
} while (!(done & 0x80)); |
|
2004 | 1320 |
if (--bp->height == 0) return; |
0 | 1321 |
} |
1322 |
} |
|
1323 |
} |
|
1324 |
||
1325 |
static void GfxBlitZoomOutUncomp(BlitterParams *bp) |
|
1326 |
{ |
|
4171 | 1327 |
const byte *src = bp->sprite; |
2062 | 1328 |
Pixel *dst = bp->dst; |
0 | 1329 |
int height = bp->height; |
1330 |
int width = bp->width; |
|
1331 |
int i; |
|
1332 |
||
1333 |
assert(height > 0); |
|
1334 |
assert(width > 0); |
|
1335 |
||
1336 |
if (bp->mode & 1) { |
|
1337 |
if (bp->info & 1) { |
|
1357 | 1338 |
const byte *ctab = _color_remap_ptr; |
1339 |
||
1996 | 1340 |
for (height >>= 2; height != 0; height--) { |
1341 |
for (i = 0; i != width >> 2; i++) { |
|
1342 |
byte b = ctab[src[i * 4]]; |
|
1343 |
||
1344 |
if (b != 0) dst[i] = b; |
|
1345 |
} |
|
0 | 1346 |
src += bp->width_org * 4; |
1347 |
dst += bp->pitch; |
|
1996 | 1348 |
} |
0 | 1349 |
} |
1350 |
} else if (bp->mode & 2) { |
|
1351 |
if (bp->info & 1) { |
|
1357 | 1352 |
const byte *ctab = _color_remap_ptr; |
1353 |
||
1996 | 1354 |
for (height >>= 2; height != 0; height--) { |
1355 |
for (i = 0; i != width >> 2; i++) |
|
1356 |
if (src[i * 4] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 1357 |
src += bp->width_org * 4; |
1358 |
dst += bp->pitch; |
|
1996 | 1359 |
} |
0 | 1360 |
} |
1361 |
} else { |
|
1362 |
if (bp->info & 1) { |
|
1996 | 1363 |
for (height >>= 2; height != 0; height--) { |
1364 |
for (i = 0; i != width >> 2; i++) |
|
1365 |
if (src[i * 4] != 0) dst[i] = src[i * 4]; |
|
0 | 1366 |
src += bp->width_org * 4; |
1367 |
dst += bp->pitch; |
|
1996 | 1368 |
} |
0 | 1369 |
} |
1370 |
} |
|
1371 |
} |
|
1372 |
||
1373 |
typedef void (*BlitZoomFunc)(BlitterParams *bp); |
|
1374 |
||
4171 | 1375 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, int mode) |
0 | 1376 |
{ |
4171 | 1377 |
const DrawPixelInfo *dpi = _cur_dpi; |
0 | 1378 |
int start_x, start_y; |
1379 |
byte info; |
|
1380 |
BlitterParams bp; |
|
2005 | 1381 |
int zoom_mask = ~((1 << dpi->zoom) - 1); |
0 | 1382 |
|
1383 |
/* decode sprite header */ |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1384 |
x += sprite->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1385 |
y += sprite->y_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1386 |
bp.width_org = bp.width = sprite->width; |
1348 | 1387 |
bp.height_org = bp.height = sprite->height; |
1388 |
info = sprite->info; |
|
0 | 1389 |
bp.info = info; |
1348 | 1390 |
bp.sprite_org = bp.sprite = sprite->data; |
0 | 1391 |
bp.dst = dpi->dst_ptr; |
1392 |
bp.mode = mode; |
|
1393 |
bp.pitch = dpi->pitch; |
|
1394 |
||
1395 |
assert(bp.height > 0); |
|
1396 |
assert(bp.width > 0); |
|
1397 |
||
1398 |
if (info & 8) { |
|
1399 |
/* tile blit */ |
|
1400 |
start_y = 0; |
|
1401 |
||
1402 |
if (dpi->zoom > 0) { |
|
2005 | 1403 |
start_y += bp.height & ~zoom_mask; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1404 |
bp.height &= zoom_mask; |
0 | 1405 |
if (bp.height == 0) return; |
2005 | 1406 |
y &= zoom_mask; |
0 | 1407 |
} |
1408 |
||
1409 |
if ( (y -= dpi->top) < 0) { |
|
2005 | 1410 |
bp.height += y; |
1411 |
if (bp.height <= 0) return; |
|
0 | 1412 |
start_y -= y; |
1413 |
y = 0; |
|
1414 |
} else { |
|
2005 | 1415 |
bp.dst += bp.pitch * (y >> dpi->zoom); |
0 | 1416 |
} |
1417 |
bp.start_y = start_y; |
|
1418 |
||
1419 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
2005 | 1420 |
bp.height -= y; |
1421 |
if (bp.height <= 0) return; |
|
0 | 1422 |
} |
1423 |
||
1424 |
start_x = 0; |
|
1425 |
x &= zoom_mask; |
|
1426 |
if ( (x -= dpi->left) < 0) { |
|
2005 | 1427 |
bp.width += x; |
1428 |
if (bp.width <= 0) return; |
|
0 | 1429 |
start_x -= x; |
1430 |
x = 0; |
|
1431 |
} |
|
1432 |
bp.start_x = start_x; |
|
2005 | 1433 |
bp.dst += x >> dpi->zoom; |
0 | 1434 |
|
1435 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
2005 | 1436 |
bp.width -= x; |
1437 |
if (bp.width <= 0) return; |
|
0 | 1438 |
} |
1439 |
||
4425
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1440 |
switch (dpi->zoom) { |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1441 |
default: NOT_REACHED(); |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1442 |
case 0: GfxBlitTileZoomIn(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1443 |
case 1: GfxBlitTileZoomMedium(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1444 |
case 2: GfxBlitTileZoomOut(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1445 |
} |
0 | 1446 |
} else { |
1447 |
bp.sprite += bp.width * (bp.height & ~zoom_mask); |
|
1448 |
bp.height &= zoom_mask; |
|
2005 | 1449 |
if (bp.height == 0) return; |
0 | 1450 |
|
1451 |
y &= zoom_mask; |
|
1452 |
||
1453 |
if ( (y -= dpi->top) < 0) { |
|
2005 | 1454 |
bp.height += y; |
1455 |
if (bp.height <= 0) return; |
|
0 | 1456 |
bp.sprite -= bp.width * y; |
1457 |
y = 0; |
|
1458 |
} else { |
|
2005 | 1459 |
bp.dst += bp.pitch * (y >> dpi->zoom); |
0 | 1460 |
} |
1461 |
||
2037
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1462 |
if (bp.height > dpi->height - y) { |
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1463 |
bp.height = dpi->height - y; |
2005 | 1464 |
if (bp.height <= 0) return; |
0 | 1465 |
} |
1466 |
||
1467 |
x &= zoom_mask; |
|
1468 |
||
1469 |
if ( (x -= dpi->left) < 0) { |
|
2005 | 1470 |
bp.width += x; |
1471 |
if (bp.width <= 0) return; |
|
0 | 1472 |
bp.sprite -= x; |
1473 |
x = 0; |
|
1474 |
} |
|
2005 | 1475 |
bp.dst += x >> dpi->zoom; |
0 | 1476 |
|
2037
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1477 |
if (bp.width > dpi->width - x) { |
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1478 |
bp.width = dpi->width - x; |
2005 | 1479 |
if (bp.width <= 0) return; |
0 | 1480 |
} |
1481 |
||
4425
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1482 |
switch (dpi->zoom) { |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1483 |
default: NOT_REACHED(); |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1484 |
case 0: GfxBlitZoomInUncomp(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1485 |
case 1: GfxBlitZoomMediumUncomp(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1486 |
case 2: GfxBlitZoomOutUncomp(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1487 |
} |
0 | 1488 |
} |
1489 |
} |
|
1490 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1491 |
void DoPaletteAnimations(void); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1492 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1493 |
void GfxInitPalettes(void) |
0 | 1494 |
{ |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1495 |
memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette)); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1496 |
|
0 | 1497 |
_pal_first_dirty = 0; |
1498 |
_pal_last_dirty = 255; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1499 |
DoPaletteAnimations(); |
0 | 1500 |
} |
1501 |
||
2010 | 1502 |
#define EXTR(p, q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) |
1503 |
#define EXTR2(p, q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) |
|
0 | 1504 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1505 |
void DoPaletteAnimations(void) |
0 | 1506 |
{ |
4171 | 1507 |
const Colour *s; |
1508 |
Colour *d; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1509 |
/* Amount of colors to be rotated. |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1510 |
* A few more for the DOS palette, because the water colors are |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1511 |
* 245-254 for DOS and 217-226 for Windows. */ |
0 | 1512 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
2005 | 1513 |
int c = _use_dos_palette ? 38 : 28; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1514 |
Colour old_val[38]; // max(38, 28) |
2005 | 1515 |
uint i; |
1516 |
uint j; |
|
0 | 1517 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1518 |
d = &_cur_palette[217]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1519 |
memcpy(old_val, d, c * sizeof(*old_val)); |
0 | 1520 |
|
1521 |
// Dark blue water |
|
2005 | 1522 |
s = (_opt.landscape == LT_CANDY) ? ev->ac : ev->a; |
1523 |
j = EXTR(320, 5); |
|
1524 |
for (i = 0; i != 5; i++) { |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1525 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1526 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1527 |
if (j == 5) j = 0; |
0 | 1528 |
} |
1529 |
||
1530 |
// Glittery water |
|
2005 | 1531 |
s = (_opt.landscape == LT_CANDY) ? ev->bc : ev->b; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1532 |
j = EXTR(128, 15); |
2005 | 1533 |
for (i = 0; i != 5; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1534 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1535 |
j += 3; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1536 |
if (j >= 15) j -= 15; |
0 | 1537 |
} |
1538 |
||
1539 |
s = ev->e; |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1540 |
j = EXTR2(512, 5); |
2005 | 1541 |
for (i = 0; i != 5; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1542 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1543 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1544 |
if (j == 5) j = 0; |
0 | 1545 |
} |
1546 |
||
1547 |
// Oil refinery fire animation |
|
1548 |
s = ev->oil_ref; |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1549 |
j = EXTR2(512, 7); |
2005 | 1550 |
for (i = 0; i != 7; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1551 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1552 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1553 |
if (j == 7) j = 0; |
0 | 1554 |
} |
1555 |
||
1556 |
// Radio tower blinking |
|
1557 |
{ |
|
2005 | 1558 |
byte i = (_timer_counter >> 1) & 0x7F; |
1559 |
byte v; |
|
1560 |
||
0 | 1561 |
(v = 255, i < 0x3f) || |
1562 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1563 |
(v = 20); |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1564 |
d->r = v; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1565 |
d->g = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1566 |
d->b = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1567 |
d++; |
0 | 1568 |
|
1569 |
i ^= 0x40; |
|
1570 |
(v = 255, i < 0x3f) || |
|
1571 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1572 |
(v = 20); |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1573 |
d->r = v; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1574 |
d->g = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1575 |
d->b = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1576 |
d++; |
0 | 1577 |
} |
1578 |
||
1579 |
// Handle lighthouse and stadium animation |
|
1580 |
s = ev->lighthouse; |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1581 |
j = EXTR(256, 4); |
2005 | 1582 |
for (i = 0; i != 4; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1583 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1584 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1585 |
if (j == 4) j = 0; |
0 | 1586 |
} |
1587 |
||
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1588 |
// Animate water for old DOS graphics |
2005 | 1589 |
if (_use_dos_palette) { |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1590 |
// Dark blue water DOS |
2005 | 1591 |
s = (_opt.landscape == LT_CANDY) ? ev->ac : ev->a; |
1592 |
j = EXTR(320, 5); |
|
1593 |
for (i = 0; i != 5; i++) { |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1594 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1595 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1596 |
if (j == 5) j = 0; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1597 |
} |
915 | 1598 |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1599 |
// Glittery water DOS |
2005 | 1600 |
s = (_opt.landscape == LT_CANDY) ? ev->bc : ev->b; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1601 |
j = EXTR(128, 15); |
2005 | 1602 |
for (i = 0; i != 5; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1603 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1604 |
j += 3; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1605 |
if (j >= 15) j -= 15; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1606 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1607 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1608 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1609 |
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { |
0 | 1610 |
if (_pal_first_dirty > 217) _pal_first_dirty = 217; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1611 |
if (_pal_last_dirty < 217 + c) _pal_last_dirty = 217 + c; |
0 | 1612 |
} |
1613 |
} |
|
1614 |
||
1615 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1616 |
void LoadStringWidthTable(void) |
0 | 1617 |
{ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1618 |
SpriteID base; |
2005 | 1619 |
uint i; |
0 | 1620 |
|
3797
db2306464bbe
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
1621 |
/* Normal font */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1622 |
base = GetFontBase(FS_NORMAL); |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1623 |
for (i = 0; i != 224; i++) { |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1624 |
_stringwidth_table[FS_NORMAL][i] = SpriteExists(base + i) ? GetSprite(base + i)->width : 0; |
0 | 1625 |
} |
1626 |
||
3797
db2306464bbe
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
1627 |
/* Small font */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1628 |
base = GetFontBase(FS_SMALL); |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1629 |
for (i = 0; i != 224; i++) { |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1630 |
_stringwidth_table[FS_SMALL][i] = SpriteExists(base + i) ? GetSprite(base + i)->width + 1 : 0; |
0 | 1631 |
} |
1632 |
||
3797
db2306464bbe
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
1633 |
/* Large font */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1634 |
base = GetFontBase(FS_LARGE); |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1635 |
for (i = 0; i != 224; i++) { |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1636 |
_stringwidth_table[FS_LARGE][i] = SpriteExists(base + i) ? GetSprite(base + i)->width + 1 : 0; |
0 | 1637 |
} |
1638 |
} |
|
1639 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1640 |
void ScreenSizeChanged(void) |
0 | 1641 |
{ |
1642 |
// check the dirty rect |
|
1643 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
|
1644 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
1645 |
||
1646 |
// screen size changed and the old bitmap is invalid now, so we don't want to undraw it |
|
1647 |
_cursor.visible = false; |
|
1648 |
} |
|
1649 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1650 |
void UndrawMouseCursor(void) |
0 | 1651 |
{ |
1652 |
if (_cursor.visible) { |
|
1653 |
_cursor.visible = false; |
|
1654 |
memcpy_pitch( |
|
1655 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
1656 |
_cursor_backup, |
|
1657 |
_cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x, _screen.pitch); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1658 |
|
0 | 1659 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
1660 |
} |
|
1661 |
} |
|
1662 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1663 |
void DrawMouseCursor(void) |
0 | 1664 |
{ |
2010 | 1665 |
int x; |
1666 |
int y; |
|
1667 |
int w; |
|
1668 |
int h; |
|
0 | 1669 |
|
3312
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
1670 |
/* Redraw mouse cursor but only when it's inside the window */ |
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
1671 |
if (!_cursor.in_window) return; |
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
1672 |
|
0 | 1673 |
// Don't draw the mouse cursor if it's already drawn |
1674 |
if (_cursor.visible) { |
|
2010 | 1675 |
if (!_cursor.dirty) return; |
0 | 1676 |
UndrawMouseCursor(); |
1677 |
} |
|
1678 |
||
1679 |
w = _cursor.size.x; |
|
1680 |
x = _cursor.pos.x + _cursor.offs.x; |
|
2010 | 1681 |
if (x < 0) { |
1682 |
w += x; |
|
1683 |
x = 0; |
|
1684 |
} |
|
1685 |
if (w > _screen.width - x) w = _screen.width - x; |
|
0 | 1686 |
if (w <= 0) return; |
1687 |
_cursor.draw_pos.x = x; |
|
1688 |
_cursor.draw_size.x = w; |
|
1689 |
||
1690 |
h = _cursor.size.y; |
|
1691 |
y = _cursor.pos.y + _cursor.offs.y; |
|
2010 | 1692 |
if (y < 0) { |
1693 |
h += y; |
|
1694 |
y = 0; |
|
1695 |
} |
|
1696 |
if (h > _screen.height - y) h = _screen.height - y; |
|
0 | 1697 |
if (h <= 0) return; |
1698 |
_cursor.draw_pos.y = y; |
|
1699 |
_cursor.draw_size.y = h; |
|
1700 |
||
2010 | 1701 |
assert(w * h < (int)sizeof(_cursor_backup)); |
0 | 1702 |
|
1703 |
// Make backup of stuff below cursor |
|
1704 |
memcpy_pitch( |
|
1705 |
_cursor_backup, |
|
1706 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
1707 |
_cursor.draw_size.x, _cursor.draw_size.y, _screen.pitch, _cursor.draw_size.x); |
0 | 1708 |
|
1709 |
// Draw cursor on screen |
|
1710 |
_cur_dpi = &_screen; |
|
1711 |
DrawSprite(_cursor.sprite, _cursor.pos.x, _cursor.pos.y); |
|
1712 |
||
1713 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
|
1714 |
||
1715 |
_cursor.visible = true; |
|
1716 |
_cursor.dirty = false; |
|
1717 |
} |
|
1718 |
||
798 | 1719 |
#if defined(_DEBUG) |
410 | 1720 |
static void DbgScreenRect(int left, int top, int right, int bottom) |
0 | 1721 |
{ |
2010 | 1722 |
DrawPixelInfo dp; |
4171 | 1723 |
DrawPixelInfo *old; |
0 | 1724 |
|
1725 |
old = _cur_dpi; |
|
1726 |
_cur_dpi = &dp; |
|
1727 |
dp = _screen; |
|
2010 | 1728 |
GfxFillRect(left, top, right - 1, bottom - 1, rand() & 255); |
0 | 1729 |
_cur_dpi = old; |
1730 |
} |
|
798 | 1731 |
#endif |
0 | 1732 |
|
1733 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1734 |
{ |
|
1735 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1736 |
if (_cursor.visible) { |
|
1737 |
if (right > _cursor.draw_pos.x && |
|
1738 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1739 |
bottom > _cursor.draw_pos.y && |
|
1740 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1741 |
UndrawMouseCursor(); |
|
1742 |
} |
|
1743 |
} |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1744 |
UndrawTextMessage(); |
0 | 1745 |
|
1746 |
#if defined(_DEBUG) |
|
1747 |
if (_dbg_screen_rect) |
|
1748 |
DbgScreenRect(left, top, right, bottom); |
|
1749 |
else |
|
1750 |
#endif |
|
1751 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
|
1752 |
||
2010 | 1753 |
_video_driver->make_dirty(left, top, right - left, bottom - top); |
0 | 1754 |
} |
1755 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1756 |
void DrawDirtyBlocks(void) |
0 | 1757 |
{ |
1758 |
byte *b = _dirty_blocks; |
|
2398
912f16512ce2
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents:
2367
diff
changeset
|
1759 |
const int w = ALIGN(_screen.width, 64); |
912f16512ce2
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents:
2367
diff
changeset
|
1760 |
const int h = ALIGN(_screen.height, 8); |
2025 | 1761 |
int x; |
1762 |
int y; |
|
0 | 1763 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1764 |
if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1765 |
|
2025 | 1766 |
y = 0; |
0 | 1767 |
do { |
2025 | 1768 |
x = 0; |
1769 |
do { |
|
1770 |
if (*b != 0) { |
|
1771 |
int left; |
|
1772 |
int top; |
|
1773 |
int right = x + 64; |
|
1774 |
int bottom = y; |
|
1775 |
byte *p = b; |
|
1776 |
int h2; |
|
0 | 1777 |
|
2025 | 1778 |
// First try coalescing downwards |
0 | 1779 |
do { |
2025 | 1780 |
*p = 0; |
1781 |
p += DIRTY_BYTES_PER_LINE; |
|
1782 |
bottom += 8; |
|
1783 |
} while (bottom != h && *p != 0); |
|
0 | 1784 |
|
2025 | 1785 |
// Try coalescing to the right too. |
1786 |
h2 = (bottom - y) >> 3; |
|
1787 |
assert(h2 > 0); |
|
1788 |
p = b; |
|
0 | 1789 |
|
2025 | 1790 |
while (right != w) { |
1791 |
byte *p2 = ++p; |
|
1792 |
int h = h2; |
|
1793 |
// Check if a full line of dirty flags is set. |
|
1794 |
do { |
|
1795 |
if (!*p2) goto no_more_coalesc; |
|
1796 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1797 |
} while (--h != 0); |
|
1798 |
||
1799 |
// Wohoo, can combine it one step to the right! |
|
1800 |
// Do that, and clear the bits. |
|
1801 |
right += 64; |
|
1802 |
||
1803 |
h = h2; |
|
1804 |
p2 = p; |
|
1805 |
do { |
|
1806 |
*p2 = 0; |
|
1807 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1808 |
} while (--h != 0); |
|
1809 |
} |
|
1810 |
no_more_coalesc: |
|
1811 |
||
1812 |
left = x; |
|
1813 |
top = y; |
|
1814 |
||
1815 |
if (left < _invalid_rect.left ) left = _invalid_rect.left; |
|
1816 |
if (top < _invalid_rect.top ) top = _invalid_rect.top; |
|
1817 |
if (right > _invalid_rect.right ) right = _invalid_rect.right; |
|
1818 |
if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom; |
|
1819 |
||
1820 |
if (left < right && top < bottom) { |
|
1821 |
RedrawScreenRect(left, top, right, bottom); |
|
1822 |
} |
|
1823 |
||
0 | 1824 |
} |
2025 | 1825 |
} while (b++, (x += 64) != w); |
1826 |
} while (b += -(w >> 6) + DIRTY_BYTES_PER_LINE, (y += 8) != h); |
|
0 | 1827 |
|
1828 |
_invalid_rect.left = w; |
|
1829 |
_invalid_rect.top = h; |
|
1830 |
_invalid_rect.right = 0; |
|
1831 |
_invalid_rect.bottom = 0; |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1832 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1833 |
/* If we are generating a world, and waiting for a paint run, mark it here |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1834 |
* as done painting, so we can continue generating. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1835 |
if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1836 |
SetGeneratingWorldPaintStatus(false); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1837 |
} |
0 | 1838 |
} |
1839 |
||
1840 |
||
1841 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
|
1842 |
{ |
|
1843 |
byte *b; |
|
2010 | 1844 |
int width; |
1845 |
int height; |
|
0 | 1846 |
|
1847 |
if (left < 0) left = 0; |
|
1848 |
if (top < 0) top = 0; |
|
1849 |
if (right > _screen.width) right = _screen.width; |
|
1850 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1851 |
||
2010 | 1852 |
if (left >= right || top >= bottom) return; |
0 | 1853 |
|
2010 | 1854 |
if (left < _invalid_rect.left ) _invalid_rect.left = left; |
1855 |
if (top < _invalid_rect.top ) _invalid_rect.top = top; |
|
1856 |
if (right > _invalid_rect.right ) _invalid_rect.right = right; |
|
1857 |
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom; |
|
0 | 1858 |
|
1859 |
left >>= 6; |
|
2010 | 1860 |
top >>= 3; |
0 | 1861 |
|
1862 |
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left; |
|
1863 |
||
2010 | 1864 |
width = ((right - 1) >> 6) - left + 1; |
1865 |
height = ((bottom - 1) >> 3) - top + 1; |
|
0 | 1866 |
|
1867 |
assert(width > 0 && height > 0); |
|
1868 |
||
1869 |
do { |
|
2010 | 1870 |
int i = width; |
1871 |
||
0 | 1872 |
do b[--i] = 0xFF; while (i); |
1873 |
||
1874 |
b += DIRTY_BYTES_PER_LINE; |
|
2010 | 1875 |
} while (--height != 0); |
0 | 1876 |
} |
1877 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1878 |
void MarkWholeScreenDirty(void) |
0 | 1879 |
{ |
1880 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1881 |
} |
|
1882 |
||
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1883 |
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height) |
0 | 1884 |
{ |
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1885 |
const DrawPixelInfo *o = _cur_dpi; |
0 | 1886 |
|
1887 |
n->zoom = 0; |
|
1888 |
||
1889 |
assert(width > 0); |
|
1890 |
assert(height > 0); |
|
1891 |
||
1892 |
if ((left -= o->left) < 0) { |
|
2010 | 1893 |
width += left; |
1894 |
if (width < 0) return false; |
|
0 | 1895 |
n->left = -left; |
1896 |
left = 0; |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1897 |
} else { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1898 |
n->left = 0; |
0 | 1899 |
} |
1900 |
||
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1901 |
if (width > o->width - left) { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1902 |
width = o->width - left; |
2010 | 1903 |
if (width < 0) return false; |
0 | 1904 |
} |
1905 |
n->width = width; |
|
1906 |
||
1907 |
if ((top -= o->top) < 0) { |
|
2010 | 1908 |
height += top; |
1909 |
if (height < 0) return false; |
|
0 | 1910 |
n->top = -top; |
1911 |
top = 0; |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1912 |
} else { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1913 |
n->top = 0; |
0 | 1914 |
} |
1915 |
||
1916 |
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch); |
|
1917 |
||
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1918 |
if (height > o->height - top) { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1919 |
height = o->height - top; |
2010 | 1920 |
if (height < 0) return false; |
0 | 1921 |
} |
1922 |
n->height = height; |
|
1923 |
||
1924 |
return true; |
|
1925 |
} |
|
1926 |
||
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1927 |
static void SetCursorSprite(CursorID cursor) |
0 | 1928 |
{ |
1929 |
CursorVars *cv = &_cursor; |
|
1348 | 1930 |
const Sprite *p; |
0 | 1931 |
|
2010 | 1932 |
if (cv->sprite == cursor) return; |
0 | 1933 |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
1934 |
p = GetSprite(cursor & SPRITE_MASK); |
0 | 1935 |
cv->sprite = cursor; |
1348 | 1936 |
cv->size.y = p->height; |
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1937 |
cv->size.x = p->width; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1938 |
cv->offs.x = p->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1939 |
cv->offs.y = p->y_offs; |
0 | 1940 |
|
1941 |
cv->dirty = true; |
|
1942 |
} |
|
1943 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1944 |
static void SwitchAnimatedCursor(void) |
0 | 1945 |
{ |
1946 |
CursorVars *cv = &_cursor; |
|
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1947 |
const CursorID *cur = cv->animate_cur; |
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1948 |
CursorID sprite; |
0 | 1949 |
|
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1950 |
// ANIM_CURSOR_END is 0xFFFF in table/animcursors.h |
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1951 |
if (cur == NULL || *cur == 0xFFFF) cur = cv->animate_list; |
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1952 |
|
0 | 1953 |
sprite = cur[0]; |
1954 |
cv->animate_timeout = cur[1]; |
|
1955 |
cv->animate_cur = cur + 2; |
|
1956 |
||
1957 |
SetCursorSprite(sprite); |
|
1958 |
} |
|
1959 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1960 |
void CursorTick(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1961 |
{ |
2010 | 1962 |
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) |
0 | 1963 |
SwitchAnimatedCursor(); |
1964 |
} |
|
1965 |
||
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1966 |
void SetMouseCursor(CursorID cursor) |
0 | 1967 |
{ |
1968 |
// Turn off animation |
|
1969 |
_cursor.animate_timeout = 0; |
|
1970 |
// Set cursor |
|
1971 |
SetCursorSprite(cursor); |
|
1972 |
} |
|
1973 |
||
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1974 |
void SetAnimatedMouseCursor(const CursorID *table) |
0 | 1975 |
{ |
1976 |
_cursor.animate_list = table; |
|
1977 |
_cursor.animate_cur = NULL; |
|
1978 |
SwitchAnimatedCursor(); |
|
1979 |
} |
|
1980 |
||
1981 |
bool ChangeResInGame(int w, int h) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1982 |
{ |
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1983 |
return |
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1984 |
(_screen.width == w && _screen.height == h) || |
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1985 |
_video_driver->change_resolution(w, h); |
0 | 1986 |
} |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1987 |
|
1829
e90fe433fa7d
(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
|
1988 |
void ToggleFullScreen(bool fs) {_video_driver->toggle_fullscreen(fs);} |
e90fe433fa7d
(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
|
1989 |
|
1806
5a55d508c23e
(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:
1390
diff
changeset
|
1990 |
static int CDECL compare_res(const void *pa, const void *pb) |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1991 |
{ |
1806
5a55d508c23e
(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:
1390
diff
changeset
|
1992 |
int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0]; |
5a55d508c23e
(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:
1390
diff
changeset
|
1993 |
if (x != 0) return x; |
5a55d508c23e
(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:
1390
diff
changeset
|
1994 |
return ((const uint16*)pa)[1] - ((const uint16*)pb)[1]; |
5a55d508c23e
(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:
1390
diff
changeset
|
1995 |
} |
5a55d508c23e
(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:
1390
diff
changeset
|
1996 |
|
5a55d508c23e
(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:
1390
diff
changeset
|
1997 |
void SortResolutions(int count) |
5a55d508c23e
(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:
1390
diff
changeset
|
1998 |
{ |
5a55d508c23e
(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:
1390
diff
changeset
|
1999 |
qsort(_resolutions, count, sizeof(_resolutions[0]), compare_res); |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
2000 |
} |