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