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