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