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