src/gfx.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 21:51:14 +0300
changeset 11180 982e9f814f97
parent 11142 2319fe9cea7d
permissions -rw-r--r--
scan for tarfiles in CACHE_DIR, remember what Subdirectory a tar was found in, set the GCF_FLAG on GRFs loaded from there, and hide those in the NewGRF GUI
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10247
diff changeset
     3
/** @file gfx.cpp Handling of drawing text and other gfx related stuff. */
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1829
diff changeset
     6
#include "openttd.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
     7
#include "gfx_func.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1348
diff changeset
     8
#include "spritecache.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2134
diff changeset
     9
#include "variables.h"
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
    10
#include "fontcache.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
    11
#include "genworld.h"
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
    12
#include "debug.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    13
#include "zoom_func.h"
7494
99eac2a2cd8b (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 7481
diff changeset
    14
#include "texteff.hpp"
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
    15
#include "blitter/factory.hpp"
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7514
diff changeset
    16
#include "video/video_driver.hpp"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8609
diff changeset
    17
#include "strings_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8619
diff changeset
    18
#include "core/math_func.hpp"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8760
diff changeset
    19
#include "settings_type.h"
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
    20
#include "core/alloc_func.hpp"
10969
e5fd50b81dc7 (svn r13523) -Codechange: replace qsort by the internal typesafe QSortT for resolution sorting
skidd13
parents: 10948
diff changeset
    21
#include "core/sort_func.hpp"
10444
3876060cdef7 (svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents: 10429
diff changeset
    22
#include "landscape_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8745
diff changeset
    24
#include "table/palettes.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8745
diff changeset
    25
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8745
diff changeset
    26
#include "table/control_codes.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8745
diff changeset
    27
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    28
byte _dirkeys;        ///< 1 = left, 2 = up, 4 = right, 8 = down
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    29
bool _fullscreen;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    30
CursorVars _cursor;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    31
bool _ctrl_pressed;   ///< Is Ctrl pressed?
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    32
bool _shift_pressed;  ///< Is Shift pressed?
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    33
byte _fast_forward;
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9233
diff changeset
    34
bool _left_button_down;     ///< Is left mouse button pressed?
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9233
diff changeset
    35
bool _left_button_clicked;  ///< Is left mouse button clicked?
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9233
diff changeset
    36
bool _right_button_down;    ///< Is right mouse button pressed?
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9233
diff changeset
    37
bool _right_button_clicked; ///< Is right mouse button clicked?
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    38
DrawPixelInfo _screen;
8745
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8710
diff changeset
    39
bool _screen_disable_anim = false;   ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    40
bool _exit_game;
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    41
bool _networking;         ///< are we in networking mode?
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    42
byte _game_mode;
9166
b37d9f4017e5 (svn r12335) -Codechange: Don't stuff signed values into a unsigned variable when the variable can just be unsigned...
peter1138
parents: 8766
diff changeset
    43
int8 _pause_game;
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    44
int _pal_first_dirty;
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
    45
int _pal_count_dirty;
5887
063ca43b682c (svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents: 5838
diff changeset
    46
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
    47
Colour _cur_palette[256];
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
    48
byte _stringwidth_table[FS_END][224];
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    49
DrawPixelInfo *_cur_dpi;
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    50
byte _colour_gradient[16][8];
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    51
bool _use_dos_palette;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
    52
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
    53
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
    55
FontSize _cur_fontsize;
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
    56
static FontSize _last_fontsize;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7348
diff changeset
    57
static uint8 _cursor_backup[64 * 64 * 4];
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    58
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    59
/**
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    60
 * The rect for repaint.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    61
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    62
 * This rectangle defines the area which should be repaint by the video driver.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    63
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    64
 * @ingroup dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
    65
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
static Rect _invalid_rect;
1357
a5acbb1f20fe (svn r1861) Constify Get(Non)Sprite()
tron
parents: 1351
diff changeset
    67
static const byte *_color_remap_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
static byte _string_colorremap[3];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
    70
enum {
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
    71
	DIRTY_BLOCK_HEIGHT   = 8,
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
    72
	DIRTY_BLOCK_WIDTH    = 64,
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
    73
};
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
    74
static uint _dirty_bytes_per_line = 0;
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
    75
static byte *_dirty_blocks = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    77
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    78
{
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
    79
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    81
	if (xo == 0 && yo == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
    83
	if (_cursor.visible) UndrawMouseCursor();
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7918
diff changeset
    84
	UndrawChatMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
7447
2537a074be26 (svn r10206) -Codechange: more moving things to blitter-layer: ScrollBuffer
truelight
parents: 7444
diff changeset
    86
	blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
    87
	/* This part of the screen is now dirty. */
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7514
diff changeset
    88
	_video_driver->MakeDirty(left, top, width, height);
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
11092
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    92
/**
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    93
 * Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    94
 *
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    95
 * @pre dpi->zoom == ZOOM_LVL_NORMAL, right >= left, bottom >= top
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    96
 * @param left Minimum X (inclusive)
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    97
 * @param top Minimum Y (inclusive)
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    98
 * @param right Maximum X (inclusive)
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
    99
 * @param bottom Maximum Y (inclusive)
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   100
 * @param color A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolor spritenumber (FILLRECT_RECOLOR)
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   101
 * @param mode
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   102
 *         FILLRECT_OPAQUE:   Fill the rectangle with the specified color
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   103
 *         FILLRECT_CHECKER:  Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things)
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   104
 *         FILLRECT_RECOLOR:  Apply a recolor sprite to every pixel in the rectangle currently on screen
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   105
 */
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   106
void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMode mode)
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   107
{
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
   108
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7348
diff changeset
   109
	const DrawPixelInfo *dpi = _cur_dpi;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7348
diff changeset
   110
	void *dst;
332
745ec2bbdd5e (svn r499) Merge r498 to trunk:
tron
parents: 306
diff changeset
   111
	const int otop = top;
745ec2bbdd5e (svn r499) Merge r498 to trunk:
tron
parents: 306
diff changeset
   112
	const int oleft = left;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 7111
diff changeset
   114
	if (dpi->zoom != ZOOM_LVL_NORMAL) return;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   115
	if (left > right || top > bottom) return;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   116
	if (right < dpi->left || left >= dpi->left + dpi->width) return;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   117
	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
   118
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	if ( (left -= dpi->left) < 0) left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	right = right - dpi->left + 1;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   121
	if (right > dpi->width) right = dpi->width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	right -= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	assert(right > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	if ( (top -= dpi->top) < 0) top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	bottom = bottom - dpi->top + 1;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   127
	if (bottom > dpi->height) bottom = dpi->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	bottom -= top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
	assert(bottom > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
   131
	dst = blitter->MoveTo(dpi->dst_ptr, left, top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
11092
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   133
	switch (mode) {
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   134
		default: // FILLRECT_OPAQUE
7443
b8c8a0d029fd (svn r10201) -Codechange: Replace Blitter::SetHorizontalLine with Blitter::DrawRect, as the former was only used by the rectangle drawing code anyway. This lets us draw rectangles in one go.
peter1138
parents: 7433
diff changeset
   135
			blitter->DrawRect(dst, right, bottom, (uint8)color);
11092
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   136
			break;
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   137
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   138
		case FILLRECT_RECOLOR:
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
   139
			blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
11092
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   140
			break;
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   141
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   142
		case FILLRECT_CHECKER: {
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   143
			byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   144
			do {
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   145
				for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   146
				dst = blitter->MoveTo(dst, 0, 1);
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   147
			} while (--bottom > 0);
e4fce2b3cded (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 10983
diff changeset
   148
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
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
   154
{
7444
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   155
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   156
	DrawPixelInfo *dpi = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
7444
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   158
	x -= dpi->left;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   159
	x2 -= dpi->left;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   160
	y -= dpi->top;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   161
	y2 -= dpi->top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
7444
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   163
	/* Check clipping */
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   164
	if (x < 0 && x2 < 0) return;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   165
	if (y < 0 && y2 < 0) return;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   166
	if (x > dpi->width  && x2 > dpi->width)  return;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   167
	if (y > dpi->height && y2 > dpi->height) return;
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   168
705a57aa0076 (svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents: 7443
diff changeset
   169
	blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, 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
8147
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   172
void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int color)
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   173
{
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   174
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   175
	DrawPixelInfo *dpi = _cur_dpi;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   176
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   177
	x -= dpi->left;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   178
	x2 -= dpi->left;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   179
	y -= dpi->top;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   180
	y2 -= dpi->top;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   181
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   182
	/* Check clipping */
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   183
	if (x < 0 && x2 < 0) return;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   184
	if (y < 0 && y2 < 0) return;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   185
	if (x > dpi->width  && x2 > dpi->width)  return;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   186
	if (y > dpi->height && y2 > dpi->height) return;
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   187
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   188
	blitter->DrawLine(dpi->dst_ptr, UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   189
			UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom),
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   190
			UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   191
}
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   192
8139
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   193
/**
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   194
 * Draws the projection of a parallelepiped.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   195
 * This can be used to draw boxes in world coordinates.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   196
 *
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   197
 * @param x   Screen X-coordinate of top front corner.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   198
 * @param y   Screen Y-coordinate of top front corner.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   199
 * @param dx1 Screen X-length of first edge.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   200
 * @param dy1 Screen Y-length of first edge.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   201
 * @param dx2 Screen X-length of second edge.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   202
 * @param dy2 Screen Y-length of second edge.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   203
 * @param dx3 Screen X-length of third edge.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   204
 * @param dy3 Screen Y-length of third edge.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   205
 */
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   206
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   207
{
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   208
	/*           ....
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   209
	 *         ..    ....
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   210
	 *       ..          ....
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   211
	 *     ..                ^
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   212
	 *   <--__(dx1,dy1)    /(dx2,dy2)
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   213
	 *   :    --__       /   :
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   214
	 *   :        --__ /     :
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   215
	 *   :            *(x,y) :
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   216
	 *   :            |      :
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   217
	 *   :            |     ..
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   218
	 *    ....        |(dx3,dy3)
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   219
	 *        ....    | ..
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   220
	 *            ....V.
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   221
	 */
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   222
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   223
	static const byte color = 255;
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   224
8147
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   225
	GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   226
	GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   227
	GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, color);
8139
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   228
8147
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   229
	GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   230
	GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   231
	GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   232
	GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   233
	GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, color);
93775539c977 (svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents: 8139
diff changeset
   234
	GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, color);
8139
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   235
}
16ad832aa538 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 8041
diff changeset
   236
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   237
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   238
/** Truncate a given string to a maximum width if neccessary.
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   239
 * If the string is truncated, add three dots ('...') to show this.
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6974
diff changeset
   240
 * @param *str string that is checked and possibly truncated
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   241
 * @param maxw maximum width in pixels of the string
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   242
 * @return new width of (truncated) string */
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   243
static int TruncateString(char *str, int maxw)
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   244
{
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   245
	int w = 0;
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   246
	FontSize size = _cur_fontsize;
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   247
	int ddd, ddd_w;
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   248
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   249
	WChar c;
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   250
	char *ddd_pos;
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   251
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   252
	ddd_w = ddd = GetCharacterWidth(size, '.') * 3;
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   253
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   254
	for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   255
		if (IsPrintable(c)) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   256
			w += GetCharacterWidth(size, c);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   257
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   258
			if (w >= maxw) {
11142
2319fe9cea7d (svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents: 11141
diff changeset
   259
				/* string got too big... insert dotdotdot, but make sure we do not
2319fe9cea7d (svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents: 11141
diff changeset
   260
				 * print anything beyond the string termination character. */
2319fe9cea7d (svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents: 11141
diff changeset
   261
				for (int i = 0; *ddd_pos != '\0' && i < 3; i++, ddd_pos++) *ddd_pos = '.';
2319fe9cea7d (svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents: 11141
diff changeset
   262
				*ddd_pos = '\0';
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   263
				return ddd_w;
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   264
			}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   265
		} else {
11141
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   266
			if (c == SCC_SETX) {
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   267
				w = *str;
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   268
				str++;
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   269
			} else if (c == SCC_SETXY) {
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   270
				w = *str;
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   271
				str += 2;
38a15a29725b (svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents: 11092
diff changeset
   272
			} else if (c == SCC_TINYFONT) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   273
				size = FS_SMALL;
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   274
				ddd = GetCharacterWidth(size, '.') * 3;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   275
			} else if (c == SCC_BIGFONT) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   276
				size = FS_LARGE;
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   277
				ddd = GetCharacterWidth(size, '.') * 3;
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   278
			}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   279
		}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   280
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   281
		/* Remember the last position where three dots fit. */
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   282
		if (w + ddd < maxw) {
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   283
			ddd_w = w + ddd;
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   284
			ddd_pos = str;
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   285
		}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   286
	}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   287
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   288
	return w;
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   289
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   290
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   291
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last)
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   292
{
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   293
	GetString(dest, src, last);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   294
	return TruncateString(dest, maxw);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   295
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
/* returns right coordinate */
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   298
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
   299
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   300
	char buffer[512];
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   301
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   302
	GetString(buffer, str, lastof(buffer));
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   303
	return DoDrawString(buffer, x, y, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   306
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw)
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   307
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   308
	char buffer[512];
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   309
	TruncateStringID(str, buffer, maxw, lastof(buffer));
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   310
	return DoDrawString(buffer, x, y, color);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   311
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   313
4314
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   314
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
   315
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   316
	char buffer[512];
4314
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   317
	int w;
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   318
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   319
	GetString(buffer, str, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   320
	w = GetStringBoundingBox(buffer).width;
4314
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   321
	DoDrawString(buffer, x - w, y, color);
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   322
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   323
	return w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   326
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw)
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   327
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   328
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   330
	TruncateStringID(str, buffer, maxw, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   331
	DoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   332
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   333
4314
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   334
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color)
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   335
{
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   336
	int w = DrawStringRightAligned(x, y, str, color);
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   337
	GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]);
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   338
}
c7ded7546e7f (svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents: 4300
diff changeset
   339
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   340
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   341
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
   342
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   343
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	int w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   346
	GetString(buffer, str, lastof(buffer));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   348
	w = GetStringBoundingBox(buffer).width;
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   349
	DoDrawString(buffer, x - w / 2, y, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   354
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color)
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   355
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   356
	char buffer[512];
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   357
	int w = TruncateStringID(str, buffer, xr - xl, lastof(buffer));
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   358
	return DoDrawString(buffer, (xl + xr - w) / 2, y, color);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   359
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   360
2134
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   361
int DoDrawStringCentered(int x, int y, const char *str, uint16 color)
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   362
{
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   363
	int w = GetStringBoundingBox(str).width;
2134
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   364
	DoDrawString(str, x - w / 2, y, color);
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   365
	return w;
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   366
}
7192d5266a96 (svn r2644) - Fix: my name was mistyped ;p
Darkvater
parents: 2113
diff changeset
   367
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   368
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
   369
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	int w = DrawStringCentered(x, y, str, color);
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   371
	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
   372
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   374
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color)
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   375
{
2113
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   376
	int w = DrawStringCenteredTruncated(xl, xr, y, str, color);
f228b399da01 (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2107
diff changeset
   377
	GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]);
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   378
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   379
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
   380
/**
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
   381
 * 'Correct' a string to a maximum length. Longer strings will be cut into
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   382
 * additional lines at whitespace characters if possible. The string parameter
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   383
 * is modified with terminating characters mid-string which are the
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6974
diff changeset
   384
 * placeholders for the newlines.
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   385
 * The string WILL be truncated if there was no whitespace for the current
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   386
 * line's maximum width.
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   387
 *
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6974
diff changeset
   388
 * @note To know if the terminating '\0' is the string end or just a
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   389
 * newline, the returned 'num' value should be consulted. The num'th '\0',
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   390
 * starting with index 0 is the real string end.
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   391
 *
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   392
 * @param str string to check and correct for length restrictions
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   393
 * @param maxw the maximum width the string can have on one line
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   394
 * @return return a 32bit wide number consisting of 2 packed values:
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   395
 *  0 - 15 the number of lines ADDED to the string
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
   396
 * 16 - 31 the fontsize in which the length calculation was done at
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
   397
 */
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   398
uint32 FormatStringLinebreaks(char *str, int maxw)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   399
{
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   400
	FontSize size = _cur_fontsize;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
	int num = 0;
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   402
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   403
	assert(maxw > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   405
	for (;;) {
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   406
		char *last_space = NULL;
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   407
		int w = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   409
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   410
			WChar c = Utf8Consume((const char **)&str);
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   411
			/* whitespace is where we will insert the line-break */
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   412
			if (IsWhitespace(c)) last_space = str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   414
			if (IsPrintable(c)) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   415
				w += GetCharacterWidth(size, c);
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   416
				/* string is longer than maximum width so we need to decide what to
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   417
				 * do. We can do two things:
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   418
				 * 1. If no whitespace was found at all up until now (on this line) then
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   419
				 *    we will truncate the string and bail out.
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   420
				 * 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
   421
				if (w > maxw) {
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   422
					if (last_space == NULL) {
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   423
						*Utf8PrevChar(str) = '\0';
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   424
						return num + (size << 16);
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   425
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
					str = last_space;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
			} else {
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   430
				switch (c) {
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   431
					case '\0': return num + (size << 16); break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   432
					case SCC_SETX:  str++; break;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   433
					case SCC_SETXY: str += 2; break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   434
					case SCC_TINYFONT: size = FS_SMALL; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   435
					case SCC_BIGFONT:  size = FS_LARGE; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   436
					case '\n': goto end_of_inner_loop;
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   437
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
		}
4954
d773d01b35f5 (svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents: 4949
diff changeset
   440
end_of_inner_loop:
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   441
		/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   442
		 * and increase linecount. We use Utf8PrevChar() as also non 1 char long
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   443
		 * whitespace seperators are supported */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		num++;
6541
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   445
		char *s = Utf8PrevChar(str);
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   446
		*s++ = '\0';
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   447
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   448
		/* In which case (see above) we will shift remainder to left and close the gap */
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   449
		if (str - s >= 1) {
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   450
			for (; str[-1] != '\0';) *s++ = *str++;
ff575414f0d2 (svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents: 6505
diff changeset
   451
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
10662
f455941692a3 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 10444
diff changeset
   455
/** Draw a given string with the centre around the given (x,y) coordinates
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   456
 * @param x Centre the string around this pixel width
10662
f455941692a3 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 10444
diff changeset
   457
 * @param y Centre the string around this pixel height
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   458
 * @param str String to draw
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6974
diff changeset
   459
 * @param maxw Maximum width the string can have before it is wrapped */
2634
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
   460
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
   461
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   462
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	uint32 tmp;
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2548
diff changeset
   464
	int num, w, mt;
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   465
	const char *src;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   466
	WChar c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   468
	GetString(buffer, str, lastof(buffer));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   470
	tmp = FormatStringLinebreaks(buffer, maxw);
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2634
diff changeset
   471
	num = GB(tmp, 0, 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   473
	mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
	y -= (mt >> 1) * num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   477
	src = buffer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   479
	for (;;) {
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   480
		w = GetStringBoundingBox(src).width;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   481
		DoDrawString(src, x - (w >> 1), y, 0xFE);
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   482
		_cur_fontsize = _last_fontsize;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   484
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   485
			c = Utf8Consume(&src);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
			if (c == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
				y += mt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
				if (--num < 0) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   489
					_cur_fontsize = FS_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
					return;
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
				break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   493
			} else if (c == SCC_SETX) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
				src++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   495
			} else if (c == SCC_SETXY) {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   496
				src += 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   502
6703
9ddfcb1849e4 (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6683
diff changeset
   503
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   504
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   505
	char buffer[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
	uint32 tmp;
2753
15012faaa68a (svn r3298) Remove unused and write-only variables
tron
parents: 2658
diff changeset
   507
	int num, mt;
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   508
	uint total_height;
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   509
	const char *src;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   510
	WChar c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4819
diff changeset
   512
	GetString(buffer, str, lastof(buffer));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   514
	tmp = FormatStringLinebreaks(buffer, maxw);
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2634
diff changeset
   515
	num = GB(tmp, 0, 16);
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2548
diff changeset
   516
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   517
	mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   518
	total_height = (num + 1) * mt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
6708
77b9506be3c3 (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: 6703
diff changeset
   520
	if (maxh != -1 && (int)total_height > maxh) {
77b9506be3c3 (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: 6703
diff changeset
   521
		/* Check there's room enough for at least one line. */
77b9506be3c3 (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: 6703
diff changeset
   522
		if (maxh < mt) return 0;
77b9506be3c3 (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: 6703
diff changeset
   523
6703
9ddfcb1849e4 (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6683
diff changeset
   524
		num = maxh / mt - 1;
9ddfcb1849e4 (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6683
diff changeset
   525
		total_height = (num + 1) * mt;
9ddfcb1849e4 (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6683
diff changeset
   526
	}
9ddfcb1849e4 (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6683
diff changeset
   527
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1323
diff changeset
   528
	src = buffer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   530
	for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
		DoDrawString(src, x, y, 0xFE);
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   532
		_cur_fontsize = _last_fontsize;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   534
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   535
			c = Utf8Consume(&src);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
			if (c == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
				y += mt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
				if (--num < 0) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   539
					_cur_fontsize = FS_NORMAL;
4928
4cdb51b5db7b (svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents: 4912
diff changeset
   540
					return total_height;
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
				break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   543
			} else if (c == SCC_SETX) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
				src++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   545
			} else if (c == SCC_SETXY) {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   546
				src += 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   552
/** Return the string dimension in pixels. The height and width are returned
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8610
diff changeset
   553
 * in a single Dimension value. TINYFONT, BIGFONT modifiers are only
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   554
 * supported as the first character of the string. The returned dimensions
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   555
 * are therefore a rough estimation correct for all the current strings
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   556
 * but not every possible combination
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   557
 * @param str string to calculate pixel-width
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   558
 * @return string width and height in pixels */
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8610
diff changeset
   559
Dimension GetStringBoundingBox(const char *str)
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   560
{
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   561
	FontSize size = _cur_fontsize;
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8610
diff changeset
   562
	Dimension br;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   563
	int max_width;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   564
	WChar c;
4557
112872feb6fd (svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents: 4525
diff changeset
   565
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   566
	br.width = br.height = max_width = 0;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   567
	for (;;) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   568
		c = Utf8Consume(&str);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   569
		if (c == 0) break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   570
		if (IsPrintable(c)) {
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   571
			br.width += GetCharacterWidth(size, c);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
		} else {
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   573
			switch (c) {
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   574
				case SCC_SETX: br.width += (byte)*str++; break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   575
				case SCC_SETXY:
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   576
					br.width += (byte)*str++;
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   577
					br.height += (byte)*str++;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   578
					break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   579
				case SCC_TINYFONT: size = FS_SMALL; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   580
				case SCC_BIGFONT:  size = FS_LARGE; break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   581
				case '\n':
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   582
					br.height += GetCharacterHeight(size);
4610
45ac1d25fd62 (svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents: 4609
diff changeset
   583
					if (br.width > max_width) max_width = br.width;
45ac1d25fd62 (svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents: 4609
diff changeset
   584
					br.width = 0;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   585
					break;
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   586
			}
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
	}
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   589
	br.height += GetCharacterHeight(size);
4557
112872feb6fd (svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents: 4525
diff changeset
   590
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   591
	br.width  = max(br.width, max_width);
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4557
diff changeset
   592
	return br;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
9233
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   595
void DrawCharCentered(WChar c, int x, int y, uint16 real_color)
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   596
{
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   597
	FontSize size = FS_NORMAL;
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   598
	byte color = real_color & 0xFF;
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   599
	uint palette = _use_dos_palette ? 1 : 0;
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   600
	int w = GetCharacterWidth(size, c);
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   601
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   602
	_string_colorremap[1] = _string_colormap[palette][color].text;
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   603
	_string_colorremap[2] = _string_colormap[palette][color].shadow;
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   604
	_color_remap_ptr = _string_colorremap;
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   605
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   606
	GfxMainBlitter(GetGlyph(size, c), x - w / 2, y, BM_COLOUR_REMAP);
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   607
}
4daa9bb8dbf7 (svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents: 9166
diff changeset
   608
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   609
/** Draw a string at the given coordinates with the given colour
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   610
 * @param string the string to draw
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   611
 * @param x offset from left side of the screen, if negative offset from the right side
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6974
diff changeset
   612
 * @param y offset from top side of the screen, if negative offset from the bottom
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   613
 * @param real_color colour of the string, see _string_colormap in
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
   614
 * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
4949
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   615
 * @return the x-coordinates where the drawing has finished. If nothing is drawn
fa564e9c2aea (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents: 4928
diff changeset
   616
 * the originally passed x-coordinate is returned */
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   617
int DoDrawString(const char *string, int x, int y, uint16 real_color)
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   618
{
4522
3f90e8cf2435 (svn r6347) Undo
tron
parents: 4521
diff changeset
   619
	DrawPixelInfo *dpi = _cur_dpi;
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   620
	FontSize size = _cur_fontsize;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   621
	WChar c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	int xo = x, yo = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
7918
3b2e2a49a093 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7904
diff changeset
   624
	byte color = real_color & 0xFF;
3b2e2a49a093 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7904
diff changeset
   625
	byte previous_color = color;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   626
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	if (color != 0xFE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
		if (x >= dpi->left + dpi->width ||
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   629
				x + _screen.width * 2 <= dpi->left ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
				y >= dpi->top + dpi->height ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
				y + _screen.height <= dpi->top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
					return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
		if (color != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
switch_color:;
657
40a9032b454b (svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents: 619
diff changeset
   636
			if (real_color & IS_PALETTE_COLOR) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   637
				_string_colorremap[1] = color;
6974
24490c839582 (svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents: 6708
diff changeset
   638
				_string_colorremap[2] = _use_dos_palette ? 1 : 215;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   639
			} else {
6974
24490c839582 (svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents: 6708
diff changeset
   640
				uint palette = _use_dos_palette ? 1 : 0;
24490c839582 (svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents: 6708
diff changeset
   641
				_string_colorremap[1] = _string_colormap[palette][color].text;
24490c839582 (svn r9654) -Fix: Add string colours for the DOS palette and use them when playing with the DOS data files.
maedhros
parents: 6708
diff changeset
   642
				_string_colorremap[2] = _string_colormap[palette][color].shadow;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 510
diff changeset
   643
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
			_color_remap_ptr = _string_colorremap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
check_bounds:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	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
   650
skip_char:;
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   651
		for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   652
			c = Utf8Consume(&string);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   653
			if (!IsPrintable(c)) goto skip_cont;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2753
diff changeset
   657
	for (;;) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   658
		c = Utf8Consume(&string);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
skip_cont:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		if (c == 0) {
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   661
			_last_fontsize = size;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
			return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
		}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   664
		if (IsPrintable(c)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
			if (x >= dpi->left + dpi->width) goto skip_char;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
			if (x + 26 >= dpi->left) {
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   667
				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
   668
			}
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   669
			x += GetCharacterWidth(size, c);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   670
		} else if (c == '\n') { // newline = {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
			x = xo;
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   672
			y += GetCharacterHeight(size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
			goto check_bounds;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   674
		} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change color?
7918
3b2e2a49a093 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7904
diff changeset
   675
			previous_color = color;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   676
			color = (byte)(c - SCC_BLUE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
			goto switch_color;
7918
3b2e2a49a093 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7904
diff changeset
   678
		} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous color
3b2e2a49a093 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7904
diff changeset
   679
			Swap(color, previous_color);
3b2e2a49a093 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7904
diff changeset
   680
			goto switch_color;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   681
		} else if (c == SCC_SETX) { // {SETX}
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   682
			x = xo + (byte)*string++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   683
		} else if (c == SCC_SETXY) {// {SETXY}
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   684
			x = xo + (byte)*string++;
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1309
diff changeset
   685
			y = yo + (byte)*string++;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   686
		} else if (c == SCC_TINYFONT) { // {TINYFONT}
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   687
			size = FS_SMALL;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   688
		} else if (c == SCC_BIGFONT) { // {BIGFONT}
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   689
			size = FS_LARGE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		} else {
5579
be371346efae (svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents: 5568
diff changeset
   691
			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
   692
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
2097
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   696
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw)
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   697
{
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   698
	char buffer[512];
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   699
	ttd_strlcpy(buffer, str, sizeof(buffer));
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   700
	TruncateString(buffer, maxw);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   701
	return DoDrawString(buffer, x, y, color);
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   702
}
82b1e11883fd (svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents: 2062
diff changeset
   703
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   704
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub)
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   705
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8423
diff changeset
   706
	if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   707
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   708
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT, sub);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   709
	} else if (pal != PAL_NONE) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
   710
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   711
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP, sub);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
	} else {
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   713
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL, sub);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
10948
66145f71ebb9 (svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents: 10775
diff changeset
   717
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   719
	const DrawPixelInfo *dpi = _cur_dpi;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   720
	Blitter::BlitterParams bp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   722
	/* Amount of pixels to clip from the source sprite */
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   723
	int clip_left   = (sub != NULL ? max(0,                   -sprite->x_offs + sub->left       ) : 0);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   724
	int clip_top    = (sub != NULL ? max(0,                   -sprite->y_offs + sub->top        ) : 0);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   725
	int clip_right  = (sub != NULL ? max(0, sprite->width  - (-sprite->x_offs + sub->right  + 1)) : 0);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   726
	int clip_bottom = (sub != NULL ? max(0, sprite->height - (-sprite->y_offs + sub->bottom + 1)) : 0);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   727
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   728
	if (clip_left + clip_right >= sprite->width) return;
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   729
	if (clip_top + clip_bottom >= sprite->height) return;
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   730
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   731
	/* Move to the correct offset */
1351
3e7aa0d35f8f (svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents: 1350
diff changeset
   732
	x += sprite->x_offs;
3e7aa0d35f8f (svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents: 1350
diff changeset
   733
	y += sprite->y_offs;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   734
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   735
	/* Copy the main data directly from the sprite */
4518
8c3411b8d4c0 (svn r6303) -Codechange: Remove dead code
tron
parents: 4517
diff changeset
   736
	bp.sprite = sprite->data;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   737
	bp.sprite_width = sprite->width;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   738
	bp.sprite_height = sprite->height;
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   739
	bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, dpi->zoom);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   740
	bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, dpi->zoom);
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   741
	bp.top = 0;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   742
	bp.left = 0;
10948
66145f71ebb9 (svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents: 10775
diff changeset
   743
	bp.skip_left = UnScaleByZoomLower(clip_left, dpi->zoom);
66145f71ebb9 (svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents: 10775
diff changeset
   744
	bp.skip_top = UnScaleByZoomLower(clip_top, dpi->zoom);
8177
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   745
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   746
	x += ScaleByZoom(bp.skip_left, dpi->zoom);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   747
	y += ScaleByZoom(bp.skip_top, dpi->zoom);
f0bcc8e149f3 (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents: 8147
diff changeset
   748
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	bp.dst = dpi->dst_ptr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	bp.pitch = dpi->pitch;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   751
	bp.remap = _color_remap_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   753
	assert(sprite->width > 0);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   754
	assert(sprite->height > 0);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   755
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   756
	if (bp.width <= 0) return;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   757
	if (bp.height <= 0) return;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   758
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   759
	y -= dpi->top;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   760
	/* Check for top overflow */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   761
	if (y < 0) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   762
		bp.height -= -UnScaleByZoom(y, dpi->zoom);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   763
		if (bp.height <= 0) return;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   764
		bp.skip_top += -UnScaleByZoom(y, dpi->zoom);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   765
		y = 0;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   766
	} else {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   767
		bp.top = UnScaleByZoom(y, dpi->zoom);
7300
6c3d987e8e6d (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: 7149
diff changeset
   768
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   770
	/* Check for bottom overflow */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   771
	y += ScaleByZoom(bp.height, dpi->zoom) - dpi->height;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   772
	if (y > 0) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   773
		bp.height -= UnScaleByZoom(y, dpi->zoom);
7300
6c3d987e8e6d (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: 7149
diff changeset
   774
		if (bp.height <= 0) return;
6c3d987e8e6d (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: 7149
diff changeset
   775
	}
6c3d987e8e6d (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: 7149
diff changeset
   776
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   777
	x -= dpi->left;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   778
	/* Check for left overflow */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   779
	if (x < 0) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   780
		bp.width -= -UnScaleByZoom(x, dpi->zoom);
7300
6c3d987e8e6d (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: 7149
diff changeset
   781
		if (bp.width <= 0) return;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   782
		bp.skip_left += -UnScaleByZoom(x, dpi->zoom);
7300
6c3d987e8e6d (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: 7149
diff changeset
   783
		x = 0;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   784
	} else {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   785
		bp.left = UnScaleByZoom(x, dpi->zoom);
7300
6c3d987e8e6d (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: 7149
diff changeset
   786
	}
6c3d987e8e6d (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: 7149
diff changeset
   787
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   788
	/* Check for right overflow */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   789
	x += ScaleByZoom(bp.width, dpi->zoom) - dpi->width;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   790
	if (x > 0) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   791
		bp.width -= UnScaleByZoom(x, dpi->zoom);
7300
6c3d987e8e6d (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: 7149
diff changeset
   792
		if (bp.width <= 0) return;
6c3d987e8e6d (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: 7149
diff changeset
   793
	}
6c3d987e8e6d (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: 7149
diff changeset
   794
10948
66145f71ebb9 (svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents: 10775
diff changeset
   795
	assert(bp.skip_left + bp.width <= UnScaleByZoom(sprite->width, dpi->zoom));
66145f71ebb9 (svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents: 10775
diff changeset
   796
	assert(bp.skip_top + bp.height <= UnScaleByZoom(sprite->height, dpi->zoom));
66145f71ebb9 (svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents: 10775
diff changeset
   797
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 7327
diff changeset
   798
	BlitterFactoryBase::GetCurrentBlitter()->Draw(&bp, mode, dpi->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   801
void DoPaletteAnimations();
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   802
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   803
void GfxInitPalettes()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
{
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   805
	memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette));
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   806
7460
46c24d1287cf (svn r10220) -Fix r10216: even more fuck-ups for non-SDL video backends
truelight
parents: 7456
diff changeset
   807
	DoPaletteAnimations();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	_pal_first_dirty = 0;
7888
d26883560502 (svn r10761) -Fix (FS#1101, r10216): _pal_last_dirty changed to _pal_count_dirty without updating, so it was of by one
glx
parents: 7858
diff changeset
   809
	_pal_count_dirty = 256;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7495
diff changeset
   812
#define EXTR(p, q) (((uint16)(_palette_animation_counter * (p)) * (q)) >> 16)
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7495
diff changeset
   813
#define EXTR2(p, q) (((uint16)(~_palette_animation_counter * (p)) * (q)) >> 16)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   815
void DoPaletteAnimations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
{
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   817
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   818
	const Colour *s;
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3798
diff changeset
   819
	Colour *d;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   820
	/* Amount of colors to be rotated.
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   821
	 * A few more for the DOS palette, because the water colors are
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   822
	 * 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
   823
	const ExtraPaletteValues *ev = &_extra_palette_values;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   824
	int c = _use_dos_palette ? 38 : 28;
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   825
	Colour old_val[38];
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   826
	uint i;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   827
	uint j;
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7495
diff changeset
   828
	uint old_tc = _palette_animation_counter;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7348
diff changeset
   829
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   830
	if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7495
diff changeset
   831
		_palette_animation_counter = 0;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7348
diff changeset
   832
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   834
	d = &_cur_palette[217];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   835
	memcpy(old_val, d, c * sizeof(*old_val));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   837
	/* Dark blue water */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   838
	s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->ac : ev->a;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   839
	j = EXTR(320, 5);
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   840
	for (i = 0; i != 5; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   841
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   842
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   843
		if (j == 5) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   846
	/* Glittery water */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   847
	s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->bc : ev->b;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   848
	j = EXTR(128, 15);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   849
	for (i = 0; i != 5; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   850
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   851
		j += 3;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   852
		if (j >= 15) j -= 15;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
	s = ev->e;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   856
	j = EXTR2(512, 5);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   857
	for (i = 0; i != 5; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   858
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   859
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   860
		if (j == 5) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   863
	/* Oil refinery fire animation */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	s = ev->oil_ref;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   865
	j = EXTR2(512, 7);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   866
	for (i = 0; i != 7; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   867
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   868
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   869
		if (j == 7) j = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   872
	/* Radio tower blinking */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	{
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7495
diff changeset
   874
		byte i = (_palette_animation_counter >> 1) & 0x7F;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   875
		byte v;
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   876
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
		(v = 255, i < 0x3f) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
		(v = 128, i < 0x4A || i >= 0x75) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
		(v = 20);
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   880
		d->r = v;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   881
		d->g = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   882
		d->b = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   883
		d++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
		i ^= 0x40;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
		(v = 255, i < 0x3f) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
		(v = 128, i < 0x4A || i >= 0x75) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
		(v = 20);
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   889
		d->r = v;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   890
		d->g = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   891
		d->b = 0;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   892
		d++;
0
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
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   895
	/* Handle lighthouse and stadium animation */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	s = ev->lighthouse;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   897
	j = EXTR(256, 4);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   898
	for (i = 0; i != 4; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   899
		*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   900
		j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   901
		if (j == 4) j = 0;
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
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   904
	/* Animate water for old DOS graphics */
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   905
	if (_use_dos_palette) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   906
		/* Dark blue water DOS */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   907
		s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->ac : ev->a;
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   908
		j = EXTR(320, 5);
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   909
		for (i = 0; i != 5; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   910
			*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   911
			j++;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   912
			if (j == 5) j = 0;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   913
		}
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 798
diff changeset
   914
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   915
		/* Glittery water DOS */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   916
		s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->bc : ev->b;
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   917
		j = EXTR(128, 15);
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   918
		for (i = 0; i != 5; i++) {
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   919
			*d++ = s[j];
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   920
			j += 3;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1914
diff changeset
   921
			if (j >= 15) j -= 15;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   922
		}
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   923
	}
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 543
diff changeset
   924
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   925
	if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7495
diff changeset
   926
		_palette_animation_counter = old_tc;
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   927
	} else {
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   928
		if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) {
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   929
			_pal_first_dirty = 217;
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   930
			_pal_count_dirty = c;
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7447
diff changeset
   931
		}
0
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   936
void LoadStringWidthTable()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
{
2005
8331cf472aea (svn r2513) Small cleanup
tron
parents: 2004
diff changeset
   938
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
3797
86749951a1bf (svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents: 3312
diff changeset
   940
	/* Normal font */
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   941
	for (i = 0; i != 224; i++) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   942
		_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
   943
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
3797
86749951a1bf (svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents: 3312
diff changeset
   945
	/* Small font */
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   946
	for (i = 0; i != 224; i++) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   947
		_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
   948
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
3797
86749951a1bf (svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents: 3312
diff changeset
   950
	/* Large font */
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3797
diff changeset
   951
	for (i = 0; i != 224; i++) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   952
		_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
   953
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   956
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   957
byte GetCharacterWidth(FontSize size, WChar key)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   958
{
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   959
	if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32];
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   960
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   961
	return GetGlyphWidth(size, key);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   962
}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   963
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4958
diff changeset
   964
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   965
void ScreenSizeChanged()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
{
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
   967
	_dirty_bytes_per_line = (_screen.width + DIRTY_BLOCK_WIDTH - 1) / DIRTY_BLOCK_WIDTH;
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
   968
	_dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * ((_screen.height + DIRTY_BLOCK_HEIGHT - 1) / DIRTY_BLOCK_HEIGHT));
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
   969
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   970
	/* check the dirty rect */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	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
   972
	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
   973
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
   974
	/* 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
   975
	_cursor.visible = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   978
void UndrawMouseCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	if (_cursor.visible) {
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
   981
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
		_cursor.visible = false;
7481
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7460
diff changeset
   983
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7514
diff changeset
   984
		_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   988
void DrawMouseCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
{
7904
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7888
diff changeset
   990
#if defined(WINCE)
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7888
diff changeset
   991
	/* Don't ever draw the mouse for WinCE, as we work with a stylus */
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7888
diff changeset
   992
	return;
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7888
diff changeset
   993
#endif
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7888
diff changeset
   994
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
   995
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   996
	int x;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   997
	int y;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   998
	int w;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
   999
	int h;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
3312
593789444b01 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3252
diff changeset
  1001
	/* Redraw mouse cursor but only when it's inside the window */
593789444b01 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3252
diff changeset
  1002
	if (!_cursor.in_window) return;
593789444b01 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3252
diff changeset
  1003
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1004
	/* 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
  1005
	if (_cursor.visible) {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1006
		if (!_cursor.dirty) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
		UndrawMouseCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	}
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
	w = _cursor.size.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	x = _cursor.pos.x + _cursor.offs.x;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1012
	if (x < 0) {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1013
		w += x;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1014
		x = 0;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1015
	}
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1016
	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
  1017
	if (w <= 0) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	_cursor.draw_pos.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	_cursor.draw_size.x = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
	h = _cursor.size.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
	y = _cursor.pos.y + _cursor.offs.y;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1023
	if (y < 0) {
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1024
		h += y;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1025
		y = 0;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1026
	}
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1027
	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
  1028
	if (h <= 0) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	_cursor.draw_pos.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
	_cursor.draw_size.y = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
  1032
	assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1034
	/* Make backup of stuff below cursor */
7481
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7460
diff changeset
  1035
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1037
	/* Draw cursor on screen */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	_cur_dpi = &_screen;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1039
	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
  1040
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7514
diff changeset
  1041
	_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
	_cursor.visible = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
	_cursor.dirty = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
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
  1048
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
	assert(right <= _screen.width && bottom <= _screen.height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
	if (_cursor.visible) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
		if (right > _cursor.draw_pos.x &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
				left < _cursor.draw_pos.x + _cursor.draw_size.x &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
				bottom > _cursor.draw_pos.y &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
				top < _cursor.draw_pos.y + _cursor.draw_size.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
			UndrawMouseCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	}
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7918
diff changeset
  1058
	UndrawChatMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
7495
3bed6c98b8f3 (svn r10255) -Codechange: remove some old debug code nobody was using anymore
truelight
parents: 7494
diff changeset
  1060
	DrawOverlappedWindowForAll(left, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7514
diff changeset
  1062
	_video_driver->MakeDirty(left, top, right - left, bottom - top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1065
/*!
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1066
 * Repaints the rectangle blocks which are marked as 'dirty'.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1067
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1068
 * @see SetDirtyBlocks
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1069
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1070
void DrawDirtyBlocks()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
	byte *b = _dirty_blocks;
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1073
	const int w = Align(_screen.width,  DIRTY_BLOCK_WIDTH);
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1074
	const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT);
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1075
	int x;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1076
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1078
	if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1079
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1080
	y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
	do {
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1082
		x = 0;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1083
		do {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1084
			if (*b != 0) {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1085
				int left;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1086
				int top;
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1087
				int right = x + DIRTY_BLOCK_WIDTH;
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1088
				int bottom = y;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1089
				byte *p = b;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1090
				int h2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1092
				/* First try coalescing downwards */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
				do {
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1094
					*p = 0;
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
  1095
					p += _dirty_bytes_per_line;
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1096
					bottom += DIRTY_BLOCK_HEIGHT;
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1097
				} while (bottom != h && *p != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1099
				/* Try coalescing to the right too. */
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1100
				h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1101
				assert(h2 > 0);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1102
				p = b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1104
				while (right != w) {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1105
					byte *p2 = ++p;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1106
					int h = h2;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1107
					/* Check if a full line of dirty flags is set. */
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1108
					do {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1109
						if (!*p2) goto no_more_coalesc;
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
  1110
						p2 += _dirty_bytes_per_line;
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1111
					} while (--h != 0);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1112
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1113
					/* Wohoo, can combine it one step to the right!
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1114
					 * Do that, and clear the bits. */
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1115
					right += DIRTY_BLOCK_WIDTH;
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1116
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1117
					h = h2;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1118
					p2 = p;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1119
					do {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1120
						*p2 = 0;
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
  1121
						p2 += _dirty_bytes_per_line;
2025
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1122
					} while (--h != 0);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1123
				}
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1124
				no_more_coalesc:
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1125
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1126
				left = x;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1127
				top = y;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1128
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1129
				if (left   < _invalid_rect.left  ) left   = _invalid_rect.left;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1130
				if (top    < _invalid_rect.top   ) top    = _invalid_rect.top;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1131
				if (right  > _invalid_rect.right ) right  = _invalid_rect.right;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1132
				if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1133
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1134
				if (left < right && top < bottom) {
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1135
					RedrawScreenRect(left, top, right, bottom);
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1136
				}
b0b897359fdf (svn r2534) Small cleanup
tron
parents: 2014
diff changeset
  1137
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
			}
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1139
		} while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
  1140
	} while (b += -(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	_invalid_rect.left = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
	_invalid_rect.top = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	_invalid_rect.right = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	_invalid_rect.bottom = 0;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1146
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1147
	/* If we are generating a world, and waiting for a paint run, mark it here
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1148
	 *  as done painting, so we can continue generating. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1149
	if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1150
		SetGeneratingWorldPaintStatus(false);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1151
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1154
/*!
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1155
 * This function extends the internal _invalid_rect rectangle as it
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1156
 * now contains the rectangle defined by the given parameters. Note
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1157
 * the point (0,0) is top left.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1158
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1159
 * @param left The left edge of the rectangle
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1160
 * @param top The top edge of the rectangle
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1161
 * @param right The right edge of the rectangle
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1162
 * @param bottom The bottm edge of the rectangle
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1163
 * @see DrawDirtyBlocks
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1164
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1165
 * @todo The name of the function should be called like @c AddDirtyBlock as
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1166
 *       it neither set a dirty rect nor add several dirty rects although
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1167
 *       the function name is in plural. (Progman)
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1168
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
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
  1170
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	byte *b;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1172
	int width;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1173
	int height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	if (left < 0) left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	if (top < 0) top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	if (right > _screen.width) right = _screen.width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
	if (bottom > _screen.height) bottom = _screen.height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1180
	if (left >= right || top >= bottom) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1182
	if (left   < _invalid_rect.left  ) _invalid_rect.left   = left;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1183
	if (top    < _invalid_rect.top   ) _invalid_rect.top    = top;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1184
	if (right  > _invalid_rect.right ) _invalid_rect.right  = right;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1185
	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
  1186
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1187
	left /= DIRTY_BLOCK_WIDTH;
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1188
	top  /= DIRTY_BLOCK_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
  1190
	b = _dirty_blocks + top * _dirty_bytes_per_line + left;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
10241
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1192
	width  = ((right  - 1) / DIRTY_BLOCK_WIDTH)  - left + 1;
4c95503096ac (svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents: 10083
diff changeset
  1193
	height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top  + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	assert(width > 0 && height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
	do {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1198
		int i = width;
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1199
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
		do b[--i] = 0xFF; while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
10247
145d0458b685 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 10241
diff changeset
  1202
		b += _dirty_bytes_per_line;
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1203
	} while (--height != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1206
/*!
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1207
 * This function mark the whole screen as dirty. This results in repainting
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1208
 * the whole screen. Use this with care as this function will break the
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1209
 * idea about marking only parts of the screen as 'dirty'.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7950
diff changeset
  1210
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1211
void MarkWholeScreenDirty()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	SetDirtyBlocks(0, 0, _screen.width, _screen.height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
4958
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1216
/** Set up a clipping area for only drawing into a certain area. To do this,
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1217
 * Fill a DrawPixelInfo object with the supplied relative rectangle, backup
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1218
 * the original (calling) _cur_dpi and assign the just returned DrawPixelInfo
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1219
 * _cur_dpi. When you are done, give restore _cur_dpi's original value
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1220
 * @param *n the DrawPixelInfo that will be the clipping rectangle box allowed
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1221
 * for drawing
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1222
 * @param left,top,width,height the relative coordinates of the clipping
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1223
 * rectangle relative to the current _cur_dpi. This will most likely be the
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1224
 * offset from the calling window coordinates
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1225
 * @return return false if the requested rectangle is not possible with the
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1226
 * current dpi pointer. Only continue of the return value is true, or you'll
aaa8a92059bf (svn r6957) -Cleanup: comments, coding style
Darkvater
parents: 4954
diff changeset
  1227
 * get some nasty results */
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1228
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
  1229
{
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
  1230
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1231
	const DrawPixelInfo *o = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 7111
diff changeset
  1233
	n->zoom = ZOOM_LVL_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	assert(height > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	if ((left -= o->left) < 0) {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1239
		width += left;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1240
		if (width <= 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
		n->left = -left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
		left = 0;
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1243
	} else {
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1244
		n->left = 0;
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
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1247
	if (width > o->width - left) {
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1248
		width = o->width - left;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1249
		if (width <= 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	n->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
	if ((top -= o->top) < 0) {
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1254
		height += top;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1255
		if (height <= 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		n->top = -top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
		top = 0;
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1258
	} else {
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1259
		n->top = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7385
diff changeset
  1262
	n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7348
diff changeset
  1263
	n->pitch = o->pitch;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
4429
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1265
	if (height > o->height - top) {
1bb01569940c (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4428
diff changeset
  1266
		height = o->height - top;
4525
fa3aabcd12bc (svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents: 4522
diff changeset
  1267
		if (height <= 0) return false;
0
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
	n->height = height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1274
static void SetCursorSprite(SpriteID cursor, SpriteID pal)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	CursorVars *cv = &_cursor;
1348
1d123409026e (svn r1852) Start cleaning up sprite handling:
tron
parents: 1336
diff changeset
  1277
	const Sprite *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1279
	if (cv->sprite == cursor) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1281
	p = GetSprite(GB(cursor, 0, SPRITE_WIDTH));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	cv->sprite = cursor;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1283
	cv->pal    = pal;
1348
1d123409026e (svn r1852) Start cleaning up sprite handling:
tron
parents: 1336
diff changeset
  1284
	cv->size.y = p->height;
1351
3e7aa0d35f8f (svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents: 1350
diff changeset
  1285
	cv->size.x = p->width;
3e7aa0d35f8f (svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents: 1350
diff changeset
  1286
	cv->offs.x = p->x_offs;
3e7aa0d35f8f (svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents: 1350
diff changeset
  1287
	cv->offs.y = p->y_offs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
	cv->dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1292
static void SwitchAnimatedCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
{
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1294
	const AnimCursor *cur = _cursor.animate_cur;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1296
	if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list;
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  1297
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1298
	SetCursorSprite(cur->sprite, _cursor.pal);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1300
	_cursor.animate_timeout = cur->display_time;
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1301
	_cursor.animate_cur     = cur + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1304
void CursorTick()
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1056
diff changeset
  1305
{
2010
fc4e04467881 (svn r2518) Small cleanup
tron
parents: 2005
diff changeset
  1306
	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
  1307
		SwitchAnimatedCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1310
void SetMouseCursor(SpriteID sprite, SpriteID pal)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
{
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1312
	/* Turn off animation */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
	_cursor.animate_timeout = 0;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6464
diff changeset
  1314
	/* Set cursor */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1315
	SetCursorSprite(sprite, pal);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
6464
1c3515433409 (svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents: 5919
diff changeset
  1318
void SetAnimatedMouseCursor(const AnimCursor *table)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
	_cursor.animate_list = table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
	_cursor.animate_cur = NULL;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5887
diff changeset
  1322
	_cursor.pal = PAL_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	SwitchAnimatedCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
7856
121ae75a45a0 (svn r10723) -Codechange: dynamically sized (width) main toolbars and status bar for when the window becomes less than 640 pixels in width.
rubidium
parents: 7666
diff changeset
  1326
bool ChangeResInGame(int width, int height)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 126
diff changeset
  1327
{
7858
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7857
diff changeset
  1328
	return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
}
298
b3e83b94be19 (svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents: 193
diff changeset
  1330
8667
c916a5375166 (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8627
diff changeset
  1331
bool ToggleFullScreen(bool fs)
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1332
{
8667
c916a5375166 (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8627
diff changeset
  1333
	bool result = _video_driver->ToggleFullscreen(fs);
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1334
	if (_fullscreen != fs && _num_resolutions == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5217
diff changeset
  1335
		DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1336
	}
8667
c916a5375166 (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8627
diff changeset
  1337
	return result;
5217
21c23507c002 (svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents: 5156
diff changeset
  1338
}
1829
0b6de3b4458a (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1806
diff changeset
  1339
10983
e734f891d1f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 10969
diff changeset
  1340
static int CDECL compare_res(const Dimension *pa, const Dimension *pb)
298
b3e83b94be19 (svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents: 193
diff changeset
  1341
{
10983
e734f891d1f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 10969
diff changeset
  1342
	int x = pa->width - pb->width;
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1390
diff changeset
  1343
	if (x != 0) return x;
10983
e734f891d1f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 10969
diff changeset
  1344
	return pa->height - pb->height;
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1390
diff changeset
  1345
}
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1390
diff changeset
  1346
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1390
diff changeset
  1347
void SortResolutions(int count)
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1390
diff changeset
  1348
{
10983
e734f891d1f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 10969
diff changeset
  1349
	QSortT(_resolutions, count, &compare_res);
298
b3e83b94be19 (svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents: 193
diff changeset
  1350
}