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