src/gfx.cpp
author celestar
Wed, 13 Jun 2007 11:45:14 +0000
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9912 1ac8aac92385
permissions -rw-r--r--
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
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
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
     3
/** @file gfx.cpp */
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1829
diff changeset
     6
#include "openttd.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2154
diff changeset
     7
#include "functions.h"
4428
0b0ee542d5b6 (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4425
diff changeset
     8
#include "macros.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1348
diff changeset
     9
#include "spritecache.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1130
diff changeset
    10
#include "strings.h"
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
    11
#include "string.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "table/palettes.h"
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
    14
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "hal.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2134
diff changeset
    16
#include "variables.h"
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
    17
#include "table/control_codes.h"
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
    18
#include "fontcache.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
    19
#include "genworld.h"
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
    20
#include "debug.h"
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    21
#include "zoom.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
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
    23
#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
    24
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
    25
#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
    26
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    27
byte _dirkeys;        ///< 1 = left, 2 = up, 4 = right, 8 = down
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    28
bool _fullscreen;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    29
CursorVars _cursor;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    30
bool _ctrl_pressed;   ///< Is Ctrl pressed?
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    31
bool _shift_pressed;  ///< Is Shift pressed?
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    32
byte _fast_forward;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    33
bool _left_button_down;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    34
bool _left_button_clicked;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    35
bool _right_button_down;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    36
bool _right_button_clicked;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    37
DrawPixelInfo _screen;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    38
bool _exit_game;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    39
bool _networking;         ///< are we in networking mode?
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    40
byte _game_mode;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    41
byte _pause_game;
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    42
int _pal_first_dirty;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    43
int _pal_last_dirty;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    44
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
    45
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
    46
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
    47
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    48
enum BlitterMode {
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
    49
	BM_NORMAL,
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
    50
	BM_COLOUR_REMAP,
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
    51
	BM_TRANSPARENT,
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
    52
};
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
    53
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
    54
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
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
    56
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
    57
static FontSize _last_fontsize;
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
    58
static Pixel _cursor_backup[64 * 64];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
static Rect _invalid_rect;
1357
a5acbb1f20fe (svn r1861) Constify Get(Non)Sprite()
tron
parents: 1351
diff changeset
    60
static const byte *_color_remap_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
static byte _string_colorremap[3];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    63
#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
    64
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
    65
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
    66
void memcpy_pitch(void *dst, void *src, int w, int h, int srcpitch, int dstpitch)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
{
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    68
	Pixel *dstp = (Pixel *)dst;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    69
	Pixel *srcp = (Pixel *)src;
0
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
	assert(h >= 0);
1056
ff3cfd9042a3 (svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents: 1009
diff changeset
    72
	for (; h != 0; --h) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    73
		memcpy(dstp, srcp, w * sizeof(Pixel));
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
    74
		dstp += dstpitch;
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
    75
		srcp += srcpitch;
1056
ff3cfd9042a3 (svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents: 1009
diff changeset
    76
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    79
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    80
{
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
    81
	const Pixel *src;
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
    82
	Pixel *dst;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	int p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	int ht;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    86
	if (xo == 0 && yo == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    88
	if (_cursor.visible) UndrawMouseCursor();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
    89
	UndrawTextMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	p = _screen.pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
    93
	if (yo > 0) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    94
		/*Calculate pointers */
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
    95
		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
    96
		src = dst - yo * p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    98
		/* Decrease height and increase top */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
		top += yo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
		height -= yo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		assert(height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   103
		/* Adjust left & width */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
		if (xo >= 0) {
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   105
			dst += xo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
			left += 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
		} else {
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   109
			src -= xo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
			width += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   113
		for (ht = height; ht > 0; --ht) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   114
			memcpy(dst, src, width * sizeof(Pixel));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
			src -= p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
			dst -= p;
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   117
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	} else {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   119
		/* Calculate pointers */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
		dst = _screen.dst_ptr + top * p + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
		src = dst - yo * p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   123
		/* Decrese height. (yo is <=0). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
		height += yo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
		assert(height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   127
		/* Adjust left & width */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		if (xo >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
			dst += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
			left += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
			width -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
			src -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
			width += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   137
		/* the y-displacement may be 0 therefore we have to use memmove,
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   138
		 * because source and destination may overlap */
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   139
		for (ht = height; ht > 0; --ht) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   140
			memmove(dst, src, width * sizeof(Pixel));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
			src += p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
			dst += p;
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   143
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	}
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   145
	/* This part of the screen is now dirty. */
375
6a1e279049d2 (svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents: 332
diff changeset
   146
	_video_driver->make_dirty(left, top, width, height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   150
void GfxFillRect(int left, int top, int right, int bottom, int color)
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   151
{
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
   152
	const DrawPixelInfo* dpi = _cur_dpi;
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
   153
	Pixel *dst;
332
745ec2bbdd5e (svn r499) Merge r498 to trunk:
tron
parents: 306
diff changeset
   154
	const int otop = top;
745ec2bbdd5e (svn r499) Merge r498 to trunk:
tron
parents: 306
diff changeset
   155
	const int oleft = left;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   157
	if (dpi->zoom != ZOOM_LVL_NORMAL) return;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   158
	if (left > right || top > bottom) return;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   159
	if (right < dpi->left || left >= dpi->left + dpi->width) return;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   160
	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
   161
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	if ( (left -= dpi->left) < 0) left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	right = right - dpi->left + 1;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   164
	if (right > dpi->width) right = dpi->width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	right -= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	assert(right > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	if ( (top -= dpi->top) < 0) top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	bottom = bottom - dpi->top + 1;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   170
	if (bottom > dpi->height) bottom = dpi->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	bottom -= top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	assert(bottom > 0);
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
	dst = dpi->dst_ptr + top * dpi->pitch + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   176
	if (!HASBIT(color, PALETTE_MODIFIER_GREYOUT)) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   177
		if (!HASBIT(color, USE_COLORTABLE)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
			do {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   179
				memset(dst, color, right * sizeof(Pixel));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
				dst += dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
			} while (--bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
			/* use colortable mode */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   184
			const byte* ctab = GetNonSprite(GB(color, 0, PALETTE_WIDTH)) + 1;
1357
a5acbb1f20fe (svn r1861) Constify Get(Non)Sprite()
tron
parents: 1351
diff changeset
   185
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
				int i;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   188
				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
   189
				dst += dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
			} while (--bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	} else {
332
745ec2bbdd5e (svn r499) Merge r498 to trunk:
tron
parents: 306
diff changeset
   193
		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
   194
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
			int i;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   196
			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
   197
			dst += dpi->pitch;
332
745ec2bbdd5e (svn r499) Merge r498 to trunk:
tron
parents: 306
diff changeset
   198
		} while (--bottom > 0);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 375
diff changeset
   202
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
   203
{
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
   204
	const DrawPixelInfo* dpi = _cur_dpi;
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   205
	if ((x -= dpi->left) < 0 || x >= dpi->width || (y -= dpi->top)<0 || y >= dpi->height)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		return;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   207
	dpi->dst_ptr[y * dpi->pitch + x] = color;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
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
   211
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	int dy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	int dx;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   214
	int stepx;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   215
	int stepy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	int frac;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   218
	/* Check clipping first */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	{
4522
3f90e8cf2435 (svn r6347) Undo
tron
parents: 4521
diff changeset
   220
		DrawPixelInfo *dpi = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		int t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   223
		if (x < dpi->left && x2 < dpi->left) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   225
		if (y < dpi->top && y2 < dpi->top) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		t = dpi->left + dpi->width;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   228
		if (x > t && x2 > t) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
		t = dpi->top + dpi->height;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   231
		if (y > t && y2 > t) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	dy = (y2 - y) * 2;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   235
	if (dy < 0) {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   236
		dy = -dy;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   237
		stepy = -1;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   238
	} else {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   239
		stepy = 1;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   240
	}
0
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
	dx = (x2 - x) * 2;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   243
	if (dx < 0) {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   244
		dx = -dx;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   245
		stepx = -1;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   246
	} else {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   247
		stepx = 1;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   248
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	GfxSetPixel(x, y, color);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	if (dx > dy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
		frac = dy - (dx >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		while (x != x2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
			if (frac >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
				y += stepy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
				frac -= dx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			x += stepx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
			frac += dy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
			GfxSetPixel(x, y, color);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		frac = dx - (dy >> 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
		while (y != y2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
			if (frac >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
				x += stepx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
				frac -= dy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
			y += stepy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
			frac += dx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
			GfxSetPixel(x, y, color);
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
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
   276
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   277
/** 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
   278
 * If the string is truncated, add three dots ('...') to show this.
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   279
 * @param *str string that is checked and possibly truncated
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   280
 * @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
   281
 * @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
   282
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
   283
{
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
   284
	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
   285
	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
   286
	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
   287
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   288
	WChar c;
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   289
	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
   290
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
   291
	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
   292
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   293
	for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   294
		if (IsPrintable(c)) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   295
			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
   296
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   297
			if (w >= maxw) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   298
				/* string got too big... insert dotdotdot */
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   299
				ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.';
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   300
				ddd_pos[3] = '\0';
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   301
				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
   302
			}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   303
		} else {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   304
			if (c == SCC_SETX) str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   305
			else if (c == SCC_SETXY) str += 2;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   306
			else if (c == SCC_TINYFONT) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   307
				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
   308
				ddd = GetCharacterWidth(size, '.') * 3;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   309
			} else if (c == SCC_BIGFONT) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   310
				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
   311
				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
   312
			}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   313
		}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   314
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   315
		/* Remember the last position where three dots fit. */
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   316
		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
   317
			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
   318
			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
   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
	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
   323
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   324
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   325
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last)
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   326
{
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   327
	GetString(dest, src, last);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   328
	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
   329
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
/* 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
   332
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
   333
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   334
	char buffer[512];
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   335
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   336
	GetString(buffer, str, lastof(buffer));
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   337
	return DoDrawString(buffer, x, y, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   340
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
   341
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   342
	char buffer[512];
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   343
	TruncateStringID(str, buffer, maxw, lastof(buffer));
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   344
	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
   345
}
0
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
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
   348
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
   349
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   350
	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
   351
	int w;
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   352
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   353
	GetString(buffer, str, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   354
	w = GetStringBoundingBox(buffer).width;
4314
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   355
	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
   356
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
   357
	return w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   360
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
   361
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   362
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   364
	TruncateStringID(str, buffer, maxw, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   365
	DoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   366
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   367
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
   368
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
   369
{
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
   370
	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
   371
	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
   372
}
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   373
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   374
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   375
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
   376
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   377
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	int w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   380
	GetString(buffer, str, lastof(buffer));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   382
	w = GetStringBoundingBox(buffer).width;
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   383
	DoDrawString(buffer, x - w / 2, y, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
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
   388
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
   389
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   390
	char buffer[512];
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   391
	int w = TruncateStringID(str, buffer, xr - xl, lastof(buffer));
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   392
	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
   393
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   394
2134
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   395
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
   396
{
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   397
	int w = GetStringBoundingBox(str).width;
2134
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   398
	DoDrawString(str, x - w / 2, y, color);
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   399
	return w;
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   400
}
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   401
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   402
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
   403
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	int w = DrawStringCentered(x, y, str, color);
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   405
	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
   406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
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
   408
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
   409
{
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
   410
	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
   411
	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
   412
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   413
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   414
/** 'Correct' a string to a maximum length. Longer strings will be cut into
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   415
 * additional lines at whitespace characters if possible. The string parameter
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   416
 * is modified with terminating characters mid-string which are the
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   417
 * placeholders for the newlines.
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   418
 * The string WILL be truncated if there was no whitespace for the current
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   419
 * line's maximum width.
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   420
 *
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   421
 * @note To know if the terminating '\0' is the string end or just a
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   422
 * newline, the returned 'num' value should be consulted. The num'th '\0',
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   423
 * starting with index 0 is the real string end.
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   424
 *
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   425
 * @param str string to check and correct for length restrictions
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   426
 * @param maxw the maximum width the string can have on one line
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   427
 * @return return a 32bit wide number consisting of 2 packed values:
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   428
 *  0 - 15 the number of lines ADDED to the string
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   429
 * 16 - 31 the fontsize in which the length calculation was done at */
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   430
uint32 FormatStringLinebreaks(char *str, int maxw)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   431
{
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   432
	FontSize size = _cur_fontsize;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	int num = 0;
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   434
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   435
	assert(maxw > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   437
	for (;;) {
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   438
		char *last_space = NULL;
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   439
		int w = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   441
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   442
			WChar c = Utf8Consume((const char **)&str);
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   443
			/* whitespace is where we will insert the line-break */
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   444
			if (IsWhitespace(c)) last_space = str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   446
			if (IsPrintable(c)) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   447
				w += GetCharacterWidth(size, c);
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   448
				/* string is longer than maximum width so we need to decide what to
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   449
				 * do. We can do two things:
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   450
				 * 1. If no whitespace was found at all up until now (on this line) then
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   451
				 *    we will truncate the string and bail out.
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   452
				 * 2. In all other cases force a linebreak at the last seen whitespace */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
				if (w > maxw) {
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   454
					if (last_space == NULL) {
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   455
						*Utf8PrevChar(str) = '\0';
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   456
						return num + (size << 16);
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   457
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
					str = last_space;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
			} else {
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   462
				switch (c) {
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   463
					case '\0': return num + (size << 16); break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   464
					case SCC_SETX:  str++; break;
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   465
					case SCC_SETXY: str += 2; break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   466
					case SCC_TINYFONT: size = FS_SMALL; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   467
					case SCC_BIGFONT:  size = FS_LARGE; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   468
					case '\n': goto end_of_inner_loop;
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   469
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
		}
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   472
end_of_inner_loop:
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   473
		/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   474
		 * and increase linecount. We use Utf8PrevChar() as also non 1 char long
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   475
		 * whitespace seperators are supported */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
		num++;
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   477
		char *s = Utf8PrevChar(str);
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   478
		*s++ = '\0';
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   479
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   480
		/* In which case (see above) we will shift remainder to left and close the gap */
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   481
		if (str - s >= 1) {
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   482
			for (; str[-1] != '\0';) *s++ = *str++;
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   483
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   487
/** Draw a given string with the centre around the given x coordinates
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   488
 * @param x Centre the string around this pixel width
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   489
 * @param y Draw the string at this pixel height (first line's bottom)
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   490
 * @param str String to draw
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   491
 * @param maxw Maximum width the string can have before it is wrapped */
2634
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
   492
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
   493
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   494
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	uint32 tmp;
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2548
diff changeset
   496
	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
   497
	const char *src;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   498
	WChar c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   500
	GetString(buffer, str, lastof(buffer));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   502
	tmp = FormatStringLinebreaks(buffer, maxw);
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2634
diff changeset
   503
	num = GB(tmp, 0, 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   505
	mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	y -= (mt >> 1) * num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   509
	src = buffer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   511
	for (;;) {
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   512
		w = GetStringBoundingBox(src).width;
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   513
		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
   514
		_cur_fontsize = _last_fontsize;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   516
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   517
			c = Utf8Consume(&src);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
			if (c == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
				y += mt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				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
   521
					_cur_fontsize = FS_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
				break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   525
			} else if (c == SCC_SETX) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
				src++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   527
			} else if (c == SCC_SETXY) {
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   528
				src += 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   534
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   535
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   536
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   537
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
	uint32 tmp;
2753
15012faaa68a (svn r3298) Remove unused and write-only variables
tron
parents: 2658
diff changeset
   539
	int num, mt;
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   540
	uint total_height;
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   541
	const char *src;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   542
	WChar c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   544
	GetString(buffer, str, lastof(buffer));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   546
	tmp = FormatStringLinebreaks(buffer, maxw);
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2634
diff changeset
   547
	num = GB(tmp, 0, 16);
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2548
diff changeset
   548
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   549
	mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   550
	total_height = (num + 1) * mt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   552
	if (maxh != -1 && (int)total_height > maxh) {
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   553
		/* Check there's room enough for at least one line. */
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   554
		if (maxh < mt) return 0;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   555
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   556
		num = maxh / mt - 1;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   557
		total_height = (num + 1) * mt;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   558
	}
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9906
diff changeset
   559
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   560
	src = buffer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   562
	for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
		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
   564
		_cur_fontsize = _last_fontsize;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   566
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   567
			c = Utf8Consume(&src);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
			if (c == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
				y += mt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
				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
   571
					_cur_fontsize = FS_NORMAL;
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   572
					return total_height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
				break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   575
			} else if (c == SCC_SETX) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
				src++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   577
			} else if (c == SCC_SETXY) {
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   578
				src += 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   584
/** Return the string dimension in pixels. The height and width are returned
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   585
 * in a single BoundingRect value. TINYFONT, BIGFONT modifiers are only
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   586
 * supported as the first character of the string. The returned dimensions
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   587
 * are therefore a rough estimation correct for all the current strings
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   588
 * but not every possible combination
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   589
 * @param str string to calculate pixel-width
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   590
 * @return string width and height in pixels */
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   591
BoundingRect GetStringBoundingBox(const char *str)
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   592
{
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
   593
	FontSize size = _cur_fontsize;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   594
	BoundingRect br;
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   595
	int max_width;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   596
	WChar c;
4557
112872feb6fd (svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents: 4525
diff changeset
   597
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   598
	br.width = br.height = max_width = 0;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   599
	for (;;) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   600
		c = Utf8Consume(&str);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   601
		if (c == 0) break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   602
		if (IsPrintable(c)) {
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   603
			br.width += GetCharacterWidth(size, c);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
		} else {
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   605
			switch (c) {
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   606
				case SCC_SETX: br.width += (byte)*str++; break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   607
				case SCC_SETXY:
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   608
					br.width += (byte)*str++;
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   609
					br.height += (byte)*str++;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   610
					break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   611
				case SCC_TINYFONT: size = FS_SMALL; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   612
				case SCC_BIGFONT:  size = FS_LARGE; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   613
				case '\n':
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   614
					br.height += GetCharacterHeight(size);
4610
45ac1d25fd62 (svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents: 4609
diff changeset
   615
					if (br.width > max_width) max_width = br.width;
45ac1d25fd62 (svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents: 4609
diff changeset
   616
					br.width = 0;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   617
					break;
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   618
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	}
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   621
	br.height += GetCharacterHeight(size);
4557
112872feb6fd (svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents: 4525
diff changeset
   622
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   623
	br.width  = max(br.width, max_width);
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   624
	return br;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   627
/** Draw a string at the given coordinates with the given colour
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   628
 * @param string the string to draw
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   629
 * @param x offset from left side of the screen, if negative offset from the right side
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   630
 * @param y offset from top side of the screen, if negative offset from the bottom
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   631
 * @param real_color colour of the string, see _string_colormap in
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   632
 * table/palettes.h or docs/ottd-colourtext-palette.png
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   633
 * @return the x-coordinates where the drawing has finished. If nothing is drawn
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   634
 * the originally passed x-coordinate is returned */
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   635
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
   636
{
4522
3f90e8cf2435 (svn r6347) Undo
tron
parents: 4521
diff changeset
   637
	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
   638
	FontSize size = _cur_fontsize;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   639
	WChar c;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   640
	byte color;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	int xo = x, yo = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   643
	color = real_color & 0xFF;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   644
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	if (color != 0xFE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
		if (x >= dpi->left + dpi->width ||
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   647
				x + _screen.width * 2 <= dpi->left ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
				y >= dpi->top + dpi->height ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
				y + _screen.height <= dpi->top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
					return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
		if (color != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
switch_color:;
657
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 619
diff changeset
   654
			if (real_color & IS_PALETTE_COLOR) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   655
				_string_colorremap[1] = color;
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   656
				_string_colorremap[2] = _use_dos_palette ? 1 : 215;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   657
			} else {
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   658
				uint palette = _use_dos_palette ? 1 : 0;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   659
				_string_colorremap[1] = _string_colormap[palette][color].text;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9907
diff changeset
   660
				_string_colorremap[2] = _string_colormap[palette][color].shadow;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   661
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
			_color_remap_ptr = _string_colorremap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
check_bounds:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	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
   668
skip_char:;
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   669
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   670
			c = Utf8Consume(&string);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   671
			if (!IsPrintable(c)) goto skip_cont;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   675
	for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   676
		c = Utf8Consume(&string);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
skip_cont:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
		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
   679
			_last_fontsize = size;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
			return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
		}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   682
		if (IsPrintable(c)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
			if (x >= dpi->left + dpi->width) goto skip_char;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
			if (x + 26 >= dpi->left) {
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
   685
				GfxMainBlitter(GetGlyph(size, c), x, y, BM_COLOUR_REMAP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
			}
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
   687
			x += GetCharacterWidth(size, c);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   688
		} else if (c == '\n') { // newline = {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
			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
   690
			y += GetCharacterHeight(size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
			goto check_bounds;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   692
		} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change color?
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   693
			color = (byte)(c - SCC_BLUE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
			goto switch_color;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   695
		} else if (c == SCC_SETX) { // {SETX}
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   696
			x = xo + (byte)*string++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   697
		} else if (c == SCC_SETXY) {// {SETXY}
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   698
			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
   699
			y = yo + (byte)*string++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   700
		} else if (c == SCC_TINYFONT) { // {TINYFONT}
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   701
			size = FS_SMALL;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   702
		} else if (c == SCC_BIGFONT) { // {BIGFONT}
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   703
			size = FS_LARGE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
		} else {
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   705
			DEBUG(misc, 0, "[utf8] unknown string command character %d", c);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   710
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
   711
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   712
	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
   713
	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
   714
	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
   715
	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
   716
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   717
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   718
void DrawSprite(SpriteID img, SpriteID pal, int x, int y)
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   719
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   720
	if (HASBIT(img, PALETTE_MODIFIER_TRANSPARENT)) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   721
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   722
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   723
	} else if (pal != PAL_NONE) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   724
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   725
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	} else {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   727
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	}
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
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   731
struct BlitterParams {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	int start_x, start_y;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   733
	const byte *sprite;
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
   734
	Pixel *dst;
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
   735
	BlitterMode mode;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	int width, height;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   737
	int width_org;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
	int pitch;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
   739
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   741
static void GfxBlitZoomUncomp(BlitterParams *bp, ZoomLevel zoom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
{
1357
a5acbb1f20fe (svn r1861) Constify Get(Non)Sprite()
tron
parents: 1351
diff changeset
   743
	const byte *src = bp->sprite;
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
   744
	Pixel *dst = bp->dst;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	int height = bp->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	int width = bp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	assert(height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   752
	height = UnScaleByZoom(height, zoom);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   753
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   754
	switch (bp->mode) {
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
   755
		case BM_COLOUR_REMAP: {
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   756
			const byte *ctab = _color_remap_ptr;
2004
6b975f28c351 (svn r2512) Small cleanup
tron
parents: 1997
diff changeset
   757
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   758
			for (; height != 0; height--) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   759
				for (i = 0; i != UnScaleByZoom(width, zoom); i++) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   760
					byte b = ctab[src[ScaleByZoom(i, zoom)]];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   762
					if (b != 0) dst[i] = b;
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   763
				}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   764
				src += ScaleByZoom(bp->width_org, zoom);
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   765
				dst += bp->pitch;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   766
			}
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   767
			break;
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   768
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
   770
		case BM_TRANSPARENT: {
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   771
			const byte *ctab = _color_remap_ptr;
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   772
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   773
			for (; height != 0; height--) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   774
				for (i = 0; i != UnScaleByZoom(width, zoom); i++)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   775
					if (src[ScaleByZoom(i, zoom)] != 0) dst[i] = ctab[dst[i]];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   776
				src += ScaleByZoom(bp->width_org, zoom);
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   777
				dst += bp->pitch;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   778
			}
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   779
			break;
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   780
		}
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   781
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   782
		default:
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   783
			for (; height != 0; height--) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   784
				for (i = 0; i != UnScaleByZoom(width, zoom); i++)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   785
					if (src[ScaleByZoom(i, zoom)] != 0) dst[i] = src[ScaleByZoom(i, zoom)];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   786
				src += ScaleByZoom(bp->width_org, zoom);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   787
				dst += bp->pitch;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   788
			}
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   789
			break;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   793
static void GfxBlitTileZoom(BlitterParams *bp, ZoomLevel zoom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   795
	const byte *src_o = bp->sprite;
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   796
	const byte *src;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
	int num, skip;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	byte done;
2062
00f7d339fdcb (svn r2571) Add explicit type Pixel for ... Pixels
tron
parents: 2037
diff changeset
   799
	Pixel *dst;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   800
	const byte *ctab;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   802
	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
   803
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   804
	for (;;) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   805
		do {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   806
			done = src_o[0];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   807
			num = done & 0x7F;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   808
			skip = src_o[1];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   809
			src = src_o + 2;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   810
			src_o += num + 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   812
			dst = bp->dst;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   814
			if (zoom >= ZOOM_LVL_OUT_2X && (skip & 1)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   815
				skip += 1;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   816
				src += 1;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   817
				num -= 1;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   818
				if (num <= 0) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   819
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   821
			if (zoom >= ZOOM_LVL_OUT_4X && (skip & 2)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   822
				skip += 2;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   823
				src += 2;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   824
				num -= 2;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   825
				if (num <= 0) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   826
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   827
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   828
			if (zoom >= ZOOM_LVL_OUT_8X && (skip & 4)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   829
				skip += 4;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   830
				src += 4;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   831
				num -= 4;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   832
				if (num <= 0) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   833
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   834
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   835
			if (zoom >= ZOOM_LVL_OUT_16X && (skip & 8)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   836
				skip += 8;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   837
				src += 8;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   838
				num -= 8;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   839
				if (num <= 0) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   840
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   841
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   842
			if ( (skip -= bp->start_x) > 0) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   843
				dst += UnScaleByZoom(skip, zoom);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   844
			} else {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   845
				src -= skip;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   846
				num += skip;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   847
				if (num <= 0) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   848
				skip = 0;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   849
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   850
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   851
			skip = skip + num - bp->width;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   852
			if (skip > 0) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   853
				num -= skip;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   854
				if (num <= 0) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   855
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   856
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   857
			num = UnScaleByZoom(num + ScaleByZoom(1, zoom) - 1, zoom);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   858
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   859
			switch (bp->mode) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   860
				case BM_COLOUR_REMAP:
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   861
					ctab = _color_remap_ptr;
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   862
					for (; num != 0; num--) {
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   863
							*dst = ctab[*src];
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   864
							dst++;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   865
							src += ScaleByZoom(1, zoom);
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   866
					}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   867
					break;
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   868
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   869
				case BM_TRANSPARENT:
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   870
					ctab = _color_remap_ptr;
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   871
					for (; num != 0; num--) {
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   872
							*dst = ctab[*dst];
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   873
							dst++;
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   874
					}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   875
					break;
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   876
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   877
				default:
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   878
					for (; num != 0; num--) {
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   879
							*dst = *src;
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   880
							dst++;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   881
							src += ScaleByZoom(1, zoom);
4516
a3e267733804 (svn r6301) -Codechange: if () cascades -> switch ()
tron
parents: 4437
diff changeset
   882
					}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   883
					break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   884
			}
1357
a5acbb1f20fe (svn r1861) Constify Get(Non)Sprite()
tron
parents: 1351
diff changeset
   885
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   886
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   887
		} while (!(done & 0x80));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   888
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   889
		bp->dst += bp->pitch;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   890
		if (--bp->height == 0) return;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   891
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   892
		for (int i = 0; i < ScaleByZoom(1, zoom) - 1; i++) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   893
			do {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   894
				done = src_o[0];
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   895
				src_o += (done & 0x7F) + 2;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   896
			} while (!(done & 0x80));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   897
			if (--bp->height == 0) return;
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   898
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
5818
f0cccdf91665 (svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents: 5726
diff changeset
   902
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   904
	const DrawPixelInfo *dpi = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	int start_x, start_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	BlitterParams bp;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   907
	int zoom_mask = ~(ScaleByZoom(1, dpi->zoom) - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	/* 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
   910
	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
   911
	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
   912
	bp.width_org = bp.width = sprite->width;
4518
8c3411b8d4c0 (svn r6303) -Codechange: Remove dead code
tron
parents: 4517
diff changeset
   913
	bp.height = sprite->height;
8c3411b8d4c0 (svn r6303) -Codechange: Remove dead code
tron
parents: 4517
diff changeset
   914
	bp.sprite = sprite->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	bp.dst = dpi->dst_ptr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
	bp.mode = mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
	bp.pitch = dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	assert(bp.height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	assert(bp.width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
4517
82cae2aa7c4a (svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents: 4516
diff changeset
   922
	if (sprite->info & 8) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
		/* tile blit */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
		start_y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   926
		if (dpi->zoom > ZOOM_LVL_NORMAL) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   927
			start_y += bp.height & ~zoom_mask;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 126
diff changeset
   928
			bp.height &= zoom_mask;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
			if (bp.height == 0) return;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   930
			y &= zoom_mask;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
		if ( (y -= dpi->top) < 0) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   934
			bp.height += y;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   935
			if (bp.height <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
			start_y -= y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
			y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
		} else {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   939
			bp.dst += bp.pitch * UnScaleByZoom(y, dpi->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
		bp.start_y = start_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
		if ( (y = y + bp.height - dpi->height) > 0) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   944
			bp.height -= y;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   945
			if (bp.height <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
		start_x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		x &= zoom_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
		if ( (x -= dpi->left) < 0) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   951
			bp.width += x;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   952
			if (bp.width <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
			start_x -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
		bp.start_x = start_x;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   957
		bp.dst += UnScaleByZoom(x, dpi->zoom);
0
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
		if ( (x = x + bp.width - dpi->width) > 0) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   960
			bp.width -= x;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   961
			if (bp.width <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   964
		GfxBlitTileZoom(&bp, dpi->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
		bp.sprite += bp.width * (bp.height & ~zoom_mask);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
		bp.height &= zoom_mask;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   968
		if (bp.height == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
		y &= zoom_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
		if ( (y -= dpi->top) < 0) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   973
			bp.height += y;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   974
			if (bp.height <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
			bp.sprite -= bp.width * y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
			y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
		} else {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   978
			bp.dst += bp.pitch * UnScaleByZoom(y, dpi->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
2037
380e80aed97a (svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents: 2025
diff changeset
   981
		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
   982
			bp.height = dpi->height - y;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   983
			if (bp.height <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
		}
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
		x &= zoom_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
		if ( (x -= dpi->left) < 0) {
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   989
			bp.width += x;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   990
			if (bp.width <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
			bp.sprite -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
		}
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   994
		bp.dst += UnScaleByZoom(x, dpi->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
2037
380e80aed97a (svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents: 2025
diff changeset
   996
		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
   997
			bp.width = dpi->width - x;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   998
			if (bp.width <= 0) return;
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
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1001
		GfxBlitZoomUncomp(&bp, dpi->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1005
void DoPaletteAnimations();
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
  1006
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1007
void GfxInitPalettes()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
{
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1009
	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
  1010
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	_pal_first_dirty = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	_pal_last_dirty = 255;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
  1013
	DoPaletteAnimations();
0
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
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1016
#define EXTR(p, q) (((uint16)(_timer_counter * (p)) * (q)) >> 16)
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1017
#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
  1018
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1019
void DoPaletteAnimations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
  1021
	const Colour *s;
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
  1022
	Colour *d;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
  1023
	/* 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
  1024
	 * 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
  1025
	 * 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
  1026
	const ExtraPaletteValues *ev = &_extra_palette_values;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1027
	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
  1028
	Colour old_val[38]; // max(38, 28)
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1029
	uint i;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1030
	uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1032
	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
  1033
	memcpy(old_val, d, c * sizeof(*old_val));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1035
	/* Dark blue water */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
  1036
	s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1037
	j = EXTR(320, 5);
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1038
	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
  1039
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1040
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1041
		if (j == 5) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1044
	/* Glittery water */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
  1045
	s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1046
	j = EXTR(128, 15);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1047
	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
  1048
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1049
		j += 3;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1050
		if (j >= 15) j -= 15;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
	}
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
	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
  1054
	j = EXTR2(512, 5);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1055
	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
  1056
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1057
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1058
		if (j == 5) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1061
	/* Oil refinery fire animation */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	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
  1063
	j = EXTR2(512, 7);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1064
	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
  1065
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1066
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1067
		if (j == 7) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1070
	/* Radio tower blinking */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	{
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1072
		byte i = (_timer_counter >> 1) & 0x7F;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1073
		byte v;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1074
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
		(v = 255, i < 0x3f) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
		(v = 128, i < 0x4A || i >= 0x75) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
		(v = 20);
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1078
		d->r = v;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1079
		d->g = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1080
		d->b = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1081
		d++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		i ^= 0x40;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
		(v = 255, i < 0x3f) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
		(v = 128, i < 0x4A || i >= 0x75) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
		(v = 20);
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1087
		d->r = v;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1088
		d->g = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1089
		d->b = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1090
		d++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1093
	/* Handle lighthouse and stadium animation */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	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
  1095
	j = EXTR(256, 4);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1096
	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
  1097
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1098
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1099
		if (j == 4) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1102
	/* Animate water for old DOS graphics */
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1103
	if (_use_dos_palette) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1104
		/* Dark blue water DOS */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
  1105
		s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1106
		j = EXTR(320, 5);
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1107
		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
  1108
			*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1109
			j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1110
			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
  1111
		}
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 798
diff changeset
  1112
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1113
		/* Glittery water DOS */
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
  1114
		s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1115
		j = EXTR(128, 15);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1116
		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
  1117
			*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1118
			j += 3;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1119
			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
  1120
		}
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
  1121
	}
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
  1122
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
  1123
	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
  1124
		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
  1125
		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
  1126
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1130
void LoadStringWidthTable()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
{
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
  1132
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
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
  1134
	/* 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
  1135
	for (i = 0; i != 224; i++) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1136
		_stringwidth_table[FS_NORMAL][i] = GetGlyphWidth(FS_NORMAL, i + 32);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
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
  1139
	/* 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
  1140
	for (i = 0; i != 224; i++) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1141
		_stringwidth_table[FS_SMALL][i] = GetGlyphWidth(FS_SMALL, i + 32);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
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
  1144
	/* 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
  1145
	for (i = 0; i != 224; i++) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1146
		_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1150
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1151
byte GetCharacterWidth(FontSize size, WChar key)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1152
{
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1153
	if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32];
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1154
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1155
	return GetGlyphWidth(size, key);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1156
}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1157
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
  1158
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1159
void ScreenSizeChanged()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
{
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1161
	/* check the dirty rect */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	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
  1163
	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
  1164
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1165
	/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	_cursor.visible = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1169
void UndrawMouseCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	if (_cursor.visible) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
		_cursor.visible = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
		memcpy_pitch(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
			_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
  1175
			_cursor_backup,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
			_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
  1177
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
		_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
  1179
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1182
void DrawMouseCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
{
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1184
	int x;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1185
	int y;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1186
	int w;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1187
	int h;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
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
  1189
	/* 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
  1190
	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
  1191
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1192
	/* Don't draw the mouse cursor if it's already drawn */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
	if (_cursor.visible) {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1194
		if (!_cursor.dirty) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
		UndrawMouseCursor();
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	w = _cursor.size.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
	x = _cursor.pos.x + _cursor.offs.x;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1200
	if (x < 0) {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1201
		w += x;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1202
		x = 0;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1203
	}
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1204
	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
  1205
	if (w <= 0) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	_cursor.draw_pos.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	_cursor.draw_size.x = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	h = _cursor.size.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
	y = _cursor.pos.y + _cursor.offs.y;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1211
	if (y < 0) {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1212
		h += y;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1213
		y = 0;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1214
	}
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1215
	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
  1216
	if (h <= 0) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	_cursor.draw_pos.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	_cursor.draw_size.y = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1220
	assert(w * h < (int)sizeof(_cursor_backup));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1222
	/* Make backup of stuff below cursor */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	memcpy_pitch(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
		_cursor_backup,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
		_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
  1226
		_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
  1227
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1228
	/* Draw cursor on screen */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	_cur_dpi = &_screen;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1230
	DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x, _cursor.pos.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	_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
  1233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	_cursor.visible = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	_cursor.dirty = false;
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
798
6b5518bf858f (svn r1268) -Fix: some warnings in gfx.c fixed
darkvater
parents: 657
diff changeset
  1238
#if defined(_DEBUG)
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 375
diff changeset
  1239
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
  1240
{
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1241
	DrawPixelInfo dp;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
  1242
	DrawPixelInfo *old;
0
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
	old = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
	_cur_dpi = &dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
	dp = _screen;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1247
	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
  1248
	_cur_dpi = old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
}
798
6b5518bf858f (svn r1268) -Fix: some warnings in gfx.c fixed
darkvater
parents: 657
diff changeset
  1250
#endif
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
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
  1253
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
	assert(right <= _screen.width && bottom <= _screen.height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	if (_cursor.visible) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		if (right > _cursor.draw_pos.x &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
				left < _cursor.draw_pos.x + _cursor.draw_size.x &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
				bottom > _cursor.draw_pos.y &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
				top < _cursor.draw_pos.y + _cursor.draw_size.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
			UndrawMouseCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
  1263
	UndrawTextMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
#if defined(_DEBUG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
	if (_dbg_screen_rect)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
		DbgScreenRect(left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
		DrawOverlappedWindowForAll(left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1272
	_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
  1273
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1275
void DrawDirtyBlocks()
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
	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
  1278
	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
  1279
	const int h = ALIGN(_screen.height, 8);
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1280
	int x;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1281
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1283
	if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1284
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1285
	y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	do {
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1287
		x = 0;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1288
		do {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1289
			if (*b != 0) {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1290
				int left;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1291
				int top;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1292
				int right = x + 64;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1293
				int bottom = y;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1294
				byte *p = b;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1295
				int h2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1297
				/* First try coalescing downwards */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
				do {
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1299
					*p = 0;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1300
					p += DIRTY_BYTES_PER_LINE;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1301
					bottom += 8;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1302
				} while (bottom != h && *p != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1304
				/* Try coalescing to the right too. */
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1305
				h2 = (bottom - y) >> 3;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1306
				assert(h2 > 0);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1307
				p = b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1309
				while (right != w) {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1310
					byte *p2 = ++p;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1311
					int h = h2;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1312
					/* Check if a full line of dirty flags is set. */
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1313
					do {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1314
						if (!*p2) goto no_more_coalesc;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1315
						p2 += DIRTY_BYTES_PER_LINE;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1316
					} while (--h != 0);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1317
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1318
					/* Wohoo, can combine it one step to the right!
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1319
					 * Do that, and clear the bits. */
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1320
					right += 64;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1321
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1322
					h = h2;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1323
					p2 = p;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1324
					do {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1325
						*p2 = 0;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1326
						p2 += DIRTY_BYTES_PER_LINE;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1327
					} while (--h != 0);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1328
				}
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1329
				no_more_coalesc:
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1330
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1331
				left = x;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1332
				top = y;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1333
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1334
				if (left   < _invalid_rect.left  ) left   = _invalid_rect.left;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1335
				if (top    < _invalid_rect.top   ) top    = _invalid_rect.top;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1336
				if (right  > _invalid_rect.right ) right  = _invalid_rect.right;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1337
				if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1338
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1339
				if (left < right && top < bottom) {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1340
					RedrawScreenRect(left, top, right, bottom);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1341
				}
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1342
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
			}
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1344
		} while (b++, (x += 64) != w);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1345
	} 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
  1346
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
	_invalid_rect.left = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
	_invalid_rect.top = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
	_invalid_rect.right = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
	_invalid_rect.bottom = 0;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1351
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1352
	/* 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
  1353
	 *  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
  1354
	if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1355
		SetGeneratingWorldPaintStatus(false);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1356
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
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
  1361
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
	byte *b;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1363
	int width;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1364
	int height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
	if (left < 0) left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
	if (top < 0) top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
	if (right > _screen.width) right = _screen.width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
	if (bottom > _screen.height) bottom = _screen.height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1371
	if (left >= right || top >= bottom) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1373
	if (left   < _invalid_rect.left  ) _invalid_rect.left   = left;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1374
	if (top    < _invalid_rect.top   ) _invalid_rect.top    = top;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1375
	if (right  > _invalid_rect.right ) _invalid_rect.right  = right;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1376
	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
  1377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
	left >>= 6;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1379
	top  >>= 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
	b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1383
	width  = ((right  - 1) >> 6) - left + 1;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1384
	height = ((bottom - 1) >> 3) - top  + 1;
0
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
	assert(width > 0 && height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	do {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1389
		int i = width;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1390
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
		do b[--i] = 0xFF; while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
		b += DIRTY_BYTES_PER_LINE;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1394
	} while (--height != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1397
void MarkWholeScreenDirty()
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
	SetDirtyBlocks(0, 0, _screen.width, _screen.height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
4958
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1402
/** Set up a clipping area for only drawing into a certain area. To do this,
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1403
 * Fill a DrawPixelInfo object with the supplied relative rectangle, backup
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1404
 * the original (calling) _cur_dpi and assign the just returned DrawPixelInfo
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1405
 * _cur_dpi. When you are done, give restore _cur_dpi's original value
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1406
 * @param *n the DrawPixelInfo that will be the clipping rectangle box allowed
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1407
 * for drawing
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1408
 * @param left,top,width,height the relative coordinates of the clipping
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1409
 * rectangle relative to the current _cur_dpi. This will most likely be the
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1410
 * offset from the calling window coordinates
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1411
 * @return return false if the requested rectangle is not possible with the
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1412
 * current dpi pointer. Only continue of the return value is true, or you'll
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1413
 * get some nasty results */
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1414
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
  1415
{
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
  1416
	const DrawPixelInfo *o = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1418
	n->zoom = ZOOM_LVL_NORMAL;
0
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
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
	assert(height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	if ((left -= o->left) < 0) {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1424
		width += left;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1425
		if (width <= 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
		n->left = -left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
		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
  1428
	} 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
  1429
		n->left = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
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
  1432
	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
  1433
		width = o->width - left;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1434
		if (width <= 0) return false;
0
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
	n->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
	if ((top -= o->top) < 0) {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1439
		height += top;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1440
		if (height <= 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
		n->top = -top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
		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
  1443
	} 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
  1444
		n->top = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	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
  1448
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
  1449
	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
  1450
		height = o->height - top;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1451
		if (height <= 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
	n->height = height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
	return true;
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
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1458
static void SetCursorSprite(SpriteID cursor, SpriteID pal)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	CursorVars *cv = &_cursor;
1348
1d123409026e (svn r1852) Start cleaning up sprite handling:
tron
parents: 1336
diff changeset
  1461
	const Sprite *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1463
	if (cv->sprite == cursor) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1465
	p = GetSprite(GB(cursor, 0, SPRITE_WIDTH));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	cv->sprite = cursor;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1467
	cv->pal    = pal;
1348
1d123409026e (svn r1852) Start cleaning up sprite handling:
tron
parents: 1336
diff changeset
  1468
	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
  1469
	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
  1470
	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
  1471
	cv->offs.y = p->y_offs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
	cv->dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1476
static void SwitchAnimatedCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
{
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1478
	const AnimCursor *cur = _cursor.animate_cur;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1480
	if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list;
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  1481
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1482
	SetCursorSprite(cur->sprite, _cursor.pal);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1484
	_cursor.animate_timeout = cur->display_time;
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1485
	_cursor.animate_cur     = cur + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6541
diff changeset
  1488
void CursorTick()
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1056
diff changeset
  1489
{
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1490
	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
  1491
		SwitchAnimatedCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1494
void SetMouseCursor(SpriteID sprite, SpriteID pal)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
{
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1496
	/* Turn off animation */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
	_cursor.animate_timeout = 0;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1498
	/* Set cursor */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1499
	SetCursorSprite(sprite, pal);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1502
void SetAnimatedMouseCursor(const AnimCursor *table)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
	_cursor.animate_list = table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	_cursor.animate_cur = NULL;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1506
	_cursor.pal = PAL_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
	SwitchAnimatedCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
bool ChangeResInGame(int w, int h)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 126
diff changeset
  1511
{
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2639
diff changeset
  1512
	return
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2639
diff changeset
  1513
		(_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
  1514
		_video_driver->change_resolution(w, h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
}
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
  1516
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1517
void ToggleFullScreen(bool fs)
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1518
{
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1519
	_video_driver->toggle_fullscreen(fs);
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1520
	if (_fullscreen != fs && _num_resolutions == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5217
diff changeset
  1521
		DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1522
	}
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1523
}
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
  1524
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
  1525
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
  1526
{
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
  1527
	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
  1528
	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
  1529
	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
  1530
}
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
  1531
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
  1532
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
  1533
{
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
  1534
	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
  1535
}