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