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