author | truelight |
Mon, 11 Jun 2007 11:50:49 +0000 | |
changeset 7348 | becce3f57dc7 |
parent 7327 | fa2e72e31f59 |
child 7374 | 54c06f06ecc8 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
3 |
/** @file gfx.cpp */ |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1829
diff
changeset
|
6 |
#include "openttd.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
7 |
#include "functions.h" |
4428
0b0ee542d5b6
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4425
diff
changeset
|
8 |
#include "macros.h" |
1349
07514c2cc6d1
(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
|
9 |
#include "spritecache.h" |
1309
dab90d4cbf2d
(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
|
10 |
#include "strings.h" |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
11 |
#include "string.h" |
0 | 12 |
#include "gfx.h" |
13 |
#include "table/palettes.h" |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
14 |
#include "table/sprites.h" |
0 | 15 |
#include "hal.h" |
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2134
diff
changeset
|
16 |
#include "variables.h" |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
17 |
#include "table/control_codes.h" |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
18 |
#include "fontcache.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
19 |
#include "genworld.h" |
5217
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
20 |
#include "debug.h" |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
7111
diff
changeset
|
21 |
#include "zoom.hpp" |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
22 |
#include "blitter/blitter.hpp" |
0 | 23 |
|
2649
7cd504bd4e51
(svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents:
2645
diff
changeset
|
24 |
#ifdef _DEBUG |
7cd504bd4e51
(svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents:
2645
diff
changeset
|
25 |
bool _dbg_screen_rect; |
7cd504bd4e51
(svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents:
2645
diff
changeset
|
26 |
#endif |
7cd504bd4e51
(svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents:
2645
diff
changeset
|
27 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
28 |
byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
29 |
bool _fullscreen; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
30 |
CursorVars _cursor; |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
31 |
bool _ctrl_pressed; ///< Is Ctrl pressed? |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
32 |
bool _shift_pressed; ///< Is Shift pressed? |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
33 |
byte _fast_forward; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
34 |
bool _left_button_down; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
35 |
bool _left_button_clicked; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
36 |
bool _right_button_down; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
37 |
bool _right_button_clicked; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
38 |
DrawPixelInfo _screen; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
39 |
bool _exit_game; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
40 |
bool _networking; ///< are we in networking mode? |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
41 |
byte _game_mode; |
6557
8381016f71f3
(svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents:
6541
diff
changeset
|
42 |
byte _pause_game; |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
43 |
int _pal_first_dirty; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
44 |
int _pal_last_dirty; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
45 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
46 |
Colour _cur_palette[256]; |
3798
37a2090eac94
(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
|
47 |
byte _stringwidth_table[FS_END][224]; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
48 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
49 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode); |
0 | 50 |
|
3798
37a2090eac94
(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
|
51 |
FontSize _cur_fontsize; |
37a2090eac94
(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
|
52 |
static FontSize _last_fontsize; |
2062 | 53 |
static Pixel _cursor_backup[64 * 64]; |
0 | 54 |
static Rect _invalid_rect; |
1357 | 55 |
static const byte *_color_remap_ptr; |
0 | 56 |
static byte _string_colorremap[3]; |
57 |
||
2010 | 58 |
#define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH / 64) |
0 | 59 |
static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8]; |
60 |
||
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
61 |
void memcpy_pitch(void *dst, void *src, int w, int h, int srcpitch, int dstpitch) |
0 | 62 |
{ |
7111
269c76b5b987
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6987
diff
changeset
|
63 |
Pixel *dstp = (Pixel *)dst; |
269c76b5b987
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6987
diff
changeset
|
64 |
Pixel *srcp = (Pixel *)src; |
0 | 65 |
|
66 |
assert(h >= 0); |
|
1056
ff3cfd9042a3
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
67 |
for (; h != 0; --h) { |
7111
269c76b5b987
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6987
diff
changeset
|
68 |
memcpy(dstp, srcp, w * sizeof(Pixel)); |
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
69 |
dstp += dstpitch; |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
70 |
srcp += srcpitch; |
1056
ff3cfd9042a3
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
71 |
} |
0 | 72 |
} |
73 |
||
2010 | 74 |
void GfxScroll(int left, int top, int width, int height, int xo, int yo) |
75 |
{ |
|
2062 | 76 |
const Pixel *src; |
77 |
Pixel *dst; |
|
0 | 78 |
int p; |
79 |
int ht; |
|
80 |
||
2010 | 81 |
if (xo == 0 && yo == 0) return; |
0 | 82 |
|
2010 | 83 |
if (_cursor.visible) UndrawMouseCursor(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
84 |
UndrawTextMessage(); |
0 | 85 |
|
86 |
p = _screen.pitch; |
|
87 |
||
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
88 |
if (yo > 0) { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
89 |
/*Calculate pointers */ |
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
90 |
dst = _screen.dst_ptr + (top + height - 1) * p + left; |
0 | 91 |
src = dst - yo * p; |
92 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
93 |
/* Decrease height and increase top */ |
0 | 94 |
top += yo; |
95 |
height -= yo; |
|
96 |
assert(height > 0); |
|
97 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
98 |
/* Adjust left & width */ |
0 | 99 |
if (xo >= 0) { |
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
100 |
dst += xo; |
0 | 101 |
left += xo; |
102 |
width -= xo; |
|
103 |
} else { |
|
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
104 |
src -= xo; |
0 | 105 |
width += xo; |
106 |
} |
|
107 |
||
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
108 |
for (ht = height; ht > 0; --ht) { |
7111
269c76b5b987
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6987
diff
changeset
|
109 |
memcpy(dst, src, width * sizeof(Pixel)); |
0 | 110 |
src -= p; |
111 |
dst -= p; |
|
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
112 |
} |
0 | 113 |
} else { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
114 |
/* Calculate pointers */ |
0 | 115 |
dst = _screen.dst_ptr + top * p + left; |
116 |
src = dst - yo * p; |
|
117 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
118 |
/* Decrese height. (yo is <=0). */ |
0 | 119 |
height += yo; |
120 |
assert(height > 0); |
|
121 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
122 |
/* Adjust left & width */ |
0 | 123 |
if (xo >= 0) { |
124 |
dst += xo; |
|
125 |
left += xo; |
|
126 |
width -= xo; |
|
127 |
} else { |
|
128 |
src -= xo; |
|
129 |
width += xo; |
|
130 |
} |
|
131 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
132 |
/* the y-displacement may be 0 therefore we have to use memmove, |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
133 |
* because source and destination may overlap */ |
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
134 |
for (ht = height; ht > 0; --ht) { |
7111
269c76b5b987
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6987
diff
changeset
|
135 |
memmove(dst, src, width * sizeof(Pixel)); |
0 | 136 |
src += p; |
137 |
dst += p; |
|
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
138 |
} |
0 | 139 |
} |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
140 |
/* This part of the screen is now dirty. */ |
375
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
141 |
_video_driver->make_dirty(left, top, width, height); |
0 | 142 |
} |
143 |
||
144 |
||
2010 | 145 |
void GfxFillRect(int left, int top, int right, int bottom, int color) |
146 |
{ |
|
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
147 |
const DrawPixelInfo* dpi = _cur_dpi; |
2062 | 148 |
Pixel *dst; |
332 | 149 |
const int otop = top; |
150 |
const int oleft = left; |
|
0 | 151 |
|
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
7111
diff
changeset
|
152 |
if (dpi->zoom != ZOOM_LVL_NORMAL) return; |
2010 | 153 |
if (left > right || top > bottom) return; |
154 |
if (right < dpi->left || left >= dpi->left + dpi->width) return; |
|
155 |
if (bottom < dpi->top || top >= dpi->top + dpi->height) return; |
|
0 | 156 |
|
157 |
if ( (left -= dpi->left) < 0) left = 0; |
|
158 |
right = right - dpi->left + 1; |
|
2010 | 159 |
if (right > dpi->width) right = dpi->width; |
0 | 160 |
right -= left; |
161 |
assert(right > 0); |
|
162 |
||
163 |
if ( (top -= dpi->top) < 0) top = 0; |
|
164 |
bottom = bottom - dpi->top + 1; |
|
2010 | 165 |
if (bottom > dpi->height) bottom = dpi->height; |
0 | 166 |
bottom -= top; |
167 |
assert(bottom > 0); |
|
168 |
||
169 |
dst = dpi->dst_ptr + top * dpi->pitch + left; |
|
170 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
171 |
if (!HASBIT(color, PALETTE_MODIFIER_GREYOUT)) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
172 |
if (!HASBIT(color, USE_COLORTABLE)) { |
0 | 173 |
do { |
7111
269c76b5b987
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6987
diff
changeset
|
174 |
memset(dst, color, right * sizeof(Pixel)); |
0 | 175 |
dst += dpi->pitch; |
176 |
} while (--bottom); |
|
177 |
} else { |
|
178 |
/* use colortable mode */ |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
179 |
const byte* ctab = GetNonSprite(GB(color, 0, PALETTE_WIDTH)) + 1; |
1357 | 180 |
|
0 | 181 |
do { |
182 |
int i; |
|
2005 | 183 |
for (i = 0; i != right; i++) dst[i] = ctab[dst[i]]; |
0 | 184 |
dst += dpi->pitch; |
185 |
} while (--bottom); |
|
186 |
} |
|
187 |
} else { |
|
332 | 188 |
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; |
0 | 189 |
do { |
190 |
int i; |
|
2005 | 191 |
for (i = (bo ^= 1); i < right; i += 2) dst[i] = (byte)color; |
0 | 192 |
dst += dpi->pitch; |
332 | 193 |
} while (--bottom > 0); |
0 | 194 |
} |
195 |
} |
|
196 |
||
410 | 197 |
static void GfxSetPixel(int x, int y, int color) |
0 | 198 |
{ |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
199 |
const DrawPixelInfo* dpi = _cur_dpi; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
200 |
if ((x -= dpi->left) < 0 || x >= dpi->width || (y -= dpi->top)<0 || y >= dpi->height) |
0 | 201 |
return; |
2010 | 202 |
dpi->dst_ptr[y * dpi->pitch + x] = color; |
0 | 203 |
} |
204 |
||
205 |
void GfxDrawLine(int x, int y, int x2, int y2, int color) |
|
206 |
{ |
|
207 |
int dy; |
|
208 |
int dx; |
|
2010 | 209 |
int stepx; |
210 |
int stepy; |
|
0 | 211 |
int frac; |
212 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
213 |
/* Check clipping first */ |
0 | 214 |
{ |
4522 | 215 |
DrawPixelInfo *dpi = _cur_dpi; |
0 | 216 |
int t; |
217 |
||
2010 | 218 |
if (x < dpi->left && x2 < dpi->left) return; |
0 | 219 |
|
2010 | 220 |
if (y < dpi->top && y2 < dpi->top) return; |
0 | 221 |
|
222 |
t = dpi->left + dpi->width; |
|
2010 | 223 |
if (x > t && x2 > t) return; |
0 | 224 |
|
225 |
t = dpi->top + dpi->height; |
|
2010 | 226 |
if (y > t && y2 > t) return; |
0 | 227 |
} |
228 |
||
229 |
dy = (y2 - y) * 2; |
|
2010 | 230 |
if (dy < 0) { |
231 |
dy = -dy; |
|
232 |
stepy = -1; |
|
233 |
} else { |
|
234 |
stepy = 1; |
|
235 |
} |
|
0 | 236 |
|
237 |
dx = (x2 - x) * 2; |
|
2010 | 238 |
if (dx < 0) { |
239 |
dx = -dx; |
|
240 |
stepx = -1; |
|
241 |
} else { |
|
242 |
stepx = 1; |
|
243 |
} |
|
0 | 244 |
|
245 |
GfxSetPixel(x, y, color); |
|
246 |
if (dx > dy) { |
|
247 |
frac = dy - (dx >> 1); |
|
248 |
while (x != x2) { |
|
249 |
if (frac >= 0) { |
|
250 |
y += stepy; |
|
251 |
frac -= dx; |
|
252 |
} |
|
253 |
x += stepx; |
|
254 |
frac += dy; |
|
255 |
GfxSetPixel(x, y, color); |
|
256 |
} |
|
257 |
} else { |
|
258 |
frac = dx - (dy >> 1); |
|
259 |
while (y != y2) { |
|
260 |
if (frac >= 0) { |
|
261 |
x += stepx; |
|
262 |
frac -= dy; |
|
263 |
} |
|
264 |
y += stepy; |
|
265 |
frac += dx; |
|
266 |
GfxSetPixel(x, y, color); |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
||
3798
37a2090eac94
(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
|
271 |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
272 |
/** Truncate a given string to a maximum width if neccessary. |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
273 |
* If the string is truncated, add three dots ('...') to show this. |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6974
diff
changeset
|
274 |
* @param *str string that is checked and possibly truncated |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
275 |
* @param maxw maximum width in pixels of the string |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
276 |
* @return new width of (truncated) string */ |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
277 |
static int TruncateString(char *str, int maxw) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
278 |
{ |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
279 |
int w = 0; |
3798
37a2090eac94
(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
|
280 |
FontSize size = _cur_fontsize; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
281 |
int ddd, ddd_w; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
282 |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
283 |
WChar c; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
284 |
char *ddd_pos; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
285 |
|
3798
37a2090eac94
(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
|
286 |
ddd_w = ddd = GetCharacterWidth(size, '.') * 3; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
287 |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
288 |
for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) { |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
289 |
if (IsPrintable(c)) { |
3798
37a2090eac94
(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
|
290 |
w += GetCharacterWidth(size, c); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
291 |
|
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
292 |
if (w >= maxw) { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
293 |
/* string got too big... insert dotdotdot */ |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
294 |
ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; |
6541
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
295 |
ddd_pos[3] = '\0'; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
296 |
return ddd_w; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
297 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
298 |
} else { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
299 |
if (c == SCC_SETX) str++; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
300 |
else if (c == SCC_SETXY) str += 2; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
301 |
else if (c == SCC_TINYFONT) { |
3798
37a2090eac94
(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 |
size = FS_SMALL; |
37a2090eac94
(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
|
303 |
ddd = GetCharacterWidth(size, '.') * 3; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
304 |
} else if (c == SCC_BIGFONT) { |
3798
37a2090eac94
(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
|
305 |
size = FS_LARGE; |
37a2090eac94
(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
|
306 |
ddd = GetCharacterWidth(size, '.') * 3; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
307 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
308 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
309 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
310 |
/* Remember the last position where three dots fit. */ |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
311 |
if (w + ddd < maxw) { |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
312 |
ddd_w = w + ddd; |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
313 |
ddd_pos = str; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
314 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
315 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
316 |
|
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
317 |
return w; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
318 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
319 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
320 |
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
321 |
{ |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
322 |
GetString(dest, src, last); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
323 |
return TruncateString(dest, maxw); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
324 |
} |
0 | 325 |
|
326 |
/* returns right coordinate */ |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
327 |
int DrawString(int x, int y, StringID str, uint16 color) |
0 | 328 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
329 |
char buffer[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
330 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
331 |
GetString(buffer, str, lastof(buffer)); |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
332 |
return DoDrawString(buffer, x, y, color); |
0 | 333 |
} |
334 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
335 |
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
336 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
337 |
char buffer[512]; |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
338 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
339 |
return DoDrawString(buffer, x, y, color); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
340 |
} |
0 | 341 |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
342 |
|
4314
c7ded7546e7f
(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
|
343 |
int DrawStringRightAligned(int x, int y, StringID str, uint16 color) |
0 | 344 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
345 |
char buffer[512]; |
4314
c7ded7546e7f
(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
|
346 |
int w; |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
347 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
348 |
GetString(buffer, str, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
349 |
w = GetStringBoundingBox(buffer).width; |
4314
c7ded7546e7f
(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
|
350 |
DoDrawString(buffer, x - w, y, color); |
c7ded7546e7f
(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
|
351 |
|
c7ded7546e7f
(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
|
352 |
return w; |
0 | 353 |
} |
354 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
355 |
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
356 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
357 |
char buffer[512]; |
0 | 358 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
359 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
360 |
DoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
361 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
362 |
|
4314
c7ded7546e7f
(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 |
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color) |
c7ded7546e7f
(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 |
{ |
c7ded7546e7f
(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
|
365 |
int w = DrawStringRightAligned(x, y, str, color); |
c7ded7546e7f
(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
|
366 |
GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]); |
c7ded7546e7f
(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
|
367 |
} |
c7ded7546e7f
(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
|
368 |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
369 |
|
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
370 |
int DrawStringCentered(int x, int y, StringID str, uint16 color) |
0 | 371 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
372 |
char buffer[512]; |
0 | 373 |
int w; |
374 |
||
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
375 |
GetString(buffer, str, lastof(buffer)); |
0 | 376 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
377 |
w = GetStringBoundingBox(buffer).width; |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
378 |
DoDrawString(buffer, x - w / 2, y, color); |
0 | 379 |
|
380 |
return w; |
|
381 |
} |
|
382 |
||
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
383 |
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
384 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
385 |
char buffer[512]; |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
386 |
int w = TruncateStringID(str, buffer, xr - xl, lastof(buffer)); |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
387 |
return DoDrawString(buffer, (xl + xr - w) / 2, y, color); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
388 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
389 |
|
2134 | 390 |
int DoDrawStringCentered(int x, int y, const char *str, uint16 color) |
391 |
{ |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
392 |
int w = GetStringBoundingBox(str).width; |
2134 | 393 |
DoDrawString(str, x - w / 2, y, color); |
394 |
return w; |
|
395 |
} |
|
396 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
397 |
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color) |
0 | 398 |
{ |
399 |
int w = DrawStringCentered(x, y, str, color); |
|
2010 | 400 |
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]); |
0 | 401 |
} |
402 |
||
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
403 |
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
404 |
{ |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
405 |
int w = DrawStringCenteredTruncated(xl, xr, y, str, color); |
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
406 |
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
407 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
408 |
|
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
409 |
/** 'Correct' a string to a maximum length. Longer strings will be cut into |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
410 |
* additional lines at whitespace characters if possible. The string parameter |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
411 |
* is modified with terminating characters mid-string which are the |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6974
diff
changeset
|
412 |
* placeholders for the newlines. |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
413 |
* The string WILL be truncated if there was no whitespace for the current |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
414 |
* line's maximum width. |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
415 |
* |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6974
diff
changeset
|
416 |
* @note To know if the terminating '\0' is the string end or just a |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
417 |
* newline, the returned 'num' value should be consulted. The num'th '\0', |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
418 |
* starting with index 0 is the real string end. |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
419 |
* |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
420 |
* @param str string to check and correct for length restrictions |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
421 |
* @param maxw the maximum width the string can have on one line |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
422 |
* @return return a 32bit wide number consisting of 2 packed values: |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
423 |
* 0 - 15 the number of lines ADDED to the string |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
424 |
* 16 - 31 the fontsize in which the length calculation was done at */ |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
425 |
uint32 FormatStringLinebreaks(char *str, int maxw) |
1095 | 426 |
{ |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
427 |
FontSize size = _cur_fontsize; |
0 | 428 |
int num = 0; |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
429 |
|
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
430 |
assert(maxw > 0); |
0 | 431 |
|
2952 | 432 |
for (;;) { |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
433 |
char *last_space = NULL; |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
434 |
int w = 0; |
0 | 435 |
|
2952 | 436 |
for (;;) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
437 |
WChar c = Utf8Consume((const char **)&str); |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
438 |
/* whitespace is where we will insert the line-break */ |
6541
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
439 |
if (IsWhitespace(c)) last_space = str; |
0 | 440 |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
441 |
if (IsPrintable(c)) { |
3798
37a2090eac94
(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 |
w += GetCharacterWidth(size, c); |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
443 |
/* string is longer than maximum width so we need to decide what to |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
444 |
* do. We can do two things: |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
445 |
* 1. If no whitespace was found at all up until now (on this line) then |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
446 |
* we will truncate the string and bail out. |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
447 |
* 2. In all other cases force a linebreak at the last seen whitespace */ |
0 | 448 |
if (w > maxw) { |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
449 |
if (last_space == NULL) { |
6541
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
450 |
*Utf8PrevChar(str) = '\0'; |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
451 |
return num + (size << 16); |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
452 |
} |
0 | 453 |
str = last_space; |
454 |
break; |
|
455 |
} |
|
456 |
} else { |
|
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
457 |
switch (c) { |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
458 |
case '\0': return num + (size << 16); break; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
459 |
case SCC_SETX: str++; break; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
460 |
case SCC_SETXY: str += 2; break; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
461 |
case SCC_TINYFONT: size = FS_SMALL; break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
462 |
case SCC_BIGFONT: size = FS_LARGE; break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
463 |
case '\n': goto end_of_inner_loop; |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
464 |
} |
0 | 465 |
} |
466 |
} |
|
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
467 |
end_of_inner_loop: |
6541
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
468 |
/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
469 |
* and increase linecount. We use Utf8PrevChar() as also non 1 char long |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
470 |
* whitespace seperators are supported */ |
0 | 471 |
num++; |
6541
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
472 |
char *s = Utf8PrevChar(str); |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
473 |
*s++ = '\0'; |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
474 |
|
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
475 |
/* In which case (see above) we will shift remainder to left and close the gap */ |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
476 |
if (str - s >= 1) { |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
477 |
for (; str[-1] != '\0';) *s++ = *str++; |
ff575414f0d2
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6505
diff
changeset
|
478 |
} |
0 | 479 |
} |
480 |
} |
|
481 |
||
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
482 |
/** Draw a given string with the centre around the given x coordinates |
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
483 |
* @param x Centre the string around this pixel width |
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
484 |
* @param y Draw the string at this pixel height (first line's bottom) |
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
485 |
* @param str String to draw |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6974
diff
changeset
|
486 |
* @param maxw Maximum width the string can have before it is wrapped */ |
2634
16334e1a4862
(svn r3176) Use proper types, not some variants of int
tron
parents:
2631
diff
changeset
|
487 |
void DrawStringMultiCenter(int x, int y, StringID str, int maxw) |
0 | 488 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
489 |
char buffer[512]; |
0 | 490 |
uint32 tmp; |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
491 |
int num, w, mt; |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
492 |
const char *src; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
493 |
WChar c; |
0 | 494 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
495 |
GetString(buffer, str, lastof(buffer)); |
0 | 496 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
497 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 498 |
num = GB(tmp, 0, 16); |
0 | 499 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
500 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
0 | 501 |
|
502 |
y -= (mt >> 1) * num; |
|
503 |
||
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
504 |
src = buffer; |
0 | 505 |
|
2952 | 506 |
for (;;) { |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
507 |
w = GetStringBoundingBox(src).width; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
508 |
DoDrawString(src, x - (w >> 1), y, 0xFE); |
3798
37a2090eac94
(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
|
509 |
_cur_fontsize = _last_fontsize; |
0 | 510 |
|
2952 | 511 |
for (;;) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
512 |
c = Utf8Consume(&src); |
0 | 513 |
if (c == 0) { |
514 |
y += mt; |
|
515 |
if (--num < 0) { |
|
3798
37a2090eac94
(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 |
_cur_fontsize = FS_NORMAL; |
0 | 517 |
return; |
518 |
} |
|
519 |
break; |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
520 |
} else if (c == SCC_SETX) { |
0 | 521 |
src++; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
522 |
} else if (c == SCC_SETXY) { |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
523 |
src += 2; |
0 | 524 |
} |
525 |
} |
|
526 |
} |
|
527 |
} |
|
528 |
||
4928
4cdb51b5db7b
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
529 |
|
6703
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
530 |
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh) |
2010 | 531 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
532 |
char buffer[512]; |
0 | 533 |
uint32 tmp; |
2753 | 534 |
int num, mt; |
4928
4cdb51b5db7b
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
535 |
uint total_height; |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
536 |
const char *src; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
537 |
WChar c; |
0 | 538 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
539 |
GetString(buffer, str, lastof(buffer)); |
0 | 540 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
541 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 542 |
num = GB(tmp, 0, 16); |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
543 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
544 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
4928
4cdb51b5db7b
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
545 |
total_height = (num + 1) * mt; |
0 | 546 |
|
6708
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
547 |
if (maxh != -1 && (int)total_height > maxh) { |
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
548 |
/* Check there's room enough for at least one line. */ |
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
549 |
if (maxh < mt) return 0; |
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
550 |
|
6703
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
551 |
num = maxh / mt - 1; |
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
552 |
total_height = (num + 1) * mt; |
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
553 |
} |
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
554 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
555 |
src = buffer; |
0 | 556 |
|
2952 | 557 |
for (;;) { |
0 | 558 |
DoDrawString(src, x, y, 0xFE); |
3798
37a2090eac94
(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
|
559 |
_cur_fontsize = _last_fontsize; |
0 | 560 |
|
2952 | 561 |
for (;;) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
562 |
c = Utf8Consume(&src); |
0 | 563 |
if (c == 0) { |
564 |
y += mt; |
|
565 |
if (--num < 0) { |
|
3798
37a2090eac94
(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
|
566 |
_cur_fontsize = FS_NORMAL; |
4928
4cdb51b5db7b
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
567 |
return total_height; |
0 | 568 |
} |
569 |
break; |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
570 |
} else if (c == SCC_SETX) { |
0 | 571 |
src++; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
572 |
} else if (c == SCC_SETXY) { |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
573 |
src += 2; |
0 | 574 |
} |
575 |
} |
|
576 |
} |
|
577 |
} |
|
578 |
||
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
579 |
/** Return the string dimension in pixels. The height and width are returned |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
580 |
* in a single BoundingRect value. TINYFONT, BIGFONT modifiers are only |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
581 |
* supported as the first character of the string. The returned dimensions |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
582 |
* are therefore a rough estimation correct for all the current strings |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
583 |
* but not every possible combination |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
584 |
* @param str string to calculate pixel-width |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
585 |
* @return string width and height in pixels */ |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
586 |
BoundingRect GetStringBoundingBox(const char *str) |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
587 |
{ |
3798
37a2090eac94
(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
|
588 |
FontSize size = _cur_fontsize; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
589 |
BoundingRect br; |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
590 |
int max_width; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
591 |
WChar c; |
4557
112872feb6fd
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
592 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
593 |
br.width = br.height = max_width = 0; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
594 |
for (;;) { |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
595 |
c = Utf8Consume(&str); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
596 |
if (c == 0) break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
597 |
if (IsPrintable(c)) { |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
598 |
br.width += GetCharacterWidth(size, c); |
0 | 599 |
} else { |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
600 |
switch (c) { |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
601 |
case SCC_SETX: br.width += (byte)*str++; break; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
602 |
case SCC_SETXY: |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
603 |
br.width += (byte)*str++; |
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
604 |
br.height += (byte)*str++; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
605 |
break; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
606 |
case SCC_TINYFONT: size = FS_SMALL; break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
607 |
case SCC_BIGFONT: size = FS_LARGE; break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
608 |
case '\n': |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
609 |
br.height += GetCharacterHeight(size); |
4610
45ac1d25fd62
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
610 |
if (br.width > max_width) max_width = br.width; |
45ac1d25fd62
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
611 |
br.width = 0; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
612 |
break; |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
613 |
} |
0 | 614 |
} |
615 |
} |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
616 |
br.height += GetCharacterHeight(size); |
4557
112872feb6fd
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
617 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
618 |
br.width = max(br.width, max_width); |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
619 |
return br; |
0 | 620 |
} |
621 |
||
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
622 |
/** Draw a string at the given coordinates with the given colour |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
623 |
* @param string the string to draw |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
624 |
* @param x offset from left side of the screen, if negative offset from the right side |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6974
diff
changeset
|
625 |
* @param y offset from top side of the screen, if negative offset from the bottom |
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
626 |
* @param real_color colour of the string, see _string_colormap in |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
627 |
* table/palettes.h or docs/ottd-colourtext-palette.png |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
628 |
* @return the x-coordinates where the drawing has finished. If nothing is drawn |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
629 |
* the originally passed x-coordinate is returned */ |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
630 |
int DoDrawString(const char *string, int x, int y, uint16 real_color) |
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
631 |
{ |
4522 | 632 |
DrawPixelInfo *dpi = _cur_dpi; |
3798
37a2090eac94
(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
|
633 |
FontSize size = _cur_fontsize; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
634 |
WChar c; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
635 |
byte color; |
0 | 636 |
int xo = x, yo = y; |
637 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
638 |
color = real_color & 0xFF; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
639 |
|
0 | 640 |
if (color != 0xFE) { |
641 |
if (x >= dpi->left + dpi->width || |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
642 |
x + _screen.width * 2 <= dpi->left || |
0 | 643 |
y >= dpi->top + dpi->height || |
644 |
y + _screen.height <= dpi->top) |
|
645 |
return x; |
|
646 |
||
647 |
if (color != 0xFF) { |
|
648 |
switch_color:; |
|
657
40a9032b454b
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
649 |
if (real_color & IS_PALETTE_COLOR) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
650 |
_string_colorremap[1] = color; |
6974
24490c839582
(svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents:
6708
diff
changeset
|
651 |
_string_colorremap[2] = _use_dos_palette ? 1 : 215; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
652 |
} else { |
6974
24490c839582
(svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents:
6708
diff
changeset
|
653 |
uint palette = _use_dos_palette ? 1 : 0; |
24490c839582
(svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents:
6708
diff
changeset
|
654 |
_string_colorremap[1] = _string_colormap[palette][color].text; |
24490c839582
(svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents:
6708
diff
changeset
|
655 |
_string_colorremap[2] = _string_colormap[palette][color].shadow; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
656 |
} |
0 | 657 |
_color_remap_ptr = _string_colorremap; |
658 |
} |
|
659 |
} |
|
660 |
||
661 |
check_bounds: |
|
662 |
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) { |
|
663 |
skip_char:; |
|
2952 | 664 |
for (;;) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
665 |
c = Utf8Consume(&string); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
666 |
if (!IsPrintable(c)) goto skip_cont; |
0 | 667 |
} |
668 |
} |
|
669 |
||
2952 | 670 |
for (;;) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
671 |
c = Utf8Consume(&string); |
0 | 672 |
skip_cont:; |
673 |
if (c == 0) { |
|
3798
37a2090eac94
(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
|
674 |
_last_fontsize = size; |
0 | 675 |
return x; |
676 |
} |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
677 |
if (IsPrintable(c)) { |
0 | 678 |
if (x >= dpi->left + dpi->width) goto skip_char; |
679 |
if (x + 26 >= dpi->left) { |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
680 |
GfxMainBlitter(GetGlyph(size, c), x, y, BM_COLOUR_REMAP); |
0 | 681 |
} |
3798
37a2090eac94
(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
|
682 |
x += GetCharacterWidth(size, c); |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
683 |
} else if (c == '\n') { // newline = {} |
0 | 684 |
x = xo; |
3798
37a2090eac94
(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
|
685 |
y += GetCharacterHeight(size); |
0 | 686 |
goto check_bounds; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
687 |
} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change color? |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
688 |
color = (byte)(c - SCC_BLUE); |
0 | 689 |
goto switch_color; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
690 |
} else if (c == SCC_SETX) { // {SETX} |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
691 |
x = xo + (byte)*string++; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
692 |
} else if (c == SCC_SETXY) {// {SETXY} |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
693 |
x = xo + (byte)*string++; |
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
694 |
y = yo + (byte)*string++; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
695 |
} else if (c == SCC_TINYFONT) { // {TINYFONT} |
3798
37a2090eac94
(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
|
696 |
size = FS_SMALL; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
697 |
} else if (c == SCC_BIGFONT) { // {BIGFONT} |
3798
37a2090eac94
(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
|
698 |
size = FS_LARGE; |
0 | 699 |
} else { |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
700 |
DEBUG(misc, 0, "[utf8] unknown string command character %d", c); |
0 | 701 |
} |
702 |
} |
|
703 |
} |
|
704 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
705 |
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw) |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
706 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
707 |
char buffer[512]; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
708 |
ttd_strlcpy(buffer, str, sizeof(buffer)); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
709 |
TruncateString(buffer, maxw); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
710 |
return DoDrawString(buffer, x, y, color); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
711 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
712 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
713 |
void DrawSprite(SpriteID img, SpriteID pal, int x, int y) |
2010 | 714 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
715 |
if (HASBIT(img, PALETTE_MODIFIER_TRANSPARENT)) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
716 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
717 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
718 |
} else if (pal != PAL_NONE) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
719 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
720 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP); |
0 | 721 |
} else { |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
722 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL); |
0 | 723 |
} |
724 |
} |
|
725 |
||
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
726 |
static inline void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode) |
0 | 727 |
{ |
4171 | 728 |
const DrawPixelInfo *dpi = _cur_dpi; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
729 |
Blitter::BlitterParams bp; |
0 | 730 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
731 |
/* Move to the correct offset */ |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
732 |
x += sprite->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
733 |
y += sprite->y_offs; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
734 |
|
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
735 |
/* Copy the main data directly from the sprite */ |
4518 | 736 |
bp.sprite = sprite->data; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
737 |
bp.sprite_width = sprite->width; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
738 |
bp.sprite_height = sprite->height; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
739 |
bp.width = UnScaleByZoom(sprite->width, dpi->zoom); |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
740 |
bp.height = UnScaleByZoom(sprite->height, dpi->zoom); |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
741 |
bp.top = 0; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
742 |
bp.left = 0; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
743 |
bp.skip_left = 0; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
744 |
bp.skip_top = 0; |
0 | 745 |
bp.dst = dpi->dst_ptr; |
746 |
bp.pitch = dpi->pitch; |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
747 |
bp.remap = _color_remap_ptr; |
0 | 748 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
749 |
assert(sprite->width > 0); |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
750 |
assert(sprite->height > 0); |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
751 |
|
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
752 |
if (bp.width <= 0) return; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
753 |
if (bp.height <= 0) return; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
754 |
|
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
755 |
y -= dpi->top; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
756 |
/* Check for top overflow */ |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
757 |
if (y < 0) { |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
758 |
bp.height -= -UnScaleByZoom(y, dpi->zoom); |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
759 |
if (bp.height <= 0) return; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
760 |
bp.skip_top += -UnScaleByZoom(y, dpi->zoom); |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
761 |
y = 0; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
762 |
} else { |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
763 |
bp.top = UnScaleByZoom(y, dpi->zoom); |
7300
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
764 |
} |
0 | 765 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
766 |
/* Check for bottom overflow */ |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
767 |
y += ScaleByZoom(bp.height, dpi->zoom) - dpi->height; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
768 |
if (y > 0) { |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
769 |
bp.height -= UnScaleByZoom(y, dpi->zoom); |
7300
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
770 |
if (bp.height <= 0) return; |
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
771 |
} |
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
772 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
773 |
x -= dpi->left; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
774 |
/* Check for left overflow */ |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
775 |
if (x < 0) { |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
776 |
bp.width -= -UnScaleByZoom(x, dpi->zoom); |
7300
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
777 |
if (bp.width <= 0) return; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
778 |
bp.skip_left += -UnScaleByZoom(x, dpi->zoom); |
7300
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
779 |
x = 0; |
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
780 |
} else { |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
781 |
bp.left = UnScaleByZoom(x, dpi->zoom); |
7300
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
782 |
} |
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
783 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
784 |
/* Check for right overflow */ |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
785 |
x += ScaleByZoom(bp.width, dpi->zoom) - dpi->width; |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
786 |
if (x > 0) { |
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
787 |
bp.width -= UnScaleByZoom(x, dpi->zoom); |
7300
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
788 |
if (bp.width <= 0) return; |
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
789 |
} |
6c3d987e8e6d
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
7149
diff
changeset
|
790 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7327
diff
changeset
|
791 |
BlitterFactoryBase::GetCurrentBlitter()->Draw(&bp, mode, dpi->zoom); |
0 | 792 |
} |
793 |
||
6573 | 794 |
void DoPaletteAnimations(); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
795 |
|
6573 | 796 |
void GfxInitPalettes() |
0 | 797 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
798 |
memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette)); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
799 |
|
0 | 800 |
_pal_first_dirty = 0; |
801 |
_pal_last_dirty = 255; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
802 |
DoPaletteAnimations(); |
0 | 803 |
} |
804 |
||
2010 | 805 |
#define EXTR(p, q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) |
806 |
#define EXTR2(p, q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) |
|
0 | 807 |
|
6573 | 808 |
void DoPaletteAnimations() |
0 | 809 |
{ |
4171 | 810 |
const Colour *s; |
811 |
Colour *d; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
812 |
/* Amount of colors to be rotated. |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
813 |
* A few more for the DOS palette, because the water colors are |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
814 |
* 245-254 for DOS and 217-226 for Windows. */ |
0 | 815 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
2005 | 816 |
int c = _use_dos_palette ? 38 : 28; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
817 |
Colour old_val[38]; // max(38, 28) |
2005 | 818 |
uint i; |
819 |
uint j; |
|
0 | 820 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
821 |
d = &_cur_palette[217]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
822 |
memcpy(old_val, d, c * sizeof(*old_val)); |
0 | 823 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
824 |
/* Dark blue water */ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6574
diff
changeset
|
825 |
s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a; |
2005 | 826 |
j = EXTR(320, 5); |
827 |
for (i = 0; i != 5; i++) { |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
828 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
829 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
830 |
if (j == 5) j = 0; |
0 | 831 |
} |
832 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
833 |
/* Glittery water */ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6574
diff
changeset
|
834 |
s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
835 |
j = EXTR(128, 15); |
2005 | 836 |
for (i = 0; i != 5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
837 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
838 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
839 |
if (j >= 15) j -= 15; |
0 | 840 |
} |
841 |
||
842 |
s = ev->e; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
843 |
j = EXTR2(512, 5); |
2005 | 844 |
for (i = 0; i != 5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
845 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
846 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
847 |
if (j == 5) j = 0; |
0 | 848 |
} |
849 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
850 |
/* Oil refinery fire animation */ |
0 | 851 |
s = ev->oil_ref; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
852 |
j = EXTR2(512, 7); |
2005 | 853 |
for (i = 0; i != 7; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
854 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
855 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
856 |
if (j == 7) j = 0; |
0 | 857 |
} |
858 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
859 |
/* Radio tower blinking */ |
0 | 860 |
{ |
2005 | 861 |
byte i = (_timer_counter >> 1) & 0x7F; |
862 |
byte v; |
|
863 |
||
0 | 864 |
(v = 255, i < 0x3f) || |
865 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
866 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
867 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
868 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
869 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
870 |
d++; |
0 | 871 |
|
872 |
i ^= 0x40; |
|
873 |
(v = 255, i < 0x3f) || |
|
874 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
875 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
876 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
877 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
878 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
879 |
d++; |
0 | 880 |
} |
881 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
882 |
/* Handle lighthouse and stadium animation */ |
0 | 883 |
s = ev->lighthouse; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
884 |
j = EXTR(256, 4); |
2005 | 885 |
for (i = 0; i != 4; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
886 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
887 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
888 |
if (j == 4) j = 0; |
0 | 889 |
} |
890 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
891 |
/* Animate water for old DOS graphics */ |
2005 | 892 |
if (_use_dos_palette) { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
893 |
/* Dark blue water DOS */ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6574
diff
changeset
|
894 |
s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a; |
2005 | 895 |
j = EXTR(320, 5); |
896 |
for (i = 0; i != 5; i++) { |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
897 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
898 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
899 |
if (j == 5) j = 0; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
900 |
} |
915 | 901 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
902 |
/* Glittery water DOS */ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6574
diff
changeset
|
903 |
s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
904 |
j = EXTR(128, 15); |
2005 | 905 |
for (i = 0; i != 5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
906 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
907 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
908 |
if (j >= 15) j -= 15; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
909 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
910 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
911 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
912 |
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { |
0 | 913 |
if (_pal_first_dirty > 217) _pal_first_dirty = 217; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
914 |
if (_pal_last_dirty < 217 + c) _pal_last_dirty = 217 + c; |
0 | 915 |
} |
916 |
} |
|
917 |
||
918 |
||
6573 | 919 |
void LoadStringWidthTable() |
0 | 920 |
{ |
2005 | 921 |
uint i; |
0 | 922 |
|
3797
86749951a1bf
(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
|
923 |
/* Normal font */ |
3798
37a2090eac94
(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
|
924 |
for (i = 0; i != 224; i++) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
925 |
_stringwidth_table[FS_NORMAL][i] = GetGlyphWidth(FS_NORMAL, i + 32); |
0 | 926 |
} |
927 |
||
3797
86749951a1bf
(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
|
928 |
/* Small font */ |
3798
37a2090eac94
(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
|
929 |
for (i = 0; i != 224; i++) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
930 |
_stringwidth_table[FS_SMALL][i] = GetGlyphWidth(FS_SMALL, i + 32); |
0 | 931 |
} |
932 |
||
3797
86749951a1bf
(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
|
933 |
/* Large font */ |
3798
37a2090eac94
(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
|
934 |
for (i = 0; i != 224; i++) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
935 |
_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32); |
0 | 936 |
} |
937 |
} |
|
938 |
||
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
939 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
940 |
byte GetCharacterWidth(FontSize size, WChar key) |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
941 |
{ |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
942 |
if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32]; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
943 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
944 |
return GetGlyphWidth(size, key); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
945 |
} |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
946 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
947 |
|
6573 | 948 |
void ScreenSizeChanged() |
0 | 949 |
{ |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
950 |
/* check the dirty rect */ |
0 | 951 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
952 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
953 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
954 |
/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */ |
0 | 955 |
_cursor.visible = false; |
956 |
} |
|
957 |
||
6573 | 958 |
void UndrawMouseCursor() |
0 | 959 |
{ |
960 |
if (_cursor.visible) { |
|
961 |
_cursor.visible = false; |
|
962 |
memcpy_pitch( |
|
963 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
964 |
_cursor_backup, |
|
965 |
_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
|
966 |
|
0 | 967 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
968 |
} |
|
969 |
} |
|
970 |
||
6573 | 971 |
void DrawMouseCursor() |
0 | 972 |
{ |
2010 | 973 |
int x; |
974 |
int y; |
|
975 |
int w; |
|
976 |
int h; |
|
0 | 977 |
|
3312
593789444b01
(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
|
978 |
/* Redraw mouse cursor but only when it's inside the window */ |
593789444b01
(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
|
979 |
if (!_cursor.in_window) return; |
593789444b01
(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
|
980 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
981 |
/* Don't draw the mouse cursor if it's already drawn */ |
0 | 982 |
if (_cursor.visible) { |
2010 | 983 |
if (!_cursor.dirty) return; |
0 | 984 |
UndrawMouseCursor(); |
985 |
} |
|
986 |
||
987 |
w = _cursor.size.x; |
|
988 |
x = _cursor.pos.x + _cursor.offs.x; |
|
2010 | 989 |
if (x < 0) { |
990 |
w += x; |
|
991 |
x = 0; |
|
992 |
} |
|
993 |
if (w > _screen.width - x) w = _screen.width - x; |
|
0 | 994 |
if (w <= 0) return; |
995 |
_cursor.draw_pos.x = x; |
|
996 |
_cursor.draw_size.x = w; |
|
997 |
||
998 |
h = _cursor.size.y; |
|
999 |
y = _cursor.pos.y + _cursor.offs.y; |
|
2010 | 1000 |
if (y < 0) { |
1001 |
h += y; |
|
1002 |
y = 0; |
|
1003 |
} |
|
1004 |
if (h > _screen.height - y) h = _screen.height - y; |
|
0 | 1005 |
if (h <= 0) return; |
1006 |
_cursor.draw_pos.y = y; |
|
1007 |
_cursor.draw_size.y = h; |
|
1008 |
||
2010 | 1009 |
assert(w * h < (int)sizeof(_cursor_backup)); |
0 | 1010 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1011 |
/* Make backup of stuff below cursor */ |
0 | 1012 |
memcpy_pitch( |
1013 |
_cursor_backup, |
|
1014 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
306
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
1015 |
_cursor.draw_size.x, _cursor.draw_size.y, _screen.pitch, _cursor.draw_size.x); |
0 | 1016 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1017 |
/* Draw cursor on screen */ |
0 | 1018 |
_cur_dpi = &_screen; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1019 |
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x, _cursor.pos.y); |
0 | 1020 |
|
1021 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
|
1022 |
||
1023 |
_cursor.visible = true; |
|
1024 |
_cursor.dirty = false; |
|
1025 |
} |
|
1026 |
||
798 | 1027 |
#if defined(_DEBUG) |
410 | 1028 |
static void DbgScreenRect(int left, int top, int right, int bottom) |
0 | 1029 |
{ |
2010 | 1030 |
DrawPixelInfo dp; |
4171 | 1031 |
DrawPixelInfo *old; |
0 | 1032 |
|
1033 |
old = _cur_dpi; |
|
1034 |
_cur_dpi = &dp; |
|
1035 |
dp = _screen; |
|
2010 | 1036 |
GfxFillRect(left, top, right - 1, bottom - 1, rand() & 255); |
0 | 1037 |
_cur_dpi = old; |
1038 |
} |
|
798 | 1039 |
#endif |
0 | 1040 |
|
1041 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1042 |
{ |
|
1043 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1044 |
if (_cursor.visible) { |
|
1045 |
if (right > _cursor.draw_pos.x && |
|
1046 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1047 |
bottom > _cursor.draw_pos.y && |
|
1048 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1049 |
UndrawMouseCursor(); |
|
1050 |
} |
|
1051 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1052 |
UndrawTextMessage(); |
0 | 1053 |
|
1054 |
#if defined(_DEBUG) |
|
1055 |
if (_dbg_screen_rect) |
|
1056 |
DbgScreenRect(left, top, right, bottom); |
|
1057 |
else |
|
1058 |
#endif |
|
1059 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
|
1060 |
||
2010 | 1061 |
_video_driver->make_dirty(left, top, right - left, bottom - top); |
0 | 1062 |
} |
1063 |
||
6573 | 1064 |
void DrawDirtyBlocks() |
0 | 1065 |
{ |
1066 |
byte *b = _dirty_blocks; |
|
2398
70de6626d65f
(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
|
1067 |
const int w = ALIGN(_screen.width, 64); |
70de6626d65f
(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
|
1068 |
const int h = ALIGN(_screen.height, 8); |
2025 | 1069 |
int x; |
1070 |
int y; |
|
0 | 1071 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1072 |
if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1073 |
|
2025 | 1074 |
y = 0; |
0 | 1075 |
do { |
2025 | 1076 |
x = 0; |
1077 |
do { |
|
1078 |
if (*b != 0) { |
|
1079 |
int left; |
|
1080 |
int top; |
|
1081 |
int right = x + 64; |
|
1082 |
int bottom = y; |
|
1083 |
byte *p = b; |
|
1084 |
int h2; |
|
0 | 1085 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1086 |
/* First try coalescing downwards */ |
0 | 1087 |
do { |
2025 | 1088 |
*p = 0; |
1089 |
p += DIRTY_BYTES_PER_LINE; |
|
1090 |
bottom += 8; |
|
1091 |
} while (bottom != h && *p != 0); |
|
0 | 1092 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1093 |
/* Try coalescing to the right too. */ |
2025 | 1094 |
h2 = (bottom - y) >> 3; |
1095 |
assert(h2 > 0); |
|
1096 |
p = b; |
|
0 | 1097 |
|
2025 | 1098 |
while (right != w) { |
1099 |
byte *p2 = ++p; |
|
1100 |
int h = h2; |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1101 |
/* Check if a full line of dirty flags is set. */ |
2025 | 1102 |
do { |
1103 |
if (!*p2) goto no_more_coalesc; |
|
1104 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1105 |
} while (--h != 0); |
|
1106 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1107 |
/* Wohoo, can combine it one step to the right! |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1108 |
* Do that, and clear the bits. */ |
2025 | 1109 |
right += 64; |
1110 |
||
1111 |
h = h2; |
|
1112 |
p2 = p; |
|
1113 |
do { |
|
1114 |
*p2 = 0; |
|
1115 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1116 |
} while (--h != 0); |
|
1117 |
} |
|
1118 |
no_more_coalesc: |
|
1119 |
||
1120 |
left = x; |
|
1121 |
top = y; |
|
1122 |
||
1123 |
if (left < _invalid_rect.left ) left = _invalid_rect.left; |
|
1124 |
if (top < _invalid_rect.top ) top = _invalid_rect.top; |
|
1125 |
if (right > _invalid_rect.right ) right = _invalid_rect.right; |
|
1126 |
if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom; |
|
1127 |
||
1128 |
if (left < right && top < bottom) { |
|
1129 |
RedrawScreenRect(left, top, right, bottom); |
|
1130 |
} |
|
1131 |
||
0 | 1132 |
} |
2025 | 1133 |
} while (b++, (x += 64) != w); |
1134 |
} while (b += -(w >> 6) + DIRTY_BYTES_PER_LINE, (y += 8) != h); |
|
0 | 1135 |
|
1136 |
_invalid_rect.left = w; |
|
1137 |
_invalid_rect.top = h; |
|
1138 |
_invalid_rect.right = 0; |
|
1139 |
_invalid_rect.bottom = 0; |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1140 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1141 |
/* If we are generating a world, and waiting for a paint run, mark it here |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1142 |
* as done painting, so we can continue generating. */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1143 |
if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1144 |
SetGeneratingWorldPaintStatus(false); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1145 |
} |
0 | 1146 |
} |
1147 |
||
1148 |
||
1149 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
|
1150 |
{ |
|
1151 |
byte *b; |
|
2010 | 1152 |
int width; |
1153 |
int height; |
|
0 | 1154 |
|
1155 |
if (left < 0) left = 0; |
|
1156 |
if (top < 0) top = 0; |
|
1157 |
if (right > _screen.width) right = _screen.width; |
|
1158 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1159 |
||
2010 | 1160 |
if (left >= right || top >= bottom) return; |
0 | 1161 |
|
2010 | 1162 |
if (left < _invalid_rect.left ) _invalid_rect.left = left; |
1163 |
if (top < _invalid_rect.top ) _invalid_rect.top = top; |
|
1164 |
if (right > _invalid_rect.right ) _invalid_rect.right = right; |
|
1165 |
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom; |
|
0 | 1166 |
|
1167 |
left >>= 6; |
|
2010 | 1168 |
top >>= 3; |
0 | 1169 |
|
1170 |
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left; |
|
1171 |
||
2010 | 1172 |
width = ((right - 1) >> 6) - left + 1; |
1173 |
height = ((bottom - 1) >> 3) - top + 1; |
|
0 | 1174 |
|
1175 |
assert(width > 0 && height > 0); |
|
1176 |
||
1177 |
do { |
|
2010 | 1178 |
int i = width; |
1179 |
||
0 | 1180 |
do b[--i] = 0xFF; while (i); |
1181 |
||
1182 |
b += DIRTY_BYTES_PER_LINE; |
|
2010 | 1183 |
} while (--height != 0); |
0 | 1184 |
} |
1185 |
||
6573 | 1186 |
void MarkWholeScreenDirty() |
0 | 1187 |
{ |
1188 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1189 |
} |
|
1190 |
||
4958 | 1191 |
/** Set up a clipping area for only drawing into a certain area. To do this, |
1192 |
* Fill a DrawPixelInfo object with the supplied relative rectangle, backup |
|
1193 |
* the original (calling) _cur_dpi and assign the just returned DrawPixelInfo |
|
1194 |
* _cur_dpi. When you are done, give restore _cur_dpi's original value |
|
1195 |
* @param *n the DrawPixelInfo that will be the clipping rectangle box allowed |
|
1196 |
* for drawing |
|
1197 |
* @param left,top,width,height the relative coordinates of the clipping |
|
1198 |
* rectangle relative to the current _cur_dpi. This will most likely be the |
|
1199 |
* offset from the calling window coordinates |
|
1200 |
* @return return false if the requested rectangle is not possible with the |
|
1201 |
* current dpi pointer. Only continue of the return value is true, or you'll |
|
1202 |
* get some nasty results */ |
|
4429
1bb01569940c
(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
|
1203 |
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height) |
0 | 1204 |
{ |
4429
1bb01569940c
(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
|
1205 |
const DrawPixelInfo *o = _cur_dpi; |
0 | 1206 |
|
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
7111
diff
changeset
|
1207 |
n->zoom = ZOOM_LVL_NORMAL; |
0 | 1208 |
|
1209 |
assert(width > 0); |
|
1210 |
assert(height > 0); |
|
1211 |
||
1212 |
if ((left -= o->left) < 0) { |
|
2010 | 1213 |
width += left; |
4525
fa3aabcd12bc
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1214 |
if (width <= 0) return false; |
0 | 1215 |
n->left = -left; |
1216 |
left = 0; |
|
4429
1bb01569940c
(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
|
1217 |
} else { |
1bb01569940c
(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
|
1218 |
n->left = 0; |
0 | 1219 |
} |
1220 |
||
4429
1bb01569940c
(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
|
1221 |
if (width > o->width - left) { |
1bb01569940c
(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
|
1222 |
width = o->width - left; |
4525
fa3aabcd12bc
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1223 |
if (width <= 0) return false; |
0 | 1224 |
} |
1225 |
n->width = width; |
|
1226 |
||
1227 |
if ((top -= o->top) < 0) { |
|
2010 | 1228 |
height += top; |
4525
fa3aabcd12bc
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1229 |
if (height <= 0) return false; |
0 | 1230 |
n->top = -top; |
1231 |
top = 0; |
|
4429
1bb01569940c
(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
|
1232 |
} else { |
1bb01569940c
(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
|
1233 |
n->top = 0; |
0 | 1234 |
} |
1235 |
||
1236 |
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch); |
|
1237 |
||
4429
1bb01569940c
(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
|
1238 |
if (height > o->height - top) { |
1bb01569940c
(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
|
1239 |
height = o->height - top; |
4525
fa3aabcd12bc
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1240 |
if (height <= 0) return false; |
0 | 1241 |
} |
1242 |
n->height = height; |
|
1243 |
||
1244 |
return true; |
|
1245 |
} |
|
1246 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1247 |
static void SetCursorSprite(SpriteID cursor, SpriteID pal) |
0 | 1248 |
{ |
1249 |
CursorVars *cv = &_cursor; |
|
1348 | 1250 |
const Sprite *p; |
0 | 1251 |
|
2010 | 1252 |
if (cv->sprite == cursor) return; |
0 | 1253 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1254 |
p = GetSprite(GB(cursor, 0, SPRITE_WIDTH)); |
0 | 1255 |
cv->sprite = cursor; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1256 |
cv->pal = pal; |
1348 | 1257 |
cv->size.y = p->height; |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1258 |
cv->size.x = p->width; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1259 |
cv->offs.x = p->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1260 |
cv->offs.y = p->y_offs; |
0 | 1261 |
|
1262 |
cv->dirty = true; |
|
1263 |
} |
|
1264 |
||
6573 | 1265 |
static void SwitchAnimatedCursor() |
0 | 1266 |
{ |
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1267 |
const AnimCursor *cur = _cursor.animate_cur; |
0 | 1268 |
|
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1269 |
if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list; |
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1270 |
|
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1271 |
SetCursorSprite(cur->sprite, _cursor.pal); |
0 | 1272 |
|
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1273 |
_cursor.animate_timeout = cur->display_time; |
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1274 |
_cursor.animate_cur = cur + 1; |
0 | 1275 |
} |
1276 |
||
6573 | 1277 |
void CursorTick() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1278 |
{ |
2010 | 1279 |
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) |
0 | 1280 |
SwitchAnimatedCursor(); |
1281 |
} |
|
1282 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1283 |
void SetMouseCursor(SpriteID sprite, SpriteID pal) |
0 | 1284 |
{ |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1285 |
/* Turn off animation */ |
0 | 1286 |
_cursor.animate_timeout = 0; |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1287 |
/* Set cursor */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1288 |
SetCursorSprite(sprite, pal); |
0 | 1289 |
} |
1290 |
||
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1291 |
void SetAnimatedMouseCursor(const AnimCursor *table) |
0 | 1292 |
{ |
1293 |
_cursor.animate_list = table; |
|
1294 |
_cursor.animate_cur = NULL; |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1295 |
_cursor.pal = PAL_NONE; |
0 | 1296 |
SwitchAnimatedCursor(); |
1297 |
} |
|
1298 |
||
1299 |
bool ChangeResInGame(int w, int h) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1300 |
{ |
2645
964bd8fe3ce2
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1301 |
return |
964bd8fe3ce2
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1302 |
(_screen.width == w && _screen.height == h) || |
964bd8fe3ce2
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1303 |
_video_driver->change_resolution(w, h); |
0 | 1304 |
} |
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1305 |
|
5217
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1306 |
void ToggleFullScreen(bool fs) |
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1307 |
{ |
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1308 |
_video_driver->toggle_fullscreen(fs); |
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1309 |
if (_fullscreen != fs && _num_resolutions == 0) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
1310 |
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution"); |
5217
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1311 |
} |
21c23507c002
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1312 |
} |
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1806
diff
changeset
|
1313 |
|
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1314 |
static int CDECL compare_res(const void *pa, const void *pb) |
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1315 |
{ |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1316 |
int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0]; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1317 |
if (x != 0) return x; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1318 |
return ((const uint16*)pa)[1] - ((const uint16*)pb)[1]; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1319 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1320 |
|
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1321 |
void SortResolutions(int count) |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1322 |
{ |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1323 |
qsort(_resolutions, count, sizeof(_resolutions[0]), compare_res); |
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1324 |
} |