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