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