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