src/viewport.cpp
author richk
Tue, 17 Jun 2008 13:22:13 +0000
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
permissions -rw-r--r--
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
     3
/** @file viewport.cpp Handling of all viewports.
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
     4
 *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
     5
 * \verbatim
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
     6
 * The in-game coordinate system looks like this *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
     7
 *                                               *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
     8
 *                    ^ Z                        *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
     9
 *                    |                          *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    10
 *                    |                          *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    11
 *                    |                          *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    12
 *                    |                          *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    13
 *                 /     \                       *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    14
 *              /           \                    *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    15
 *           /                 \                 *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    16
 *        /                       \              *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    17
 *   X <                             > Y         *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    18
 * \endverbatim
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    19
 */
6443
b8f06d8eb7be (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: 6432
diff changeset
    20
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1864
diff changeset
    22
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1172
diff changeset
    23
#include "debug.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    24
#include "tile_cmd.h"
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
    25
#include "gui.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1309
diff changeset
    26
#include "spritecache.h"
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
    27
#include "landscape.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    28
#include "viewport_func.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    29
#include "station_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
#include "town.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    31
#include "signs_base.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    32
#include "signs_func.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
    33
#include "waypoint.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2125
diff changeset
    34
#include "variables.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2662
diff changeset
    35
#include "train.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    36
#include "roadveh.h"
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
    37
#include "vehicle_gui.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    38
#include "blitter/factory.hpp"
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
    39
#include "newgrf_fsmports.h"
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    40
#include "transparency.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    41
#include "strings_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    42
#include "zoom_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    43
#include "vehicle_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    44
#include "player_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    45
#include "settings_type.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    46
#include "station_func.h"
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
    47
#include "core/alloc_type.hpp"
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
    48
#include "misc/smallvec.h"
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
    49
#include "window_func.h"
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
    50
#include "tilehighlight_func.h"
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
    51
#include "window_gui.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    52
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    53
#include "table/sprites.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    54
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    56
PlaceProc *_place_proc;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    57
Point _tile_fract_coords;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
    58
ZoomLevel _saved_scrollpos_zoom;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
    59
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    60
struct StringSpriteToDraw {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	uint16 string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	uint16 color;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    63
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    64
	int32 y;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    65
	uint64 params[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	uint16 width;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    67
};
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    68
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    69
struct TileSpriteToDraw {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
    70
	SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
    71
	SpriteID pal;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    72
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    73
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    74
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	byte z;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    76
};
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    77
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    78
struct ChildScreenSpriteToDraw {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
    79
	SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
    80
	SpriteID pal;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    81
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    82
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    83
	int32 y;
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
    84
	int next;                       ///< next child to draw (-1 at the end)
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    85
};
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    86
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    87
struct ParentSpriteToDraw {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    88
	SpriteID image;                 ///< sprite to draw
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    89
	SpriteID pal;                   ///< palette to use
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    90
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    91
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    92
	int32 x;                        ///< screen X coordinate of sprite
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    93
	int32 y;                        ///< screen Y coordinate of sprite
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    94
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    95
	int32 left;                     ///< minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    96
	int32 top;                      ///< minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    97
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    98
	int32 xmin;                     ///< minimal world X coordinate of bounding box
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    99
	int32 xmax;                     ///< maximal world X coordinate of bounding box
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   100
	int32 ymin;                     ///< minimal world Y coordinate of bounding box
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   101
	int32 ymax;                     ///< maximal world Y coordinate of bounding box
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   102
	int zmin;                       ///< minimal world Z coordinate of bounding box
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   103
	int zmax;                       ///< maximal world Z coordinate of bounding box
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   104
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   105
	int first_child;                ///< the first child to draw.
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   106
	bool comparison_done;           ///< Used during sprite sorting: true if sprite has been compared with all other sprites
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   107
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   109
/* Enumeration of multi-part foundations */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   110
enum FoundationPart {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   111
	FOUNDATION_PART_NONE     = 0xFF,  ///< Neither foundation nor groundsprite drawn yet.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   112
	FOUNDATION_PART_NORMAL   = 0,     ///< First part (normal foundation or no foundation)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   113
	FOUNDATION_PART_HALFTILE = 1,     ///< Second part (halftile foundation)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   114
	FOUNDATION_PART_END
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   115
};
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   116
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   117
typedef SmallVector<TileSpriteToDraw, 64> TileSpriteToDrawVector;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   118
typedef SmallVector<StringSpriteToDraw, 4> StringSpriteToDrawVector;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   119
typedef SmallVector<ParentSpriteToDraw, 64> ParentSpriteToDrawVector;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   120
typedef SmallVector<ParentSpriteToDraw*, 64> ParentSpriteToSortVector;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   121
typedef SmallVector<ChildScreenSpriteToDraw, 16> ChildScreenSpriteToDrawVector;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   122
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   123
struct ViewportDrawer {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	DrawPixelInfo dpi;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   125
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   126
	StringSpriteToDrawVector string_sprites_to_draw;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   127
	TileSpriteToDrawVector tile_sprites_to_draw;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   128
	ParentSpriteToDrawVector parent_sprites_to_draw;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   129
	ParentSpriteToSortVector parent_sprites_to_sort;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   130
	ChildScreenSpriteToDrawVector child_screen_sprites_to_draw;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   131
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   132
	int *last_child;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	byte combine_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   136
	int foundation[FOUNDATION_PART_END];             ///< Foundation sprites (index into parent_sprites_to_draw).
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   137
	FoundationPart foundation_part;                  ///< Currently active foundation for ground sprite drawing.
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   138
	int *last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw)
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   139
	Point foundation_offset[FOUNDATION_PART_END];    ///< Pixeloffset for ground sprites on the foundations.
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   140
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   142
static ViewportDrawer _vd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   144
TileHighlightData _thd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
static TileInfo *_cur_ti;
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
   146
bool _draw_bounding_boxes = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   148
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
   149
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	Point p = RemapCoords(x, y, z);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   151
	p.x -= vp->virtual_width / 2;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   152
	p.y -= vp->virtual_height / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   156
void DeleteWindowViewport(Window *w)
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   157
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   158
	free(w->viewport);
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   159
	w->viewport = NULL;
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   160
}
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5120
diff changeset
   161
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   162
/**
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   163
 * Initialize viewport of the window for use.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   164
 * @param w Window to use/display the viewport in
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   165
 * @param x Offset of left edge of viewport with respect to left edge window \a w
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   166
 * @param y Offset of top edge of viewport with respect to top edge window \a w
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   167
 * @param width Width of the viewport
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   168
 * @param height Height of the viewport
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   169
 * @param follow_flags Flags controlling the viewport.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   170
 *        - If bit 31 is set, the lower 16 bits are the vehicle that the viewport should follow.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   171
 *        - If bit 31 is clear, it is a tile position.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   172
 * @param zoom Zoomlevel to display
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   173
 */
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   174
void InitializeWindowViewport(Window *w, int x, int y,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   175
	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
   176
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
   177
	assert(w->viewport == NULL);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
   178
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   179
	ViewportData *vp = CallocT<ViewportData>(1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	vp->left = x + w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	vp->top = y + w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	vp->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	vp->height = height;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   185
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	vp->zoom = zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   188
	vp->virtual_width = ScaleByZoom(width, zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   189
	vp->virtual_height = ScaleByZoom(height, zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
   191
	Point pt;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
   192
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
	if (follow_flags & 0x80000000) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   194
		const Vehicle *veh;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   195
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   196
		vp->follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   197
		veh = GetVehicle(vp->follow_vehicle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
		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
   199
	} else {
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   200
		uint x = TileX(follow_flags) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   201
		uint y = TileY(follow_flags) * TILE_SIZE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   202
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   203
		vp->follow_vehicle = INVALID_VEHICLE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   204
		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
0
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
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   207
	vp->scrollpos_x = pt.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   208
	vp->scrollpos_y = pt.y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   209
	vp->dest_scrollpos_x = pt.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   210
	vp->dest_scrollpos_y = pt.y;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   211
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	w->viewport = vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	vp->virtual_left = 0;//pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	vp->virtual_top = 0;//pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
static Point _vp_move_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5124
diff changeset
   219
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
   220
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   221
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   222
	for (; wz != _last_z_window; wz++) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   223
		const Window *w = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   224
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
		if (left + width > w->left &&
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   226
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
				top + height > w->top &&
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   228
				w->top + w->height > top) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   229
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
			if (left < w->left) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   231
				DoSetViewportPosition(wz, left, top, w->left - left, height);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   232
				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
   233
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			if (left + width > w->left + w->width) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   237
				DoSetViewportPosition(wz, left, top, (w->left + w->width - left), height);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   238
				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
   239
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
			if (top < w->top) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   243
				DoSetViewportPosition(wz, left, top, width, (w->top - top));
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   244
				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
   245
				return;
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
			if (top + height > w->top + w->height) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   249
				DoSetViewportPosition(wz, left, top, width, (w->top + w->height - top));
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   250
				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
   251
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
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
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
		int xo = _vp_move_offs.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		int yo = _vp_move_offs.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
		if (abs(xo) >= width || abs(yo) >= height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
			/* fully_outside */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   264
			RedrawScreenRect(left, top, left + width, top + height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
			return;
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
		GfxScroll(left, top, width, height, xo, yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		if (xo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
			RedrawScreenRect(left, top, xo + left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
			left += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
			width -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		} else if (xo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
			RedrawScreenRect(left+width+xo, top, left+width, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
			width += xo;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		if (yo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
			RedrawScreenRect(left, top, width+left, top + yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		} else if (yo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
			RedrawScreenRect(left, top + height + yo, width+left, top + 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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
   287
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
   288
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	int old_left = vp->virtual_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	int old_top = vp->virtual_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	int left, top, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	vp->virtual_left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	vp->virtual_top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   298
	/* viewport is bound to its left top corner, so it must be rounded down (UnScaleByZoomLower)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   299
	 * else glitch described in FS#1412 will happen (offset by 1 pixel with zoom level > NORMAL)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   300
	 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   301
	old_left = UnScaleByZoomLower(old_left, vp->zoom);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   302
	old_top = UnScaleByZoomLower(old_top, vp->zoom);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   303
	x = UnScaleByZoomLower(x, vp->zoom);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   304
	y = UnScaleByZoomLower(y, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	old_left -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	old_top -= y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   309
	if (old_top == 0 && old_left == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	_vp_move_offs.x = old_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	_vp_move_offs.y = old_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	left = vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	top = vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	width = vp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	height = vp->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	if (left < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
		width += left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
		left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   324
	i = left + width - _screen.width;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   325
	if (i >= 0) width -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	if (width > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
		if (top < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			height += top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
			top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   332
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   333
		i = top + height - _screen.height;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   334
		if (i >= 0) height -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   336
		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
   337
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   340
/**
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   341
 * Is a xy position inside the viewport of the window?
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   342
 * @param w Window to examine its viewport
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   343
 * @param x X coordinate of the xy position
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   344
 * @param y Y coordinate of the xy position
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   345
 * @return Pointer to the viewport if the xy position is in the viewport of the window,
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   346
 *         otherwise \c NULL is returned.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   347
 */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   348
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
   349
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	ViewPort *vp = w->viewport;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   351
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	if (vp != NULL &&
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   353
			IsInsideMM(x, vp->left, vp->left + vp->width) &&
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   354
			IsInsideMM(y, vp->top, vp->top + vp->height))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
		return vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   360
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   361
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	int a,b;
5014
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   364
	uint z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
				(uint)(y -= vp->top) >= (uint)vp->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
				Point pt = {-1, -1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
				return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   372
	x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> 2;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   373
	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
   374
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	a = y-x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	b = y+x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
5014
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   378
	/* we need to move variables in to the valid range, as the
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   379
	 * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   380
	 * when the user tries to zoom out along the sides of the map */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   381
	a = Clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   382
	b = Clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   383
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   384
	/* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   385
	 * Now find the Z-world coordinate by fix point iteration.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   386
	 * This is a bit tricky because the tile height is non-continuous at foundations.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   387
	 * The clicked point should be approached from the back, otherwise there are regions that are not clickable.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   388
	 * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   389
	 * So give it a z-malus of 4 in the first iterations.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   390
	 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   391
	z = 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   392
	for (int i = 0; i < 5; i++) z = GetSlopeZ(a + max(z, 4u) - 4, b + max(z, 4u) - 4) / 2;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   393
	for (uint malus = 3; malus > 0; malus--) z = GetSlopeZ(a + max(z, malus) - malus, b + max(z, malus) - malus) / 2;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   394
	for (int i = 0; i < 5; i++) z = GetSlopeZ(a + z, b + z) / 2;
5014
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   395
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   396
	pt.x = a + z;
aaa61af89635 (svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents: 4912
diff changeset
   397
	pt.y = b + z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   402
/* When used for zooming, check area below current coordinates (x,y)
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   403
 * and return the tile of the zoomed out/in position (zoom_x, zoom_y)
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   404
 * when you just want the tile, make x = zoom_x and y = zoom_y */
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   405
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
   406
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	Point pt;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   410
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   411
	if ( (w = FindWindowFromPt(x, y)) != NULL &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			 (vp = IsPtInWindowViewport(w, x, y)) != NULL)
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   413
				return TranslateXYToTileCoord(vp, zoom_x, zoom_y);
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
	pt.y = pt.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
   419
Point GetTileBelowCursor()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
{
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   421
	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
   422
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
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
   424
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
   425
Point GetTileZoomCenterWindow(bool in, Window * w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	int x, y;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
   428
	ViewPort *vp = w->viewport;
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
   429
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2023
diff changeset
   430
	if (in) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   431
		x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   432
		y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   433
	} 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
   434
		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
   435
		y = vp->height - (_cursor.pos.y - vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
	}
981
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   437
	/* Get the tile below the cursor and center on the zoomed-out center */
25c7b445dcb8 (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   438
	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
   439
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
5045
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   441
/** Update the status of the zoom-buttons according to the zoom-level
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   442
 * of the viewport. This will update their status and invalidate accordingly
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   443
 * @param w Window pointer to the window that has the zoom buttons
5045
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   444
 * @param vp pointer to the viewport whose zoom-level the buttons represent
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   445
 * @param widget_zoom_in widget index for window with zoom-in button
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   446
 * @param widget_zoom_out widget index for window with zoom-out button */
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   447
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   448
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   449
	w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == ZOOM_LVL_MIN);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   450
	w->InvalidateWidget(widget_zoom_in);
5045
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   451
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   452
	w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == ZOOM_LVL_MAX);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   453
	w->InvalidateWidget(widget_zoom_out);
5045
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   454
}
3e734e178dae (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5027
diff changeset
   455
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   456
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   457
 * Draws a ground sprite at a specific world-coordinate.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   458
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   459
 * @param image the image to draw.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   460
 * @param pal the provided palette.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   461
 * @param x position x of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   462
 * @param y position y of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   463
 * @param z position z of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   464
 * @param sub Only draw a part of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   465
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   466
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   467
void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
{
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   469
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   471
	TileSpriteToDraw *ts = _vd.tile_sprites_to_draw.Append();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	ts->image = image;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
   473
	ts->pal = pal;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   474
	ts->sub = sub;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
	ts->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	ts->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	ts->z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   480
/**
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   481
 * Adds a child sprite to the active foundation.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   482
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   483
 * The pixel offset of the sprite relative to the ParentSprite is the sum of the offset passed to OffsetGroundSprite() and extra_offs_?.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   484
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   485
 * @param image the image to draw.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   486
 * @param pal the provided palette.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   487
 * @param sub Only draw a part of the sprite.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   488
 * @param foundation_part Foundation part.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   489
 * @param extra_offs_x Pixel X offset for the sprite position.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   490
 * @param extra_offs_y Pixel Y offset for the sprite position.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   491
 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   492
static void AddChildSpriteToFoundation(SpriteID image, SpriteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   493
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   494
	assert(IsInsideMM(foundation_part, 0, FOUNDATION_PART_END));
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   495
	assert(_vd.foundation[foundation_part] != -1);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   496
	Point offs = _vd.foundation_offset[foundation_part];
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   497
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   498
	/* Change the active ChildSprite list to the one of the foundation */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   499
	int *old_child = _vd.last_child;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   500
	_vd.last_child = _vd.last_foundation_child[foundation_part];
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   501
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   502
	AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y, false, sub);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   503
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   504
	/* Switch back to last ChildSprite list */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   505
	_vd.last_child = old_child;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   506
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   507
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   508
/**
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   509
 * Draws a ground sprite for the current tile.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   510
 * If the current tile is drawn on top of a foundation the sprite is added as child sprite to the "foundation"-ParentSprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   511
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   512
 * @param image the image to draw.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   513
 * @param pal the provided palette.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   514
 * @param sub Only draw a part of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   515
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   516
void DrawGroundSprite(SpriteID image, SpriteID pal, const SubSprite *sub)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   518
	/* Switch to first foundation part, if no foundation was drawn */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   519
	if (_vd.foundation_part == FOUNDATION_PART_NONE) _vd.foundation_part = FOUNDATION_PART_NORMAL;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   520
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   521
	if (_vd.foundation[_vd.foundation_part] != -1) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   522
		AddChildSpriteToFoundation(image, pal, sub, _vd.foundation_part, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	} else {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   524
		DrawGroundSpriteAt(image, pal, _cur_ti->x, _cur_ti->y, _cur_ti->z, sub);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   529
/**
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   530
 * Called when a foundation has been drawn for the current tile.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   531
 * Successive ground sprites for the current tile will be drawn as child sprites of the "foundation"-ParentSprite, not as TileSprites.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   532
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   533
 * @param x sprite x-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   534
 * @param y sprite y-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   535
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
void OffsetGroundSprite(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   538
	/* Switch to next foundation part */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   539
	switch (_vd.foundation_part) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   540
		case FOUNDATION_PART_NONE:
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   541
			_vd.foundation_part = FOUNDATION_PART_NORMAL;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   542
			break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   543
		case FOUNDATION_PART_NORMAL:
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   544
			_vd.foundation_part = FOUNDATION_PART_HALFTILE;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   545
			break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   546
		default: NOT_REACHED();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   547
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   548
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   549
	/* _vd.last_child == NULL if foundation sprite was clipped by the viewport bounds */
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   550
	if (_vd.last_child != NULL) _vd.foundation[_vd.foundation_part] = _vd.parent_sprites_to_draw.items - 1;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   551
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   552
	_vd.foundation_offset[_vd.foundation_part].x = x;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   553
	_vd.foundation_offset[_vd.foundation_part].y = y;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   554
	_vd.last_foundation_child[_vd.foundation_part] = _vd.last_child;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   557
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   558
 * Adds a child sprite to a parent sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   559
 * In contrast to "AddChildSpriteScreen()" the sprite position is in world coordinates
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   560
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   561
 * @param image the image to draw.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   562
 * @param pal the provided palette.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   563
 * @param x position x of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   564
 * @param y position y of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   565
 * @param z position z of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   566
 * @param sub Only draw a part of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   567
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   568
static void AddCombinedSprite(SpriteID image, SpriteID pal, int x, int y, byte z, const SubSprite *sub)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	Point pt = RemapCoords(x, y, z);
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   571
	const Sprite* spr = GetSprite(image & SPRITE_MASK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   573
	if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   574
			pt.x + spr->x_offs + spr->width <= _vd.dpi.left ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   575
			pt.y + spr->y_offs >= _vd.dpi.top + _vd.dpi.height ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   576
			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
   577
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   579
	const ParentSpriteToDraw *pstd = _vd.parent_sprites_to_draw.End() - 1;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   580
	AddChildSpriteScreen(image, pal, pt.x - pstd->left, pt.y - pstd->top, false, sub);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   583
/** Draw a (transparent) sprite at given coordinates with a given bounding box.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   584
 * 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.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   585
 * Bounding boxes with bb_offset_x == w or bb_offset_y == h or bb_offset_z == dz are allowed and produce thin slices.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   586
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   587
 * @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
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   588
 *       defined by the sprite offset in the grf file.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   589
 *       However if modifying the sprite offsets is not suitable (e.g. when using existing graphics), the bounding box can be tuned by bb_offset.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   590
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   591
 * @pre w >= bb_offset_x, h >= bb_offset_y, dz >= bb_offset_z. Else w, h or dz are ignored.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   592
 *
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   593
 * @param image the image to combine and draw,
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   594
 * @param pal the provided palette,
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   595
 * @param x position X (world) of the sprite,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   596
 * @param y position Y (world) of the sprite,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   597
 * @param w bounding box extent towards positive X (world),
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   598
 * @param h bounding box extent towards positive Y (world),
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   599
 * @param dz bounding box extent towards positive Z (world),
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   600
 * @param z position Z (world) of the sprite,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   601
 * @param transparent if true, switch the palette between the provided palette and the transparent palette,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   602
 * @param bb_offset_x bounding box extent towards negative X (world),
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   603
 * @param bb_offset_y bounding box extent towards negative Y (world),
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   604
 * @param bb_offset_z bounding box extent towards negative Z (world)
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   605
 * @param sub Only draw a part of the sprite.
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   606
 */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   607
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, const SubSprite *sub)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
{
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   609
	int32 left, right, top, bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   611
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   613
	/* make the sprites transparent with the right palette */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   614
	if (transparent) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   615
		SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   616
		pal = PALETTE_TO_TRANSPARENT;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   617
	}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6720
diff changeset
   618
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   619
	if (_vd.combine_sprites == 2) {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   620
		AddCombinedSprite(image, pal, x, y, z, sub);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   624
	_vd.last_child = NULL;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   625
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   626
	Point pt = RemapCoords(x, y, z);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   627
	int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   628
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   629
	/* Compute screen extents of sprite */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   630
	if (image == SPR_EMPTY_BOUNDING_BOX) {
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   631
		left = tmp_left = RemapCoords(x + w          , y + bb_offset_y, z + bb_offset_z).x;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   632
		right           = RemapCoords(x + bb_offset_x, y + h          , z + bb_offset_z).x + 1;
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   633
		top  = tmp_top  = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz         ).y;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   634
		bottom          = RemapCoords(x + w          , y + h          , z + bb_offset_z).y + 1;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   635
	} else {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   636
		const Sprite *spr = GetSprite(image & SPRITE_MASK);
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   637
		left = tmp_left = (pt.x += spr->x_offs);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   638
		right           = (pt.x +  spr->width );
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   639
		top  = tmp_top  = (pt.y += spr->y_offs);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   640
		bottom          = (pt.y +  spr->height);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   641
	}
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   642
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   643
	if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   644
		/* Compute maximal extents of sprite and it's bounding box */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   645
		left   = min(left  , RemapCoords(x + w          , y + bb_offset_y, z + bb_offset_z).x);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   646
		right  = max(right , RemapCoords(x + bb_offset_x, y + h          , z + bb_offset_z).x + 1);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   647
		top    = min(top   , RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz         ).y);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   648
		bottom = max(bottom, RemapCoords(x + w          , y + h          , z + bb_offset_z).y + 1);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   649
	}
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   650
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   651
	/* Do not add the sprite to the viewport, if it is outside */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   652
	if (left   >= _vd.dpi.left + _vd.dpi.width ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   653
	    right  <= _vd.dpi.left                 ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   654
	    top    >= _vd.dpi.top + _vd.dpi.height ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   655
	    bottom <= _vd.dpi.top) {
4189
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   656
		return;
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   657
	}
258f98b17f57 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   658
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   659
	ParentSpriteToDraw *ps = _vd.parent_sprites_to_draw.Append();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   660
	ps->x = tmp_x;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   661
	ps->y = tmp_y;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   662
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   663
	ps->left = tmp_left;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   664
	ps->top  = tmp_top;
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
	ps->image = image;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
   667
	ps->pal = pal;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   668
	ps->sub = sub;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   669
	ps->xmin = x + bb_offset_x;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   670
	ps->xmax = x + max(bb_offset_x, w) - 1;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   671
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   672
	ps->ymin = y + bb_offset_y;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   673
	ps->ymax = y + max(bb_offset_y, h) - 1;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   674
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   675
	ps->zmin = z + bb_offset_z;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   676
	ps->zmax = z + max(bb_offset_z, dz) - 1;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   677
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   678
	ps->comparison_done = false;
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   679
	ps->first_child = -1;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   680
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   681
	_vd.last_child = &ps->first_child;
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   682
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   683
	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
   684
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
   686
void StartSpriteCombine()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   688
	_vd.combine_sprites = 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
   691
void EndSpriteCombine()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   693
	_vd.combine_sprites = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   696
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   697
 * Add a child sprite to a parent sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   698
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   699
 * @param image the image to draw.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   700
 * @param pal the provided palette.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   701
 * @param x sprite x-offset (screen coordinates) relative to parent sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   702
 * @param y sprite y-offset (screen coordinates) relative to parent sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   703
 * @param transparent if true, switch the palette between the provided palette and the transparent palette,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   704
 * @param sub Only draw a part of the sprite.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   705
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   706
void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y, bool transparent, const SubSprite *sub)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
{
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   708
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   710
	/* If the ParentSprite was clipped by the viewport bounds, do not draw the ChildSprites either */
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   711
	if (_vd.last_child == NULL) return;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   712
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   713
	/* make the sprites transparent with the right palette */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   714
	if (transparent) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   715
		SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   716
		pal = PALETTE_TO_TRANSPARENT;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   717
	}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   718
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   719
	*_vd.last_child = _vd.child_screen_sprites_to_draw.items;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   720
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   721
	ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
	cs->image = image;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
   723
	cs->pal = pal;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   724
	cs->sub = sub;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	cs->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	cs->y = y;
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   727
	cs->next = -1;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   728
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   729
	/* Append the sprite to the active ChildSprite list.
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   730
	 * If the active ParentSprite is a foundation, update last_foundation_child as well.
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   731
	 * Note: ChildSprites of foundations are NOT sequential in the vector, as selection sprites are added at last. */
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   732
	if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = &cs->next;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   733
	if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = &cs->next;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   734
	_vd.last_child = &cs->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
/* Returns a StringSpriteToDraw */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   738
void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   740
	StringSpriteToDraw *ss = _vd.string_sprites_to_draw.Append();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
	ss->string = string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
	ss->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	ss->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
	ss->params[0] = params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	ss->params[1] = params_2;
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   746
	ss->width = width;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   747
	ss->color = color;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3809
diff changeset
   750
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   751
/**
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   752
 * Draws sprites between ground sprite and everything above.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   753
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   754
 * The sprite is either drawn as TileSprite or as ChildSprite of the active foundation.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   755
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   756
 * @param image the image to draw.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   757
 * @param pal the provided palette.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   758
 * @param ti TileInfo Tile that is being drawn
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   759
 * @param z_offset Z offset relative to the groundsprite. Only used for the sprite position, not for sprite sorting.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   760
 * @param foundation_part Foundation part the sprite belongs to.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   761
 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   762
static void DrawSelectionSprite(SpriteID image, SpriteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   764
	/* FIXME: This is not totally valid for some autorail highlights, that extent over the edges of the tile. */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   765
	if (_vd.foundation[foundation_part] == -1) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   766
		/* draw on real ground */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   767
		DrawGroundSpriteAt(image, pal, ti->x, ti->y, ti->z + z_offset);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   768
	} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   769
		/* draw on top of foundation */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   770
		AddChildSpriteToFoundation(image, pal, NULL, foundation_part, 0, -z_offset);
1083
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   771
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   774
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   775
 * Draws a selection rectangle on a tile.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   776
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   777
 * @param ti TileInfo Tile that is being drawn
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   778
 * @param pal Palette to apply.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   779
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   780
static void DrawTileSelectionRect(const TileInfo *ti, SpriteID pal)
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   781
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   782
	SpriteID sel;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   783
	if (IsHalftileSlope(ti->tileh)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   784
		Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   785
		SpriteID sel2 = SPR_HALFTILE_SELECTION_FLAT + halftile_corner;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   786
		DrawSelectionSprite(sel2, pal, ti, 7 + TILE_HEIGHT, FOUNDATION_PART_HALFTILE);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   787
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   788
		Corner opposite_corner = OppositeCorner(halftile_corner);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   789
		if (IsSteepSlope(ti->tileh)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   790
			sel = SPR_HALFTILE_SELECTION_DOWN;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   791
		} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   792
			sel = ((ti->tileh & SlopeWithOneCornerRaised(opposite_corner)) != 0 ? SPR_HALFTILE_SELECTION_UP : SPR_HALFTILE_SELECTION_FLAT);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   793
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   794
		sel += opposite_corner;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   795
	} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   796
		sel = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh];
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   797
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   798
	DrawSelectionSprite(sel, pal, ti, 7, FOUNDATION_PART_NORMAL);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   799
}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   800
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
static bool IsPartOfAutoLine(int px, int py)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   803
	px -= _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   804
	py -= _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   806
	if ((_thd.drawstyle & ~HT_DIR_MASK) != HT_LINE) return false;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   807
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   808
	switch (_thd.drawstyle & HT_DIR_MASK) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   809
		case HT_DIR_X:  return py == 0; // x direction
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   810
		case HT_DIR_Y:  return px == 0; // y direction
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   811
		case HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   812
		case HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   813
		case HT_DIR_VL: return px == py || px == py + 16; // vertival left
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   814
		case HT_DIR_VR: return px == py || px == py - 16; // vertical right
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   815
		default:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   816
			NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   820
// [direction][side]
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   821
static const HighLightStyle _autorail_type[6][2] = {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   822
	{ HT_DIR_X,  HT_DIR_X },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   823
	{ HT_DIR_Y,  HT_DIR_Y },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   824
	{ HT_DIR_HU, HT_DIR_HL },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   825
	{ HT_DIR_HL, HT_DIR_HU },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   826
	{ HT_DIR_VL, HT_DIR_VR },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   827
	{ HT_DIR_VR, HT_DIR_VL }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   828
};
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   829
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   830
#include "table/autorail.h"
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   831
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   832
/**
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   833
 * Draws autorail highlights.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   834
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   835
 * @param *ti TileInfo Tile that is being drawn
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   836
 * @param autorail_type Offset into _AutorailTilehSprite[][]
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   837
 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   838
static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type)
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   839
{
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   840
	SpriteID image;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   841
	SpriteID pal;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   842
	int offset;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   843
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   844
	FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   845
	Slope autorail_tileh = RemoveHalftileSlope(ti->tileh);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   846
	if (IsHalftileSlope(ti->tileh)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   847
		static const uint _lower_rail[4] = { 5U, 2U, 4U, 3U };
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   848
		Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   849
		if (autorail_type != _lower_rail[halftile_corner]) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   850
			foundation_part = FOUNDATION_PART_HALFTILE;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   851
			/* Here we draw the highlights of the "three-corners-raised"-slope. That looks ok to me. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   852
			autorail_tileh = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   853
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   854
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   855
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   856
	offset = _AutorailTilehSprite[autorail_tileh][autorail_type];
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   857
	if (offset >= 0) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   858
		image = SPR_AUTORAIL_BASE + offset;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   859
		pal = PAL_NONE;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   860
	} else {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   861
		image = SPR_AUTORAIL_BASE - offset;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   862
		pal = PALETTE_SEL_TILE_RED;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   863
	}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   864
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   865
	DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti, 7, foundation_part);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   866
}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   867
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   868
/**
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   869
 * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   870
 * @param *ti TileInfo Tile that is being drawn
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   871
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
static void DrawTileSelection(const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   874
	/* Draw a red error square? */
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   875
	bool is_redsq = _thd.redsq != 0 && _thd.redsq == ti->tile;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   876
	if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   878
	/* no selection active? */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   879
	if (_thd.drawstyle == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   881
	/* Inside the inner area? */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   882
	if (IsInsideBS(ti->x, _thd.pos.x, _thd.size.x) &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   883
			IsInsideBS(ti->y, _thd.pos.y, _thd.size.y)) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   884
		if (_thd.drawstyle & HT_RECT) {
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   885
			if (_thd.FSMportLayout != NULL) {
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   886
				byte *b = *_thd.FSMportLayout;
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   887
				byte *m;
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   888
				if (_thd.FSMportMask != NULL) m = *_thd.FSMportMask;
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   889
				b++; b++;
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   890
				if (_thd.FSMportMask != NULL) { m++; m++; } //skip orientation and minipic bytes
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   891
				for (uint i = 0; i < ((ti->y - _thd.pos.y) / TILE_SIZE * _thd.size.x / TILE_SIZE); i++) {
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   892
					b++;
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   893
					if (_thd.FSMportMask != NULL) m++;
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   894
				}
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   895
				for (uint j = 0; j < ((ti->x - _thd.pos.x) / TILE_SIZE ); j++) {
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   896
					b++;
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   897
					if (_thd.FSMportMask != NULL) m++;
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   898
				}
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   899
				if (*b != 255) {
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   900
					if (_thd.FSMportMask != NULL) {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   901
						DrawTileSelectionRect(ti, *m & 0x80 ? PALETTE_SEL_TILE_BLUE : PALETTE_SEL_TILE_GREEN);
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   902
					} else {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   903
						DrawTileSelectionRect(ti, PAL_NONE);
6812
35bd847c2aba (svn r10889) [NewGRF_ports] -Feature: Colour of highlight for FSMs with placement masks shows Green for land tiles, and Blue for water tiles.
richk
parents: 6807
diff changeset
   904
					}
6807
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   905
				}
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   906
			}
436fc766fc34 (svn r10881) [NewGRF_ports] -Feature: Adds irregular highlight to airport placement based on the FSMportLayout data. You can now see where the holes should be!
richk
parents: 6743
diff changeset
   907
			if (_thd.FSMportLayout == NULL) {
10310
c8b1eafc56bd (svn r12851) [NewGRF_ports] -Fix: Slight mis-sync disabled colouring of selection tiles for seaplane airports.
richk
parents: 10274
diff changeset
   908
				if (!is_redsq) DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6574
diff changeset
   909
			}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   910
		} else if (_thd.drawstyle & HT_POINT) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   911
			/* Figure out the Z coordinate for the single dot. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   912
			byte z = 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   913
			FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3609
diff changeset
   914
			if (ti->tileh & SLOPE_N) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   915
				z += TILE_HEIGHT;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   916
				if (RemoveHalftileSlope(ti->tileh) == SLOPE_STEEP_N) z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   918
			if (IsHalftileSlope(ti->tileh)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   919
				Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   920
				if ((halftile_corner == CORNER_W) || (halftile_corner == CORNER_E)) z += TILE_HEIGHT;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   921
				if (halftile_corner != CORNER_S) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   922
					foundation_part = FOUNDATION_PART_HALFTILE;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   923
					if (IsSteepSlope(ti->tileh)) z -= TILE_HEIGHT;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   924
				}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   925
			}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   926
			DrawSelectionSprite(_cur_dpi->zoom <= ZOOM_LVL_DETAIL ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti, z, foundation_part);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   927
		} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   928
			/* autorail highlight piece under cursor */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   929
			uint type = _thd.drawstyle & 0xF;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   930
			assert(type <= 5);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   931
			DrawAutorailSelection(ti, _autorail_type[type][0]);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   932
		} else if (IsPartOfAutoLine(ti->x, ti->y)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   933
			/* autorail highlighting long line */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   934
			int dir = _thd.drawstyle & ~0xF0;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   935
			uint side;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   936
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   937
			if (dir < 2) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   938
				side = 0;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   939
			} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   940
				TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   941
				side = Delta(Delta(TileX(start), TileX(ti->tile)), Delta(TileY(start), TileY(ti->tile)));
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   942
			}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   943
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   944
			DrawAutorailSelection(ti, _autorail_type[dir][side]);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   945
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		return;
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
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   949
	/* Check if it's inside the outer area? */
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   950
	if (!is_redsq && _thd.outersize.x &&
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   951
			_thd.size.x < _thd.size.x + _thd.outersize.x &&
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   952
			IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   953
			IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   954
		/* Draw a blue rect. */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   955
		DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
   960
static void ViewportAddLandscape()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	int x, y, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
	bool direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
	_cur_ti = &ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   968
	/* Transform into tile coordinates and round to closest full tile */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   969
	x = ((_vd.dpi.top >> 1) - (_vd.dpi.left >> 2)) & ~0xF;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   970
	y = ((_vd.dpi.top >> 1) + (_vd.dpi.left >> 2) - 0x10) & ~0xF;
5752
7e417aab8074 (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5726
diff changeset
   971
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   972
	/* determine size of area */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
		Point pt = RemapCoords(x, y, 241);
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   975
		width = (_vd.dpi.left + _vd.dpi.width - pt.x + 95) >> 6;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
   976
		height = (_vd.dpi.top + _vd.dpi.height - pt.y) >> 5 << 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	assert(height > 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   981
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
	direction = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
		int width_cur = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
		int x_cur = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
		int y_cur = y;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   988
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
		do {
4238
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   990
			TileType tt;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   991
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   992
			ti.x = x_cur;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   993
			ti.y = y_cur;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   994
			if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE &&
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   995
					0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) {
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   996
				TileIndex tile = TileVirtXY(x_cur, y_cur);
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   997
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   998
				ti.tile = tile;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   999
				ti.tileh = GetTileSlope(tile, &ti.z);
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1000
				tt = GetTileType(tile);
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1001
			} else {
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1002
				ti.tileh = SLOPE_FLAT;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1003
				ti.tile = 0;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1004
				ti.z = 0;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1005
				tt = MP_VOID;
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1006
			}
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1007
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
			x_cur -= 0x10;
5752
7e417aab8074 (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5726
diff changeset
  1010
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1011
			_vd.foundation_part = FOUNDATION_PART_NONE;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1012
			_vd.foundation[0] = -1;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1013
			_vd.foundation[1] = -1;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1014
			_vd.last_foundation_child[0] = NULL;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1015
			_vd.last_foundation_child[1] = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1016
4238
e017178ca040 (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
  1017
			_tile_type_procs[tt]->draw_tile_proc(&ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
			DrawTileSelection(&ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
		} while (--width_cur);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1020
5752
7e417aab8074 (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5726
diff changeset
  1021
		if ((direction ^= 1) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
			y += 0x10;
5752
7e417aab8074 (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5726
diff changeset
  1023
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
			x += 0x10;
5752
7e417aab8074 (svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents: 5726
diff changeset
  1025
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1026
	} while (--height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1030
static void ViewportAddTownNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1035
	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
  1036
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1043
	switch (dpi->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1044
		case ZOOM_LVL_NORMAL:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1045
			FOR_ALL_TOWNS(t) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1046
				if (bottom > t->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1047
						top    < t->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1048
						right  > t->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1049
						left   < t->sign.left + t->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1050
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1051
						_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1052
						t->index, t->population);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1053
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1055
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1056
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1057
		case ZOOM_LVL_OUT_2X:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1058
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1059
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1060
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1061
			FOR_ALL_TOWNS(t) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1062
				if (bottom > t->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1063
						top    < t->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1064
						right  > t->sign.left &&
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1065
						left   < t->sign.left + t->sign.width_1 * 2) {
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1066
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1067
						_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1068
						t->index, t->population);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1069
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1070
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1071
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1072
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1073
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1074
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1075
			right += ScaleByZoom(1, dpi->zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1076
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1077
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1078
			FOR_ALL_TOWNS(t) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1079
				if (bottom > t->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1080
						top    < t->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1081
						right  > t->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1082
						left   < t->sign.left + ScaleByZoom(t->sign.width_2, dpi->zoom)) {
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1083
					AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1084
					AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1085
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1086
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1087
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1088
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1089
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1093
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1094
static void AddStation(const Station *st, StringID str, uint16 width)
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1095
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1096
	AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities, (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner], width);
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1097
}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1098
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1099
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1100
static void ViewportAddStationNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	int left, top, right, bottom;
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1103
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1105
	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
  1106
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1113
	switch (dpi->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1114
		case ZOOM_LVL_NORMAL:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1115
			FOR_ALL_STATIONS(st) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1116
				if (bottom > st->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1117
						top    < st->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1118
						right  > st->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1119
						left   < st->sign.left + st->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1120
					AddStation(st, STR_305C_0, st->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1121
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1123
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1124
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1125
		case ZOOM_LVL_OUT_2X:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1126
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1127
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1128
			FOR_ALL_STATIONS(st) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1129
				if (bottom > st->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1130
						top    < st->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1131
						right  > st->sign.left &&
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1132
						left   < st->sign.left + st->sign.width_1 * 2) {
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1133
					AddStation(st, STR_305C_0, st->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1134
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1136
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1137
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1138
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1139
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1140
			right += ScaleByZoom(1, dpi->zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1141
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1142
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1143
			FOR_ALL_STATIONS(st) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1144
				if (bottom > st->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1145
						top    < st->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1146
						right  > st->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1147
						left   < st->sign.left + ScaleByZoom(st->sign.width_2, dpi->zoom)) {
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1148
					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1149
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1151
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1152
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1153
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1157
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1158
static void AddSign(const Sign *si, StringID str, uint16 width)
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1159
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1160
	AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->index, 0, (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner], width);
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1161
}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1162
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1163
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1164
static void ViewportAddSigns(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
{
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1166
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1169
	/* Signs are turned off or are invisible */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1170
	if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1177
	switch (dpi->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1178
		case ZOOM_LVL_NORMAL:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1179
			FOR_ALL_SIGNS(si) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1180
				if (bottom > si->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1181
						top    < si->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1182
						right  > si->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1183
						left   < si->sign.left + si->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1184
					AddSign(si, STR_2806, si->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1185
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1187
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1188
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1189
		case ZOOM_LVL_OUT_2X:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1190
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1191
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1192
			FOR_ALL_SIGNS(si) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1193
				if (bottom > si->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1194
						top    < si->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1195
						right  > si->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1196
						left   < si->sign.left + si->sign.width_1 * 2) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1197
					AddSign(si, STR_2806, si->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1198
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1200
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1201
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1202
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1203
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1204
			right += ScaleByZoom(1, dpi->zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1205
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1206
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1207
			FOR_ALL_SIGNS(si) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1208
				if (bottom > si->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1209
						top    < si->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1210
						right  > si->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1211
						left   < si->sign.left + ScaleByZoom(si->sign.width_2, dpi->zoom)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1212
					AddSign(si, IsTransparencySet(TO_SIGNS) ? STR_2002_WHITE : STR_2002, si->sign.width_2 | 0x8000);
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1213
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1215
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1216
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1217
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1221
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1222
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width)
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1223
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1224
	AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, (wp->deleted ? 0xE : 11), width);
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1225
}
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1226
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1227
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1228
static void ViewportAddWaypoints(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
{
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1230
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1233
	if (!HasBit(_display_opt, DO_WAYPOINTS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1241
	switch (dpi->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1242
		case ZOOM_LVL_NORMAL:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1243
			FOR_ALL_WAYPOINTS(wp) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1244
				if (bottom > wp->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1245
						top    < wp->sign.top + 12 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1246
						right  > wp->sign.left &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1247
						left   < wp->sign.left + wp->sign.width_1) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1248
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1249
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1251
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1252
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1253
		case ZOOM_LVL_OUT_2X:
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1254
			right += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1255
			bottom += 2;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1256
			FOR_ALL_WAYPOINTS(wp) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1257
				if (bottom > wp->sign.top &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1258
						top    < wp->sign.top + 24 &&
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1259
						right  > wp->sign.left &&
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1260
						left   < wp->sign.left + wp->sign.width_1 * 2) {
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1261
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1262
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1264
			break;
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1265
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1266
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1267
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1268
			right += ScaleByZoom(1, dpi->zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1269
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1270
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1271
			FOR_ALL_WAYPOINTS(wp) {
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1272
				if (bottom > wp->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1273
						top    < wp->sign.top + ScaleByZoom(12, dpi->zoom) &&
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1274
						right  > wp->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1275
						left   < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) {
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1276
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1277
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
			}
5027
1141f07a15b4 (svn r7068) if () cascades -> switch ()
tron
parents: 5026
diff changeset
  1279
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1280
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1281
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
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
  1286
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	char buffer[128];
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1288
	uint w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
	sign->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4885
diff changeset
  1292
	GetString(buffer, str, lastof(buffer));
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1293
	w = GetStringBoundingBox(buffer).width + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
	sign->width_1 = w;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1295
	sign->left = left - w / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1297
	/* zoomed out version */
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3645
diff changeset
  1298
	_cur_fontsize = FS_SMALL;
4609
6c337b3fbf4b (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1299
	w = GetStringBoundingBox(buffer).width + 3;
3798
37a2090eac94 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3645
diff changeset
  1300
	_cur_fontsize = FS_NORMAL;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1301
	sign->width_2 = w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1305
static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1306
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1307
	const TileSpriteToDraw *tsend = tstdv->End();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1308
	for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
		Point pt = RemapCoords(ts->x, ts->y, ts->z);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1310
		DrawSprite(ts->image, ts->pal, pt.x, pt.y, ts->sub);
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1311
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1314
static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1316
	ParentSpriteToDraw **psdvend = psdv->End();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1317
	ParentSpriteToDraw **psd = psdv->Begin();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1318
	while (psd != psdvend) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1319
		ParentSpriteToDraw *ps = *psd;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1320
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1321
		if (ps->comparison_done) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1322
			psd++;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1323
			continue;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1324
		}
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1325
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1326
		ps->comparison_done = true;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1327
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1328
		for (ParentSpriteToDraw **psd2 = psd + 1; psd2 != psdvend; psd2++) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1329
			ParentSpriteToDraw *ps2 = *psd2;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1330
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1331
			if (ps2->comparison_done) continue;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1332
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1333
			/* Decide which comparator to use, based on whether the bounding
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1334
			 * boxes overlap
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1335
			 */
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1336
			if (ps->xmax >= ps2->xmin && ps->xmin <= ps2->xmax && // overlap in X?
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1337
					ps->ymax >= ps2->ymin && ps->ymin <= ps2->ymax && // overlap in Y?
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1338
					ps->zmax >= ps2->zmin && ps->zmin <= ps2->zmax) { // overlap in Z?
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1339
				/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1340
				 * the screen and with higher Z elevation, are drawn in front.
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1341
				 * Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1342
				 * i.e. X=(left+right)/2, etc.
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1343
				 * However, since we only care about order, don't actually divide / 2
4187
50b94420d9a2 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1344
				 */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1345
				if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <=
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1346
						ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1347
					continue;
1934
b3d568113d4d (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1348
				}
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1349
			} else {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1350
				/* We only change the order, if it is definite.
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1351
				 * I.e. every single order of X, Y, Z says ps2 is behind ps or they overlap.
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1352
				 * That is: If one partial order says ps behind ps2, do not change the order.
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1353
				 */
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1354
				if (ps->xmax < ps2->xmin ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1355
						ps->ymax < ps2->ymin ||
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1356
						ps->zmax < ps2->zmin) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1357
					continue;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1358
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
			}
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1360
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1361
			/* Swap the two sprites ps and ps2 using bubble-sort algorithm. */
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1362
			ParentSpriteToDraw **psd3 = psd;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1363
			do {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1364
				ParentSpriteToDraw *temp = *psd3;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1365
				*psd3 = ps2;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1366
				ps2 = temp;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1367
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1368
				psd3++;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1369
			} while (psd3 <= psd2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
	}
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
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1374
static void ViewportDrawParentSprites(const ParentSpriteToSortVector *psd, const ChildScreenSpriteToDrawVector *csstdv)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1376
	const ParentSpriteToDraw * const *psd_end = psd->End();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1377
	for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1378
		const ParentSpriteToDraw *ps = *it;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1379
		if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1381
		int child_idx = ps->first_child;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1382
		while (child_idx >= 0) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1383
			const ChildScreenSpriteToDraw *cs = csstdv->Get(child_idx);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1384
			child_idx = cs->next;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1385
			DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
0
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1390
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1391
 * Draws the bounding boxes of all ParentSprites
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1392
 * @param psd Array of ParentSprites
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1393
 */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1394
static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd)
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1395
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1396
	const ParentSpriteToDraw * const *psd_end = psd->End();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1397
	for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1398
		const ParentSpriteToDraw *ps = *it;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1399
		Point pt1 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmax + 1); // top front corner
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1400
		Point pt2 = RemapCoords(ps->xmin    , ps->ymax + 1, ps->zmax + 1); // top left corner
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1401
		Point pt3 = RemapCoords(ps->xmax + 1, ps->ymin    , ps->zmax + 1); // top right corner
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1402
		Point pt4 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmin    ); // bottom front corner
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1403
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1404
		DrawBox(        pt1.x,         pt1.y,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1405
		        pt2.x - pt1.x, pt2.y - pt1.y,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1406
		        pt3.x - pt1.x, pt3.y - pt1.y,
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1407
		        pt4.x - pt1.x, pt4.y - pt1.y);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1408
	}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1409
}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1410
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1411
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVector *sstdv)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
	DrawPixelInfo dp;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1414
	ZoomLevel zoom;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1415
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
	_cur_dpi = &dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	dp = *dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1419
	zoom = dp.zoom;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1420
	dp.zoom = ZOOM_LVL_NORMAL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1421
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1422
	dp.left   = UnScaleByZoom(dp.left,   zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1423
	dp.top    = UnScaleByZoom(dp.top,    zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1424
	dp.width  = UnScaleByZoom(dp.width,  zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1425
	dp.height = UnScaleByZoom(dp.height, zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1427
	const StringSpriteToDraw *ssend = sstdv->End();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1428
	for (const StringSpriteToDraw *ss = sstdv->Begin(); ss != ssend; ++ss) {
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1429
		uint16 colour;
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1430
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
		if (ss->width != 0) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1432
			/* Do not draw signs nor station names if they are set invisible */
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1433
			if (IsInvisibilitySet(TO_SIGNS) && ss->string != STR_2806) continue;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1434
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1435
			int x = UnScaleByZoom(ss->x, zoom) - 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1436
			int y = UnScaleByZoom(ss->y, zoom) - 1;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1437
			int bottom = y + 11;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1438
			int w = ss->width;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1439
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
			if (w & 0x8000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
				w &= ~0x8000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
				y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
				bottom -= 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
				w -= 3;
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
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1447
		/* Draw the rectangle if 'tranparent station signs' is off,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1448
		 * or if we are drawing a general text sign (STR_2806) */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1449
			if (!IsTransparencySet(TO_SIGNS) || ss->string == STR_2806) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1450
				DrawFrameRect(
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1451
					x, y, x + w, bottom, ss->color,
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1452
					IsTransparencySet(TO_SIGNS) ? FR_TRANSPARENT : FR_NONE
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1453
				);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1454
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1457
		SetDParam(0, ss->params[0]);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1458
		SetDParam(1, ss->params[1]);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1459
		/* if we didn't draw a rectangle, or if transparant building is on,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1460
		 * draw the text in the color the rectangle would have */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1461
		if (IsTransparencySet(TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1462
			/* Real colors need the IS_PALETTE_COLOR flag
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1463
			 * otherwise colors from _string_colormap are assumed. */
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1464
			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
  1465
		} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1466
			colour = TC_BLACK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
		}
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1468
		DrawString(
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1469
			UnScaleByZoom(ss->x, zoom), UnScaleByZoom(ss->y, zoom) - (ss->width & 0x8000 ? 2 : 0),
5025
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1470
			ss->string, colour
48314eb3efde (svn r7066) -Codechange: Factorise common code
tron
parents: 5014
diff changeset
  1471
		);
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1472
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
  1475
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
  1476
{
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1477
	DrawPixelInfo *old_dpi = _cur_dpi;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1478
	_cur_dpi = &_vd.dpi;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1479
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1480
	_vd.dpi.zoom = vp->zoom;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1481
	int mask = ScaleByZoom(-1, vp->zoom);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1482
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1483
	_vd.combine_sprites = 0;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1484
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1485
	_vd.dpi.width = (right - left) & mask;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1486
	_vd.dpi.height = (bottom - top) & mask;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1487
	_vd.dpi.left = left & mask;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1488
	_vd.dpi.top = top & mask;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1489
	_vd.dpi.pitch = old_dpi->pitch;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1490
	_vd.last_child = NULL;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1491
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1492
	int x = UnScaleByZoom(_vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1493
	int y = UnScaleByZoom(_vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1494
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1495
	_vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1496
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
	ViewportAddLandscape();
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1498
	ViewportAddVehicles(&_vd.dpi);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1499
	DrawTextEffects(&_vd.dpi);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1500
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1501
	ViewportAddTownNames(&_vd.dpi);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1502
	ViewportAddStationNames(&_vd.dpi);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1503
	ViewportAddSigns(&_vd.dpi);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1504
	ViewportAddWaypoints(&_vd.dpi);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1505
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1506
	if (_vd.tile_sprites_to_draw.items != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1507
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1508
	ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End();
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1509
	for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) {
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1510
		*_vd.parent_sprites_to_sort.Append() = it;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1511
	}
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1512
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1513
	ViewportSortParentSprites(&_vd.parent_sprites_to_sort);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1514
	ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1515
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1516
	if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(&_vd.parent_sprites_to_sort);
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1517
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1518
	if (_vd.string_sprites_to_draw.items != 0) ViewportDrawStrings(&_vd.dpi, &_vd.string_sprites_to_draw);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1519
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
	_cur_dpi = old_dpi;
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1521
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1522
	_vd.string_sprites_to_draw.items = 0;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1523
	_vd.tile_sprites_to_draw.items = 0;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1524
	_vd.parent_sprites_to_draw.items = 0;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1525
	_vd.parent_sprites_to_sort.items = 0;
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  1526
	_vd.child_screen_sprites_to_draw.items = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1529
/** Make sure we don't draw a too big area at a time.
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1530
 * If we do, the sprite memory will overflow. */
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1531
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
  1532
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1533
	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
  1534
		if ((bottom - top) > (right - left)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
			int t = (top + bottom) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
			ViewportDrawChk(vp, left, top, right, t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
			ViewportDrawChk(vp, left, t, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
			int t = (left + right) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
			ViewportDrawChk(vp, left, top, t, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
			ViewportDrawChk(vp, t, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1544
		ViewportDoDraw(vp,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1545
			ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1546
			ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1547
			ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1548
			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
  1549
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5045
diff changeset
  1553
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
  1554
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1555
	if (right <= vp->left || bottom <= vp->top) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1557
	if (left >= vp->left + vp->width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
	if (left < vp->left) left = vp->left;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1560
	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
  1561
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1562
	if (top >= vp->top + vp->height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
	if (top < vp->top) top = vp->top;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1565
	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
  1566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
	ViewportDrawChk(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1570
void Window::DrawViewport() const
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1571
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
	DrawPixelInfo *dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1574
	dpi->left += this->left;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1575
	dpi->top += this->top;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1576
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1577
	ViewportDraw(this->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1578
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1579
	dpi->left -= this->left;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1580
	dpi->top -= this->top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1583
static inline void ClampViewportToMap(const ViewPort *vp, int &x, int &y)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1584
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1585
	/* Centre of the viewport is hot spot */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1586
	x += vp->virtual_width / 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1587
	y += vp->virtual_height / 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1588
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1589
	/* Convert viewport coordinates to map coordinates
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1590
	 * Calculation is scaled by 4 to avoid rounding errors */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1591
	int vx = -x + y * 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1592
	int vy =  x + y * 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1593
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1594
	/* clamp to size of map */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1595
	vx = Clamp(vx, 0, MapMaxX() * TILE_SIZE * 4);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1596
	vy = Clamp(vy, 0, MapMaxY() * TILE_SIZE * 4);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1597
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1598
	/* Convert map coordinates to viewport coordinates */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1599
	x = (-vx + vy) / 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1600
	y = ( vx + vy) / 4;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1601
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1602
	/* Remove centreing */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1603
	x -= vp->virtual_width / 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1604
	y -= vp->virtual_height / 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1605
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1606
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
void UpdateViewportPosition(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1609
	const ViewPort *vp = w->viewport;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1611
	if (w->viewport->follow_vehicle != INVALID_VEHICLE) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1612
		const Vehicle* veh = GetVehicle(w->viewport->follow_vehicle);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1613
		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
  1614
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
		SetViewportPosition(w, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
	} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1617
		/* Ensure the destination location is within the map */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1618
		ClampViewportToMap(vp, w->viewport->dest_scrollpos_x, w->viewport->dest_scrollpos_y);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1619
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1620
		int delta_x = w->viewport->dest_scrollpos_x - w->viewport->scrollpos_x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1621
		int delta_y = w->viewport->dest_scrollpos_y - w->viewport->scrollpos_y;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1622
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1623
		if (delta_x != 0 || delta_y != 0) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1624
			if (_settings_client.gui.smooth_scroll) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1625
				int max_scroll = ScaleByMapSize1D(512);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1626
				/* Not at our desired positon yet... */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1627
				w->viewport->scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1628
				w->viewport->scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1629
			} else {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1630
				w->viewport->scrollpos_x = w->viewport->dest_scrollpos_x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1631
				w->viewport->scrollpos_y = w->viewport->dest_scrollpos_y;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1632
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1633
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1634
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1635
		ClampViewportToMap(vp, w->viewport->scrollpos_x, w->viewport->scrollpos_y);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1636
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  1637
		SetViewportPosition(w, w->viewport->scrollpos_x, w->viewport->scrollpos_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1641
/**
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1642
 * Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1643
 * @param vp     The viewport to mark as dirty
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1644
 * @param left   Left edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1645
 * @param top    Top edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1646
 * @param right  Right edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1647
 * @param bottom Bottom edge of area to repaint
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1648
 * @ingroup dirty
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1649
 */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1650
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
  1651
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1652
	right -= vp->virtual_left;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1653
	if (right <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1655
	bottom -= vp->virtual_top;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1656
	if (bottom <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1658
	left = max(0, left - vp->virtual_left);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1660
	if (left >= vp->virtual_width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1662
	top = max(0, top - vp->virtual_top);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1663
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1664
	if (top >= vp->virtual_height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
	SetDirtyBlocks(
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1667
		UnScaleByZoom(left, vp->zoom) + vp->left,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1668
		UnScaleByZoom(top, vp->zoom) + vp->top,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1669
		UnScaleByZoom(right, vp->zoom) + vp->left,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1670
		UnScaleByZoom(bottom, vp->zoom) + vp->top
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1674
/**
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1675
 * Mark all viewports that display an area as dirty (in need of repaint).
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1676
 * @param left   Left edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1677
 * @param top    Top edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1678
 * @param right  Right edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1679
 * @param bottom Bottom edge of area to repaint
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1680
 * @ingroup dirty
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1681
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
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
  1683
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1684
	Window **wz;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1685
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1686
	FOR_ALL_WINDOWS(wz) {
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1687
		ViewPort *vp = (*wz)->viewport;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1688
		if (vp != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
			assert(vp->width != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
			MarkViewportDirty(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
		}
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
  1692
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1695
void MarkTileDirtyByTile(TileIndex tile)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1696
{
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1697
	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
  1698
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
void MarkTileDirty(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1708
	uint z = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
	Point pt;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1710
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1711
	if (IsInsideMM(x, 0, MapSizeX() * TILE_SIZE) &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1712
			IsInsideMM(y, 0, MapSizeY() * TILE_SIZE))
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1713
		z = GetTileZ(TileVirtXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
	pt = RemapCoords(x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
	);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1722
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1724
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1725
 * Marks the selected tiles as dirty.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1726
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1727
 * This function marks the selected tiles as dirty for repaint
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1728
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1729
 * @note Documentation may be wrong (Progman)
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1730
 * @ingroup dirty
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1731
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  1732
static void SetSelectionTilesDirty()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
	int y_size, x_size;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1735
	int x = _thd.pos.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1736
	int y = _thd.pos.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1738
	x_size = _thd.size.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1739
	y_size = _thd.size.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1741
	if (_thd.outersize.x) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1742
		x_size += _thd.outersize.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1743
		x += _thd.offs.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1744
		y_size += _thd.outersize.y;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1745
		y += _thd.offs.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
	assert(x_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
	assert(y_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	x_size += x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	y_size += y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
		int y_bk = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
			MarkTileDirty(x, y);
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1758
		} while ( (y += TILE_SIZE) != y_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
		y = y_bk;
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1760
	} while ( (x += TILE_SIZE) != x_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
1990
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1764
void SetSelectionRed(bool b)
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1765
{
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1766
	_thd.make_square_red = b;
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1767
	SetSelectionTilesDirty();
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1768
}
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1769
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1770
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1771
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
  1772
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1773
	const Town *t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1775
	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
  1776
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1777
	switch (vp->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1778
		case ZOOM_LVL_NORMAL:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1779
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1780
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1781
			FOR_ALL_TOWNS(t) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1782
				if (y >= t->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1783
						y < t->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1784
						x >= t->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1785
						x < t->sign.left + t->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1786
					ShowTownViewWindow(t->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1787
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1788
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1790
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1791
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1792
		case ZOOM_LVL_OUT_2X:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1793
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1794
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1795
			FOR_ALL_TOWNS(t) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1796
				if (y >= t->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1797
						y < t->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1798
						x >= t->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1799
						x < t->sign.left + t->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1800
					ShowTownViewWindow(t->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1801
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1802
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1804
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1805
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1806
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1807
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1808
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1809
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1810
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1811
			FOR_ALL_TOWNS(t) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1812
				if (y >= t->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1813
						y < t->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1814
						x >= t->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1815
						x < t->sign.left + ScaleByZoom(t->sign.width_2, vp->zoom)) {
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1816
					ShowTownViewWindow(t->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1817
					return true;
4134f0452cd6 (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
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1820
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1821
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1822
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1828
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1829
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
  1830
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1831
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1833
	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
  1834
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1835
	switch (vp->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1836
		case ZOOM_LVL_NORMAL:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1837
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1838
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1839
			FOR_ALL_STATIONS(st) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1840
				if (y >= st->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1841
						y < st->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1842
						x >= st->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1843
						x < st->sign.left + st->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1844
					ShowStationViewWindow(st->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1845
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1846
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1848
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1849
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1850
		case ZOOM_LVL_OUT_2X:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1851
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1852
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1853
			FOR_ALL_STATIONS(st) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1854
				if (y >= st->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1855
						y < st->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1856
						x >= st->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1857
						x < st->sign.left + st->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1858
					ShowStationViewWindow(st->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1859
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1860
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1862
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1863
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1864
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1865
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1866
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1867
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1868
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1869
			FOR_ALL_STATIONS(st) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1870
				if (y >= st->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1871
						y < st->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1872
						x >= st->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1873
						x < st->sign.left + ScaleByZoom(st->sign.width_2, vp->zoom)) {
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1874
					ShowStationViewWindow(st->index);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1875
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1876
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1878
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1879
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1880
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1886
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1887
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
  1888
{
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1889
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1891
	/* Signs are turned off, or they are transparent and invisibility is ON, or player is a spectator */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1892
	if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS) || _current_player == PLAYER_SPECTATOR) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1894
	switch (vp->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1895
		case ZOOM_LVL_NORMAL:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1896
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1897
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1898
			FOR_ALL_SIGNS(si) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1899
				if (y >= si->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1900
						y <  si->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1901
						x >= si->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1902
						x <  si->sign.left + si->sign.width_1) {
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1903
					HandleClickOnSign(si);
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1904
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1905
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1907
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1908
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1909
		case ZOOM_LVL_OUT_2X:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1910
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1911
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1912
			FOR_ALL_SIGNS(si) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1913
				if (y >= si->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1914
						y <  si->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1915
						x >= si->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1916
						x <  si->sign.left + si->sign.width_1 * 2) {
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1917
					HandleClickOnSign(si);
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1918
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1919
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1921
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1922
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1923
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1924
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1925
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1926
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1927
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1928
			FOR_ALL_SIGNS(si) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1929
				if (y >= si->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1930
						y <  si->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1931
						x >= si->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1932
						x <  si->sign.left + ScaleByZoom(si->sign.width_2, vp->zoom)) {
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1933
					HandleClickOnSign(si);
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1934
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1935
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1937
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1938
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1939
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1945
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1946
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
  1947
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1948
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1950
	if (!HasBit(_display_opt, DO_WAYPOINTS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1952
	switch (vp->zoom) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1953
		case ZOOM_LVL_NORMAL:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1954
			x = x - vp->left + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1955
			y = y - vp->top  + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1956
			FOR_ALL_WAYPOINTS(wp) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1957
				if (y >= wp->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1958
						y < wp->sign.top + 12 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1959
						x >= wp->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1960
						x < wp->sign.left + wp->sign.width_1) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1961
					ShowRenameWaypointWindow(wp);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1962
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1963
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1965
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1966
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1967
		case ZOOM_LVL_OUT_2X:
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1968
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1969
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1970
			FOR_ALL_WAYPOINTS(wp) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1971
				if (y >= wp->sign.top &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1972
						y < wp->sign.top + 24 &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1973
						x >= wp->sign.left &&
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1974
						x < wp->sign.left + wp->sign.width_1 * 2) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1975
					ShowRenameWaypointWindow(wp);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1976
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1977
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1979
			break;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1980
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1981
		case ZOOM_LVL_OUT_4X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1982
		case ZOOM_LVL_OUT_8X:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1983
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1984
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1985
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1986
			FOR_ALL_WAYPOINTS(wp) {
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1987
				if (y >= wp->sign.top &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1988
						y < wp->sign.top + ScaleByZoom(12, vp->zoom) &&
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1989
						x >= wp->sign.left &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1990
						x < wp->sign.left + ScaleByZoom(wp->sign.width_2, vp->zoom)) {
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1991
					ShowRenameWaypointWindow(wp);
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1992
					return true;
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1993
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
			}
4471
4134f0452cd6 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1995
			break;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1996
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1997
		default: NOT_REACHED();
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
	return false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2004
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
  2005
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2006
	Point pt = TranslateXYToTileCoord(vp, x, y);
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  2007
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2008
	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
  2009
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2011
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2012
static void SafeShowTrainViewWindow(const Vehicle* v)
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2013
{
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
  2014
	if (!IsFrontEngine(v)) v = v->First();
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
  2015
	ShowVehicleViewWindow(v);
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2016
}
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2017
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2018
static void SafeShowRoadVehViewWindow(const Vehicle *v)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2019
{
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
  2020
	if (!IsRoadVehFront(v)) v = v->First();
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
  2021
	ShowVehicleViewWindow(v);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2022
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2023
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  2024
static void Nop(const Vehicle *v) {}
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2025
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  2026
typedef void OnVehicleClickProc(const Vehicle *v);
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2027
static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2028
	SafeShowTrainViewWindow,
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2029
	SafeShowRoadVehViewWindow,
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
  2030
	ShowVehicleViewWindow,
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6840
diff changeset
  2031
	ShowVehicleViewWindow,
2662
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2032
	Nop, // Special vehicles
42c11a1a0a4b (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  2033
	Nop  // Disaster vehicles
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2036
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
  2037
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  2038
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2040
	if (CheckClickOnTown(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2041
	if (CheckClickOnStation(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2042
	if (CheckClickOnSign(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2043
	if (CheckClickOnWaypoint(vp, x, y)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
	CheckClickOnLandscape(vp, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2046
	v = CheckClickOnVehicle(vp, x, y);
3809
cff6d5e916f7 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  2047
	if (v != NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5137
diff changeset
  2048
		DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v);
6206
67358999d80d (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: 6144
diff changeset
  2049
		_on_vehicle_click_proc[v->type](v);
3809
cff6d5e916f7 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  2050
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  2053
Vehicle *CheckMouseOverVehicle()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  2055
	const Window *w;
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  2056
	const ViewPort *vp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
	int x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
	int y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2061
	w = FindWindowFromPt(x, y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2062
	if (w == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
	vp = IsPtInWindowViewport(w, x, y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2065
	return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2068
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  2070
void PlaceObject()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2073
	Window *w;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2074
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2075
	pt = GetTileBelowCursor();
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2076
	if (pt.x == -1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2078
	if (_thd.place_mode == VHM_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
		pt.x += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
		pt.y += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2081
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2083
	_tile_fract_coords.x = pt.x & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
	_tile_fract_coords.y = pt.y & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2086
	w = GetCallbackWnd();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2087
	if (w != NULL) w->OnPlaceObject(pt, TileVirtXY(pt.x, pt.y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
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
  2090
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
  2091
/* scrolls the viewport in a window to a given location */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2092
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
  2093
{
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2094
	/* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2095
	Point pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(Clamp(x, 0, MapSizeX()), Clamp(y, 0, MapSizeY())));
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2096
	w->viewport->follow_vehicle = INVALID_VEHICLE;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2097
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2098
	if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y)
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2099
		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
  2100
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2101
	if (instant) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2102
		w->viewport->scrollpos_x = pt.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2103
		w->viewport->scrollpos_y = pt.y;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2104
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2105
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2106
	w->viewport->dest_scrollpos_x = pt.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2107
	w->viewport->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
  2108
	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
  2109
}
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
  2110
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2111
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2113
	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
  2114
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
void SetRedErrorSquare(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
	TileIndex old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
	old = _thd.redsq;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
	_thd.redsq = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
	if (tile != old) {
3281
0f3d836e35b1 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
  2124
		if (tile != 0) MarkTileDirtyByTile(tile);
0f3d836e35b1 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
  2125
		if (old  != 0) MarkTileDirtyByTile(old);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
void SetTileSelectSize(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
{
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2131
	_thd.new_size.x = w * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2132
	_thd.new_size.y = h * TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2133
	_thd.new_outersize.x = 0;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2134
	_thd.new_outersize.y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2137
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2138
{
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2139
	_thd.offs.x = ox * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2140
	_thd.offs.y = oy * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2141
	_thd.new_outersize.x = sx * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2142
	_thd.new_outersize.y = sy * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2145
/** returns the best autorail highlight type from map coordinates */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2146
static HighLightStyle GetAutorailHT(int x, int y)
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2147
{
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2148
	return HT_RAIL | _autorail_piece[x & 0xF][y & 0xF];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2149
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2151
/**
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2152
 * Updates tile highlighting for all cases.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2153
 * Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2154
 * Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2155
 * Once for the old and once for the new selection.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2156
 * _thd is TileHighlightData, found in viewport.h
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2157
 * Called by MouseLoop() in windows.cpp
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2158
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  2159
void UpdateTileSelection()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2161
	int x1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2162
	int y1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2164
	_thd.new_drawstyle = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2166
	if (_thd.place_mode == VHM_SPECIAL) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2167
		x1 = _thd.selend.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2168
		y1 = _thd.selend.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
		if (x1 != -1) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2170
			int x2 = _thd.selstart.x & ~0xF;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2171
			int y2 = _thd.selstart.y & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
			x1 &= ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
			y1 &= ~0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2174
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6401
diff changeset
  2175
			if (x1 >= x2) Swap(x1, x2);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6401
diff changeset
  2176
			if (y1 >= y2) Swap(y1, y2);
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2177
			_thd.new_pos.x = x1;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2178
			_thd.new_pos.y = y1;
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2179
			_thd.new_size.x = x2 - x1 + TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2180
			_thd.new_size.y = y2 - y1 + TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2181
			_thd.new_drawstyle = _thd.next_drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2182
		}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2183
	} else if (_thd.place_mode != VHM_NONE) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2184
		Point pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2185
		x1 = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2186
		y1 = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
		if (x1 != -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2188
			switch (_thd.place_mode) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2189
				case VHM_RECT:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2190
					_thd.new_drawstyle = HT_RECT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2191
					break;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2192
				case VHM_POINT:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2193
					_thd.new_drawstyle = HT_POINT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2194
					x1 += 8;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2195
					y1 += 8;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2196
					break;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2197
				case VHM_RAIL:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2198
					_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2199
					break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2200
				default:
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2201
					NOT_REACHED();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2202
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2203
			}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2204
			_thd.new_pos.x = x1 & ~0xF;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2205
			_thd.new_pos.y = y1 & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2206
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2209
	/* redraw selection */
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2210
	if (_thd.drawstyle != _thd.new_drawstyle ||
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2211
			_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
4539
0b13858554fb (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  2212
			_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y ||
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2213
			_thd.outersize.x != _thd.new_outersize.x ||
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2214
			_thd.outersize.y != _thd.new_outersize.y) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2215
		/* clear the old selection? */
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2216
		if (_thd.drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2218
		_thd.drawstyle = _thd.new_drawstyle;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2219
		_thd.pos = _thd.new_pos;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2220
		_thd.size = _thd.new_size;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2221
		_thd.outersize = _thd.new_outersize;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2222
		_thd.dirty = 0xff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2223
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2224
		/* draw the new selection? */
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2225
		if (_thd.new_drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2226
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2227
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2228
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2229
/** highlighting tiles while only going over them with the mouse */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2230
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2231
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2232
	_thd.select_method = method;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2233
	_thd.select_proc   = process;
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2234
	_thd.selend.x = TileX(tile) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2235
	_thd.selstart.x = TileX(tile) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2236
	_thd.selend.y = TileY(tile) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2237
	_thd.selstart.y = TileY(tile) * TILE_SIZE;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2238
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2239
	/* Needed so several things (road, autoroad, bridges, ...) are placed correctly.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2240
	 * In effect, placement starts from the centre of a tile
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2241
	 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2242
	if (method == VPM_X_OR_Y || method == VPM_FIX_X || method == VPM_FIX_Y) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2243
		_thd.selend.x += TILE_SIZE / 2;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2244
		_thd.selend.y += TILE_SIZE / 2;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2245
		_thd.selstart.x += TILE_SIZE / 2;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2246
		_thd.selstart.y += TILE_SIZE / 2;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2247
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2248
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2249
	if (_thd.place_mode == VHM_RECT) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2250
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2251
		_thd.next_drawstyle = HT_RECT;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2252
	} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2253
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2254
		_thd.next_drawstyle = _thd.drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2255
	} else {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2256
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2257
		_thd.next_drawstyle = HT_POINT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2258
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2259
	_special_mouse_mode = WSM_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2262
void VpSetPlaceSizingLimit(int limit)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2263
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2264
	_thd.sizelimit = limit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2265
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2266
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2267
/**
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2268
* Highlights all tiles between a set of two tiles. Used in dock and tunnel placement
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2269
* @param from TileIndex of the first tile to highlight
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2270
* @param to TileIndex of the last tile to highlight */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2271
void VpSetPresizeRange(TileIndex from, TileIndex to)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2272
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2273
	uint64 distance = DistanceManhattan(from, to) + 1;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2274
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2275
	_thd.selend.x = TileX(to) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2276
	_thd.selend.y = TileY(to) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2277
	_thd.selstart.x = TileX(from) * TILE_SIZE;
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  2278
	_thd.selstart.y = TileY(from) * TILE_SIZE;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2279
	_thd.next_drawstyle = HT_RECT;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2280
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2281
	/* show measurement only if there is any length to speak of */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2282
	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
  2283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2284
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  2285
static void VpStartPreSizing()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2286
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2287
	_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2288
	_special_mouse_mode = WSM_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2289
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2290
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2291
/** returns information about the 2x1 piece to be build.
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2292
 * The lower bits (0-3) are the track type. */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2293
static HighLightStyle Check2x1AutoRail(int mode)
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2294
{
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2295
	int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2296
	int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2297
	int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2298
	int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2299
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
  2300
	switch (mode) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2301
		default: NOT_REACHED();
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2302
		case 0: // end piece is lower right
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2303
			if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_HL; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2304
			if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return HT_DIR_VR; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2305
			return HT_DIR_Y;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2306
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2307
		case 1:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2308
			if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_VL; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2309
			if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return HT_DIR_HU; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2310
			return HT_DIR_Y;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2311
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2312
		case 2:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2313
			if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return HT_DIR_VL; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2314
			if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_HL; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2315
			return HT_DIR_X;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2316
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2317
		case 3:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2318
			if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return HT_DIR_VR; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2319
			if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return HT_DIR_HU; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2320
			return HT_DIR_X;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2321
	}
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2322
}
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2323
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2324
/** Check if the direction of start and end tile should be swapped based on
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2325
 * the dragging-style. Default directions are:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2326
 * in the case of a line (HT_RAIL, HT_LINE):  DIR_NE, DIR_NW, DIR_N, DIR_E
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2327
 * in the case of a rect (HT_RECT, HT_POINT): DIR_S, DIR_E
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2328
 * For example dragging a rectangle area from south to north should be swapped to
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2329
 * north-south (DIR_S) to obtain the same results with less code. This is what
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2330
 * the return value signifies.
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2331
 * @param style HighLightStyle dragging style
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2332
 * @param start_tile start tile of drag
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2333
 * @param end_tile end tile of drag
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2334
 * @return boolean value which when true means start/end should be swapped */
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2335
static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile)
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2336
{
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2337
	uint start_x = TileX(start_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2338
	uint start_y = TileY(start_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2339
	uint end_x = TileX(end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2340
	uint end_y = TileY(end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2341
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2342
	switch (style & HT_DRAG_MASK) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2343
		case HT_RAIL:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2344
		case HT_LINE: return (end_x > start_x || (end_x == start_x && end_y > start_y));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2345
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2346
		case HT_RECT:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2347
		case HT_POINT: return (end_x != start_x && end_y < start_y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2348
		default: NOT_REACHED();
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2349
	}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2350
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2351
	return false;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2352
}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2353
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2354
/** Calculates height difference between one tile and another
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2355
* Multiplies the result to suit the standard given by minimap - 50 meters high
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2356
* To correctly get the height difference we need the direction we are dragging
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2357
* in, as well as with what kind of tool we are dragging. For example a horizontal
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2358
* autorail tool that starts in bottom and ends at the top of a tile will need the
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2359
* maximum of SW, S and SE, N corners respectively. This is handled by the lookup table below
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2360
* See _tileoffs_by_dir in map.c for the direction enums if you can't figure out
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2361
* the values yourself.
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2362
* @param style HightlightStyle of drag. This includes direction and style (autorail, rect, etc.)
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2363
* @param distance amount of tiles dragged, important for horizontal/vertical drags
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2364
*        ignored for others
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2365
* @param start_tile, end_tile start and end tile of drag operation
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2366
* @return height difference between two tiles. Tile measurement tool utilizes
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2367
* this value in its tooltips */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2368
static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile)
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2369
{
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2370
	bool swap = SwapDirection(style, start_tile, end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2371
	byte style_t;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2372
	uint h0, h1, ht; // start heigth, end height, and temp variable
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2373
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2374
	if (start_tile == end_tile) return 0;
5984
fbef81292ff9 (svn r8276) -Fix
tron
parents: 5924
diff changeset
  2375
	if (swap) Swap(start_tile, end_tile);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2376
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2377
	switch (style & HT_DRAG_MASK) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2378
		case HT_RECT: {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2379
			static const TileIndexDiffC heightdiff_area_by_dir[] = {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2380
				/* Start */ {1, 0}, /* Dragging east */ {0, 0}, /* Dragging south */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2381
				/* End   */ {0, 1}, /* Dragging east */ {1, 1}  /* Dragging south */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2382
			};
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2383
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2384
			/* In the case of an area we can determine whether we were dragging south or
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2385
			 * east by checking the X-coordinates of the tiles */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2386
			style_t = (byte)(TileX(end_tile) > TileX(start_tile));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2387
			start_tile = TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_area_by_dir[style_t]));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2388
			end_tile   = TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_area_by_dir[2 + style_t]));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2389
		}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2390
		/* Fallthrough */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2391
		case HT_POINT:
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2392
			h0 = TileHeight(start_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2393
			h1 = TileHeight(end_tile);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2394
			break;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2395
		default: { /* All other types, this is mostly only line/autorail */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2396
			static const HighLightStyle flip_style_direction[] = {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2397
				HT_DIR_X, HT_DIR_Y, HT_DIR_HL, HT_DIR_HU, HT_DIR_VR, HT_DIR_VL
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2398
			};
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2399
			static const TileIndexDiffC heightdiff_line_by_dir[] = {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2400
				/* Start */ {1, 0}, {1, 1}, /* HT_DIR_X  */ {0, 1}, {1, 1}, /* HT_DIR_Y  */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2401
				/* Start */ {1, 0}, {0, 0}, /* HT_DIR_HU */ {1, 0}, {1, 1}, /* HT_DIR_HL */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2402
				/* Start */ {1, 0}, {1, 1}, /* HT_DIR_VL */ {0, 1}, {1, 1}, /* HT_DIR_VR */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2403
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2404
				/* Start */ {0, 1}, {0, 0}, /* HT_DIR_X  */ {1, 0}, {0, 0}, /* HT_DIR_Y  */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2405
				/* End   */ {0, 1}, {0, 0}, /* HT_DIR_HU */ {1, 1}, {0, 1}, /* HT_DIR_HL */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2406
				/* End   */ {1, 0}, {0, 0}, /* HT_DIR_VL */ {0, 0}, {0, 1}, /* HT_DIR_VR */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2407
			};
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2408
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2409
			distance %= 2; // we're only interested if the distance is even or uneven
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2410
			style &= HT_DIR_MASK;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2411
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2412
			/* To handle autorail, we do some magic to be able to use a lookup table.
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2413
			 * Firstly if we drag the other way around, we switch start&end, and if needed
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2414
			 * also flip the drag-position. Eg if it was on the left, and the distance is even
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2415
			 * that means the end, which is now the start is on the right */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2416
			if (swap && distance == 0) style = flip_style_direction[style];
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2417
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2418
			/* Use lookup table for start-tile based on HighLightStyle direction */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2419
			style_t = style * 2;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2420
			assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2421
			h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t])));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2422
			ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1])));
5852
cb3f71b16e1a (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: 5838
diff changeset
  2423
			h0 = max(h0, ht);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2424
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2425
			/* Use lookup table for end-tile based on HighLightStyle direction
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2426
			 * flip around side (lower/upper, left/right) based on distance */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2427
			if (distance == 0) style_t = flip_style_direction[style] * 2;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2428
			assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2429
			h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t])));
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2430
			ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1])));
5852
cb3f71b16e1a (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: 5838
diff changeset
  2431
			h1 = max(h1, ht);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2432
		} break;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2433
	}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2434
5984
fbef81292ff9 (svn r8276) -Fix
tron
parents: 5924
diff changeset
  2435
	if (swap) Swap(h0, h1);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2436
	/* Minimap shows height in intervals of 50 meters, let's do the same */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2437
	return (int)(h1 - h0) * 50;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2438
}
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2439
4885
c9fe8c52fd50 (svn r6822) -Fix r6821: add type for measure_strings_length[]
glx
parents: 4884
diff changeset
  2440
static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF};
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2441
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2442
/** while dragging */
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2443
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
  2444
{
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2445
	HighLightStyle b;
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2446
	uint w, h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2447
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2448
	int dx = thd->selstart.x - (thd->selend.x & ~0xF);
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2449
	int dy = thd->selstart.y - (thd->selend.y & ~0xF);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2450
	w = abs(dx) + 16;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2451
	h = abs(dy) + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2452
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2453
	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2454
		if (method == VPM_RAILDIRS) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2455
			b = GetAutorailHT(x, y);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2456
		} else { // rect for autosignals on one tile
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2457
			b = HT_RECT;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2458
		}
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2459
	} else if (h == 16) { // Is this in X direction?
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2460
		if (dx == 16) { // 2x1 special handling
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2461
			b = (Check2x1AutoRail(3)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2462
		} else if (dx == -16) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2463
			b = (Check2x1AutoRail(2)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2464
		} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2465
			b = HT_LINE | HT_DIR_X;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2466
		}
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2467
		y = thd->selstart.y;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2468
	} else if (w == 16) { // Or Y direction?
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2469
		if (dy == 16) { // 2x1 special handling
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2470
			b = (Check2x1AutoRail(1)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2471
		} else if (dy == -16) { // 2x1 other direction
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2472
			b = (Check2x1AutoRail(0)) | HT_LINE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2473
		} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2474
			b = HT_LINE | HT_DIR_Y;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2475
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2476
		x = thd->selstart.x;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2477
	} else if (w > h * 2) { // still count as x dir?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2478
		b = HT_LINE | HT_DIR_X;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2479
		y = thd->selstart.y;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2480
	} else if (h > w * 2) { // still count as y dir?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2481
		b = HT_LINE | HT_DIR_Y;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2482
		x = thd->selstart.x;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2483
	} else { // complicated direction
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2484
		int d = w - h;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2485
		thd->selend.x = thd->selend.x & ~0xF;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2486
		thd->selend.y = thd->selend.y & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2487
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2488
		// four cases.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2489
		if (x > thd->selstart.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2490
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2491
				// south
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2492
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2493
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2494
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2495
					x = thd->selstart.x + h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2496
					b = HT_LINE | HT_DIR_VL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2497
					// return px == py || px == py + 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2498
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2499
					y = thd->selstart.y + w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2500
					b = HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2501
				} // return px == py || px == py - 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2502
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2503
				// west
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2504
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2505
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2506
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2507
					x = thd->selstart.x + h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2508
					b = HT_LINE | HT_DIR_HL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2509
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2510
					y = thd->selstart.y - w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2511
					b = HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2512
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2513
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2514
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2515
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2516
				// east
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2517
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2518
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2519
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2520
					x = thd->selstart.x - h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2521
					b = HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2522
					// return px == -py || px == -py - 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2523
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2524
					y = thd->selstart.y + w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2525
					b = HT_LINE | HT_DIR_HL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2526
				} // return px == -py || px == -py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2527
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2528
				// north
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2529
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2530
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2531
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2532
					x = thd->selstart.x - h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2533
					b = HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2534
					// return px == py || px == py - 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2535
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2536
					y = thd->selstart.y - w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2537
					b = HT_LINE | HT_DIR_VL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2538
				} //return px == py || px == py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2539
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2540
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2541
	}
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2542
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2543
	if (_settings_client.gui.measure_tooltip) {
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2544
		TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2545
		TileIndex t1 = TileVirtXY(x, y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2546
		uint distance = DistanceManhattan(t0, t1) + 1;
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2547
		byte index = 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2548
		uint64 params[2];
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2549
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2550
		if (distance != 1) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2551
			int heightdiff = CalcHeightdiff(b, distance, t0, t1);
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2552
			/* If we are showing a tooltip for horizontal or vertical drags,
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2553
			 * 2 tiles have a length of 1. To bias towards the ceiling we add
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2554
			 * one before division. It feels more natural to count 3 lengths as 2 */
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2555
			if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2556
				distance = (distance + 1) / 2;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2557
			}
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2558
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2559
			params[index++] = distance;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2560
			if (heightdiff != 0) params[index++] = heightdiff;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2561
		}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2562
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2563
		GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2564
	}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2565
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2566
	thd->selend.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2567
	thd->selend.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2568
	thd->next_drawstyle = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2569
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2570
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2571
/**
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2572
 * Selects tiles while dragging
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2573
 * @param x X coordinate of end of selection
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2574
 * @param y Y coordinate of end of selection
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2575
 * @param method modifies the way tiles are selected. Possible
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2576
 * methods are VPM_* in viewport.h */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2577
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2578
{
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2579
	int sx, sy;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2580
	HighLightStyle style;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2581
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2582
	if (x == -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2583
		_thd.selend.x = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2584
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2585
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2586
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2587
	/* 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
  2588
	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2589
		_thd.selend.x = x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2590
		_thd.selend.y = y;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2591
		CalcRaildirsDrawstyle(&_thd, x, y, method);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2592
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2593
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2594
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2595
	/* Needed so level-land is placed correctly */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2596
	if (_thd.next_drawstyle == HT_POINT) {
4799
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2597
		x += TILE_SIZE / 2;
a32af5dd7b6c (svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents: 4634
diff changeset
  2598
		y += TILE_SIZE / 2;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2599
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2600
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2601
	sx = _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2602
	sy = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2603
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2604
	switch (method) {
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2605
		case VPM_X_OR_Y: /* drag in X or Y direction */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2606
			if (abs(sy - y) < abs(sx - x)) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2607
				y = sy;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2608
				style = HT_DIR_X;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2609
			} else {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2610
				x = sx;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2611
				style = HT_DIR_Y;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2612
			}
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2613
			goto calc_heightdiff_single_direction;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2614
		case VPM_FIX_X: /* drag in Y direction */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2615
			x = sx;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2616
			style = HT_DIR_Y;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2617
			goto calc_heightdiff_single_direction;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2618
		case VPM_FIX_Y: /* drag in X direction */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2619
			y = sy;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2620
			style = HT_DIR_X;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2621
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2622
calc_heightdiff_single_direction:;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2623
			if (_settings_client.gui.measure_tooltip) {
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2624
				TileIndex t0 = TileVirtXY(sx, sy);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2625
				TileIndex t1 = TileVirtXY(x, y);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2626
				uint distance = DistanceManhattan(t0, t1) + 1;
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2627
				byte index = 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2628
				uint64 params[2];
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2629
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2630
				if (distance != 1) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2631
					/* With current code passing a HT_LINE style to calculate the height
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2632
					 * difference is enough. However if/when a point-tool is created
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2633
					 * with this method, function should be called with new_style (below)
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2634
					 * instead of HT_LINE | style case HT_POINT is handled specially
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2635
					 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2636
					int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1);
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2637
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2638
					params[index++] = distance;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2639
					if (heightdiff != 0) params[index++] = heightdiff;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2640
				}
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2641
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2642
				GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2643
			} break;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2644
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2645
		case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2646
			int limit = (_thd.sizelimit - 1) * TILE_SIZE;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2647
			x = sx + Clamp(x - sx, -limit, limit);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2648
			y = sy + Clamp(y - sy, -limit, limit);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2649
			} /* Fallthrough */
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2650
		case VPM_X_AND_Y: { /* drag an X by Y area */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2651
			if (_settings_client.gui.measure_tooltip) {
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2652
				static const StringID measure_strings_area[] = {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2653
					STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2654
				};
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2655
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2656
				TileIndex t0 = TileVirtXY(sx, sy);
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2657
				TileIndex t1 = TileVirtXY(x, y);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2658
				uint dx = Delta(TileX(t0), TileX(t1)) + 1;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2659
				uint dy = Delta(TileY(t0), TileY(t1)) + 1;
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2660
				byte index = 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2661
				uint64 params[3];
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2662
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2663
				/* If dragging an area (eg dynamite tool) and it is actually a single
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2664
				 * row/column, change the type to 'line' to get proper calculation for height */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2665
				style = (HighLightStyle)_thd.next_drawstyle;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2666
				if (style & HT_RECT) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2667
					if (dx == 1) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2668
						style = HT_LINE | HT_DIR_Y;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2669
					} else if (dy == 1) {
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2670
						style = HT_LINE | HT_DIR_X;
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2671
					}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2672
				}
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2673
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2674
				if (dx != 1 || dy != 1) {
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2675
					int heightdiff = CalcHeightdiff(style, 0, t0, t1);
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2676
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2677
					params[index++] = dx;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2678
					params[index++] = dy;
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2679
					if (heightdiff != 0) params[index++] = heightdiff;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2680
				}
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2681
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2682
				GuiShowTooltipsWithArgs(measure_strings_area[index], index, params);
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2683
			}
4884
895f06b87934 (svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents: 4838
diff changeset
  2684
		break;
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2685
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2686
		}
4834
ddcf440d0ffd (svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents: 4799
diff changeset
  2687
		default: NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2688
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2689
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2690
	_thd.selend.x = x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2691
	_thd.selend.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2692
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2693
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2694
/**
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2695
 * Handle the mouse while dragging for placement/resizing.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2696
 * @return Boolean whether search for a handler should continue
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2697
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  2698
bool VpHandlePlaceSizingDrag()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2699
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2700
	if (_special_mouse_mode != WSM_SIZING) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2701
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2702
	/* stop drag mode if the window has been closed */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2703
	Window *w = FindWindowById(_thd.window_class, _thd.window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2704
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2705
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2706
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2707
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2708
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2709
	/* 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
  2710
	if (_left_button_down) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2711
		w->OnPlaceDrag(_thd.select_method, _thd.select_proc, GetTileBelowCursor());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2712
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2713
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2714
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2715
	/* mouse button released..
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2716
	 * 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
  2717
	_special_mouse_mode = WSM_NONE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2718
	if (_thd.next_drawstyle == HT_RECT) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2719
		_thd.place_mode = VHM_RECT;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2720
	} else if (_thd.select_method == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2721
		_thd.place_mode = VHM_RECT;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2722
	} else if (_thd.next_drawstyle & HT_LINE) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2723
		_thd.place_mode = VHM_RAIL;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2724
	} else if (_thd.next_drawstyle & HT_RAIL) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2725
		_thd.place_mode = VHM_RAIL;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2726
	} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2727
		_thd.place_mode = VHM_POINT;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2728
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2729
	SetTileSelectSize(1, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2730
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2731
	w->OnPlaceMouseUp(_thd.select_method, _thd.select_proc, _thd.selend, TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2732
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2733
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2734
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2735
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2736
void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode, Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2737
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
  2738
	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
  2739
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2740
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2741
#include "table/animcursors.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2742
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2743
void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2744
{
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2745
	/* undo clicking on button and drag & drop */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2746
	if (_thd.place_mode != VHM_NONE || _special_mouse_mode == WSM_DRAGDROP) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2747
		Window *w = FindWindowById(_thd.window_class, _thd.window_number);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2748
		if (w != NULL) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2749
			/* Call the abort function, but set the window class to something
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2750
			 * that will never be used to avoid infinite loops. Setting it to
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2751
			 * the 'next' window class must not be done because recursion into
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2752
			 * this function might in some cases reset the newly set object to
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2753
			 * place or not properly reset the original selection. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2754
			_thd.window_class = WC_INVALID;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2755
			w->OnPlaceObjectAbort();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2756
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2757
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2758
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2759
	SetTileSelectSize(1, 1);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2760
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2761
	_thd.make_square_red = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2762
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2763
	if (mode == VHM_DRAG) { // VHM_DRAG is for dragdropping trains in the depot window
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2764
		mode = VHM_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2765
		_special_mouse_mode = WSM_DRAGDROP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2766
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2767
		_special_mouse_mode = WSM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2768
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2769
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2770
	_thd.place_mode = mode;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2771
	_thd.window_class = window_class;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2772
	_thd.window_number = window_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2773
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2774
	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
  2775
		VpStartPreSizing();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2776
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2777
	if ((int)icon < 0) {
4334
75322a204d0c (svn r6035) -Revert r5900 which supposedly fixed an invalid warning caused by buggy MS software
Darkvater
parents: 4272
diff changeset
  2778
		SetAnimatedMouseCursor(_animcursors[~icon]);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2779
	} else {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5853
diff changeset
  2780
		SetMouseCursor(icon, pal);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2781
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2782
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2783
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2784
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6443
diff changeset
  2785
void ResetObjectToPlace()
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2786
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2787
	_thd.FSMportLayout = NULL;  // ensure irregular airport support disabled
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10310
diff changeset
  2788
	_thd.FSMportMask = NULL;
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5984
diff changeset
  2789
	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
  2790
}
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2791
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2792
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2793
void SaveViewportBeforeSaveGame()
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2794
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2795
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2796
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2797
	if (w != NULL) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2798
		_saved_scrollpos_x = w->viewport->scrollpos_x;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2799
		_saved_scrollpos_y = w->viewport->scrollpos_y;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2800
		_saved_scrollpos_zoom = w->viewport->zoom;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2801
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2802
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2803
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2804
void ResetViewportAfterLoadGame()
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2805
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2806
	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2807
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2808
	w->viewport->scrollpos_x = _saved_scrollpos_x;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2809
	w->viewport->scrollpos_y = _saved_scrollpos_y;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2810
	w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2811
	w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2812
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2813
	ViewPort *vp = w->viewport;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2814
	vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2815
	vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2816
	vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2817
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2818
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2819
	MarkWholeScreenDirty();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2820
}