src/viewport.cpp
author rubidium
Wed, 26 Sep 2007 19:27:29 +0000
changeset 7643 af32b07bc027
parent 7617 804e665b79fa
child 7659 c86da4c6292f
permissions -rw-r--r--
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
Note that this is not completely glitch free, bounding boxes sometimes aren't removed properly. This is due to the fact that the bounding boxes sometimes are larger than the sprite, which causes a smaller part than the bounding box to be redrawn. This is NOT a bug, but a known implementation limit as we do not want to slow down normal games so the debug graphics are always 100% correct.
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"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6448
diff changeset
    14
#include "landscape.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
    15
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#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
    22
#include "signs.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
    23
#include "waypoint.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2125
diff changeset
    24
#include "variables.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2662
diff changeset
    25
#include "train.h"
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6853
diff changeset
    26
#include "roadveh.h"
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7333
diff changeset
    27
#include "vehicle_gui.h"
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
    28
#include "blitter/factory.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
    30
#define VIEWPORT_DRAW_MEM (65536 * 2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
    32
ZoomLevel _saved_scrollpos_zoom;
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
    33
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
    34
/* 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
    35
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
    36
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
    37
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
    38
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
static bool _added_tile_sprite;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
static bool _offset_ground_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
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
    42
/* 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
    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
 *                    ^ 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
    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
 *                    |                          *
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
 *                 /     \                       *
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
    50
 *              /           \                    *
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
    51
 *           /                 \                 *
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
    52
 *        /                       \              *
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
    53
 *   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
    54
 */
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
    55
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    56
struct StringSpriteToDraw {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	uint16 string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	uint16 color;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    59
	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
    60
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    61
	int32 y;
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 6937
diff changeset
    62
	uint64 params[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	uint16 width;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    64
};
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    65
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    66
struct TileSpriteToDraw {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
    67
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
    68
	SpriteID pal;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    69
	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
    70
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    71
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	byte z;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    73
};
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    74
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    75
struct ChildScreenSpriteToDraw {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
    76
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
    77
	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
    78
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    79
	int32 y;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    80
	ChildScreenSpriteToDraw *next;
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    81
};
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    82
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    83
struct ParentSpriteToDraw {
7569
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    84
	SpriteID image;                 ///< sprite to draw
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    85
	SpriteID pal;                   ///< palette to use
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    86
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
    87
	int32 x;                        ///< screen X coordinate of sprite
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
    88
	int32 y;                        ///< screen Y coordinate of sprite
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
    89
7569
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    90
	int32 left;                     ///< minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    91
	int32 top;                      ///< minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    92
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    93
	int32 xmin;                     ///< minimal world X coordinate of bounding box
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    94
	int32 xmax;                     ///< maximal world X coordinate of bounding box
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    95
	int32 ymin;                     ///< minimal world Y coordinate of bounding box
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    96
	int32 ymax;                     ///< maximal world Y coordinate of bounding box
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
    97
	int zmin;                       ///< minimal world Z coordinate of bounding box
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
    98
	int zmax;                       ///< maximal world Z coordinate of bounding box
7569
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
    99
86ad3f6e7a1a (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents: 7545
diff changeset
   100
	ChildScreenSpriteToDraw *child; ///< head of child list;
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   101
	bool comparison_done;           ///< Used during sprite sorting: true if sprite has been compared with all other sprites
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   102
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
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
   104
/* 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
   105
 * to prevent a buffer overflow. */
2109
545d8173eebe (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
   106
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   107
assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(StringSpriteToDraw));
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   108
assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(TileSpriteToDraw));
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   109
assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(ChildScreenSpriteToDraw));
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   110
assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(ParentSpriteToDraw));
2109
545d8173eebe (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
   111
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   112
struct ViewportDrawer {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	DrawPixelInfo dpi;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   114
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   115
	byte *spritelist_mem;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   116
	const byte *eof_spritelist_mem;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   117
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	StringSpriteToDraw **last_string, *first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	TileSpriteToDraw **last_tile, *first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	ChildScreenSpriteToDraw **last_child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	ParentSpriteToDraw **parent_list;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   124
	ParentSpriteToDraw * const *eof_parent_list;
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
	byte combine_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	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
   129
};
0
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
static ViewportDrawer *_cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   133
TileHighlightData _thd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
static TileInfo *_cur_ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
4340
89b0ebfb7615 (svn r6041) -Fix r6040: forgot to declare a function in viewport.c
truelight
parents: 4339
diff changeset
   136
extern void SmallMapCenterOnCurrentPos(Window *w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   138
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
   139
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	Point p = RemapCoords(x, y, z);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   141
	p.x -= vp->virtual_width / 2;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   142
	p.y -= vp->virtual_height / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7078
diff changeset
   146
void InitViewports()
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7078
diff changeset
   147
{
5122
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   148
	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
   149
	_active_viewports = 0;
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   150
}
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   151
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   152
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
   153
{
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   154
	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
   155
	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
   156
	w->viewport = NULL;
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   157
}
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   158
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   159
void AssignWindowViewport(Window *w, int x, int y,
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   160
	int width, int height, uint32 follow_flags, ZoomLevel zoom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	uint32 bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
5122
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   166
	for (vp = _viewports, bit = 0; ; vp++, bit++) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   167
		assert(vp != endof(_viewports));
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   168
		if (vp->width == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	}
5122
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   170
	SETBIT(_active_viewports, bit);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	vp->left = x + w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	vp->top = y + w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	vp->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	vp->height = height;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   176
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	vp->zoom = zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
6654
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
   179
	vp->virtual_width = ScaleByZoom(width, zoom);
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
   180
	vp->virtual_height = ScaleByZoom(height, zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	if (follow_flags & 0x80000000) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   183
		const Vehicle *veh;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   184
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   185
		WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   186
		veh = GetVehicle(WP(w, vp_d).follow_vehicle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		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
   188
	} else {
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   189
		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
   190
		uint y = TileY(follow_flags) * TILE_SIZE;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   191
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   192
		WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   193
		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   196
	WP(w, vp_d).scrollpos_x = pt.x;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   197
	WP(w, vp_d).scrollpos_y = pt.y;
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
   198
	WP(w, vp_d).dest_scrollpos_x = pt.x;
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
   199
	WP(w, vp_d).dest_scrollpos_y = pt.y;
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
   200
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	w->viewport = vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	vp->virtual_left = 0;//pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	vp->virtual_top = 0;//pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
}
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
static Point _vp_move_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
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
   208
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
   209
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   210
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   211
	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
   212
		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
   213
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		if (left + width > w->left &&
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   215
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
				top + height > w->top &&
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   217
				w->top + w->height > top) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   218
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
			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
   220
				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
   221
				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
   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
			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
   226
				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
   227
				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
   228
				return;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
			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
   232
				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
   233
				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
   234
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
			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
   238
				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
   239
				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
   240
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
		int xo = _vp_move_offs.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		int yo = _vp_move_offs.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
		if (abs(xo) >= width || abs(yo) >= height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
			/* fully_outside */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   253
			RedrawScreenRect(left, top, left + width, top + height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
			return;
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
		GfxScroll(left, top, width, height, xo, yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		if (xo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
			RedrawScreenRect(left, top, xo + left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
			left += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
			width -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		} else if (xo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
			RedrawScreenRect(left+width+xo, top, left+width, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
			width += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
		if (yo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
			RedrawScreenRect(left, top, width+left, top + yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		} else if (yo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
			RedrawScreenRect(left, top + height + yo, width+left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
   276
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
   277
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	int old_left = vp->virtual_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	int old_top = vp->virtual_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	int left, top, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
	vp->virtual_left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	vp->virtual_top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   287
	old_left = UnScaleByZoom(old_left, vp->zoom);
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   288
	old_top = UnScaleByZoom(old_top, vp->zoom);
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   289
	x = UnScaleByZoom(x, vp->zoom);
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   290
	y = UnScaleByZoom(y, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
	old_left -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	old_top -= y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   295
	if (old_top == 0 && old_left == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	_vp_move_offs.x = old_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	_vp_move_offs.y = old_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	left = vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	top = vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	width = vp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	height = vp->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	if (left < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
		width += left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
		left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   310
	i = left + width - _screen.width;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   311
	if (i >= 0) width -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	if (width > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
		if (top < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
			height += top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
			top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   318
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   319
		i = top + height - _screen.height;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   320
		if (i >= 0) height -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   322
		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
   323
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   327
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
   328
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	ViewPort *vp = w->viewport;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   330
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	if (vp != NULL &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	    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
   333
			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
   334
		return vp;
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
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   339
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   340
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	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
   343
	uint z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
				(uint)(y -= vp->top) >= (uint)vp->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
				Point pt = {-1, -1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
				return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   351
	x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> 2;
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   352
	y = (ScaleByZoom(y, vp->zoom) + vp->virtual_top) >> 1;
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
	a = y-x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	b = y+x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
5014
27054c09dc66 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   357
	/* 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
   358
	 * 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
   359
	 * 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
   360
	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
   361
	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
   362
27054c09dc66 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   363
	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
   364
	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
   365
	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
   366
	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
   367
	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
   368
27054c09dc66 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   369
	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
   370
	pt.y = b + z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
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
   375
/* 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
   376
 * 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
   377
 * 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
   378
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
   379
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	Point pt;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   383
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   384
	if ( (w = FindWindowFromPt(x, y)) != NULL &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
			 (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
   386
				return TranslateXYToTileCoord(vp, zoom_x, zoom_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	pt.y = pt.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
   392
Point GetTileBelowCursor()
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
	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
   395
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
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
   397
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
   398
Point GetTileZoomCenterWindow(bool in, Window * w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	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
   401
	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
   402
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
   403
	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
   404
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2023
diff changeset
   405
	if (in) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   406
		x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   407
		y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   408
	} 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
   409
		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
   410
		y = vp->height - (_cursor.pos.y - vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	}
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
   412
	/* 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
   413
	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
   414
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
5045
846098142ffe (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   416
/** 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
   417
 * of the viewport. This will update their status and invalidate accordingly
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6427
diff changeset
   418
 * @param w Window pointer to the window that has the zoom buttons
5045
846098142ffe (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   419
 * @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
   420
 * @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
   421
 * @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
   422
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
   423
{
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   424
	SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == ZOOM_LVL_MIN);
5045
846098142ffe (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   425
	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
   426
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   427
	SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == ZOOM_LVL_MAX);
5045
846098142ffe (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   428
	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
   429
}
846098142ffe (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   430
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   431
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
   432
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	TileSpriteToDraw *ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   435
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   436
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   438
	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
   439
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   442
	ts = (TileSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	vd->spritelist_mem += sizeof(TileSpriteToDraw);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   445
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	ts->image = image;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   447
	ts->pal = pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	ts->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	ts->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	ts->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	ts->z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	*vd->last_tile = ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   453
	vd->last_tile = &ts->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   456
void DrawGroundSprite(SpriteID image, SpriteID pal)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
	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
   459
		/* 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
   460
		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
   461
	} else {
1083
8e64dc3ed29f (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   462
		_added_tile_sprite = true;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   463
		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
   464
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
void OffsetGroundSprite(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	_cur_vd->offs_x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	_cur_vd->offs_y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	_offset_ground_sprites = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   475
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
   476
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   477
	const ViewportDrawer *vd = _cur_vd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	Point pt = RemapCoords(x, y, z);
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   479
	const Sprite* spr = GetSprite(image & SPRITE_MASK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   481
	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
   482
			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
   483
			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
   484
			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
   485
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   487
	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
   488
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   490
/** Draw a (transparent) sprite at given coordinates with a given bounding box.
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   491
 * The bounding box extends from (x + bb_offset_x, y + bb_offset_y, z + bb_offset_z) to (x + w - 1, y + h - 1, z + dz - 1), both corners included.
7617
804e665b79fa (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents: 7601
diff changeset
   492
 * Bounding boxes with bb_offset_x == w or bb_offset_y == h or bb_offset_z == dz are allowed and produce thin slices.
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   493
 *
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   494
 * @note Bounding boxes are normally specified with bb_offset_x = bb_offset_y = bb_offset_z = 0. The extent of the bounding box in negative direction is
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   495
 *       defined by the sprite offset in the grf file.
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   496
 *       However if modifying the sprite offsets is not suitable (e.g. when using existing graphics), the bounding box can be tuned by bb_offset.
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   497
 *
7617
804e665b79fa (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents: 7601
diff changeset
   498
 * @pre w >= bb_offset_x, h >= bb_offset_y, dz >= bb_offset_z. Else w, h or dz are ignored.
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   499
 *
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   500
 * @param image the image to combine and draw,
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   501
 * @param pal the provided palette,
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   502
 * @param x position X (world) of the sprite,
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   503
 * @param y position Y (world) of the sprite,
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   504
 * @param w bounding box extent towards positive X (world),
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   505
 * @param h bounding box extent towards positive Y (world),
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   506
 * @param dz bounding box extent towards positive Z (world),
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   507
 * @param z position Z (world) of the sprite,
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   508
 * @param transparent if true, switch the palette between the provided palette and the transparent palette,
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   509
 * @param bb_offset_x bounding box extent towards negative X (world),
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   510
 * @param bb_offset_y bounding box extent towards negative Y (world),
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   511
 * @param bb_offset_z bounding box extent towards negative Z (world)
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   512
 */
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   513
void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	ParentSpriteToDraw *ps;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	Point pt;
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   518
	int32 left, right, top, bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   520
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   522
	/* make the sprites transparent with the right palette */
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   523
	if (transparent) {
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   524
		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   525
		pal = PALETTE_TO_TRANSPARENT;
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   526
	}
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7321
diff changeset
   527
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	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
   529
		AddCombinedSprite(image, pal, x, y, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	vd->last_child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   535
	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
   536
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   539
	ps = (ParentSpriteToDraw*)vd->spritelist_mem;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   540
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   541
	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
   542
		/* 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
   543
		 *  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
   544
		 *  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
   545
		 *  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
   546
		 * 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
   547
		 *  spots on the screen ;) */
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
   548
		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
   549
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   550
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   551
4189
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   552
	pt = RemapCoords(x, y, z);
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   553
	ps->x = pt.x;
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   554
	ps->y = pt.y;
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   555
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   556
	/* Compute screen extents of sprite */
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7580
diff changeset
   557
	if (image == SPR_EMPTY_BOUNDING_BOX) {
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   558
		left = ps->left = RemapCoords(x + w          , y + bb_offset_y, z + bb_offset_z).x;
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   559
		right           = RemapCoords(x + bb_offset_x, y + h          , z + bb_offset_z).x + 1;
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   560
		top  = ps->top  = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz         ).y;
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   561
		bottom          = RemapCoords(x + w          , y + h          , z + bb_offset_z).y + 1;
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7580
diff changeset
   562
	} else {
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7580
diff changeset
   563
		const Sprite *spr = GetSprite(image & SPRITE_MASK);
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   564
		left = ps->left = (pt.x += spr->x_offs);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   565
		right           = (pt.x +  spr->width );
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   566
		top  = ps->top  = (pt.y += spr->y_offs);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   567
		bottom          = (pt.y +  spr->height);
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7580
diff changeset
   568
	}
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   569
	if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   570
		/* Compute maximal extents of sprite and it's bounding box */
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   571
		left   = min(left  , RemapCoords(x + w          , y + bb_offset_y, z + bb_offset_z).x);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   572
		right  = max(right , RemapCoords(x + bb_offset_x, y + h          , z + bb_offset_z).x + 1);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   573
		top    = min(top   , RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz         ).y);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   574
		bottom = max(bottom, RemapCoords(x + w          , y + h          , z + bb_offset_z).y + 1);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   575
	}
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   576
	/* Do not add the sprite to the viewport, if it is outside */
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   577
	if (left   >= vd->dpi.left + vd->dpi.width ||
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   578
	    right  <= vd->dpi.left ||
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   579
	    top    >= vd->dpi.top + vd->dpi.height ||
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   580
	    bottom <= vd->dpi.top) {
4189
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   581
		return;
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   582
	}
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   583
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   584
	vd->spritelist_mem += sizeof(ParentSpriteToDraw);
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
	ps->image = image;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   587
	ps->pal = pal;
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   588
	ps->xmin = x + bb_offset_x;
7617
804e665b79fa (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents: 7601
diff changeset
   589
	ps->xmax = x + max(bb_offset_x, w) - 1;
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   590
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   591
	ps->ymin = y + bb_offset_y;
7617
804e665b79fa (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents: 7601
diff changeset
   592
	ps->ymax = y + max(bb_offset_y, h) - 1;
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   593
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   594
	ps->zmin = z + bb_offset_z;
7617
804e665b79fa (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents: 7601
diff changeset
   595
	ps->zmax = z + max(bb_offset_z, dz) - 1;
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   596
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
   597
	ps->comparison_done = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	ps->child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	vd->last_child = &ps->child;
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
	*vd->parent_list++ = ps;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   603
	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
   604
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
   606
void StartSpriteCombine()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	_cur_vd->combine_sprites = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
   611
void EndSpriteCombine()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	_cur_vd->combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   616
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
   617
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	ChildScreenSpriteToDraw *cs;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   620
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   621
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   623
	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
   624
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   627
	cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
   629
	/* If the ParentSprite was clipped by the viewport bounds, do not draw the ChildSprites either */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   630
	if (vd->last_child == NULL) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   631
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   632
	vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
	*vd->last_child = cs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	vd->last_child = &cs->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
	cs->image = image;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   638
	cs->pal = pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	cs->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
	cs->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	cs->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
/* Returns a StringSpriteToDraw */
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 6937
diff changeset
   645
void *AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	StringSpriteToDraw *ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   650
	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
   651
		DEBUG(sprite, 0, "Out of sprite memory");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   654
	ss = (StringSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
	vd->spritelist_mem += sizeof(StringSpriteToDraw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	ss->string = string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	ss->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	ss->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	ss->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	ss->params[0] = params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	ss->params[1] = params_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	ss->width = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	*vd->last_string = ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	vd->last_string = &ss->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
	return ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
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
   672
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   673
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
   674
{
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   675
	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
   676
		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
   677
	} 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
   678
		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
   679
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
static bool IsPartOfAutoLine(int px, int py)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
{
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   684
	px -= _thd.selstart.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   685
	py -= _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
   687
	switch (_thd.drawstyle) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   688
	case HT_LINE | HT_DIR_X:  return py == 0; // x direction
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   689
	case HT_LINE | HT_DIR_Y:  return px == 0; // y direction
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   690
	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
   691
	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
   692
	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
   693
	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
   694
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   697
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	/* useless, but avoids compiler warning this way */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   702
// [direction][side]
2710
44278abd3ef9 (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   703
static const int _AutorailType[6][2] = {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   704
	{ HT_DIR_X,  HT_DIR_X },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   705
	{ HT_DIR_Y,  HT_DIR_Y },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   706
	{ HT_DIR_HU, HT_DIR_HL },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   707
	{ HT_DIR_HL, HT_DIR_HU },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   708
	{ HT_DIR_VL, HT_DIR_VR },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   709
	{ HT_DIR_VR, HT_DIR_VL }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   710
};
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   711
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   712
#include "table/autorail.h"
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   713
7078
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
   714
/**
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
   715
 * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
   716
 * @param *ti TileInfo Tile that is being drawn
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
   717
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
static void DrawTileSelection(const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   720
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   721
	SpriteID pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
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
   723
	/* 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
   724
	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
   725
		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
   726
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
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
   729
	/* no selection active? */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   730
	if (_thd.drawstyle == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
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
   732
	/* Inside the inner area? */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   733
	if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) &&
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   734
			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
   735
		if (_thd.drawstyle & HT_RECT) {
1864
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   736
			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
   737
			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
   738
		} 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
   739
			/* 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
   740
			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
   741
			if (ti->tileh & SLOPE_N) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   742
				z += TILE_HEIGHT;
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   743
				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
   744
			}
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
   745
			DrawGroundSpriteAt(_cur_dpi->zoom <= ZOOM_LVL_DETAIL ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti->x, ti->y, z);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   746
		} 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
   747
			/* autorail highlight piece under cursor */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   748
			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
   749
			int offset;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   750
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   751
			assert(type <= 5);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   752
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   753
			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
   754
			if (offset >= 0) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   755
				image = SPR_AUTORAIL_BASE + offset;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   756
				pal = PAL_NONE;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   757
			} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   758
				image = SPR_AUTORAIL_BASE - offset;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   759
				pal = PALETTE_TO_RED;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   760
			}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   761
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   762
			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
   763
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   764
		} 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
   765
			/* autorail highlighting long line */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   766
			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
   767
			int offset;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   768
			uint side;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   769
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   770
			if (dir < 2) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   771
				side = 0;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   772
			} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   773
				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
   774
				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
   775
			}
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   776
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   777
			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
   778
			if (offset >= 0) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   779
				image = SPR_AUTORAIL_BASE + offset;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   780
				pal = PAL_NONE;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   781
			} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   782
				image = SPR_AUTORAIL_BASE - offset;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   783
				pal = PALETTE_TO_RED;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   784
			}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   785
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   786
			DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   787
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
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
   791
	/* 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
   792
	if (_thd.outersize.x &&
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   793
			_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
   794
			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
   795
			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
   796
		/* Draw a blue rect. */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
   797
		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
   798
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
   802
static void ViewportAddLandscape()
0
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
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
	int x, y, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	bool direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	_cur_ti = &ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
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
   811
	/* 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
   812
	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
   813
	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
   814
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
   815
	/* determine size of area */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
		Point pt = RemapCoords(x, y, 241);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
		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
   819
		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
   820
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	assert(height > 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   824
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	direction = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
		int width_cur = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
		int x_cur = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
		int y_cur = y;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   831
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
		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
   833
			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
   834
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   835
			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
   836
			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
   837
			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
   838
					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
   839
				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
   840
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   841
				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
   842
				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
   843
				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
   844
			} else {
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   845
				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
   846
				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
   847
				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
   848
				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
   849
			}
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   850
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
			x_cur -= 0x10;
5501
b4e81fd72b3a (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5475
diff changeset
   853
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
			_added_tile_sprite = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
			_offset_ground_sprites = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   856
4238
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   857
			_tile_type_procs[tt]->draw_tile_proc(&ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
			DrawTileSelection(&ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		} while (--width_cur);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   860
5501
b4e81fd72b3a (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5475
diff changeset
   861
		if ((direction ^= 1) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
			y += 0x10;
5501
b4e81fd72b3a (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5475
diff changeset
   863
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
			x += 0x10;
5501
b4e81fd72b3a (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5475
diff changeset
   865
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   866
	} while (--height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   870
static void ViewportAddTownNames(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
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
   875
	if (!HASBIT(_display_opt, DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU)
0
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) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   884
		case ZOOM_LVL_NORMAL:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   885
			FOR_ALL_TOWNS(t) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   886
				if (bottom > t->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   887
						top    < t->sign.top + 12 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   888
						right  > t->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   889
						left   < t->sign.left + t->sign.width_1) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   890
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   891
						_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   892
						t->index, t->population);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   893
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   895
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   896
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   897
		case ZOOM_LVL_OUT_2X:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   898
			right += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   899
			bottom += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   900
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   901
			FOR_ALL_TOWNS(t) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   902
				if (bottom > t->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   903
						top    < t->sign.top + 24 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   904
						right  > t->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   905
						left   < t->sign.left + t->sign.width_1*2) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   906
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   907
						_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   908
						t->index, t->population);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   909
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   910
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   911
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   912
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   913
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   914
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   915
			right += ScaleByZoom(1, dpi->zoom);
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   916
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   917
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   918
			FOR_ALL_TOWNS(t) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   919
				if (bottom > t->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   920
						top    < t->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   921
						right  > t->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   922
						left   < t->sign.left + ScaleByZoom(t->sign.width_2, dpi->zoom)) {
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   923
					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
   924
					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
   925
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   926
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   927
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   928
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   929
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
5025
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
static void AddStation(const Station *st, StringID str, uint16 width)
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
	StringSpriteToDraw *sstd;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   937
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   938
	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
   939
	if (sstd != NULL) {
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   940
		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
   941
		sstd->width = width;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   942
	}
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   943
}
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   944
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   945
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   946
static void ViewportAddStationNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	int left, top, right, bottom;
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
   949
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
   951
	if (!HASBIT(_display_opt, DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   959
	switch (dpi->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   960
		case ZOOM_LVL_NORMAL:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   961
			FOR_ALL_STATIONS(st) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   962
				if (bottom > st->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   963
						top    < st->sign.top + 12 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   964
						right  > st->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   965
						left   < st->sign.left + st->sign.width_1) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   966
					AddStation(st, STR_305C_0, st->sign.width_1);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   967
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   969
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   970
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   971
		case ZOOM_LVL_OUT_2X:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   972
			right += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   973
			bottom += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   974
			FOR_ALL_STATIONS(st) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   975
				if (bottom > st->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   976
						top    < st->sign.top + 24 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   977
						right  > st->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   978
						left   < st->sign.left + st->sign.width_1*2) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   979
					AddStation(st, STR_305C_0, st->sign.width_1);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   980
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   982
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   983
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
   984
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   985
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   986
			right += ScaleByZoom(1, dpi->zoom);
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   987
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   988
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   989
			FOR_ALL_STATIONS(st) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   990
				if (bottom > st->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   991
						top    < st->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   992
						right  > st->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   993
						left   < st->sign.left + ScaleByZoom(st->sign.width_2, dpi->zoom)) {
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   994
					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   995
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
   997
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   998
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
   999
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1003
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1004
static void AddSign(const Sign *si, StringID str, uint16 width)
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1005
{
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1006
	StringSpriteToDraw *sstd;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1007
7056
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7006
diff changeset
  1008
	sstd = (StringSpriteToDraw*)AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->index, 0);
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1009
	if (sstd != NULL) {
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1010
		sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1011
		sstd->width = width;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1012
	}
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1013
}
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1014
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1015
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1016
static void ViewportAddSigns(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
{
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1018
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
  1021
	if (!HASBIT(_display_opt, DO_SHOW_SIGNS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1029
	switch (dpi->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1030
		case ZOOM_LVL_NORMAL:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1031
			FOR_ALL_SIGNS(si) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1032
				if (bottom > si->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1033
						top    < si->sign.top + 12 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1034
						right  > si->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1035
						left   < si->sign.left + si->sign.width_1) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1036
					AddSign(si, STR_2806, si->sign.width_1);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1037
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1039
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1040
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1041
		case ZOOM_LVL_OUT_2X:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1042
			right += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1043
			bottom += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1044
			FOR_ALL_SIGNS(si) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1045
				if (bottom > si->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1046
						top    < si->sign.top + 24 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1047
						right  > si->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1048
						left   < si->sign.left + si->sign.width_1 * 2) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1049
					AddSign(si, STR_2806, si->sign.width_1);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1050
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1052
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1053
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1054
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1055
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1056
			right += ScaleByZoom(1, dpi->zoom);
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1057
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1058
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1059
			FOR_ALL_SIGNS(si) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1060
				if (bottom > si->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1061
						top    < si->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1062
						right  > si->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1063
						left   < si->sign.left + ScaleByZoom(si->sign.width_2, dpi->zoom)) {
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1064
					AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1065
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1067
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1068
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1069
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1073
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1074
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width)
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1075
{
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1076
	StringSpriteToDraw *sstd;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1077
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1078
	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
  1079
	if (sstd != NULL) {
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1080
		sstd->color = (wp->deleted ? 0xE : 11);
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1081
		sstd->width = width;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1082
	}
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1083
}
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1084
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1085
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1086
static void ViewportAddWaypoints(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
{
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1088
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
  1091
	if (!HASBIT(_display_opt, DO_WAYPOINTS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1099
	switch (dpi->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1100
		case ZOOM_LVL_NORMAL:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1101
			FOR_ALL_WAYPOINTS(wp) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1102
				if (bottom > wp->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1103
						top    < wp->sign.top + 12 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1104
						right  > wp->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1105
						left   < wp->sign.left + wp->sign.width_1) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1106
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1107
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1109
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1110
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1111
		case ZOOM_LVL_OUT_2X:
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1112
			right += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1113
			bottom += 2;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1114
			FOR_ALL_WAYPOINTS(wp) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1115
				if (bottom > wp->sign.top &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1116
						top    < wp->sign.top + 24 &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1117
						right  > wp->sign.left &&
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1118
						left   < wp->sign.left + wp->sign.width_1*2) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1119
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1120
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1122
			break;
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1123
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1124
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1125
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1126
			right += ScaleByZoom(1, dpi->zoom);
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1127
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1128
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1129
			FOR_ALL_WAYPOINTS(wp) {
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1130
				if (bottom > wp->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1131
						top    < wp->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1132
						right  > wp->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1133
						left   < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) {
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1134
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1135
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
			}
5027
8dacdfc948d3 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1137
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1138
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1139
		default: NOT_REACHED();
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
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
  1144
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	char buffer[128];
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1146
	uint w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	sign->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4885
diff changeset
  1150
	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
  1151
	w = GetStringBoundingBox(buffer).width + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	sign->width_1 = w;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1153
	sign->left = left - w / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1155
	/* 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
  1156
	_cur_fontsize = FS_SMALL;
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1157
	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
  1158
	_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
  1159
	sign->width_2 = w;
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1163
static void ViewportDrawTileSprites(TileSpriteToDraw *ts)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1164
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
		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
  1167
		DrawSprite(ts->image, ts->pal, pt.x, pt.y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1168
		ts = ts->next;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1169
	} while (ts != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1172
static void ViewportSortParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1174
	while (*psd != NULL) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1175
		ParentSpriteToDraw* ps = *psd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
  1177
		if (!ps->comparison_done) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1178
			ParentSpriteToDraw** psd2 = psd;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1179
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
  1180
			ps->comparison_done = true;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1181
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1182
			while (*++psd2 != NULL) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1183
				ParentSpriteToDraw* ps2 = *psd2;
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1184
				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
  1185
7580
fc9a8300f34e (svn r11105) -Codechange [FS#1223]: add some support for tuning of the bounding boxes for some special cases (like tunnels and bridges). Patch by frosch.
rubidium
parents: 7579
diff changeset
  1186
				if (ps2->comparison_done) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
4187
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1188
				/* 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
  1189
				 * boxes overlap
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1190
				 */
7579
b7c5cc93fb3f (svn r11104) -Fix: bounding boxes also overlap when the min of a bounding box is equal to the max of another bounding box. Patch by frosch.
rubidium
parents: 7578
diff changeset
  1191
				if (ps->xmax >= ps2->xmin && ps->xmin <= ps2->xmax && // overlap in X?
b7c5cc93fb3f (svn r11104) -Fix: bounding boxes also overlap when the min of a bounding box is equal to the max of another bounding box. Patch by frosch.
rubidium
parents: 7578
diff changeset
  1192
						ps->ymax >= ps2->ymin && ps->ymin <= ps2->ymax && // overlap in Y?
b7c5cc93fb3f (svn r11104) -Fix: bounding boxes also overlap when the min of a bounding box is equal to the max of another bounding box. Patch by frosch.
rubidium
parents: 7578
diff changeset
  1193
						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
  1194
					/* 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
  1195
					 * 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
  1196
					 * 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
  1197
					 * i.e. X=(left+right)/2, etc.
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1198
					 * 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
  1199
					 */
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1200
					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
  1201
							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
  1202
						continue;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1203
					}
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
  1204
				} else {
7578
d0b783a8a3e2 (svn r11103) -Codechange: remove pointless comparison as it can never ever be true (unless you've got at least 3 bit errors and then you're screwed anyway). Patch by frosch.
rubidium
parents: 7569
diff changeset
  1205
					/* We only change the order, if it is definite.
d0b783a8a3e2 (svn r11103) -Codechange: remove pointless comparison as it can never ever be true (unless you've got at least 3 bit errors and then you're screwed anyway). Patch by frosch.
rubidium
parents: 7569
diff changeset
  1206
					 * I.e. every single order of X, Y, Z says ps2 is behind ps or they overlap.
d0b783a8a3e2 (svn r11103) -Codechange: remove pointless comparison as it can never ever be true (unless you've got at least 3 bit errors and then you're screwed anyway). Patch by frosch.
rubidium
parents: 7569
diff changeset
  1207
					 * That is: If one partial order says ps behind ps2, do not change the order.
d0b783a8a3e2 (svn r11103) -Codechange: remove pointless comparison as it can never ever be true (unless you've got at least 3 bit errors and then you're screwed anyway). Patch by frosch.
rubidium
parents: 7569
diff changeset
  1208
					 */
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1209
					if (ps->xmax < ps2->xmin ||
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1210
							ps->ymax < ps2->ymin ||
7578
d0b783a8a3e2 (svn r11103) -Codechange: remove pointless comparison as it can never ever be true (unless you've got at least 3 bit errors and then you're screwed anyway). Patch by frosch.
rubidium
parents: 7569
diff changeset
  1211
							ps->zmax < ps2->zmin) {
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1212
						continue;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1213
					}
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
  1214
				}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1215
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
  1216
				/* 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
  1217
				psd3 = psd;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1218
				do {
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1219
					ParentSpriteToDraw* temp = *psd3;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1220
					*psd3 = ps2;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1221
					ps2 = temp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1223
					psd3++;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1224
				} while (psd3 <= psd2);
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
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
			psd++;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1232
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1234
	for (; *psd != NULL; psd++) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1235
		const ParentSpriteToDraw* ps = *psd;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1236
		const ChildScreenSpriteToDraw* cs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7580
diff changeset
  1238
		if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1240
		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
  1241
			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
  1242
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1246
/**
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1247
 * Draws the bounding boxes of all ParentSprites
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1248
 * @param psd Array of ParentSprites
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1249
 */
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1250
static void ViewportDrawBoundingBoxes(ParentSpriteToDraw *psd[])
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1251
{
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1252
	for (; *psd != NULL; psd++) {
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1253
		const ParentSpriteToDraw* ps = *psd;
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1254
		Point pt1 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmax + 1); // top front corner
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1255
		Point pt2 = RemapCoords(ps->xmin    , ps->ymax + 1, ps->zmax + 1); // top left corner
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1256
		Point pt3 = RemapCoords(ps->xmax + 1, ps->ymin    , ps->zmax + 1); // top right corner
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1257
		Point pt4 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmin    ); // bottom front corner
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1258
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1259
		DrawBox(        pt1.x,         pt1.y,
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1260
		        pt2.x - pt1.x, pt2.y - pt1.y,
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1261
		        pt3.x - pt1.x, pt3.y - pt1.y,
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1262
		        pt4.x - pt1.x, pt4.y - pt1.y);
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1263
	}
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1264
}
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1265
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1266
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	DrawPixelInfo dp;
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1269
	ZoomLevel zoom;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1270
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	_cur_dpi = &dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	dp = *dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1274
	zoom = dp.zoom;
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1275
	dp.zoom = ZOOM_LVL_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
6654
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1277
	dp.left   = UnScaleByZoom(dp.left,   zoom);
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1278
	dp.top    = UnScaleByZoom(dp.top,    zoom);
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1279
	dp.width  = UnScaleByZoom(dp.width,  zoom);
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1280
	dp.height = UnScaleByZoom(dp.height, zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	do {
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1283
		uint16 colour;
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1284
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
		if (ss->width != 0) {
6654
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1286
			int x = UnScaleByZoom(ss->x, zoom) - 1;
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1287
			int y = UnScaleByZoom(ss->y, zoom) - 1;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1288
			int bottom = y + 11;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1289
			int w = ss->width;
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
			if (w & 0x8000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
				w &= ~0x8000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
				y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
				bottom -= 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
				w -= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1298
		/* Draw the rectangle if 'tranparent station signs' is off,
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1299
		 * 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
  1300
			if (!HASBIT(_transparent_opt, TO_SIGNS) || ss->string == STR_2806) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1301
				DrawFrameRect(
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1302
					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
  1303
					HASBIT(_transparent_opt, TO_SIGNS) ? FR_TRANSPARENT : FR_NONE
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1304
				);
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
  1305
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1308
		SetDParam(0, ss->params[0]);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1309
		SetDParam(1, ss->params[1]);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1310
		/* if we didn't draw a rectangle, or if transparant building is on,
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1311
		 * draw the text in the color the rectangle would have */
6448
7a1305b9f475 (svn r9596) -Fix (r9563): (non-)transparency of station signs was confused with building transparency...
peter1138
parents: 6443
diff changeset
  1312
		if (HASBIT(_transparent_opt, TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1313
			/* Real colors need the IS_PALETTE_COLOR flag
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1314
			 * otherwise colors from _string_colormap are assumed. */
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1315
			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
  1316
		} else {
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1317
			colour = 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
		}
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1319
		DrawString(
6654
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6653
diff changeset
  1320
			UnScaleByZoom(ss->x, zoom), UnScaleByZoom(ss->y, zoom) - (ss->width & 0x8000 ? 2 : 0),
5025
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1321
			ss->string, colour
889b0b291d12 (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1322
		);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1323
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1324
		ss = ss->next;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1325
	} while (ss != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
  1328
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
  1329
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
	ViewportDrawer vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
	int mask;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1332
	int x;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1333
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
	DrawPixelInfo *old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
	byte mem[VIEWPORT_DRAW_MEM];
137
73f897e1bf4a (svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents: 133
diff changeset
  1337
	ParentSpriteToDraw *parent_list[6144];
0
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
	_cur_vd = &vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	old_dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
	_cur_dpi = &vd.dpi;
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
	vd.dpi.zoom = vp->zoom;
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1345
	mask = ScaleByZoom(-1, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
	vd.combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
	vd.dpi.width = (right - left) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
	vd.dpi.height = (bottom - top) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	vd.dpi.left = left & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
	vd.dpi.top = top & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
	vd.dpi.pitch = old_dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1355
	x = UnScaleByZoom(vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1356
	y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
  1358
	vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
	vd.parent_list = parent_list;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1361
	vd.eof_parent_list = endof(parent_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
	vd.spritelist_mem = mem;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1363
	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
  1364
	vd.last_string = &vd.first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
	vd.first_string = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
	vd.last_tile = &vd.first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
	vd.first_tile = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1368
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
	ViewportAddLandscape();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
	ViewportAddVehicles(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
	DrawTextEffects(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
	ViewportAddTownNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
	ViewportAddStationNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
	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
  1376
	ViewportAddWaypoints(&vd.dpi);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
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
  1378
	/* 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
  1379
	 *  is checked) */
979
11ea18598e16 (svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents: 926
diff changeset
  1380
	assert(vd.parent_list <= endof(parent_list));
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1381
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1382
	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
  1383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
	/* null terminate parent sprite list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
	*vd.parent_list = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
	ViewportSortParentSprites(parent_list);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	ViewportDrawParentSprites(parent_list);
7643
af32b07bc027 (svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents: 7617
diff changeset
  1389
	if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(parent_list);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1390
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1391
	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
  1392
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
	_cur_dpi = old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
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
  1396
/** 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
  1397
 * 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
  1398
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
  1399
{
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1400
	if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
		if ((bottom - top) > (right - left)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
			int t = (top + bottom) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
			ViewportDrawChk(vp, left, top, right, t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
			ViewportDrawChk(vp, left, t, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
			int t = (left + right) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
			ViewportDrawChk(vp, left, top, t, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
			ViewportDrawChk(vp, t, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1411
		ViewportDoDraw(vp,
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1412
			ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1413
			ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top,
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1414
			ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left,
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1415
			ScaleByZoom(bottom - vp->top, vp->zoom) + vp->virtual_top
0
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
	}
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
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1420
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
  1421
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1422
	if (right <= vp->left || bottom <= vp->top) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1424
	if (left >= vp->left + vp->width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
	if (left < vp->left) left = vp->left;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1427
	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
  1428
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1429
	if (top >= vp->top + vp->height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
	if (top < vp->top) top = vp->top;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1432
	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
  1433
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
	ViewportDrawChk(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1437
void DrawWindowViewport(const Window *w)
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1438
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	DrawPixelInfo *dpi = _cur_dpi;
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
	dpi->left += w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
	dpi->top += w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
	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
  1445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
	dpi->left -= w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	dpi->top -= w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
7069
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1450
static inline void ClampViewportToMap(const ViewPort *vp, int &x, int &y)
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1451
{
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1452
	/* Centre of the viewport is hot spot */
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1453
	x += vp->virtual_width / 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1454
	y += vp->virtual_height / 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1455
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1456
	/* Convert viewport coordinates to map coordinates
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1457
	 * Calculation is scaled by 4 to avoid rounding errors */
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1458
	int vx = -x + y * 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1459
	int vy =  x + y * 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1460
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1461
	/* clamp to size of map */
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1462
	vx = clamp(vx, 0, MapMaxX() * TILE_SIZE * 4);
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1463
	vy = clamp(vy, 0, MapMaxY() * TILE_SIZE * 4);
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1464
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1465
	/* Convert map coordinates to viewport coordinates */
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1466
	x = (-vx + vy) / 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1467
	y = ( vx + vy) / 4;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1468
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1469
	/* Remove centreing */
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1470
	x -= vp->virtual_width / 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1471
	y -= vp->virtual_height / 2;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1472
}
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1473
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
void UpdateViewportPosition(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1476
	const ViewPort *vp = w->viewport;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1478
	if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1479
		const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1480
		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
  1481
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
		SetViewportPosition(w, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
	} else {
7069
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1484
		/* Ensure the destination location is within the map */
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1485
		ClampViewportToMap(vp, WP(w, vp_d).dest_scrollpos_x, WP(w, vp_d).dest_scrollpos_y);
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1486
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1487
		int delta_x = WP(w, vp_d).dest_scrollpos_x - WP(w, vp_d).scrollpos_x;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1488
		int delta_y = WP(w, vp_d).dest_scrollpos_y - WP(w, vp_d).scrollpos_y;
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1489
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1490
		if (delta_x != 0 || delta_y != 0) {
6731
d018207588bb (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents: 6730
diff changeset
  1491
			if (_patches.smooth_scroll) {
d018207588bb (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents: 6730
diff changeset
  1492
				int max_scroll = ScaleByMapSize1D(512);
d018207588bb (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents: 6730
diff changeset
  1493
				/* Not at our desired positon yet... */
7069
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1494
				WP(w, vp_d).scrollpos_x += clamp(delta_x / 4, -max_scroll, max_scroll);
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1495
				WP(w, vp_d).scrollpos_y += clamp(delta_y / 4, -max_scroll, max_scroll);
6731
d018207588bb (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents: 6730
diff changeset
  1496
			} else {
7069
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1497
				WP(w, vp_d).scrollpos_x = WP(w, vp_d).dest_scrollpos_x;
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1498
				WP(w, vp_d).scrollpos_y = WP(w, vp_d).dest_scrollpos_y;
6731
d018207588bb (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents: 6730
diff changeset
  1499
			}
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1500
		}
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1501
7069
c5e067d3e3cc (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents: 7056
diff changeset
  1502
		ClampViewportToMap(vp, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1503
		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
  1504
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1507
/**
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1508
 * Marks a viewport as dirty for repaint.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1509
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1510
 * @param vp The viewport to mark as dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1511
 * @todo documents the missing parameters @c left, @c top, @c right and @c bottom
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1512
 * @todo detailed description missing
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1513
 * @ingroup dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1514
 */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1515
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
  1516
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1517
	right -= vp->virtual_left;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1518
	if (right <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1520
	bottom -= vp->virtual_top;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1521
	if (bottom <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1523
	left = max(0, left - vp->virtual_left);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1525
	if (left >= vp->virtual_width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1527
	top = max(0, top - vp->virtual_top);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1528
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1529
	if (top >= vp->virtual_height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
	SetDirtyBlocks(
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1532
		UnScaleByZoom(left, vp->zoom) + vp->left,
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1533
		UnScaleByZoom(top, vp->zoom) + vp->top,
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1534
		UnScaleByZoom(right, vp->zoom) + vp->left,
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  1535
		UnScaleByZoom(bottom, vp->zoom) + vp->top
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
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
  1540
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1541
	const ViewPort *vp = _viewports;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
	uint32 act = _active_viewports;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
		if (act & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
			assert(vp->width != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
			MarkViewportDirty(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
	} while (vp++,act>>=1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1551
void MarkTileDirtyByTile(TileIndex tile)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1552
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1553
	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
  1554
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
void MarkTileDirty(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1564
	uint z = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
	Point pt;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1566
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1567
	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
  1568
			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
  1569
		z = GetTileZ(TileVirtXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
	pt = RemapCoords(x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
	);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1578
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1580
/**
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1581
 * Marks the selected tiles as dirty.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1582
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1583
 * This function marks the selected tiles as dirty for repaint
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1584
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1585
 * @note Documentation may be wrong (Progman)
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1586
 * @ingroup dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7497
diff changeset
  1587
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  1588
static void SetSelectionTilesDirty()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
	int y_size, x_size;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1591
	int x = _thd.pos.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1592
	int y = _thd.pos.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1594
	x_size = _thd.size.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1595
	y_size = _thd.size.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1597
	if (_thd.outersize.x) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1598
		x_size += _thd.outersize.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1599
		x += _thd.offs.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1600
		y_size += _thd.outersize.y;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1601
		y += _thd.offs.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
	assert(x_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
	assert(y_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
	x_size += x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
	y_size += y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
		int y_bk = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
			MarkTileDirty(x, y);
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1614
		} while ( (y += TILE_SIZE) != y_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
		y = y_bk;
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1616
	} while ( (x += TILE_SIZE) != x_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
1990
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1620
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
  1621
{
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1622
	_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
  1623
	SetSelectionTilesDirty();
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1624
}
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1625
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1626
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1627
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
  1628
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1629
	const Town *t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
  1631
	if (!HASBIT(_display_opt, DO_SHOW_TOWN_NAMES)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1633
	switch (vp->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1634
		case ZOOM_LVL_NORMAL:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1635
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1636
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1637
			FOR_ALL_TOWNS(t) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1638
				if (y >= t->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1639
						y < t->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1640
						x >= t->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1641
						x < t->sign.left + t->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1642
					ShowTownViewWindow(t->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1643
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1644
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1646
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1647
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1648
		case ZOOM_LVL_OUT_2X:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1649
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1650
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1651
			FOR_ALL_TOWNS(t) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1652
				if (y >= t->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1653
						y < t->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1654
						x >= t->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1655
						x < t->sign.left + t->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1656
					ShowTownViewWindow(t->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1657
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1658
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1660
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1661
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1662
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1663
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1664
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1665
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1666
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1667
			FOR_ALL_TOWNS(t) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1668
				if (y >= t->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1669
						y < t->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1670
						x >= t->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1671
						x < t->sign.left + ScaleByZoom(t->sign.width_2, vp->zoom)) {
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1672
					ShowTownViewWindow(t->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1673
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1674
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1676
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1677
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1678
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1684
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1685
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
  1686
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1687
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
  1689
	if (!HASBIT(_display_opt, DO_SHOW_STATION_NAMES)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1691
	switch (vp->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1692
		case ZOOM_LVL_NORMAL:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1693
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1694
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1695
			FOR_ALL_STATIONS(st) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1696
				if (y >= st->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1697
						y < st->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1698
						x >= st->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1699
						x < st->sign.left + st->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1700
					ShowStationViewWindow(st->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1701
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1702
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1704
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1705
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1706
		case ZOOM_LVL_OUT_2X:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1707
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1708
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1709
			FOR_ALL_STATIONS(st) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1710
				if (y >= st->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1711
						y < st->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1712
						x >= st->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1713
						x < st->sign.left + st->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1714
					ShowStationViewWindow(st->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1715
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1716
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1718
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1719
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1720
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1721
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1722
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1723
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1724
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1725
			FOR_ALL_STATIONS(st) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1726
				if (y >= st->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1727
						y < st->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1728
						x >= st->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1729
						x < st->sign.left + ScaleByZoom(st->sign.width_2, vp->zoom)) {
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1730
					ShowStationViewWindow(st->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1731
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1732
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1734
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1735
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1736
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1742
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1743
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
  1744
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1745
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
  1747
	if (!HASBIT(_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
  1748
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1749
	switch (vp->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1750
		case ZOOM_LVL_NORMAL:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1751
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1752
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1753
			FOR_ALL_SIGNS(si) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1754
				if (y >= si->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1755
						y <  si->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1756
						x >= si->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1757
						x <  si->sign.left + si->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1758
					ShowRenameSignWindow(si);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1759
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1760
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1762
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1763
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1764
		case ZOOM_LVL_OUT_2X:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1765
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1766
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1767
			FOR_ALL_SIGNS(si) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1768
				if (y >= si->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1769
						y <  si->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1770
						x >= si->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1771
						x <  si->sign.left + si->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1772
					ShowRenameSignWindow(si);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1773
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1774
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1776
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1777
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1778
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1779
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1780
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1781
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1782
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1783
			FOR_ALL_SIGNS(si) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1784
				if (y >= si->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1785
						y <  si->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1786
						x >= si->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1787
						x <  si->sign.left + ScaleByZoom(si->sign.width_2, vp->zoom)) {
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1788
					ShowRenameSignWindow(si);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1789
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1790
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1792
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1793
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1794
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1800
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1801
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
  1802
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1803
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
6591
514c1a22e10e (svn r9805) -Codechange: Use HASBIT() et al for display options bits.
peter1138
parents: 6491
diff changeset
  1805
	if (!HASBIT(_display_opt, DO_WAYPOINTS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1807
	switch (vp->zoom) {
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1808
		case ZOOM_LVL_NORMAL:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1809
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1810
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1811
			FOR_ALL_WAYPOINTS(wp) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1812
				if (y >= wp->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1813
						y < wp->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1814
						x >= wp->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1815
						x < wp->sign.left + wp->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1816
					ShowRenameWaypointWindow(wp);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1817
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1818
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1820
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1821
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1822
		case ZOOM_LVL_OUT_2X:
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1823
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1824
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1825
			FOR_ALL_WAYPOINTS(wp) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1826
				if (y >= wp->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1827
						y < wp->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1828
						x >= wp->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1829
						x < wp->sign.left + wp->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1830
					ShowRenameWaypointWindow(wp);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1831
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1832
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1834
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1835
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6591
diff changeset
  1836
		case ZOOM_LVL_OUT_4X:
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1837
		case ZOOM_LVL_OUT_8X:
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1838
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1839
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1840
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1841
			FOR_ALL_WAYPOINTS(wp) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1842
				if (y >= wp->sign.top &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1843
						y < wp->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1844
						x >= wp->sign.left &&
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1845
						x < wp->sign.left + ScaleByZoom(wp->sign.width_2, vp->zoom)) {
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1846
					ShowRenameWaypointWindow(wp);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1847
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1848
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1850
			break;
6653
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1851
b20fcfed0847 (svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents: 6626
diff changeset
  1852
		default: NOT_REACHED();
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1855
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1856
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1857
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1859
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
  1860
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1861
	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
  1862
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1863
	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
  1864
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
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
  1866
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
  1867
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
  1868
{
7497
40e457c0a8ac (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7486
diff changeset
  1869
	if (!IsFrontEngine(v)) v = v->First();
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7333
diff changeset
  1870
	ShowVehicleViewWindow(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
  1871
}
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
  1872
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6853
diff changeset
  1873
static void SafeShowRoadVehViewWindow(const Vehicle *v)
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6853
diff changeset
  1874
{
7497
40e457c0a8ac (svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents: 7486
diff changeset
  1875
	if (!IsRoadVehFront(v)) v = v->First();
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7333
diff changeset
  1876
	ShowVehicleViewWindow(v);
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6853
diff changeset
  1877
}
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6853
diff changeset
  1878
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1879
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
  1880
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1881
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
  1882
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
  1883
	SafeShowTrainViewWindow,
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6853
diff changeset
  1884
	SafeShowRoadVehViewWindow,
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7333
diff changeset
  1885
	ShowVehicleViewWindow,
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7333
diff changeset
  1886
	ShowVehicleViewWindow,
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
  1887
	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
  1888
	Nop  // Disaster vehicles
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1891
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
  1892
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1893
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1895
	if (CheckClickOnTown(vp, x, y)) return;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1896
	if (CheckClickOnStation(vp, x, y)) return;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1897
	if (CheckClickOnSign(vp, x, y)) return;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1898
	if (CheckClickOnWaypoint(vp, x, y)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
	CheckClickOnLandscape(vp, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1901
	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
  1902
	if (v != NULL) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
  1903
		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
  1904
		_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
  1905
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  1908
Vehicle *CheckMouseOverVehicle()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1910
	const Window *w;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1911
	const ViewPort *vp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
	int x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
	int y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
	w = FindWindowFromPt(x, y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1917
	if (w == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
	vp = IsPtInWindowViewport(w, x, y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1920
	return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  1925
void PlaceObject()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	Window *w;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1929
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	pt = GetTileBelowCursor();
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1931
	if (pt.x == -1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1933
	if (_thd.place_mode == VHM_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
		pt.x += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
		pt.y += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
	_tile_fract_coords.x = pt.x & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	_tile_fract_coords.y = pt.y & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1941
	w = GetCallbackWnd();
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1942
	if (w != NULL) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1943
		WindowEvent e;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1944
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
		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
  1946
		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
  1947
		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
  1948
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
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
  1952
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
  1953
/* scrolls the viewport in a window to a given location */
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1954
bool ScrollWindowTo(int x , int y, Window *w, bool instant)
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
  1955
{
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
  1956
	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
  1957
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
  1958
	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1959
	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
  1960
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1961
	if (WP(w, vp_d).dest_scrollpos_x == pt.x && WP(w, vp_d).dest_scrollpos_y == pt.y)
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1962
		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
  1963
6731
d018207588bb (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents: 6730
diff changeset
  1964
	if (instant) {
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1965
		WP(w, vp_d).scrollpos_x = pt.x;
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1966
		WP(w, vp_d).scrollpos_y = pt.y;
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1967
	}
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1968
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1969
	WP(w, vp_d).dest_scrollpos_x = pt.x;
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1970
	WP(w, vp_d).dest_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
  1971
	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
  1972
}
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
  1973
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
  1974
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1975
bool ScrollMainWindowTo(int x, int y, bool instant)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
{
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
  1977
	Window *w;
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1978
	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0), instant);
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
  1979
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
  1980
	/* 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
  1981
	 *  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
  1982
	 *  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
  1983
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
  1984
	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
  1985
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
  1986
	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
  1987
	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
  1988
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
  1989
	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
  1990
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
  1991
	return res;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1995
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1996
{
6730
9311a208f8f7 (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents: 6669
diff changeset
  1997
	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, instant);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
void SetRedErrorSquare(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
	TileIndex old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
	old = _thd.redsq;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
	_thd.redsq = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
	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
  2008
		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
  2009
		if (old  != 0) MarkTileDirtyByTile(old);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2013
void SetTileSelectSize(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2015
	_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
  2016
	_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
  2017
	_thd.new_outersize.x = 0;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2018
	_thd.new_outersize.y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2021
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2022
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2023
	_thd.offs.x = ox * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2024
	_thd.offs.y = oy * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2025
	_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
  2026
	_thd.new_outersize.y = sy * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2027
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
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
  2029
/** returns the best autorail highlight type from map coordinates */
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2030
static byte GetAutorailHT(int x, int y)
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2031
{
2710
44278abd3ef9 (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
  2032
	return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF];
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2033
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
7078
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2035
/**
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2036
 * Updates tile highlighting for all cases.
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2037
 * Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2038
 * Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice,
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2039
 * Once for the old and once for the new selection.
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2040
 * _thd is TileHighlightData, found in viewport.h
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2041
 * Called by MouseLoop() in windows.cpp
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2042
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  2043
void UpdateTileSelection()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2045
	int x1;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2046
	int y1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2048
	_thd.new_drawstyle = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2050
	if (_thd.place_mode == VHM_SPECIAL) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2051
		x1 = _thd.selend.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2052
		y1 = _thd.selend.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
		if (x1 != -1) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2054
			int x2 = _thd.selstart.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2055
			int y2 = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2056
			x1 &= ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
			y1 &= ~0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2058
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6075
diff changeset
  2059
			if (x1 >= x2) Swap(x1, x2);
2898cd9417fd (svn r8841) -Fix
tron
parents: 6075
diff changeset
  2060
			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
  2061
			_thd.new_pos.x = x1;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2062
			_thd.new_pos.y = y1;
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2063
			_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
  2064
			_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
  2065
			_thd.new_drawstyle = _thd.next_drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
		}
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2067
	} else if (_thd.place_mode != VHM_NONE) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2068
		Point pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
		x1 = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
		y1 = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
		if (x1 != -1) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2072
			switch (_thd.place_mode) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2073
				case VHM_RECT:
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2074
					_thd.new_drawstyle = HT_RECT;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2075
					break;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2076
				case VHM_POINT:
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2077
					_thd.new_drawstyle = HT_POINT;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2078
					x1 += 8;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2079
					y1 += 8;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2080
					break;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2081
				case VHM_RAIL:
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2082
					_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
  2083
			}
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2084
			_thd.new_pos.x = x1 & ~0xF;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2085
			_thd.new_pos.y = y1 & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
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
  2089
	/* redraw selection */
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2090
	if (_thd.drawstyle != _thd.new_drawstyle ||
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2091
			_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
  2092
			_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y ||
7078
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2093
			_thd.outersize.x != _thd.new_outersize.x ||
521bc677ce92 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents: 7069
diff changeset
  2094
			_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
  2095
		/* clear the old selection? */
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2096
		if (_thd.drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2098
		_thd.drawstyle = _thd.new_drawstyle;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2099
		_thd.pos = _thd.new_pos;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2100
		_thd.size = _thd.new_size;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2101
		_thd.outersize = _thd.new_outersize;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2102
		_thd.dirty = 0xff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
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
  2104
		/* draw the new selection? */
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2105
		if (_thd.new_drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
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
  2109
/** highlighting tiles while only going over them with the mouse */
6669
bb48a810a509 (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents: 6654
diff changeset
  2110
void VpStartPlaceSizing(TileIndex tile, byte method, byte process)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
{
6669
bb48a810a509 (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents: 6654
diff changeset
  2112
	_thd.select_method = method;
bb48a810a509 (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents: 6654
diff changeset
  2113
	_thd.select_proc   = process;
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2114
	_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
  2115
	_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
  2116
	_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
  2117
	_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
  2118
	if (_thd.place_mode == VHM_RECT) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2119
		_thd.place_mode = VHM_SPECIAL;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2120
		_thd.next_drawstyle = HT_RECT;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2121
	} 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
  2122
		_thd.place_mode = VHM_SPECIAL;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2123
		_thd.next_drawstyle = _thd.drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2124
	} else {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2125
		_thd.place_mode = VHM_SPECIAL;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2126
		_thd.next_drawstyle = HT_POINT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
	_special_mouse_mode = WSM_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
void VpSetPlaceSizingLimit(int limit)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
	_thd.sizelimit = limit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2136
/**
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2137
* 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
  2138
* @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
  2139
* @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
  2140
void VpSetPresizeRange(TileIndex from, TileIndex to)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
{
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 6937
diff changeset
  2142
	uint64 distance = DistanceManhattan(from, to) + 1;
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2143
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2144
	_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
  2145
	_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
  2146
	_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
  2147
	_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
  2148
	_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
  2149
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2150
	/* 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
  2151
	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
  2152
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2153
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  2154
static void VpStartPreSizing()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2155
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2156
	_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2157
	_special_mouse_mode = WSM_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
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
  2160
/** returns information about the 2x1 piece to be build.
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2161
 * The lower bits (0-3) are the track type. */
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2162
static byte Check2x1AutoRail(int mode)
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2163
{
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2164
	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
  2165
	int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF);
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2166
	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
  2167
	int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF);
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2168
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
  2169
	switch (mode) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2170
	case 0: // end piece is lower right
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2171
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2172
		if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2173
		return 1;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2174
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2175
	case 1:
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2176
		if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2177
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2178
		return 1;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2179
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2180
	case 2:
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2181
		if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2182
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2183
		return 0;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2184
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2185
	case 3:
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2186
		if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2187
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2188
		return 0;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2189
	}
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2190
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2191
	return 0; // avoids compiler warnings
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2192
}
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2193
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2194
/** 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
  2195
 * 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
  2196
 * 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
  2197
 * 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
  2198
 * 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
  2199
 * 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
  2200
 * the return value signifies.
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2201
 * @param style HighLightStyle dragging style
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2202
 * @param start_tile start tile of drag
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2203
 * @param end_tile end tile of drag
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6453
diff changeset
  2204
 * @return boolean value which when true means start/end should be swapped */
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2205
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
  2206
{
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2207
	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
  2208
	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
  2209
	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
  2210
	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
  2211
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2212
	switch (style & HT_DRAG_MASK) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2213
		case HT_RAIL:
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2214
		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
  2215
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2216
		case HT_RECT:
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2217
		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
  2218
		default: NOT_REACHED();
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2219
	}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2220
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2221
	return false;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2222
}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2223
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2224
/** 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
  2225
* 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
  2226
* 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
  2227
* 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
  2228
* autorail tool that starts in bottom and ends at the top of a tile will need the
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6484
diff changeset
  2229
* maximum of SW, S and SE, N corners respectively. This is handled by the lookup table below
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2230
* 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
  2231
* the values yourself.
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2232
* @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
  2233
* @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
  2234
*        ignored for others
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2235
* @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
  2236
* @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
  2237
* this value in its tooltips */
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2238
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
  2239
{
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2240
	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
  2241
	byte style_t;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2242
	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
  2243
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2244
	if (start_tile == end_tile) return 0;
5733
388bb9dcb79b (svn r8276) -Fix
tron
parents: 5673
diff changeset
  2245
	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
  2246
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2247
	switch (style & HT_DRAG_MASK) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2248
		case HT_RECT: {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2249
			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
  2250
				/* 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
  2251
				/* 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
  2252
			};
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2253
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2254
			/* 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
  2255
			 * 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
  2256
			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
  2257
			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
  2258
			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
  2259
		}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2260
		/* Fallthrough */
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2261
		case HT_POINT:
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2262
			h0 = TileHeight(start_tile);
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2263
			h1 = TileHeight(end_tile);
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2264
			break;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2265
		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
  2266
			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
  2267
				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
  2268
			};
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2269
			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
  2270
				/* 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
  2271
				/* 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
  2272
				/* 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
  2273
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2274
				/* 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
  2275
				/* 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
  2276
				/* 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
  2277
			};
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2278
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2279
			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
  2280
			style &= HT_DIR_MASK;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2281
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2282
			/* 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
  2283
			 * 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
  2284
			 * 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
  2285
			 * 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
  2286
			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
  2287
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2288
			/* 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
  2289
			style_t = style * 2;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2290
			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
  2291
			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
  2292
			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
  2293
			h0 = max(h0, ht);
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2294
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2295
			/* 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
  2296
			 * 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
  2297
			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
  2298
			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
  2299
			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
  2300
			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
  2301
			h1 = max(h1, ht);
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2302
		} break;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2303
	}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2304
5733
388bb9dcb79b (svn r8276) -Fix
tron
parents: 5673
diff changeset
  2305
	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
  2306
	/* 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
  2307
	return (int)(h1 - h0) * 50;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2308
}
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2309
4885
19e116dc240f (svn r6822) -Fix r6821: add type for measure_strings_length[]
glx
parents: 4884
diff changeset
  2310
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
  2311
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
  2312
/** while dragging */
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2313
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
  2314
{
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2315
	HighLightStyle b;
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2316
	uint w, h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2317
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2318
	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
  2319
	int dy = thd->selstart.y - (thd->selend.y & ~0xF);
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2320
	w = myabs(dx) + 16;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2321
	h = myabs(dy) + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2322
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2323
	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
  2324
		if (method == VPM_RAILDIRS) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2325
			b = GetAutorailHT(x, y);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2326
		} else { // rect for autosignals on one tile
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2327
			b = HT_RECT;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2328
		}
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2329
	} 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
  2330
		if (dx == 16) { // 2x1 special handling
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2331
			b = (Check2x1AutoRail(3)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2332
		} else if (dx == -16) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2333
			b = (Check2x1AutoRail(2)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2334
		} else {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2335
			b = HT_LINE | HT_DIR_X;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2336
		}
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2337
		y = thd->selstart.y;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2338
	} else if (w == 16) { // Or Y direction?
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2339
		if (dy == 16) { // 2x1 special handling
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2340
			b = (Check2x1AutoRail(1)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2341
		} else if (dy == -16) { // 2x1 other direction
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2342
			b = (Check2x1AutoRail(0)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2343
		} else {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2344
			b = HT_LINE | HT_DIR_Y;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2345
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2346
		x = thd->selstart.x;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2347
	} else if (w > h * 2) { // still count as x dir?
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2348
		b = HT_LINE | HT_DIR_X;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2349
		y = thd->selstart.y;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2350
	} else if (h > w * 2) { // still count as y dir?
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2351
		b = HT_LINE | HT_DIR_Y;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2352
		x = thd->selstart.x;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2353
	} else { // complicated direction
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2354
		int d = w - h;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2355
		thd->selend.x = thd->selend.x & ~0xF;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2356
		thd->selend.y = thd->selend.y & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2358
		// four cases.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2359
		if (x > thd->selstart.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2360
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2361
				// south
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2362
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2363
					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
  2364
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2365
					x = thd->selstart.x + h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2366
					b = HT_LINE | HT_DIR_VL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2367
					// return px == py || px == py + 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2368
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2369
					y = thd->selstart.y + w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2370
					b = HT_LINE | HT_DIR_VR;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2371
				} // return px == py || px == py - 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2372
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2373
				// west
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2374
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2375
					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
  2376
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2377
					x = thd->selstart.x + h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2378
					b = HT_LINE | HT_DIR_HL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2379
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2380
					y = thd->selstart.y - w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2381
					b = HT_LINE | HT_DIR_HU;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2382
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2383
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2384
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2385
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2386
				// east
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2387
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2388
					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
  2389
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2390
					x = thd->selstart.x - h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2391
					b = HT_LINE | HT_DIR_HU;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2392
					// return px == -py || px == -py - 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2393
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2394
					y = thd->selstart.y + w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2395
					b = HT_LINE | HT_DIR_HL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2396
				} // return px == -py || px == -py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2397
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2398
				// north
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2399
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2400
					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
  2401
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2402
					x = thd->selstart.x - h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2403
					b = HT_LINE | HT_DIR_VR;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2404
					// return px == py || px == py - 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2405
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2406
					y = thd->selstart.y - w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2407
					b = HT_LINE | HT_DIR_VL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2408
				} //return px == py || px == py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2409
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2410
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2411
	}
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2412
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2413
	if (_patches.measure_tooltip) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2414
		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
  2415
		TileIndex t1 = TileVirtXY(x, y);
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2416
		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
  2417
		byte index = 0;
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 6937
diff changeset
  2418
		uint64 params[2];
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2419
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2420
		if (distance != 1) {
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2421
			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
  2422
			/* 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
  2423
			 * 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
  2424
			 * 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
  2425
			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
  2426
				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
  2427
			}
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2428
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2429
			params[index++] = distance;
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2430
			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
  2431
		}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2432
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2433
		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
  2434
	}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2435
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2436
	thd->selend.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2437
	thd->selend.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2438
	thd->next_drawstyle = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2439
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2440
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2441
/**
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2442
 * Selects tiles while dragging
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2443
 * @param x X coordinate of end of selection
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2444
 * @param y Y coordinate of end of selection
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2445
 * @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
  2446
 * methods are VPM_* in viewport.h */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2447
void VpSelectTilesWithMethod(int x, int y, int method)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2448
{
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2449
	int sx, sy;
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2450
	HighLightStyle style;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2451
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2452
	if (x == -1) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2453
		_thd.selend.x = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2454
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2455
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2456
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2457
	/* 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
  2458
	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
  2459
		_thd.selend.x = x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2460
		_thd.selend.y = y;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2461
		CalcRaildirsDrawstyle(&_thd, x, y, method);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2462
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2463
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2464
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2465
	if (_thd.next_drawstyle == HT_POINT) {
4799
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2466
		x += TILE_SIZE / 2;
20311e38bedf (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2467
		y += TILE_SIZE / 2;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2468
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2469
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2470
	sx = _thd.selstart.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2471
	sy = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2472
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2473
	switch (method) {
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2474
		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
  2475
			if (myabs(sy - y) < myabs(sx - x)) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2476
				y = sy;
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2477
				style = HT_DIR_X;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2478
			} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2479
				x = sx;
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2480
				style = HT_DIR_Y;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2481
			}
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2482
			goto calc_heightdiff_single_direction;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2483
		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
  2484
			x = sx;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2485
			style = HT_DIR_Y;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2486
			goto calc_heightdiff_single_direction;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2487
		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
  2488
			y = sy;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2489
			style = HT_DIR_X;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2490
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2491
calc_heightdiff_single_direction:;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2492
			if (_patches.measure_tooltip) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2493
				TileIndex t0 = TileVirtXY(sx, sy);
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2494
				TileIndex t1 = TileVirtXY(x, y);
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2495
				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
  2496
				byte index = 0;
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 6937
diff changeset
  2497
				uint64 params[2];
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2498
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2499
				if (distance != 1) {
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2500
					/* 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
  2501
					 * 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
  2502
					 * 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
  2503
					 * 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
  2504
					 * 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
  2505
					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
  2506
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2507
					params[index++] = distance;
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2508
					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
  2509
				}
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2510
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2511
				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
  2512
			} break;
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2513
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2514
		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
  2515
			int limit = (_thd.sizelimit - 1) * TILE_SIZE;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2516
			x = sx + clamp(x - sx, -limit, limit);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2517
			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
  2518
			} /* Fallthrough */
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2519
		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
  2520
			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
  2521
				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
  2522
					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
  2523
				};
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2524
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2525
				TileIndex t0 = TileVirtXY(sx, sy);
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2526
				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
  2527
				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
  2528
				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
  2529
				byte index = 0;
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 6937
diff changeset
  2530
				uint64 params[3];
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2531
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2532
				/* 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
  2533
				 * 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
  2534
				style = _thd.next_drawstyle;
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2535
				if (style & HT_RECT) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2536
					if (dx == 1) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2537
						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
  2538
					} else if (dy == 1) {
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2539
						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
  2540
					}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2541
				}
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2542
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2543
				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
  2544
					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
  2545
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2546
					params[index++] = dx;
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2547
					params[index++] = dy;
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2548
					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
  2549
				}
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2550
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2551
				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
  2552
			}
4884
94dd5df0d584 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2553
		break;
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2554
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2555
		}
4834
3c6e8a547174 (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2556
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2557
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2558
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2559
	_thd.selend.x = x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2560
	_thd.selend.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2561
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2562
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
  2563
/** while dragging */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  2564
bool VpHandlePlaceSizingDrag()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2565
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2566
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2567
	WindowEvent e;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2568
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2569
	if (_special_mouse_mode != WSM_SIZING) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2570
6669
bb48a810a509 (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents: 6654
diff changeset
  2571
	e.we.place.select_method = _thd.select_method;
bb48a810a509 (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents: 6654
diff changeset
  2572
	e.we.place.select_proc   = _thd.select_proc;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2573
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
  2574
	/* stop drag mode if the window has been closed */
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6484
diff changeset
  2575
	w = FindWindowById(_thd.window_class, _thd.window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2576
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2577
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2578
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2579
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2580
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
  2581
	/* 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
  2582
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2583
		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
  2584
		e.we.place.pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2585
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2586
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2587
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2588
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
  2589
	/* 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
  2590
	 * 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
  2591
	_special_mouse_mode = WSM_NONE;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2592
	if (_thd.next_drawstyle == HT_RECT) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2593
		_thd.place_mode = VHM_RECT;
6669
bb48a810a509 (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents: 6654
diff changeset
  2594
	} else if (e.we.place.select_method == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2595
		_thd.place_mode = VHM_RECT;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2596
	} else if (_thd.next_drawstyle & HT_LINE) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2597
		_thd.place_mode = VHM_RAIL;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2598
	} else if (_thd.next_drawstyle & HT_RAIL) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2599
		_thd.place_mode = VHM_RAIL;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2600
	} else {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2601
		_thd.place_mode = VHM_POINT;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2602
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2603
	SetTileSelectSize(1, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2604
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
  2605
	/* and call the mouseup event. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2606
	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
  2607
	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
  2608
	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
  2609
	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
  2610
	w->wndproc(w, &e);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2611
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2612
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2613
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2614
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
  2615
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
  2616
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
  2617
	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
  2618
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2620
#include "table/animcursors.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2621
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
  2622
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
  2623
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2624
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2625
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
  2626
	/* undo clicking on button */
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2627
	if (_thd.place_mode != 0) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2628
		_thd.place_mode = 0;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2629
		w = FindWindowById(_thd.window_class, _thd.window_number);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2630
		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
  2631
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2632
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2633
	SetTileSelectSize(1, 1);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2634
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2635
	_thd.make_square_red = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2636
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2637
	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
  2638
		mode = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2639
		_special_mouse_mode = WSM_DRAGDROP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2640
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2641
		_special_mouse_mode = WSM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2642
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2644
	_thd.place_mode = mode;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2645
	_thd.window_class = window_class;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2646
	_thd.window_number = window_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2648
	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
  2649
		VpStartPreSizing();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2650
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2651
	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
  2652
		SetAnimatedMouseCursor(_animcursors[~icon]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2653
	else
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5602
diff changeset
  2654
		SetMouseCursor(icon, pal);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2655
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2656
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
  2657
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
  2658
{
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5733
diff changeset
  2659
	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
  2660
}