src/viewport.cpp
author celestar
Mon, 15 Jan 2007 20:14:06 +0000
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
child 5852 cb3f71b16e1a
permissions -rw-r--r--
(svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1864
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1172
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
     7
#include "gui.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: 1309
diff changeset
     8
#include "spritecache.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1299
diff changeset
     9
#include "strings.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1349
diff changeset
    10
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 500
diff changeset
    11
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 657
diff changeset
    12
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "town.h"
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
    19
#include "signs.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
    20
#include "waypoint.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2125
diff changeset
    21
#include "variables.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2662
diff changeset
    22
#include "train.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
    24
#define VIEWPORT_DRAW_MEM (65536 * 2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
    26
/* viewport.c */
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
    27
// XXX - maximum viewports is maximum windows - 2 (main toolbar + status bar)
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
    28
static ViewPort _viewports[25 - 2];
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
    29
static uint32 _active_viewports;    ///< bitmasked variable where each bit signifies if a viewport is in use or not
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
    30
assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8);
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
    31
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
static bool _added_tile_sprite;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
static bool _offset_ground_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    35
/* The in-game coordiante system looks like this *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    36
 *                                               *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    37
 *                    ^ Z                        *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    38
 *                    |                          *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    39
 *                    |                          *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    40
 *                    |                          *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    41
 *                    |                          *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    42
 *                 /     \                       *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    43
 *              /           \                    *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    44
 *           /                 \                 *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    45
 *        /                       \              *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    46
 *   X <                             > Y         *
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    47
 */
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    48
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
typedef struct StringSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	uint16 string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	uint16 color;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	struct StringSpriteToDraw *next;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    53
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    54
	int32 y;
5026
c8b7148798ac (svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents: 5025
diff changeset
    55
	uint32 params[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	uint16 width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
} StringSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
typedef struct TileSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	struct TileSpriteToDraw *next;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    62
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    63
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
} TileSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
typedef struct ChildScreenSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	uint32 image;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    69
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    70
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	struct ChildScreenSpriteToDraw *next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
} ChildScreenSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
typedef struct ParentSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	uint32 image;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    76
	int32 left;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    77
	int32 top;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    78
	int32 right;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    79
	int32 bottom;
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    80
	int32 xmin;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    81
	int32 ymin;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    82
	int32 xmax;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    83
	int32 ymax;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	ChildScreenSpriteToDraw *child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	byte unk16;
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    86
	byte zmin;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    87
	byte zmax;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
} ParentSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
2109
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    90
// Quick hack to know how much memory to reserve when allocating from the spritelist
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    91
// to prevent a buffer overflow.
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    92
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    93
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
typedef struct ViewportDrawer {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	DrawPixelInfo dpi;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
    96
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    97
	byte *spritelist_mem;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    98
	const byte *eof_spritelist_mem;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
    99
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	StringSpriteToDraw **last_string, *first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	TileSpriteToDraw **last_tile, *first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	ChildScreenSpriteToDraw **last_child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	ParentSpriteToDraw **parent_list;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   106
	ParentSpriteToDraw * const *eof_parent_list;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	byte combine_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	int offs_x, offs_y; // used when drawing ground sprites relative
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
} ViewportDrawer;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
static ViewportDrawer *_cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   115
TileHighlightData _thd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
static TileInfo *_cur_ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
4340
1b2bf292033b (svn r6041) -Fix r6040: forgot to declare a function in viewport.c
truelight
parents: 4339
diff changeset
   118
extern void SmallMapCenterOnCurrentPos(Window *w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   120
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	Point p = RemapCoords(x, y, z);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   123
	p.x -= vp->virtual_width / 2;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   124
	p.y -= vp->virtual_height / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   128
void InitViewports(void) {
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   129
	memset(_viewports, 0, sizeof(_viewports));
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   130
	_active_viewports = 0;
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   131
}
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   132
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   133
void DeleteWindowViewport(Window *w)
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   134
{
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   135
	CLRBIT(_active_viewports, w->viewport - _viewports);
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   136
	w->viewport->width = 0;
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   137
	w->viewport = NULL;
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   138
}
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   139
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   140
void AssignWindowViewport(Window *w, int x, int y,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	int width, int height, uint32 follow_flags, byte zoom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
	uint32 bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   147
	for (vp = _viewports, bit = 0; ; vp++, bit++) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   148
		assert(vp != endof(_viewports));
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   149
		if (vp->width == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	}
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   151
	SETBIT(_active_viewports, bit);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	vp->left = x + w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	vp->top = y + w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	vp->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	vp->height = height;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   157
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	vp->zoom = zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	vp->virtual_width = width << zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	vp->virtual_height = height << zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	if (follow_flags & 0x80000000) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   164
		const Vehicle *veh;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   165
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   166
		WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   167
		veh = GetVehicle(WP(w, vp_d).follow_vehicle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
		pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	} else {
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   170
		uint x = TileX(follow_flags) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   171
		uint y = TileY(follow_flags) * TILE_SIZE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   172
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   173
		WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   174
		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   177
	WP(w, vp_d).scrollpos_x = pt.x;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   178
	WP(w, vp_d).scrollpos_y = pt.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	w->viewport = vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	vp->virtual_left = 0;//pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	vp->virtual_top = 0;//pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
static Point _vp_move_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5124
diff changeset
   186
static void DoSetViewportPosition(Window* const *wz, int left, int top, int width, int height)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   188
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   189
	for (; wz != _last_z_window; wz++) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   190
		const Window *w = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   191
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
		if (left + width > w->left &&
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   193
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
				top + height > w->top &&
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   195
				w->top + w->height > top) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   196
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
			if (left < w->left) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   198
				DoSetViewportPosition(wz, left, top, w->left - left, height);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   199
				DoSetViewportPosition(wz, left + (w->left - left), top, width - (w->left - left), height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
			if (left + width > w->left + w->width) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   204
				DoSetViewportPosition(wz, left, top, (w->left + w->width - left), height);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   205
				DoSetViewportPosition(wz, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
			if (top < w->top) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   210
				DoSetViewportPosition(wz, left, top, width, (w->top - top));
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   211
				DoSetViewportPosition(wz, left, top + (w->top - top), width, height - (w->top - top));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
			if (top + height > w->top + w->height) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   216
				DoSetViewportPosition(wz, left, top, width, (w->top + w->height - top));
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   217
				DoSetViewportPosition(wz, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
		int xo = _vp_move_offs.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		int yo = _vp_move_offs.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
		if (abs(xo) >= width || abs(yo) >= height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
			/* fully_outside */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   231
			RedrawScreenRect(left, top, left + width, top + height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
		GfxScroll(left, top, width, height, xo, yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
		if (xo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
			RedrawScreenRect(left, top, xo + left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
			left += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			width -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		} else if (xo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
			RedrawScreenRect(left+width+xo, top, left+width, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
			width += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		if (yo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
			RedrawScreenRect(left, top, width+left, top + yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
		} else if (yo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
			RedrawScreenRect(left, top + height + yo, width+left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
   254
static void SetViewportPosition(Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
	int old_left = vp->virtual_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	int old_top = vp->virtual_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
	int left, top, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	vp->virtual_left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	vp->virtual_top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	old_left >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	old_top >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	x >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	y >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	old_left -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	old_top -= y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   273
	if (old_top == 0 && old_left == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	_vp_move_offs.x = old_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
	_vp_move_offs.y = old_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	left = vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	top = vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	width = vp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	height = vp->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	if (left < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		width += left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
		left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   288
	i = left + width - _screen.width;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   289
	if (i >= 0) width -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	if (width > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		if (top < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
			height += top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
			top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   296
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   297
		i = top + height - _screen.height;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   298
		if (i >= 0) height -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   300
		if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   305
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	ViewPort *vp = w->viewport;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   308
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	if (vp != NULL &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	    IS_INT_INSIDE(x, vp->left, vp->left + vp->width) &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
			IS_INT_INSIDE(y, vp->top, vp->top + vp->height))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
		return vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   317
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   318
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	int a,b;
5014
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   321
	uint z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
				(uint)(y -= vp->top) >= (uint)vp->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
				Point pt = {-1, -1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
				return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	x = ((x << vp->zoom) + vp->virtual_left) >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
	y = ((y << vp->zoom) + vp->virtual_top) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	a = y-x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	b = y+x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
5014
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   335
	/* we need to move variables in to the valid range, as the
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   336
	 * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   337
	 * when the user tries to zoom out along the sides of the map */
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   338
	a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   339
	b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   340
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   341
	z = GetSlopeZ(a,     b    ) / 2;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   342
	z = GetSlopeZ(a + z, b + z) / 2;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   343
	z = GetSlopeZ(a + z, b + z) / 2;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   344
	z = GetSlopeZ(a + z, b + z) / 2;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   345
	z = GetSlopeZ(a + z, b + z) / 2;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   346
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   347
	pt.x = a + z;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   348
	pt.y = b + z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   353
/* When used for zooming, check area below current coordinates (x,y)
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   354
 * and return the tile of the zoomed out/in position (zoom_x, zoom_y)
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   355
 * when you just want the tile, make x = zoom_x and y = zoom_y */
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   356
static Point GetTileFromScreenXY(int x, int y, int zoom_x, int zoom_y)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   357
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	Point pt;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   361
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   362
	if ( (w = FindWindowFromPt(x, y)) != NULL &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
			 (vp = IsPtInWindowViewport(w, x, y)) != NULL)
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   364
				return TranslateXYToTileCoord(vp, zoom_x, zoom_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	pt.y = pt.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   370
Point GetTileBelowCursor(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
{
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   372
	return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   375
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   376
Point GetTileZoomCenterWindow(bool in, Window * w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	int x, y;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   379
	ViewPort * vp;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   380
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   381
	vp = w->viewport;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   382
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2023
diff changeset
   383
	if (in) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   384
		x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   385
		y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   386
	} else {
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   387
		x = vp->width - (_cursor.pos.x - vp->left);
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   388
		y = vp->height - (_cursor.pos.y - vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	}
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   390
	/* Get the tile below the cursor and center on the zoomed-out center */
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   391
	return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
5045
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   394
/** Update the status of the zoom-buttons according to the zoom-level
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   395
 * of the viewport. This will update their status and invalidate accordingly
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   396
 * @param window pointer to the window that has the zoom buttons
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   397
 * @param vp pointer to the viewport whose zoom-level the buttons represent
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   398
 * @param widget_zoom_in widget index for window with zoom-in button
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   399
 * @param widget_zoom_out widget index for window with zoom-out button */
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   400
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   401
{
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   402
	SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == 0);
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   403
	InvalidateWidget(w, widget_zoom_in);
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   404
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   405
	SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == 2);
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   406
	InvalidateWidget(w, widget_zoom_out);
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   407
}
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   408
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
   409
void DrawGroundSpriteAt(uint32 image, int32 x, int32 y, byte z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	TileSpriteToDraw *ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   413
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   414
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   416
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
   417
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   420
	ts = (TileSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	vd->spritelist_mem += sizeof(TileSpriteToDraw);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   423
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	ts->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	ts->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	ts->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	ts->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	ts->z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	*vd->last_tile = ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   430
	vd->last_tile = &ts->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
void DrawGroundSprite(uint32 image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
	if (_offset_ground_sprites) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
		// offset ground sprite because of foundation?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
		AddChildSpriteScreen(image, _cur_vd->offs_x, _cur_vd->offs_y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	} else {
1083
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   439
		_added_tile_sprite = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		DrawGroundSpriteAt(image, _cur_ti->x, _cur_ti->y, _cur_ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
void OffsetGroundSprite(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	_cur_vd->offs_x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	_cur_vd->offs_y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	_offset_ground_sprites = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
static void AddCombinedSprite(uint32 image, int x, int y, byte z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   454
	const ViewportDrawer *vd = _cur_vd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	Point pt = RemapCoords(x, y, z);
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   456
	const Sprite* spr = GetSprite(image & SPRITE_MASK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   458
	if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   459
			pt.x + spr->x_offs + spr->width <= vd->dpi.left ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   460
			pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   461
			pt.y + spr->y_offs + spr->height <= vd->dpi.top)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   464
	AddChildSpriteScreen(image, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
void AddSortableSpriteToDraw(uint32 image, int x, int y, int w, int h, byte dz, byte z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	ParentSpriteToDraw *ps;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
   472
	const Sprite *spr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   475
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	if (vd->combine_sprites == 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
		AddCombinedSprite(image, x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	vd->last_child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   484
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
   485
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   488
	ps = (ParentSpriteToDraw*)vd->spritelist_mem;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   489
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   490
	if (vd->parent_list >= vd->eof_parent_list) {
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   491
		// This can happen rarely, mostly when you zoom out completely
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   492
		//  and have a lot of stuff that moves (and is added to the
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   493
		//  sort-list, this function). To solve it, increase
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   494
		//  parent_list somewhere below to a higher number.
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   495
		// This can not really hurt you, it just gives some black
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   496
		//  spots on the screen ;)
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
   497
		DEBUG(sprite, 0, "Out of sprite memory (parent_list)");
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   498
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   499
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   500
4189
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   501
	pt = RemapCoords(x, y, z);
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   502
	spr = GetSprite(image & SPRITE_MASK);
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   503
	if ((ps->left   = (pt.x += spr->x_offs)) >= vd->dpi.left + vd->dpi.width ||
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   504
			(ps->right  = (pt.x +  spr->width )) <= vd->dpi.left ||
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   505
			(ps->top    = (pt.y += spr->y_offs)) >= vd->dpi.top + vd->dpi.height ||
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   506
			(ps->bottom = (pt.y +  spr->height)) <= vd->dpi.top) {
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   507
		return;
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   508
	}
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   509
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   510
	vd->spritelist_mem += sizeof(ParentSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	ps->image = image;
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   513
	ps->xmin = x;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   514
	ps->xmax = x + w - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   516
	ps->ymin = y;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   517
	ps->ymax = y + h - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   519
	ps->zmin = z;
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   520
	ps->zmax = z + dz - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	ps->unk16 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	ps->child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
	vd->last_child = &ps->child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	*vd->parent_list++ = ps;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   528
	if (vd->combine_sprites == 1) vd->combine_sprites = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   531
void StartSpriteCombine(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	_cur_vd->combine_sprites = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   536
void EndSpriteCombine(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
	_cur_vd->combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
void AddChildSpriteScreen(uint32 image, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	ChildScreenSpriteToDraw *cs;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   545
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   546
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   548
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
   549
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   552
	cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   554
	if (vd->last_child == NULL) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   555
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   556
	vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	*vd->last_child = cs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	vd->last_child = &cs->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	cs->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
	cs->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
	cs->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
	cs->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
/* Returns a StringSpriteToDraw */
5026
c8b7148798ac (svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents: 5025
diff changeset
   568
void *AddStringToDraw(int x, int y, StringID string, uint32 params_1, uint32 params_2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	StringSpriteToDraw *ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   573
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
   574
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   577
	ss = (StringSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
	vd->spritelist_mem += sizeof(StringSpriteToDraw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	ss->string = string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
	ss->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	ss->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	ss->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	ss->params[0] = params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	ss->params[1] = params_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
	ss->width = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	*vd->last_string = ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
	vd->last_string = &ss->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	return ss;
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
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3809
diff changeset
   595
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
static void DrawSelectionSprite(uint32 image, const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   598
	if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground
1083
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   599
		DrawGroundSpriteAt(image, ti->x, ti->y, ti->z + 7);
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   600
	} else { // draw on top of foundation
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   601
		AddSortableSpriteToDraw(image, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7);
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   602
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
static bool IsPartOfAutoLine(int px, int py)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   607
	px -= _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   608
	py -= _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
   610
	switch (_thd.drawstyle) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   611
	case HT_LINE | HT_DIR_X:  return py == 0; // x direction
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   612
	case HT_LINE | HT_DIR_Y:  return px == 0; // y direction
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   613
	case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   614
	case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   615
	case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   616
	case HT_LINE | HT_DIR_VR: return px == py || px == py - 16; // vertical right
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   620
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	/* useless, but avoids compiler warning this way */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   625
// [direction][side]
2710
e144188c1fdb (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   626
static const int _AutorailType[6][2] = {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   627
	{ HT_DIR_X,  HT_DIR_X },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   628
	{ HT_DIR_Y,  HT_DIR_Y },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   629
	{ HT_DIR_HU, HT_DIR_HL },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   630
	{ HT_DIR_HL, HT_DIR_HU },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   631
	{ HT_DIR_VL, HT_DIR_VR },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   632
	{ HT_DIR_VR, HT_DIR_VL }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   633
};
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   634
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   635
#include "table/autorail.h"
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   636
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
static void DrawTileSelection(const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	// Draw a red error square?
3281
0f3d836e35b1 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
   642
	if (_thd.redsq != 0 && _thd.redsq == ti->tile) {
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   643
		DrawSelectionSprite(PALETTE_TILE_RED_PULSATING | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
		return;
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
	// no selection active?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   648
	if (_thd.drawstyle == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	// Inside the inner area?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   651
	if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) &&
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   652
			IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   653
		if (_thd.drawstyle & HT_RECT) {
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   654
			image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh];
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   655
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
			DrawSelectionSprite(image, ti);
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   657
		} else if (_thd.drawstyle & HT_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
			// Figure out the Z coordinate for the single dot.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
			byte z = ti->z;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3609
diff changeset
   660
			if (ti->tileh & SLOPE_N) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   661
				z += TILE_HEIGHT;
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   662
				if (ti->tileh == SLOPE_STEEP_N) z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
			}
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   664
			DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, ti->x, ti->y, z);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   665
		} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   666
			// autorail highlight piece under cursor
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   667
			uint type = _thd.drawstyle & 0xF;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   668
			assert(type <= 5);
2710
e144188c1fdb (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   669
			image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[type][0]];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   670
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   671
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   672
			DrawSelectionSprite(image, ti);
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   673
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   674
		} else if (IsPartOfAutoLine(ti->x, ti->y)) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   675
			// autorail highlighting long line
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   676
			int dir = _thd.drawstyle & ~0xF0;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   677
			uint side;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   678
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   679
			if (dir < 2) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   680
				side = 0;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   681
			} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   682
				TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   683
				side = delta(delta(TileX(start), TileX(ti->tile)), delta(TileY(start), TileY(ti->tile)));
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   684
			}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   685
2710
e144188c1fdb (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   686
			image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[dir][side]];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   687
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   688
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   689
			DrawSelectionSprite(image, ti);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   690
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
		return;
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
	// Check if it's inside the outer area?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   695
	if (_thd.outersize.x &&
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   696
			_thd.size.x < _thd.size.x + _thd.outersize.x &&
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   697
			IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   698
			IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
		// Draw a blue rect.
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   700
		DrawSelectionSprite(PALETTE_SEL_TILE_BLUE | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   705
static void ViewportAddLandscape(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	int x, y, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	bool direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
	_cur_ti = &ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	// Transform into tile coordinates and round to closest full tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	x = ((vd->dpi.top >> 1) - (vd->dpi.left >> 2)) & ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
	y = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF;
5648
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   717
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
	// determine size of area
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
		Point pt = RemapCoords(x, y, 241);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
		width = (vd->dpi.left + vd->dpi.width - pt.x + 95) >> 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
		height = (vd->dpi.top + vd->dpi.height - pt.y) >> 5 << 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	assert(height > 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   727
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	direction = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
		int width_cur = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
		int x_cur = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
		int y_cur = y;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   734
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
		do {
4238
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   736
			TileType tt;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   737
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   738
			ti.x = x_cur;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   739
			ti.y = y_cur;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   740
			if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE &&
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   741
					0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) {
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   742
				TileIndex tile = TileVirtXY(x_cur, y_cur);
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   743
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   744
				ti.tile = tile;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   745
				ti.tileh = GetTileSlope(tile, &ti.z);
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   746
				tt = GetTileType(tile);
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   747
			} else {
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   748
				ti.tileh = SLOPE_FLAT;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   749
				ti.tile = 0;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   750
				ti.z = 0;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   751
				tt = MP_VOID;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   752
			}
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   753
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
			x_cur -= 0x10;
5648
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   756
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
			_added_tile_sprite = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
			_offset_ground_sprites = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   759
4238
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   760
			_tile_type_procs[tt]->draw_tile_proc(&ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
			DrawTileSelection(&ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
		} while (--width_cur);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   763
5648
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   764
		if ((direction ^= 1) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
			y += 0x10;
5648
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   766
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
			x += 0x10;
5648
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   768
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   769
	} while (--height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   773
static void ViewportAddTownNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	if (!(_display_opt & DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   786
	switch (dpi->zoom) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   787
		case 0:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   788
			FOR_ALL_TOWNS(t) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   789
				if (bottom > t->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   790
						top    < t->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   791
						right  > t->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   792
						left   < t->sign.left + t->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   793
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   794
						_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   795
						t->index, t->population);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   796
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   798
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   799
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   800
		case 1:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   801
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   802
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   803
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   804
			FOR_ALL_TOWNS(t) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   805
				if (bottom > t->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   806
						top    < t->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   807
						right  > t->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   808
						left   < t->sign.left + t->sign.width_1*2) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   809
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   810
						_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   811
						t->index, t->population);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   812
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   813
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   814
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   815
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   816
		default: NOT_REACHED();
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   817
		case 2:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   818
			right += 4;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   819
			bottom += 5;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   820
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   821
			FOR_ALL_TOWNS(t) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   822
				if (bottom > t->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   823
						top    < t->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   824
						right  > t->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   825
						left   < t->sign.left + t->sign.width_2*4) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   826
					AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   827
					AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   828
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   829
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   830
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   834
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   835
static void AddStation(const Station *st, StringID str, uint16 width)
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   836
{
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   837
	StringSpriteToDraw *sstd;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   838
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   839
	sstd = (StringSpriteToDraw*)AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities);
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   840
	if (sstd != NULL) {
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   841
		sstd->color = (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner];
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   842
		sstd->width = width;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   843
	}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   844
}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   845
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   846
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   847
static void ViewportAddStationNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
	int left, top, right, bottom;
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   850
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
	if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
		return;
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
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   860
	switch (dpi->zoom) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   861
		case 0:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   862
			FOR_ALL_STATIONS(st) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   863
				if (bottom > st->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   864
						top    < st->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   865
						right  > st->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   866
						left   < st->sign.left + st->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   867
					AddStation(st, STR_305C_0, st->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   868
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   870
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   871
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   872
		case 1:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   873
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   874
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   875
			FOR_ALL_STATIONS(st) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   876
				if (bottom > st->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   877
						top    < st->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   878
						right  > st->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   879
						left   < st->sign.left + st->sign.width_1*2) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   880
					AddStation(st, STR_305C_0, st->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   881
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   883
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   884
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   885
		default: NOT_REACHED();
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   886
		case 2:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   887
			right += 4;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   888
			bottom += 5;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   889
			FOR_ALL_STATIONS(st) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   890
				if (bottom > st->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   891
						top    < st->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   892
						right  > st->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   893
						left   < st->sign.left + st->sign.width_2*4) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   894
					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   895
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   897
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   901
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   902
static void AddSign(const Sign *si, StringID str, uint16 width)
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   903
{
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   904
	StringSpriteToDraw *sstd;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   905
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   906
	sstd = (StringSpriteToDraw*)AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->str, 0);
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   907
	if (sstd != NULL) {
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   908
		sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   909
		sstd->width = width;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   910
	}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   911
}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   912
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   913
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   914
static void ViewportAddSigns(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
{
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   916
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	if (!(_display_opt & DO_SHOW_SIGNS))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   927
	switch (dpi->zoom) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   928
		case 0:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   929
			FOR_ALL_SIGNS(si) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   930
				if (bottom > si->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   931
						top    < si->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   932
						right  > si->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   933
						left   < si->sign.left + si->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   934
					AddSign(si, STR_2806, si->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   935
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   937
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   938
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   939
		case 1:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   940
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   941
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   942
			FOR_ALL_SIGNS(si) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   943
				if (bottom > si->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   944
						top    < si->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   945
						right  > si->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   946
						left   < si->sign.left + si->sign.width_1 * 2) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   947
					AddSign(si, STR_2806, si->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   948
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   950
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   951
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   952
		default: NOT_REACHED();
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   953
		case 2:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   954
			right += 4;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   955
			bottom += 5;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   956
			FOR_ALL_SIGNS(si) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   957
				if (bottom > si->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   958
						top    < si->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   959
						right  > si->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   960
						left   < si->sign.left + si->sign.width_2 * 4) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   961
					AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   962
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   964
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   968
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   969
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width)
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   970
{
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   971
	StringSpriteToDraw *sstd;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   972
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   973
	sstd = (StringSpriteToDraw*)AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0);
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   974
	if (sstd != NULL) {
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   975
		sstd->color = (wp->deleted ? 0xE : 11);
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   976
		sstd->width = width;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   977
	}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   978
}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   979
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   980
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   981
static void ViewportAddWaypoints(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
{
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   983
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 193
diff changeset
   986
	if (!(_display_opt & DO_WAYPOINTS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   994
	switch (dpi->zoom) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   995
		case 0:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   996
			FOR_ALL_WAYPOINTS(wp) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   997
				if (bottom > wp->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   998
						top    < wp->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   999
						right  > wp->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1000
						left   < wp->sign.left + wp->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1001
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1002
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1004
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1005
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1006
		case 1:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1007
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1008
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1009
			FOR_ALL_WAYPOINTS(wp) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1010
				if (bottom > wp->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1011
						top    < wp->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1012
						right  > wp->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1013
						left   < wp->sign.left + wp->sign.width_1*2) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1014
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1015
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1017
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1018
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1019
		default: NOT_REACHED();
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1020
		case 2:
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1021
			right += 4;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1022
			bottom += 5;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1023
			FOR_ALL_WAYPOINTS(wp) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1024
				if (bottom > wp->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1025
						top    < wp->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1026
						right  > wp->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1027
						left   < wp->sign.left + wp->sign.width_2*4) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1028
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1029
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1031
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
	char buffer[128];
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1038
	uint w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	sign->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4885
diff changeset
  1042
	GetString(buffer, str, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1043
	w = GetStringBoundingBox(buffer).width + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
	sign->width_1 = w;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1045
	sign->left = left - w / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1047
	/* zoomed out version */
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: 3645
diff changeset
  1048
	_cur_fontsize = FS_SMALL;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1049
	w = GetStringBoundingBox(buffer).width + 3;
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: 3645
diff changeset
  1050
	_cur_fontsize = FS_NORMAL;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1051
	sign->width_2 = w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1055
static void ViewportDrawTileSprites(TileSpriteToDraw *ts)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1056
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
		Point pt = RemapCoords(ts->x, ts->y, ts->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
		DrawSprite(ts->image, pt.x, pt.y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1060
		ts = ts->next;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1061
	} while (ts != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1064
static void ViewportSortParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1066
	while (*psd != NULL) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1067
		ParentSpriteToDraw* ps = *psd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
		if (!(ps->unk16 & 1)) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1070
			ParentSpriteToDraw** psd2 = psd;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1071
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
			ps->unk16 |= 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1073
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1074
			while (*++psd2 != NULL) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1075
				ParentSpriteToDraw* ps2 = *psd2;
4188
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1076
				ParentSpriteToDraw** psd3;
1934
b3d568113d4d (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1077
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1078
				if (ps2->unk16 & 1) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
4187
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1080
				/* Decide which comparator to use, based on whether the bounding
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1081
				 * boxes overlap
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1082
				 */
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1083
				if (ps->xmax > ps2->xmin && ps->xmin < ps2->xmax && // overlap in X?
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1084
						ps->ymax > ps2->ymin && ps->ymin < ps2->ymax && // overlap in Y?
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1085
						ps->zmax > ps2->zmin && ps->zmin < ps2->zmax) { // overlap in Z?
4188
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1086
					/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1087
					 * the screen and with higher Z elevation, are drawn in front.
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1088
					 * Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1089
					 * i.e. X=(left+right)/2, etc.
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1090
					 * However, since we only care about order, don't actually divide / 2
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1091
					 */
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1092
					if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <=
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1093
							ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) {
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1094
						continue;
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1095
					}
1934
b3d568113d4d (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1096
				} else {
4188
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1097
					if (ps->xmax < ps2->xmin ||
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1098
							ps->ymax < ps2->ymin ||
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1099
							ps->zmax < ps2->zmin || (
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1100
								ps->xmin < ps2->xmax &&
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1101
								ps->ymin < ps2->ymax &&
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1102
								ps->zmin < ps2->zmax
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1103
							)) {
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1104
						continue;
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1105
					}
1934
b3d568113d4d (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1106
				}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1107
4188
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1108
				// Swap the two sprites ps and ps2 using bubble-sort algorithm.
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1109
				psd3 = psd;
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1110
				do {
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1111
					ParentSpriteToDraw* temp = *psd3;
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1112
					*psd3 = ps2;
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1113
					ps2 = temp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
4188
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1115
					psd3++;
c817518c79cc (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1116
				} while (psd3 <= psd2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
			psd++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1124
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1126
	for (; *psd != NULL; psd++) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1127
		const ParentSpriteToDraw* ps = *psd;
4186
853361bea03b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
  1128
		Point pt = RemapCoords(ps->xmin, ps->ymin, ps->zmin);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1129
		const ChildScreenSpriteToDraw* cs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
		DrawSprite(ps->image, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1133
		for (cs = ps->child; cs != NULL; cs = cs->next) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
			DrawSprite(cs->image, ps->left + cs->x, ps->top + cs->y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1139
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	DrawPixelInfo dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	byte zoom;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1143
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	_cur_dpi = &dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	dp = *dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1147
	zoom = dp.zoom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	dp.zoom = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	dp.left >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	dp.top >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	dp.width >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	dp.height >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	do {
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1156
		uint16 colour;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1157
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
		if (ss->width != 0) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1159
			int x = (ss->x >> zoom) - 1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1160
			int y = (ss->y >> zoom) - 1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1161
			int bottom = y + 11;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1162
			int w = ss->width;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1163
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
			if (w & 0x8000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
				w &= ~0x8000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
				y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
				bottom -= 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
				w -= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1171
		/* Draw the rectangle if 'tranparent station signs' is off,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1172
		 * or if we are drawing a general text sign (STR_2806) */
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1173
			if (!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1174
				DrawFrameRect(
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1175
					x, y, x + w, bottom, ss->color,
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  1176
					(_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT : FR_NONE
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1177
				);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1180
		SetDParam(0, ss->params[0]);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1181
		SetDParam(1, ss->params[1]);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1182
		/* if we didn't draw a rectangle, or if transparant building is on,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1183
		 * draw the text in the color the rectangle would have */
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1184
		if ((
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1185
					(_display_opt & DO_TRANS_BUILDINGS) ||
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1186
					(_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1187
				) && ss->width != 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1188
			/* Real colors need the IS_PALETTE_COLOR flag
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1189
			 * otherwise colors from _string_colormap are assumed. */
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1190
			colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
		} else {
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1192
			colour = 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
		}
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1194
		DrawString(
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1195
			ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1196
			ss->string, colour
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1197
		);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1198
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1199
		ss = ss->next;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1200
	} while (ss != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
  1203
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom)
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
	ViewportDrawer vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	int mask;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1207
	int x;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1208
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	DrawPixelInfo *old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	byte mem[VIEWPORT_DRAW_MEM];
137
73f897e1bf4a (svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents: 133
diff changeset
  1212
	ParentSpriteToDraw *parent_list[6144];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
	_cur_vd = &vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	old_dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	_cur_dpi = &vd.dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	vd.dpi.zoom = vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	mask = (-1) << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
	vd.combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
	vd.dpi.width = (right - left) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	vd.dpi.height = (bottom - top) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	vd.dpi.left = left & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
	vd.dpi.top = top & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	vd.dpi.pitch = old_dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
	vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch;
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
	vd.parent_list = parent_list;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1236
	vd.eof_parent_list = endof(parent_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
	vd.spritelist_mem = mem;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1238
	vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
	vd.last_string = &vd.first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	vd.first_string = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	vd.last_tile = &vd.first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
	vd.first_tile = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1243
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
	ViewportAddLandscape();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
	ViewportAddVehicles(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
	DrawTextEffects(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	ViewportAddTownNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
	ViewportAddStationNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
	ViewportAddSigns(&vd.dpi);
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 193
diff changeset
  1251
	ViewportAddWaypoints(&vd.dpi);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1253
	// This assert should never happen (because the length of the parent_list
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1254
	//  is checked)
979
f12f96116cdd (svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents: 926
diff changeset
  1255
	assert(vd.parent_list <= endof(parent_list));
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1256
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1257
	if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	/* null terminate parent sprite list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
	*vd.parent_list = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	ViewportSortParentSprites(parent_list);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
	ViewportDrawParentSprites(parent_list);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1264
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1265
	if (vd.first_string != NULL) ViewportDrawStrings(&vd.dpi, vd.first_string);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1266
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
	_cur_dpi = old_dpi;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
// Make sure we don't draw a too big area at a time.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
// If we do, the sprite memory will overflow.
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1272
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	if (((bottom - top) * (right - left) << vp->zoom) > 180000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
		if ((bottom - top) > (right - left)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
			int t = (top + bottom) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
			ViewportDrawChk(vp, left, top, right, t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
			ViewportDrawChk(vp, left, t, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
			int t = (left + right) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
			ViewportDrawChk(vp, left, top, t, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
			ViewportDrawChk(vp, t, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1285
		ViewportDoDraw(vp,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
			((left - vp->left) << vp->zoom) + vp->virtual_left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
			((top - vp->top) << vp->zoom) + vp->virtual_top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
			((right - vp->left) << vp->zoom) + vp->virtual_left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
			((bottom - vp->top) << vp->zoom) + vp->virtual_top
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1294
static inline void ViewportDraw(const ViewPort *vp, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1296
	if (right <= vp->left || bottom <= vp->top) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1298
	if (left >= vp->left + vp->width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	if (left < vp->left) left = vp->left;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1301
	if (right > vp->left + vp->width) right = vp->left + vp->width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1303
	if (top >= vp->top + vp->height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	if (top < vp->top) top = vp->top;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1306
	if (bottom > vp->top + vp->height) bottom = vp->top + vp->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
	ViewportDrawChk(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1311
void DrawWindowViewport(const Window *w)
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1312
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
	DrawPixelInfo *dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
	dpi->left += w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
	dpi->top += w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
	ViewportDraw(w->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
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
	dpi->left -= w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
	dpi->top -= w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
void UpdateViewportPosition(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1326
	const ViewPort *vp = w->viewport;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1328
	if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1329
		const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1330
		Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
		SetViewportPosition(w, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
	} else {
632
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1334
		int x;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1335
		int y;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1336
		int vx;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1337
		int vy;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1338
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1339
		// Center of the viewport is hot spot
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1340
		x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1341
		y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1342
		// Convert viewport coordinates to map coordinates
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1343
		// Calculation is scaled by 4 to avoid rounding errors
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1344
		vx = -x + y * 2;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1345
		vy =  x + y * 2;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1346
		// clamp to size of map
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1347
		vx = clamp(vx, 0 * 4, MapMaxX() * TILE_SIZE * 4);
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1348
		vy = clamp(vy, 0 * 4, MapMaxY() * TILE_SIZE * 4);
632
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1349
		// Convert map coordinates to viewport coordinates
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1350
		x = (-vx + vy) / 2;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1351
		y = ( vx + vy) / 4;
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1352
		// Set position
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1353
		WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1354
		WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2;
632
0e71f12b846b (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1355
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1356
		SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1360
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1362
	right -= vp->virtual_left;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1363
	if (right <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1365
	bottom -= vp->virtual_top;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1366
	if (bottom <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1368
	left = max(0, left - vp->virtual_left);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1370
	if (left >= vp->virtual_width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1372
	top = max(0, top - vp->virtual_top);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1373
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1374
	if (top >= vp->virtual_height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
	SetDirtyBlocks(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
		(left >> vp->zoom) + vp->left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
		(top >> vp->zoom) + vp->top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
		(right >> vp->zoom) + vp->left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
		(bottom >> vp->zoom) + vp->top
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1386
	const ViewPort *vp = _viewports;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
	uint32 act = _active_viewports;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
		if (act & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
			assert(vp->width != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
			MarkViewportDirty(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
	} while (vp++,act>>=1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1396
void MarkTileDirtyByTile(TileIndex tile)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1397
{
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1398
	Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
void MarkTileDirty(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1409
	uint z = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	Point pt;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1411
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1412
	if (IS_INT_INSIDE(x, 0, MapSizeX() * TILE_SIZE) &&
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1413
			IS_INT_INSIDE(y, 0, MapSizeY() * TILE_SIZE))
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1414
		z = GetTileZ(TileVirtXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
	pt = RemapCoords(x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
	);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1423
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1425
static void SetSelectionTilesDirty(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
	int y_size, x_size;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1428
	int x = _thd.pos.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1429
	int y = _thd.pos.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1431
	x_size = _thd.size.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1432
	y_size = _thd.size.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1434
	if (_thd.outersize.x) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1435
		x_size += _thd.outersize.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1436
		x += _thd.offs.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1437
		y_size += _thd.outersize.y;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1438
		y += _thd.offs.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
	assert(x_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
	assert(y_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
	x_size += x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
	y_size += y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
		int y_bk = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
			MarkTileDirty(x, y);
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1451
		} while ( (y += TILE_SIZE) != y_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
		y = y_bk;
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1453
	} while ( (x += TILE_SIZE) != x_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
1990
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1457
void SetSelectionRed(bool b)
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1458
{
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1459
	_thd.make_square_red = b;
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1460
	SetSelectionTilesDirty();
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1461
}
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1462
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1463
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1464
static bool CheckClickOnTown(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1466
	const Town *t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1468
	if (!(_display_opt & DO_SHOW_TOWN_NAMES)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1470
	switch (vp->zoom) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1471
		case 0:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1472
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1473
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1474
			FOR_ALL_TOWNS(t) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1475
				if (y >= t->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1476
						y < t->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1477
						x >= t->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1478
						x < t->sign.left + t->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1479
					ShowTownViewWindow(t->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1480
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1481
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1483
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1484
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1485
		case 1:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1486
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1487
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1488
			FOR_ALL_TOWNS(t) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1489
				if (y >= t->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1490
						y < t->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1491
						x >= t->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1492
						x < t->sign.left + t->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1493
					ShowTownViewWindow(t->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1494
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1495
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1497
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1498
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1499
		default:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1500
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1501
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1502
			FOR_ALL_TOWNS(t) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1503
				if (y >= t->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1504
						y < t->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1505
						x >= t->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1506
						x < t->sign.left + t->sign.width_2 * 4) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1507
					ShowTownViewWindow(t->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1508
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1509
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1511
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1517
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1518
static bool CheckClickOnStation(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1520
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1522
	if (!(_display_opt & DO_SHOW_STATION_NAMES)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1524
	switch (vp->zoom) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1525
		case 0:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1526
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1527
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1528
			FOR_ALL_STATIONS(st) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1529
				if (y >= st->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1530
						y < st->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1531
						x >= st->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1532
						x < st->sign.left + st->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1533
					ShowStationViewWindow(st->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1534
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1535
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1537
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1538
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1539
		case 1:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1540
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1541
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1542
			FOR_ALL_STATIONS(st) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1543
				if (y >= st->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1544
						y < st->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1545
						x >= st->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1546
						x < st->sign.left + st->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1547
					ShowStationViewWindow(st->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1548
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1549
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1551
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1552
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1553
		default:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1554
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1555
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1556
			FOR_ALL_STATIONS(st) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1557
				if (y >= st->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1558
						y < st->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1559
						x >= st->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1560
						x < st->sign.left + st->sign.width_2 * 4) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1561
					ShowStationViewWindow(st->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1562
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1563
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1565
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1571
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1572
static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
{
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1574
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1576
	if (!(_display_opt & DO_SHOW_SIGNS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1578
	switch (vp->zoom) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1579
		case 0:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1580
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1581
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1582
			FOR_ALL_SIGNS(si) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1583
				if (y >= si->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1584
						y <  si->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1585
						x >= si->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1586
						x <  si->sign.left + si->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1587
					ShowRenameSignWindow(si);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1588
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1589
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1591
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1592
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1593
		case 1:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1594
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1595
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1596
			FOR_ALL_SIGNS(si) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1597
				if (y >= si->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1598
						y <  si->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1599
						x >= si->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1600
						x <  si->sign.left + si->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1601
					ShowRenameSignWindow(si);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1602
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1603
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1605
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1606
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1607
		default:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1608
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1609
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1610
			FOR_ALL_SIGNS(si) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1611
				if (y >= si->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1612
						y <  si->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1613
						x >= si->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1614
						x <  si->sign.left + si->sign.width_2 * 4) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1615
					ShowRenameSignWindow(si);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1616
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1617
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1619
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1625
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1626
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1628
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1630
	if (!(_display_opt & DO_WAYPOINTS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1632
	switch (vp->zoom) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1633
		case 0:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1634
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1635
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1636
			FOR_ALL_WAYPOINTS(wp) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1637
				if (y >= wp->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1638
						y < wp->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1639
						x >= wp->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1640
						x < wp->sign.left + wp->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1641
					ShowRenameWaypointWindow(wp);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1642
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1643
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1645
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1646
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1647
		case 1:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1648
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1649
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1650
			FOR_ALL_WAYPOINTS(wp) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1651
				if (y >= wp->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1652
						y < wp->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1653
						x >= wp->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1654
						x < wp->sign.left + wp->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1655
					ShowRenameWaypointWindow(wp);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1656
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1657
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1659
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1660
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1661
		default:
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1662
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1663
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1664
			FOR_ALL_WAYPOINTS(wp) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1665
				if (y >= wp->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1666
						y < wp->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1667
						x >= wp->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1668
						x < wp->sign.left + wp->sign.width_2 * 4) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1669
					ShowRenameWaypointWindow(wp);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1670
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1671
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1673
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1680
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1682
	Point pt = TranslateXYToTileCoord(vp, x, y);
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  1683
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1684
	if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1687
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1688
static void SafeShowTrainViewWindow(const Vehicle* v)
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1689
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1690
	if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v);
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1691
	ShowTrainViewWindow(v);
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1692
}
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1693
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1694
static void Nop(const Vehicle *v) {}
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1695
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1696
typedef void OnVehicleClickProc(const Vehicle *v);
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1697
static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1698
	SafeShowTrainViewWindow,
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1699
	ShowRoadVehViewWindow,
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1700
	ShowShipViewWindow,
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1701
	ShowAircraftViewWindow,
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1702
	Nop, // Special vehicles
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1703
	Nop  // Disaster vehicles
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1706
void HandleViewportClicked(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1708
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1710
	if (CheckClickOnTown(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1711
	if (CheckClickOnStation(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1712
	if (CheckClickOnSign(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1713
	if (CheckClickOnWaypoint(vp, x, y)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
	CheckClickOnLandscape(vp, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1716
	v = CheckClickOnVehicle(vp, x, y);
3809
cff6d5e916f7 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1717
	if (v != NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
  1718
		DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v);
3809
cff6d5e916f7 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1719
		_on_vehicle_click_proc[v->type - 0x10](v);
cff6d5e916f7 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1720
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1723
Vehicle *CheckMouseOverVehicle(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1725
	const Window *w;
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1726
	const ViewPort *vp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
	int x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
	int y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
	w = FindWindowFromPt(x, y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1732
	if (w == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
	vp = IsPtInWindowViewport(w, x, y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1735
	return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1740
void PlaceObject(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
	Window *w;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1744
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
	pt = GetTileBelowCursor();
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1746
	if (pt.x == -1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1748
	if (_thd.place_mode == VHM_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
		pt.x += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
		pt.y += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	_tile_fract_coords.x = pt.x & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
	_tile_fract_coords.y = pt.y & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1756
	w = GetCallbackWnd();
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1757
	if (w != NULL) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1758
		WindowEvent e;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1759
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
		e.event = WE_PLACE_OBJ;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  1761
		e.we.place.pt = pt;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  1762
		e.we.place.tile = TileVirtXY(pt.x, pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1767
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1768
/* scrolls the viewport in a window to a given location */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1769
bool ScrollWindowTo(int x , int y, Window *w)
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1770
{
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1771
	Point pt;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1772
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1773
	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1774
	WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1775
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1776
	if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1777
		return false;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1778
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1779
	WP(w, vp_d).scrollpos_x = pt.x;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1780
	WP(w, vp_d).scrollpos_y = pt.y;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1781
	return true;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1782
}
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1783
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1784
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
bool ScrollMainWindowTo(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
{
4339
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1787
	Window *w;
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1788
	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1789
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1790
	/* If a user scrolls to a tile (via what way what so ever) and already is on
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1791
	 *  that tile (e.g.: pressed twice), move the smallmap to that location,
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1792
	 *  so you directly see where you are on the smallmap. */
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1793
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1794
	if (res) return res;
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1795
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1796
	w = FindWindowById(WC_SMALLMAP, 0);
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1797
	if (w == NULL) return res;
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1798
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1799
	SmallMapCenterOnCurrentPos(w);
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1800
f5e99218131a (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1801
	return res;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
bool ScrollMainWindowToTile(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
{
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1807
	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
void SetRedErrorSquare(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1812
	TileIndex old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
	old = _thd.redsq;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
	_thd.redsq = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
	if (tile != old) {
3281
0f3d836e35b1 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
  1818
		if (tile != 0) MarkTileDirtyByTile(tile);
0f3d836e35b1 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
  1819
		if (old  != 0) MarkTileDirtyByTile(old);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
void SetTileSelectSize(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
{
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1825
	_thd.new_size.x = w * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1826
	_thd.new_size.y = h * TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1827
	_thd.new_outersize.x = 0;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1828
	_thd.new_outersize.y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1831
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1832
{
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1833
	_thd.offs.x = ox * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1834
	_thd.offs.y = oy * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1835
	_thd.new_outersize.x = sx * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1836
	_thd.new_outersize.y = sy * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1839
/* returns the best autorail highlight type from map coordinates */
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1840
static byte GetAutorailHT(int x, int y)
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1841
{
2710
e144188c1fdb (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
  1842
	return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1843
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1845
// called regular to update tile highlighting in all cases
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1846
void UpdateTileSelection(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1848
	int x1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1849
	int y1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1851
	_thd.new_drawstyle = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1852
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1853
	if (_thd.place_mode == VHM_SPECIAL) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1854
		x1 = _thd.selend.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1855
		y1 = _thd.selend.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1856
		if (x1 != -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1857
			int x2 = _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1858
			int y2 = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
			x1 &= ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
			y1 &= ~0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1861
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
			if (x1 >= x2) intswap(x1,x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
			if (y1 >= y2) intswap(y1,y2);
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1864
			_thd.new_pos.x = x1;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1865
			_thd.new_pos.y = y1;
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1866
			_thd.new_size.x = x2 - x1 + TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1867
			_thd.new_size.y = y2 - y1 + TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1868
			_thd.new_drawstyle = _thd.next_drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
		}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1870
	} else if (_thd.place_mode != VHM_NONE) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1871
		Point pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
		x1 = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
		y1 = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
		if (x1 != -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1875
			switch (_thd.place_mode) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1876
				case VHM_RECT:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1877
					_thd.new_drawstyle = HT_RECT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1878
					break;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1879
				case VHM_POINT:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1880
					_thd.new_drawstyle = HT_POINT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1881
					x1 += 8;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1882
					y1 += 8;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1883
					break;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1884
				case VHM_RAIL:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1885
					_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
			}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1887
			_thd.new_pos.x = x1 & ~0xF;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1888
			_thd.new_pos.y = y1 & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1892
	// redraw selection
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1893
	if (_thd.drawstyle != _thd.new_drawstyle ||
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1894
			_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
4539
0b13858554fb (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  1895
			_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y ||
0b13858554fb (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  1896
	    _thd.outersize.x != _thd.new_outersize.x ||
0b13858554fb (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  1897
	    _thd.outersize.y != _thd.new_outersize.y) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
		// clear the old selection?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1899
		if (_thd.drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1901
		_thd.drawstyle = _thd.new_drawstyle;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1902
		_thd.pos = _thd.new_pos;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1903
		_thd.size = _thd.new_size;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1904
		_thd.outersize = _thd.new_outersize;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1905
		_thd.dirty = 0xff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
		// draw the new selection?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1908
		if (_thd.new_drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1912
// highlighting tiles while only going over them with the mouse
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  1913
void VpStartPlaceSizing(TileIndex tile, int user)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1915
	_thd.userdata = user;
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1916
	_thd.selend.x = TileX(tile) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1917
	_thd.selstart.x = TileX(tile) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1918
	_thd.selend.y = TileY(tile) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1919
	_thd.selstart.y = TileY(tile) * TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1920
	if (_thd.place_mode == VHM_RECT) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1921
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1922
		_thd.next_drawstyle = HT_RECT;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1923
	} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1924
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1925
		_thd.next_drawstyle = _thd.drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
	} else {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1927
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1928
		_thd.next_drawstyle = HT_POINT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	_special_mouse_mode = WSM_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
void VpSetPlaceSizingLimit(int limit)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
	_thd.sizelimit = limit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1938
/**
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1939
* Highlights all tiles between a set of two tiles. Used in dock and tunnel placement
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1940
* @param from TileIndex of the first tile to highlight
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1941
* @param to TileIndex of the last tile to highlight */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1942
void VpSetPresizeRange(TileIndex from, TileIndex to)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
{
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1944
	uint distance = DistanceManhattan(from, to) + 1;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1945
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1946
	_thd.selend.x = TileX(to) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1947
	_thd.selend.y = TileY(to) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1948
	_thd.selstart.x = TileX(from) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1949
	_thd.selstart.y = TileY(from) * TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1950
	_thd.next_drawstyle = HT_RECT;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1951
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1952
	/* show measurement only if there is any length to speak of */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1953
	if (distance > 1) GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, &distance);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
  1956
static void VpStartPreSizing(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
	_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
	_special_mouse_mode = WSM_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1962
/* returns information about the 2x1 piece to be build.
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1963
 * The lower bits (0-3) are the track type. */
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1964
static byte Check2x1AutoRail(int mode)
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1965
{
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1966
	int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1967
	int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1968
	int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1969
	int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1970
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
  1971
	switch (mode) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1972
	case 0: // end piece is lower right
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1973
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1974
		if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1975
		return 1;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1976
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1977
	case 1:
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1978
		if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1979
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1980
		return 1;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1981
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1982
	case 2:
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1983
		if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1984
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1985
		return 0;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1986
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1987
	case 3:
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1988
		if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1989
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1990
		return 0;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1991
	}
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1992
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1993
	return 0; // avoids compiler warnings
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1994
}
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1995
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1996
/** Check if the direction of start and end tile should be swapped based on
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1997
 * the dragging-style. Default directions are:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1998
 * in the case of a line (HT_RAIL, HT_LINE):  DIR_NE, DIR_NW, DIR_N, DIR_E
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  1999
 * in the case of a rect (HT_RECT, HT_POINT): DIR_S, DIR_E
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2000
 * For example dragging a rectangle area from south to north should be swapped to
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2001
 * north-south (DIR_S) to obtain the same results with less code. This is what
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2002
 * the return value signifies.
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2003
 * @param style HighLightStyle dragging style
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2004
 * @param start_tile, end_tile start and end tile of drag
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2005
 * @param boolean value which when true means start/end should be swapped */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2006
static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile)
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2007
{
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2008
	uint start_x = TileX(start_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2009
	uint start_y = TileY(start_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2010
	uint end_x = TileX(end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2011
	uint end_y = TileY(end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2012
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2013
	switch (style & HT_DRAG_MASK) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2014
		case HT_RAIL:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2015
		case HT_LINE: return (end_x > start_x || (end_x == start_x && end_y > start_y));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2016
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2017
		case HT_RECT:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2018
		case HT_POINT: return (end_x != start_x && end_y < start_y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2019
		default: NOT_REACHED();
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2020
	}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2021
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2022
	return false;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2023
}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2024
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2025
/** Calculates height difference between one tile and another
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2026
* Multiplies the result to suit the standard given by minimap - 50 meters high
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2027
* To correctly get the height difference we need the direction we are dragging
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2028
* in, as well as with what kind of tool we are dragging. For example a horizontal
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2029
* autorail tool that starts in bottom and ends at the top of a tile will need the
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2030
* maximum of SW,S and SE,N corners respectively. This is handled by the lookup table below
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2031
* See _tileoffs_by_dir in map.c for the direction enums if you can't figure out
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2032
* the values yourself.
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2033
* @param style HightlightStyle of drag. This includes direction and style (autorail, rect, etc.)
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2034
* @param distance amount of tiles dragged, important for horizontal/vertical drags
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2035
*        ignored for others
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2036
* @param start_tile, end_tile start and end tile of drag operation
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2037
* @return height difference between two tiles. Tile measurement tool utilizes
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2038
* this value in its tooltips */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2039
static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile)
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2040
{
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2041
	bool swap = SwapDirection(style, start_tile, end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2042
	byte style_t;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2043
	uint h0, h1, ht; // start heigth, end height, and temp variable
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2044
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2045
	if (start_tile == end_tile) return 0;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2046
	if (swap) swap_tile(&start_tile, &end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2047
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2048
	switch (style & HT_DRAG_MASK) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2049
		case HT_RECT: {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2050
			static const TileIndexDiffC heightdiff_area_by_dir[] = {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2051
				/* Start */ {1, 0}, /* Dragging east */ {0, 0}, /* Dragging south */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2052
				/* End   */ {0, 1}, /* Dragging east */ {1, 1}  /* Dragging south */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2053
			};
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2054
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2055
			/* In the case of an area we can determine whether we were dragging south or
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2056
			 * east by checking the X-coordinates of the tiles */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2057
			style_t = (byte)(TileX(end_tile) > TileX(start_tile));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2058
			start_tile = TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_area_by_dir[style_t]));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2059
			end_tile   = TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_area_by_dir[2 + style_t]));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2060
		}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2061
		/* Fallthrough */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2062
		case HT_POINT:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2063
			h0 = TileHeight(start_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2064
			h1 = TileHeight(end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2065
			break;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2066
		default: { /* All other types, this is mostly only line/autorail */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2067
			static const HighLightStyle flip_style_direction[] = {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2068
				HT_DIR_X, HT_DIR_Y, HT_DIR_HL, HT_DIR_HU, HT_DIR_VR, HT_DIR_VL
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2069
			};
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2070
			static const TileIndexDiffC heightdiff_line_by_dir[] = {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2071
				/* Start */ {1, 0}, {1, 1}, /* HT_DIR_X  */ {0, 1}, {1, 1}, /* HT_DIR_Y  */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2072
				/* Start */ {1, 0}, {0, 0}, /* HT_DIR_HU */ {1, 0}, {1, 1}, /* HT_DIR_HL */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2073
				/* Start */ {1, 0}, {1, 1}, /* HT_DIR_VL */ {0, 1}, {1, 1}, /* HT_DIR_VR */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2074
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2075
				/* Start */ {0, 1}, {0, 0}, /* HT_DIR_X  */ {1, 0}, {0, 0}, /* HT_DIR_Y  */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2076
				/* End   */ {0, 1}, {0, 0}, /* HT_DIR_HU */ {1, 1}, {0, 1}, /* HT_DIR_HL */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2077
				/* End   */ {1, 0}, {0, 0}, /* HT_DIR_VL */ {0, 0}, {0, 1}, /* HT_DIR_VR */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2078
			};
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2079
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2080
			distance %= 2; // we're only interested if the distance is even or uneven
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2081
			style &= HT_DIR_MASK;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2082
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2083
			/* To handle autorail, we do some magic to be able to use a lookup table.
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2084
			 * Firstly if we drag the other way around, we switch start&end, and if needed
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2085
			 * also flip the drag-position. Eg if it was on the left, and the distance is even
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2086
			 * that means the end, which is now the start is on the right */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2087
			if (swap && distance == 0) style = flip_style_direction[style];
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2088
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2089
			/* Use lookup table for start-tile based on HighLightStyle direction */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2090
			style_t = style * 2;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2091
			assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2092
			h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t])));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2093
			ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1])));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2094
			h0 = maxu(h0, ht);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2095
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2096
			/* Use lookup table for end-tile based on HighLightStyle direction
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2097
			 * flip around side (lower/upper, left/right) based on distance */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2098
			if (distance == 0) style_t = flip_style_direction[style] * 2;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2099
			assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2100
			h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t])));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2101
			ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1])));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2102
			h1 = maxu(h1, ht);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2103
		} break;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2104
	}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2105
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2106
	if (swap) swap_uint32(&h0, &h1);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2107
	/* Minimap shows height in intervals of 50 meters, let's do the same */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2108
	return (int)(h1 - h0) * 50;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2109
}
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2110
4885
c9fe8c52fd50 (svn r6822) -Fix r6821: add type for measure_strings_length[]
glx
parents: 4884
diff changeset
  2111
static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF};
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2112
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2113
// while dragging
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2114
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
{
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2116
	HighLightStyle b;
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2117
	uint w, h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2118
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2119
	int dx = thd->selstart.x - (thd->selend.x & ~0xF);
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2120
	int dy = thd->selstart.y - (thd->selend.y & ~0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2121
	w = myabs(dx) + 16;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2122
	h = myabs(dy) + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2124
	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2125
		if (method == VPM_RAILDIRS) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2126
			b = GetAutorailHT(x, y);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2127
		} else { // rect for autosignals on one tile
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2128
			b = HT_RECT;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2129
		}
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2130
	} else if (h == 16) { // Is this in X direction?
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2131
		if (dx == 16) { // 2x1 special handling
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2132
			b = (Check2x1AutoRail(3)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2133
		} else if (dx == -16) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2134
			b = (Check2x1AutoRail(2)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2135
		} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2136
			b = HT_LINE | HT_DIR_X;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2137
		}
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2138
		y = thd->selstart.y;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2139
	} else if (w == 16) { // Or Y direction?
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2140
		if (dy == 16) { // 2x1 special handling
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2141
			b = (Check2x1AutoRail(1)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2142
		} else if (dy == -16) { // 2x1 other direction
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2143
			b = (Check2x1AutoRail(0)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2144
		} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2145
			b = HT_LINE | HT_DIR_Y;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2146
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
		x = thd->selstart.x;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2148
	} else if (w > h * 2) { // still count as x dir?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2149
		b = HT_LINE | HT_DIR_X;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
		y = thd->selstart.y;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2151
	} else if (h > w * 2) { // still count as y dir?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2152
		b = HT_LINE | HT_DIR_Y;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2153
		x = thd->selstart.x;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2154
	} else { // complicated direction
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2155
		int d = w - h;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2156
		thd->selend.x = thd->selend.x & ~0xF;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2157
		thd->selend.y = thd->selend.y & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
		// four cases.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
		if (x > thd->selstart.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2161
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
				// south
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2163
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2164
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2165
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2166
					x = thd->selstart.x + h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2167
					b = HT_LINE | HT_DIR_VL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2168
					// return px == py || px == py + 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2169
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2170
					y = thd->selstart.y + w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2171
					b = HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2172
				} // return px == py || px == py - 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
				// west
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2175
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2176
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2177
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2178
					x = thd->selstart.x + h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2179
					b = HT_LINE | HT_DIR_HL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2180
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2181
					y = thd->selstart.y - w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2182
					b = HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2183
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2184
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2185
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2186
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
				// east
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2188
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2189
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2190
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2191
					x = thd->selstart.x - h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2192
					b = HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2193
					// return px == -py || px == -py - 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2194
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2195
					y = thd->selstart.y + w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2196
					b = HT_LINE | HT_DIR_HL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2197
				} // return px == -py || px == -py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2199
				// north
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2200
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2201
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2202
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2203
					x = thd->selstart.x - h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2204
					b = HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2205
					// return px == py || px == py - 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2206
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2207
					y = thd->selstart.y - w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2208
					b = HT_LINE | HT_DIR_VL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2209
				} //return px == py || px == py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2211
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2212
	}
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2213
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2214
	if (_patches.measure_tooltip) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2215
		TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2216
		TileIndex t1 = TileVirtXY(x, y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2217
		uint distance = DistanceManhattan(t0, t1) + 1;
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2218
		byte index = 0;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2219
		uint params[2];
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2220
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2221
		if (distance != 1) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2222
			int heightdiff = CalcHeightdiff(b, distance, t0, t1);
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2223
			/* If we are showing a tooltip for horizontal or vertical drags,
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2224
			 * 2 tiles have a length of 1. To bias towards the ceiling we add
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2225
			 * one before division. It feels more natural to count 3 lengths as 2 */
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2226
			if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2227
				distance = (distance + 1) / 2;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2228
			}
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2229
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2230
			params[index++] = distance;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2231
			if (heightdiff != 0) params[index++] = heightdiff;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2232
		}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2233
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2234
		GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2235
	}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2236
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2237
	thd->selend.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2238
	thd->selend.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2239
	thd->next_drawstyle = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2240
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2241
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2242
/**
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2243
 * Selects tiles while dragging
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2244
 * @param x X coordinate of end of selection
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2245
 * @param y Y coordinate of end of selection
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2246
 * @param method modifies the way tiles are selected. Possible
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2247
 * methods are VPM_* in viewport.h */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
void VpSelectTilesWithMethod(int x, int y, int method)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2249
{
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2250
	int sx, sy;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2251
	HighLightStyle style;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2252
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2253
	if (x == -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2254
		_thd.selend.x = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2255
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2258
	/* Special handling of drag in any (8-way) direction */
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 0
diff changeset
  2259
	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2260
		_thd.selend.x = x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2261
		_thd.selend.y = y;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2262
		CalcRaildirsDrawstyle(&_thd, x, y, method);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2263
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2264
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2265
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2266
	if (_thd.next_drawstyle == HT_POINT) {
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2267
		x += TILE_SIZE / 2;
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2268
		y += TILE_SIZE / 2;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2269
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2270
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2271
	sx = _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2272
	sy = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2273
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2274
	switch (method) {
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2275
		case VPM_X_OR_Y: /* drag in X or Y direction */
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2276
			if (myabs(sy - y) < myabs(sx - x)) {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2277
				y = sy;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2278
				style = HT_DIR_X;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2279
			} else {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2280
				x = sx;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2281
				style = HT_DIR_Y;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2282
			}
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2283
			goto calc_heightdiff_single_direction;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2284
		case VPM_FIX_X: /* drag in Y direction */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2285
			x = sx;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2286
			style = HT_DIR_Y;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2287
			goto calc_heightdiff_single_direction;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2288
		case VPM_FIX_Y: /* drag in X direction */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2289
			y = sy;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2290
			style = HT_DIR_X;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2291
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2292
calc_heightdiff_single_direction:;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2293
			if (_patches.measure_tooltip) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2294
				TileIndex t0 = TileVirtXY(sx, sy);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2295
				TileIndex t1 = TileVirtXY(x, y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2296
				uint distance = DistanceManhattan(t0, t1) + 1;
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2297
				byte index = 0;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2298
				uint params[2];
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2299
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2300
				if (distance != 1) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2301
					/* With current code passing a HT_LINE style to calculate the height
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2302
					 * difference is enough. However if/when a point-tool is created
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2303
					 * with this method, function should be called with new_style (below)
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2304
					 * instead of HT_LINE | style case HT_POINT is handled specially
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2305
					 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2306
					int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1);
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2307
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2308
					params[index++] = distance;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2309
					if (heightdiff != 0) params[index++] = heightdiff;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2310
				}
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2311
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2312
				GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2313
			} break;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2314
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2315
		case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2316
			int limit = (_thd.sizelimit - 1) * TILE_SIZE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2317
			x = sx + clamp(x - sx, -limit, limit);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2318
			y = sy + clamp(y - sy, -limit, limit);
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  2319
			} /* Fallthrough */
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  2320
		case VPM_X_AND_Y: { /* drag an X by Y area */
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2321
			if (_patches.measure_tooltip) {
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2322
				static const StringID measure_strings_area[] = {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2323
					STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2324
				};
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2325
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2326
				TileIndex t0 = TileVirtXY(sx, sy);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2327
				TileIndex t1 = TileVirtXY(x, y);
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  2328
				uint dx = delta(TileX(t0), TileX(t1)) + 1;
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  2329
				uint dy = delta(TileY(t0), TileY(t1)) + 1;
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2330
				byte index = 0;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2331
				uint params[3];
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2332
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2333
				/* If dragging an area (eg dynamite tool) and it is actually a single
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2334
				 * row/column, change the type to 'line' to get proper calculation for height */
4838
d7570b95d5f8 (svn r6764) -Fix (r6758): Wrong height difference calculated because invalid drag-type
Darkvater
parents: 4834
diff changeset
  2335
				style = _thd.next_drawstyle;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2336
				if (style & HT_RECT) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2337
					if (dx == 1) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2338
						style = HT_LINE | HT_DIR_Y;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2339
					} else if (dy == 1) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2340
						style = HT_LINE | HT_DIR_X;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2341
					}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2342
				}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2343
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2344
				if (dx != 1 || dy != 1) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2345
					int heightdiff = CalcHeightdiff(style, 0, t0, t1);
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2346
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2347
					params[index++] = dx;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2348
					params[index++] = dy;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2349
					if (heightdiff != 0) params[index++] = heightdiff;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2350
				}
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2351
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2352
				GuiShowTooltipsWithArgs(measure_strings_area[index], index, params);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2353
			}
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2354
		break;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2355
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2356
		}
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2357
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2358
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2359
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2360
	_thd.selend.x = x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2361
	_thd.selend.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2362
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2363
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  2364
// while dragging
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2365
bool VpHandlePlaceSizingDrag(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2366
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2367
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2368
	WindowEvent e;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2369
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2370
	if (_special_mouse_mode != WSM_SIZING) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2371
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2372
	e.we.place.userdata = _thd.userdata;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2373
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2374
	// stop drag mode if the window has been closed
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2375
	w = FindWindowById(_thd.window_class,_thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2376
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2377
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2378
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2380
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2381
	// while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() )
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2382
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2383
		e.event = WE_PLACE_DRAG;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2384
		e.we.place.pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2385
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2386
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2387
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2388
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2389
	// mouse button released..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2390
	// keep the selected tool, but reset it to the original mode.
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2391
	_special_mouse_mode = WSM_NONE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2392
	if (_thd.next_drawstyle == HT_RECT) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2393
		_thd.place_mode = VHM_RECT;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2394
	} else if ((e.we.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2395
		_thd.place_mode = VHM_RECT;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2396
	} else if (_thd.next_drawstyle & HT_LINE) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2397
		_thd.place_mode = VHM_RAIL;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2398
	} else if (_thd.next_drawstyle & HT_RAIL) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2399
		_thd.place_mode = VHM_RAIL;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2400
	} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2401
		_thd.place_mode = VHM_POINT;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2402
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2403
	SetTileSelectSize(1, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2404
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2405
	// and call the mouseup event.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2406
	e.event = WE_PLACE_MOUSEUP;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2407
	e.we.place.pt = _thd.selend;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2408
	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2409
	e.we.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2410
	w->wndproc(w, &e);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2411
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2412
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2413
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2414
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2415
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2416
{
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2417
	SetObjectToPlace(icon, mode, w->window_class, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2418
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2419
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2420
#include "table/animcursors.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2421
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2422
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2423
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2425
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2426
	// undo clicking on button
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2427
	if (_thd.place_mode != 0) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2428
		_thd.place_mode = 0;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2429
		w = FindWindowById(_thd.window_class, _thd.window_number);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2430
		if (w != NULL) CallWindowEventNP(w, WE_ABORT_PLACE_OBJ);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2431
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2432
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2433
	SetTileSelectSize(1, 1);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2434
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2435
	_thd.make_square_red = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2436
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2437
	if (mode == VHM_DRAG) { // mode 4 is for dragdropping trains in the depot window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2438
		mode = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2439
		_special_mouse_mode = WSM_DRAGDROP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2440
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2441
		_special_mouse_mode = WSM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2442
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2443
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2444
	_thd.place_mode = mode;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2445
	_thd.window_class = window_class;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2446
	_thd.window_number = window_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2447
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2448
	if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2449
		VpStartPreSizing();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2450
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2451
	if ( (int)icon < 0)
4334
75322a204d0c (svn r6035) -Revert r5900 which supposedly fixed an invalid warning caused by buggy MS software
Darkvater
parents: 4272
diff changeset
  2452
		SetAnimatedMouseCursor(_animcursors[~icon]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2453
	else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2454
		SetMouseCursor(icon);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2455
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2456
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2457
void ResetObjectToPlace(void)
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2458
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2459
	SetObjectToPlace(SPR_CURSOR_MOUSE, VHM_NONE, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2460
}