annotate src/viewport.cpp @ 16312:e19d6bb9ff88 draft

(svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
author alberth <alberth@openttd.org>
date Sat, 23 Oct 2010 20:39:21 +0000
parents cced8cded106
children b1fc0cfd2943
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12708
diff changeset
9
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
10 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
11 * @file viewport.cpp Handling of all viewports.
8957
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
12 *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
13 * \verbatim
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
14 * The in-game coordinate system looks like this *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
15 * *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
16 * ^ Z *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
17 * | *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
18 * | *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
19 * | *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
20 * | *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
21 * / \ *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
22 * / \ *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
23 * / \ *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
24 * / \ *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
25 * X < > Y *
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
26 * \endverbatim
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
27 */
6117
6def6ecb1bf7 (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 <belugas@openttd.org>
parents: 6106
diff changeset
28
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
29 #include "stdafx.h"
6453
666fc3ef3174 (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 <maedhros@openttd.org>
parents: 6448
diff changeset
30 #include "landscape.h"
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
31 #include "viewport_func.h"
8785
2a8950a812dc (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium <rubidium@openttd.org>
parents: 8743
diff changeset
32 #include "station_base.h"
12475
c133b51890f4 (svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents: 12472
diff changeset
33 #include "waypoint_base.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34 #include "town.h"
8790
5ef0059ccfc0 (svn r12501) -Codechange: split signs.h.
rubidium <rubidium@openttd.org>
parents: 8785
diff changeset
35 #include "signs_base.h"
5ef0059ccfc0 (svn r12501) -Codechange: split signs.h.
rubidium <rubidium@openttd.org>
parents: 8785
diff changeset
36 #include "signs_func.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 10864
diff changeset
37 #include "vehicle_base.h"
7486
1af81beda3fb (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium <rubidium@openttd.org>
parents: 7333
diff changeset
38 #include "vehicle_gui.h"
6937
b6cf3513b2c4 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight <truelight@openttd.org>
parents: 6878
diff changeset
39 #include "blitter/factory.hpp"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 8106
diff changeset
40 #include "strings_func.h"
8123
c26c28875749 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
41 #include "zoom_func.h"
8144
d18c8a0bb638 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents: 8139
diff changeset
42 #include "vehicle_func.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
43 #include "company_func.h"
12475
c133b51890f4 (svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents: 12472
diff changeset
44 #include "waypoint_func.h"
9117
453c3d26f4bc (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium <rubidium@openttd.org>
parents: 9111
diff changeset
45 #include "window_func.h"
9127
428852b86d4d (svn r12987) -Codechange: split viewport and tile selection.
rubidium <rubidium@openttd.org>
parents: 9117
diff changeset
46 #include "tilehighlight_func.h"
9274
85a62fb8608f (svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
47 #include "window_gui.h"
8946
402107c0562f (svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8925
diff changeset
48
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
49 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
50
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
51 PlaceProc *_place_proc;
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
52 Point _tile_fract_coords;
6624
bf5d7b24a7ab (svn r9844) -Codechange: replace zoomlevel with an enum
truelight <truelight@openttd.org>
parents: 6591
diff changeset
53
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
54 struct StringSpriteToDraw {
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11082
diff changeset
55 StringID string;
13817
881715964693 (svn r18343) -Fix [FS#3336] (r18243): dark blue signs would be drawn transparent
rubidium <rubidium@openttd.org>
parents: 13721
diff changeset
56 Colours colour;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
57 int32 x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
58 int32 y;
7006
933d3ee6d37d (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 <rubidium@openttd.org>
parents: 6937
diff changeset
59 uint64 params[2];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
60 uint16 width;
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
61 };
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
62
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
63 struct TileSpriteToDraw {
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5602
diff changeset
64 SpriteID image;
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
65 PaletteID pal;
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
66 const SubSprite *sub; ///< only draw a rectangular part of the sprite
12115
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
67 int32 x; ///< screen X coordinate of sprite
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
68 int32 y; ///< screen Y coordinate of sprite
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
69 };
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
70
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
71 struct ChildScreenSpriteToDraw {
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5602
diff changeset
72 SpriteID image;
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
73 PaletteID pal;
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
74 const SubSprite *sub; ///< only draw a rectangular part of the sprite
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
75 int32 x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
76 int32 y;
9534
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
77 int next; ///< next child to draw (-1 at the end)
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
78 };
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
79
10233
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
80 /** Parent sprite that should be drawn */
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
81 struct ParentSpriteToDraw {
7569
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
82 SpriteID image; ///< sprite to draw
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
83 PaletteID pal; ///< palette to use
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
84 const SubSprite *sub; ///< only draw a rectangular part of the sprite
7569
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
85
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
86 int32 x; ///< screen X coordinate of sprite
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
87 int32 y; ///< screen Y coordinate of sprite
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
88
7569
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
89 int32 left; ///< minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
90 int32 top; ///< minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
91
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
92 int32 xmin; ///< minimal world X coordinate of bounding box
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
93 int32 xmax; ///< maximal world X coordinate of bounding box
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
94 int32 ymin; ///< minimal world Y coordinate of bounding box
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
95 int32 ymax; ///< maximal world Y coordinate of bounding box
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
96 int zmin; ///< minimal world Z coordinate of bounding box
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
97 int zmax; ///< maximal world Z coordinate of bounding box
7569
326049261489 (svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas <belugas@openttd.org>
parents: 7545
diff changeset
98
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
99 int first_child; ///< the first child to draw.
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
100 bool comparison_done; ///< Used during sprite sorting: true if sprite has been compared with all other sprites
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
101 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
102
10233
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
103 /** Enumeration of multi-part foundations */
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
104 enum FoundationPart {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
105 FOUNDATION_PART_NONE = 0xFF, ///< Neither foundation nor groundsprite drawn yet.
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
106 FOUNDATION_PART_NORMAL = 0, ///< First part (normal foundation or no foundation)
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
107 FOUNDATION_PART_HALFTILE = 1, ///< Second part (halftile foundation)
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
108 FOUNDATION_PART_END
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
109 };
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
110
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
111 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
112 * Mode of "sprite combining"
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
113 * @see StartSpriteCombine
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
114 */
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
115 enum SpriteCombineMode {
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
116 SPRITE_COMBINE_NONE, ///< Every #AddSortableSpriteToDraw start its own bounding box
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
117 SPRITE_COMBINE_PENDING, ///< %Sprite combining will start with the next unclipped sprite.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
118 SPRITE_COMBINE_ACTIVE, ///< %Sprite combining is active. #AddSortableSpriteToDraw outputs child sprites.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
119 };
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
120
8949
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
121 typedef SmallVector<TileSpriteToDraw, 64> TileSpriteToDrawVector;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
122 typedef SmallVector<StringSpriteToDraw, 4> StringSpriteToDrawVector;
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
123 typedef SmallVector<ParentSpriteToDraw, 64> ParentSpriteToDrawVector;
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
124 typedef SmallVector<ParentSpriteToDraw*, 64> ParentSpriteToSortVector;
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
125 typedef SmallVector<ChildScreenSpriteToDraw, 16> ChildScreenSpriteToDrawVector;
8946
402107c0562f (svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8925
diff changeset
126
10233
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
127 /** Data structure storing rendering information */
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
128 struct ViewportDrawer {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
129 DrawPixelInfo dpi;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
130
8946
402107c0562f (svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8925
diff changeset
131 StringSpriteToDrawVector string_sprites_to_draw;
8947
20e58270e32d (svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8946
diff changeset
132 TileSpriteToDrawVector tile_sprites_to_draw;
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
133 ParentSpriteToDrawVector parent_sprites_to_draw;
10233
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
134 ParentSpriteToSortVector parent_sprites_to_sort; ///< Parent sprite pointer array used for sorting
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
135 ChildScreenSpriteToDrawVector child_screen_sprites_to_draw;
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
136
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
137 int *last_child;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
138
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
139 SpriteCombineMode combine_sprites; ///< Current mode of "sprite combining". @see StartSpriteCombine
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
140
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
141 int foundation[FOUNDATION_PART_END]; ///< Foundation sprites (index into parent_sprites_to_draw).
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
142 FoundationPart foundation_part; ///< Currently active foundation for ground sprite drawing.
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
143 int *last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw)
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
144 Point foundation_offset[FOUNDATION_PART_END]; ///< Pixel offset for ground sprites on the foundations.
6248
0789677a15a0 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents: 6247
diff changeset
145 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
146
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
147 static ViewportDrawer _vd;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
148
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
149 TileHighlightData _thd;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
150 static TileInfo *_cur_ti;
8979
e6dbe6d84c32 (svn r12771) -Codechange: remove more from variables.h.
rubidium <rubidium@openttd.org>
parents: 8969
diff changeset
151 bool _draw_bounding_boxes = false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
152
11375
1d342902ac94 (svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
smatz <smatz@openttd.org>
parents: 11368
diff changeset
153 static Point MapXYZToViewport(const ViewPort *vp, int x, int y, int z)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
154 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
155 Point p = RemapCoords(x, y, z);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
156 p.x -= vp->virtual_width / 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
157 p.y -= vp->virtual_height / 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
158 return p;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
159 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
160
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
161 void DeleteWindowViewport(Window *w)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
162 {
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
163 free(w->viewport);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
164 w->viewport = NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
165 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
166
8992
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
167 /**
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
168 * Initialize viewport of the window for use.
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
169 * @param w Window to use/display the viewport in
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
170 * @param x Offset of left edge of viewport with respect to left edge window \a w
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
171 * @param y Offset of top edge of viewport with respect to top edge window \a w
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
172 * @param width Width of the viewport
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
173 * @param height Height of the viewport
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
174 * @param follow_flags Flags controlling the viewport.
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
175 * - If bit 31 is set, the lower 16 bits are the vehicle that the viewport should follow.
16309
19dba04d7fc5 (svn r21017) -Doc: Small fixes (by Krille).
alberth <alberth@openttd.org>
parents: 16191
diff changeset
176 * - If bit 31 is clear, it is a #TileIndex.
8992
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
177 * @param zoom Zoomlevel to display
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
178 */
8994
e4c3087abbde (svn r12789) -Codechange: rename AssignWindowViewport to InitializeWindowViewport because the viewport is now part of the window struct. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8992
diff changeset
179 void InitializeWindowViewport(Window *w, int x, int y,
6624
bf5d7b24a7ab (svn r9844) -Codechange: replace zoomlevel with an enum
truelight <truelight@openttd.org>
parents: 6591
diff changeset
180 int width, int height, uint32 follow_flags, ZoomLevel zoom)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
181 {
8957
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
182 assert(w->viewport == NULL);
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
183
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
184 ViewportData *vp = CallocT<ViewportData>(1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
185
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
186 vp->left = x + w->left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
187 vp->top = y + w->top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
188 vp->width = width;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
189 vp->height = height;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
190
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
191 vp->zoom = zoom;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
192
6654
860f3e5f70ec (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight <truelight@openttd.org>
parents: 6653
diff changeset
193 vp->virtual_width = ScaleByZoom(width, zoom);
860f3e5f70ec (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight <truelight@openttd.org>
parents: 6653
diff changeset
194 vp->virtual_height = ScaleByZoom(height, zoom);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
195
8957
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
196 Point pt;
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
197
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
198 if (follow_flags & 0x80000000) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199 const Vehicle *veh;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
200
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
201 vp->follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11765
diff changeset
202 veh = Vehicle::Get(vp->follow_vehicle);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
203 pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
204 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
205 uint x = TileX(follow_flags) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
206 uint y = TileY(follow_flags) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
207
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
208 vp->follow_vehicle = INVALID_VEHICLE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
209 pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
210 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
211
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
212 vp->scrollpos_x = pt.x;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
213 vp->scrollpos_y = pt.y;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
214 vp->dest_scrollpos_x = pt.x;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
215 vp->dest_scrollpos_y = pt.y;
6730
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
216
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
217 w->viewport = vp;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
218 vp->virtual_left = 0;//pt.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
219 vp->virtual_top = 0;//pt.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
220 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
221
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
222 static Point _vp_move_offs;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
223
10610
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
224 static void DoSetViewportPosition(const Window *w, int left, int top, int width, int height)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
225 {
10614
48b9085d5b21 (svn r14905) -Fix (r14899): in some corner cases already freed memory could be read.
rubidium <rubidium@openttd.org>
parents: 10610
diff changeset
226 FOR_ALL_WINDOWS_FROM_BACK_FROM(w, w) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
227 if (left + width > w->left &&
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
228 w->left + w->width > left &&
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
229 top + height > w->top &&
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
230 w->top + w->height > top) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
231
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
232 if (left < w->left) {
10610
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
233 DoSetViewportPosition(w, left, top, w->left - left, height);
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
234 DoSetViewportPosition(w, left + (w->left - left), top, width - (w->left - left), height);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
235 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
236 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
237
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
238 if (left + width > w->left + w->width) {
10610
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
239 DoSetViewportPosition(w, left, top, (w->left + w->width - left), height);
13175
3f4cc2986131 (svn r17682) -Codechange: remove erroneous space before some commas
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
240 DoSetViewportPosition(w, left + (w->left + w->width - left), top, width - (w->left + w->width - left), height);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
241 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
242 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
243
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244 if (top < w->top) {
10610
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
245 DoSetViewportPosition(w, left, top, width, (w->top - top));
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
246 DoSetViewportPosition(w, left, top + (w->top - top), width, height - (w->top - top));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
248 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
249
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
250 if (top + height > w->top + w->height) {
10610
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
251 DoSetViewportPosition(w, left, top, width, (w->top + w->height - top));
13175
3f4cc2986131 (svn r17682) -Codechange: remove erroneous space before some commas
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
252 DoSetViewportPosition(w, left, top + (w->top + w->height - top), width, height - (w->top + w->height - top));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
253 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
254 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
255
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
256 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
257 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
258 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
259
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
261 int xo = _vp_move_offs.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262 int yo = _vp_move_offs.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264 if (abs(xo) >= width || abs(yo) >= height) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 /* fully_outside */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
266 RedrawScreenRect(left, top, left + width, top + height);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
267 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
269
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
270 GfxScroll(left, top, width, height, xo, yo);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
271
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
272 if (xo > 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
273 RedrawScreenRect(left, top, xo + left, top + height);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
274 left += xo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
275 width -= xo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
276 } else if (xo < 0) {
10642
29bc871ff8d1 (svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
277 RedrawScreenRect(left + width + xo, top, left + width, top + height);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
278 width += xo;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
279 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
280
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
281 if (yo > 0) {
10642
29bc871ff8d1 (svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
282 RedrawScreenRect(left, top, width + left, top + yo);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283 } else if (yo < 0) {
10642
29bc871ff8d1 (svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
284 RedrawScreenRect(left, top + height + yo, width + left, top + height);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
285 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
286 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
287 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
289 static void SetViewportPosition(Window *w, int x, int y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
290 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
291 ViewPort *vp = w->viewport;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
292 int old_left = vp->virtual_left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
293 int old_top = vp->virtual_top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
294 int i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
295 int left, top, width, height;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
296
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
297 vp->virtual_left = x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
298 vp->virtual_top = y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
299
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
300 /* Viewport is bound to its left top corner, so it must be rounded down (UnScaleByZoomLower)
7905
63c86d0b97e7 (svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz <smatz@openttd.org>
parents: 7889
diff changeset
301 * else glitch described in FS#1412 will happen (offset by 1 pixel with zoom level > NORMAL)
63c86d0b97e7 (svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz <smatz@openttd.org>
parents: 7889
diff changeset
302 */
63c86d0b97e7 (svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz <smatz@openttd.org>
parents: 7889
diff changeset
303 old_left = UnScaleByZoomLower(old_left, vp->zoom);
63c86d0b97e7 (svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz <smatz@openttd.org>
parents: 7889
diff changeset
304 old_top = UnScaleByZoomLower(old_top, vp->zoom);
63c86d0b97e7 (svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz <smatz@openttd.org>
parents: 7889
diff changeset
305 x = UnScaleByZoomLower(x, vp->zoom);
63c86d0b97e7 (svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz <smatz@openttd.org>
parents: 7889
diff changeset
306 y = UnScaleByZoomLower(y, vp->zoom);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
307
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
308 old_left -= x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
309 old_top -= y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
310
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
311 if (old_top == 0 && old_left == 0) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
312
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
313 _vp_move_offs.x = old_left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
314 _vp_move_offs.y = old_top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
315
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
316 left = vp->left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
317 top = vp->top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
318 width = vp->width;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
319 height = vp->height;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
320
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
321 if (left < 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
322 width += left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
323 left = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
324 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
325
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
326 i = left + width - _screen.width;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
327 if (i >= 0) width -= i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
328
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
329 if (width > 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
330 if (top < 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
331 height += top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
332 top = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
333 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
334
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
335 i = top + height - _screen.height;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
336 if (i >= 0) height -= i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
337
10610
1d2aeaa16ec6 (svn r14899) -Feature: remove the window limit, but leave a configurable limit on the number of non-sticky non-vital windows.
rubidium <rubidium@openttd.org>
parents: 10600
diff changeset
338 if (height > 0) DoSetViewportPosition(w->z_front, left, top, width, height);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
339 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
340 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
341
8992
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
342 /**
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
343 * Is a xy position inside the viewport of the window?
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
344 * @param w Window to examine its viewport
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
345 * @param x X coordinate of the xy position
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
346 * @param y Y coordinate of the xy position
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
347 * @return Pointer to the viewport if the xy position is in the viewport of the window,
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
348 * otherwise \c NULL is returned.
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
349 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
350 ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
351 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
352 ViewPort *vp = w->viewport;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
353
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
354 if (vp != NULL &&
8562
f539be5f3bd3 (svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas <belugas@openttd.org>
parents: 8473
diff changeset
355 IsInsideMM(x, vp->left, vp->left + vp->width) &&
7954
38bb7c45688f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7951
diff changeset
356 IsInsideMM(y, vp->top, vp->top + vp->height))
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
357 return vp;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
358
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
359 return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
360 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
361
10233
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
362 /**
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
363 * Translate screen coordinate in a viewport to a tile coordinate
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
364 * @param vp Viewport that contains the (\a x, \a y) screen coordinate
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
365 * @param x Screen x coordinate
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
366 * @param y Screen y coordinate
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
367 * @return Tile coordinate
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
368 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
369 static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
370 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
371 Point pt;
10642
29bc871ff8d1 (svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
372 int a, b;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
373 uint z;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
374
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
375 if ( (uint)(x -= vp->left) >= (uint)vp->width ||
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
376 (uint)(y -= vp->top) >= (uint)vp->height) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
377 Point pt = {-1, -1};
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
378 return pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
379 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
380
6626
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
381 x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> 2;
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
382 y = (ScaleByZoom(y, vp->zoom) + vp->virtual_top) >> 1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
383
10642
29bc871ff8d1 (svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
384 a = y - x;
29bc871ff8d1 (svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents: 10626
diff changeset
385 b = y + x;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
386
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
387 /* we need to move variables in to the valid range, as the
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
388 * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
389 * when the user tries to zoom out along the sides of the map */
15188
d1bed581946f (svn r19817) -Fix: MSVC compile warnings
rubidium <rubidium@openttd.org>
parents: 15187
diff changeset
390 a = Clamp(a, -4 * (int)TILE_SIZE, (int)(MapMaxX() * TILE_SIZE) - 1);
d1bed581946f (svn r19817) -Fix: MSVC compile warnings
rubidium <rubidium@openttd.org>
parents: 15187
diff changeset
391 b = Clamp(b, -4 * (int)TILE_SIZE, (int)(MapMaxY() * TILE_SIZE) - 1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
392
7764
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
393 /* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0.
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
394 * Now find the Z-world coordinate by fix point iteration.
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
395 * This is a bit tricky because the tile height is non-continuous at foundations.
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
396 * The clicked point should be approached from the back, otherwise there are regions that are not clickable.
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
397 * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
398 * So give it a z-malus of 4 in the first iterations.
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
399 */
4cdd7ef382fe (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7726
diff changeset
400 z = 0;
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
401
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
402 int min_coord = _settings_game.construction.freeform_edges ? TILE_SIZE : 0;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
403
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
404 for (int i = 0; i < 5; i++) z = GetSlopeZ(Clamp(a + (int)max(z, 4u) - 4, min_coord, MapMaxX() * TILE_SIZE - 1), Clamp(b + (int)max(z, 4u) - 4, min_coord, MapMaxY() * TILE_SIZE - 1)) / 2;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
405 for (uint malus = 3; malus > 0; malus--) z = GetSlopeZ(Clamp(a + (int)max(z, malus) - (int)malus, min_coord, MapMaxX() * TILE_SIZE - 1), Clamp(b + (int)max(z, malus) - (int)malus, min_coord, MapMaxY() * TILE_SIZE - 1)) / 2;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
406 for (int i = 0; i < 5; i++) z = GetSlopeZ(Clamp(a + (int)z, min_coord, MapMaxX() * TILE_SIZE - 1), Clamp(b + (int)z, min_coord, MapMaxY() * TILE_SIZE - 1)) / 2;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
407
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
408 pt.x = Clamp(a + (int)z, min_coord, MapMaxX() * TILE_SIZE - 1);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
409 pt.y = Clamp(b + (int)z, min_coord, MapMaxY() * TILE_SIZE - 1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
410
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
411 return pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
412 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
413
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
414 /* When used for zooming, check area below current coordinates (x,y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
415 * and return the tile of the zoomed out/in position (zoom_x, zoom_y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
416 * when you just want the tile, make x = zoom_x and y = zoom_y */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
417 static Point GetTileFromScreenXY(int x, int y, int zoom_x, int zoom_y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
418 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
419 Window *w;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
420 ViewPort *vp;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
421 Point pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
422
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
423 if ( (w = FindWindowFromPt(x, y)) != NULL &&
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
424 (vp = IsPtInWindowViewport(w, x, y)) != NULL)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
425 return TranslateXYToTileCoord(vp, zoom_x, zoom_y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
426
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
427 pt.y = pt.x = -1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
428 return pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
429 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
430
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
431 Point GetTileBelowCursor()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
432 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
433 return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
434 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
435
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
436
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
437 Point GetTileZoomCenterWindow(bool in, Window * w)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
438 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
439 int x, y;
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
440 ViewPort *vp = w->viewport;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
441
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
442 if (in) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
443 x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
444 y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
445 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
446 x = vp->width - (_cursor.pos.x - vp->left);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
447 y = vp->height - (_cursor.pos.y - vp->top);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
448 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
449 /* Get the tile below the cursor and center on the zoomed-out center */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
450 return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
451 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
452
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
453 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
454 * Update the status of the zoom-buttons according to the zoom-level
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
455 * of the viewport. This will update their status and invalidate accordingly
6443
bc27521ccac0 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas <belugas@openttd.org>
parents: 6427
diff changeset
456 * @param w Window pointer to the window that has the zoom buttons
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
457 * @param vp pointer to the viewport whose zoom-level the buttons represent
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
458 * @param widget_zoom_in widget index for window with zoom-in button
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
459 * @param widget_zoom_out widget index for window with zoom-out button
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
460 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
461 void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
462 {
7997
d109780d515b (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium <rubidium@openttd.org>
parents: 7970
diff changeset
463 w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == ZOOM_LVL_MIN);
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 13012
diff changeset
464 w->SetWidgetDirty(widget_zoom_in);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
465
7997
d109780d515b (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium <rubidium@openttd.org>
parents: 7970
diff changeset
466 w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == ZOOM_LVL_MAX);
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 13012
diff changeset
467 w->SetWidgetDirty(widget_zoom_out);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
468 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
469
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
470 /**
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
471 * Schedules a tile sprite for drawing.
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
472 *
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
473 * @param image the image to draw.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
474 * @param pal the provided palette.
12115
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
475 * @param x position x (world coordinates) of the sprite.
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
476 * @param y position y (world coordinates) of the sprite.
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
477 * @param z position z (world coordinates) of the sprite.
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
478 * @param sub Only draw a part of the sprite.
12115
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
479 * @param extra_offs_x Pixel X offset for the sprite position.
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
480 * @param extra_offs_y Pixel Y offset for the sprite position.
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
481 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
482 static void AddTileSpriteToDraw(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub = NULL, int extra_offs_x = 0, int extra_offs_y = 0)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
483 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
484 assert((image & SPRITE_MASK) < MAX_SPRITES);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
485
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
486 TileSpriteToDraw *ts = _vd.tile_sprites_to_draw.Append();
8949
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
487 ts->image = image;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
488 ts->pal = pal;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
489 ts->sub = sub;
12115
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
490 Point pt = RemapCoords(x, y, z);
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
491 ts->x = pt.x + extra_offs_x;
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
492 ts->y = pt.y + extra_offs_y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
493 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
494
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
495 /**
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
496 * Adds a child sprite to the active foundation.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
497 *
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
498 * The pixel offset of the sprite relative to the ParentSprite is the sum of the offset passed to OffsetGroundSprite() and extra_offs_?.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
499 *
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
500 * @param image the image to draw.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
501 * @param pal the provided palette.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
502 * @param sub Only draw a part of the sprite.
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
503 * @param foundation_part Foundation part.
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
504 * @param extra_offs_x Pixel X offset for the sprite position.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
505 * @param extra_offs_y Pixel Y offset for the sprite position.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
506 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
507 static void AddChildSpriteToFoundation(SpriteID image, PaletteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y)
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
508 {
7954
38bb7c45688f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7951
diff changeset
509 assert(IsInsideMM(foundation_part, 0, FOUNDATION_PART_END));
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
510 assert(_vd.foundation[foundation_part] != -1);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
511 Point offs = _vd.foundation_offset[foundation_part];
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
512
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
513 /* Change the active ChildSprite list to the one of the foundation */
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
514 int *old_child = _vd.last_child;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
515 _vd.last_child = _vd.last_foundation_child[foundation_part];
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
516
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
517 AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y, false, sub);
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
518
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
519 /* Switch back to last ChildSprite list */
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
520 _vd.last_child = old_child;
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
521 }
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
522
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
523 /**
14154
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
524 * Draws a ground sprite at a specific world-coordinate relative to the current tile.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
525 * If the current tile is drawn on top of a foundation the sprite is added as child sprite to the "foundation"-ParentSprite.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
526 *
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
527 * @param image the image to draw.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
528 * @param pal the provided palette.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
529 * @param x position x (world coordinates) of the sprite relative to current tile.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
530 * @param y position y (world coordinates) of the sprite relative to current tile.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
531 * @param z position z (world coordinates) of the sprite relative to current tile.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
532 * @param sub Only draw a part of the sprite.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
533 * @param extra_offs_x Pixel X offset for the sprite position.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
534 * @param extra_offs_y Pixel Y offset for the sprite position.
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
535 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
536 void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
14154
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
537 {
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
538 /* Switch to first foundation part, if no foundation was drawn */
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
539 if (_vd.foundation_part == FOUNDATION_PART_NONE) _vd.foundation_part = FOUNDATION_PART_NORMAL;
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
540
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
541 if (_vd.foundation[_vd.foundation_part] != -1) {
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
542 Point pt = RemapCoords(x, y, z);
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
543 AddChildSpriteToFoundation(image, pal, sub, _vd.foundation_part, pt.x + extra_offs_x, pt.y + extra_offs_y);
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
544 } else {
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
545 AddTileSpriteToDraw(image, pal, _cur_ti->x + x, _cur_ti->y + y, _cur_ti->z + z, sub, extra_offs_x, extra_offs_y);
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
546 }
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
547 }
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
548
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
549 /**
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
550 * Draws a ground sprite for the current tile.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
551 * If the current tile is drawn on top of a foundation the sprite is added as child sprite to the "foundation"-ParentSprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
552 *
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
553 * @param image the image to draw.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
554 * @param pal the provided palette.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
555 * @param sub Only draw a part of the sprite.
12115
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
556 * @param extra_offs_x Pixel X offset for the sprite position.
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
557 * @param extra_offs_y Pixel Y offset for the sprite position.
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
558 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
559 void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
560 {
14154
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
561 DrawGroundSpriteAt(image, pal, 0, 0, 0, sub, extra_offs_x, extra_offs_y);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
562 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
563
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
564 /**
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
565 * Called when a foundation has been drawn for the current tile.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
566 * Successive ground sprites for the current tile will be drawn as child sprites of the "foundation"-ParentSprite, not as TileSprites.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
567 *
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
568 * @param x sprite x-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
569 * @param y sprite y-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
570 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
571 void OffsetGroundSprite(int x, int y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
572 {
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
573 /* Switch to next foundation part */
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
574 switch (_vd.foundation_part) {
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
575 case FOUNDATION_PART_NONE:
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
576 _vd.foundation_part = FOUNDATION_PART_NORMAL;
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
577 break;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
578 case FOUNDATION_PART_NORMAL:
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
579 _vd.foundation_part = FOUNDATION_PART_HALFTILE;
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
580 break;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
581 default: NOT_REACHED();
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
582 }
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
583
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
584 /* _vd.last_child == NULL if foundation sprite was clipped by the viewport bounds */
9553
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
585 if (_vd.last_child != NULL) _vd.foundation[_vd.foundation_part] = _vd.parent_sprites_to_draw.Length() - 1;
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
586
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
587 _vd.foundation_offset[_vd.foundation_part].x = x;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
588 _vd.foundation_offset[_vd.foundation_part].y = y;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
589 _vd.last_foundation_child[_vd.foundation_part] = _vd.last_child;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
590 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
591
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
592 /**
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
593 * Adds a child sprite to a parent sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
594 * In contrast to "AddChildSpriteScreen()" the sprite position is in world coordinates
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
595 *
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
596 * @param image the image to draw.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
597 * @param pal the provided palette.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
598 * @param x position x of the sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
599 * @param y position y of the sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
600 * @param z position z of the sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
601 * @param sub Only draw a part of the sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
602 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
603 static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, byte z, const SubSprite *sub)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
604 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
605 Point pt = RemapCoords(x, y, z);
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10645
diff changeset
606 const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
607
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
608 if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width ||
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
609 pt.x + spr->x_offs + spr->width <= _vd.dpi.left ||
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
610 pt.y + spr->y_offs >= _vd.dpi.top + _vd.dpi.height ||
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
611 pt.y + spr->y_offs + spr->height <= _vd.dpi.top)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
612 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
613
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
614 const ParentSpriteToDraw *pstd = _vd.parent_sprites_to_draw.End() - 1;
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
615 AddChildSpriteScreen(image, pal, pt.x - pstd->left, pt.y - pstd->top, false, sub);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
616 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
617
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
618 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
619 * Draw a (transparent) sprite at given coordinates with a given bounding box.
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
620 * 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.
7617
efa2262af59e (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7601
diff changeset
621 * Bounding boxes with bb_offset_x == w or bb_offset_y == h or bb_offset_z == dz are allowed and produce thin slices.
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
622 *
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
623 * @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
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
624 * defined by the sprite offset in the grf file.
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
625 * However if modifying the sprite offsets is not suitable (e.g. when using existing graphics), the bounding box can be tuned by bb_offset.
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
626 *
7617
efa2262af59e (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7601
diff changeset
627 * @pre w >= bb_offset_x, h >= bb_offset_y, dz >= bb_offset_z. Else w, h or dz are ignored.
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
628 *
7333
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
629 * @param image the image to combine and draw,
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
630 * @param pal the provided palette,
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
631 * @param x position X (world) of the sprite,
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
632 * @param y position Y (world) of the sprite,
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
633 * @param w bounding box extent towards positive X (world),
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
634 * @param h bounding box extent towards positive Y (world),
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
635 * @param dz bounding box extent towards positive Z (world),
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
636 * @param z position Z (world) of the sprite,
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
637 * @param transparent if true, switch the palette between the provided palette and the transparent palette,
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
638 * @param bb_offset_x bounding box extent towards negative X (world),
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
639 * @param bb_offset_y bounding box extent towards negative Y (world),
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
640 * @param bb_offset_z bounding box extent towards negative Z (world)
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
641 * @param sub Only draw a part of the sprite.
7333
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
642 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
643 void AddSortableSpriteToDraw(SpriteID image, PaletteID 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)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
644 {
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
645 int32 left, right, top, bottom;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
646
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
647 assert((image & SPRITE_MASK) < MAX_SPRITES);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
648
7333
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
649 /* make the sprites transparent with the right palette */
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
650 if (transparent) {
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
651 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
7333
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
652 pal = PALETTE_TO_TRANSPARENT;
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
653 }
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7321
diff changeset
654
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
655 if (_vd.combine_sprites == SPRITE_COMBINE_ACTIVE) {
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
656 AddCombinedSprite(image, pal, x, y, z, sub);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
657 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
658 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
659
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
660 _vd.last_child = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
661
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
662 Point pt = RemapCoords(x, y, z);
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
663 int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y;
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
664
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
665 /* Compute screen extents of sprite */
7601
b5ee57f72673 (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 <rubidium@openttd.org>
parents: 7580
diff changeset
666 if (image == SPR_EMPTY_BOUNDING_BOX) {
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
667 left = tmp_left = RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x;
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
668 right = RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1;
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
669 top = tmp_top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y;
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
670 bottom = RemapCoords(x + w , y + h , z + bb_offset_z).y + 1;
7601
b5ee57f72673 (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 <rubidium@openttd.org>
parents: 7580
diff changeset
671 } else {
10056
7867701f63e4 (svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium <rubidium@openttd.org>
parents: 10055
diff changeset
672 const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
673 left = tmp_left = (pt.x += spr->x_offs);
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
674 right = (pt.x + spr->width );
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
675 top = tmp_top = (pt.y += spr->y_offs);
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
676 bottom = (pt.y + spr->height);
7601
b5ee57f72673 (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 <rubidium@openttd.org>
parents: 7580
diff changeset
677 }
8562
f539be5f3bd3 (svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas <belugas@openttd.org>
parents: 8473
diff changeset
678
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
679 if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
15002
baf0e12ad2b4 (svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents: 14448
diff changeset
680 /* Compute maximal extents of sprite and its bounding box */
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
681 left = min(left , RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x);
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
682 right = max(right , RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1);
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
683 top = min(top , RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y);
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
684 bottom = max(bottom, RemapCoords(x + w , y + h , z + bb_offset_z).y + 1);
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
685 }
8562
f539be5f3bd3 (svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas <belugas@openttd.org>
parents: 8473
diff changeset
686
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
687 /* Do not add the sprite to the viewport, if it is outside */
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
688 if (left >= _vd.dpi.left + _vd.dpi.width ||
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
689 right <= _vd.dpi.left ||
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
690 top >= _vd.dpi.top + _vd.dpi.height ||
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
691 bottom <= _vd.dpi.top) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
692 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
693 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
694
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
695 ParentSpriteToDraw *ps = _vd.parent_sprites_to_draw.Append();
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
696 ps->x = tmp_x;
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
697 ps->y = tmp_y;
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
698
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
699 ps->left = tmp_left;
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
700 ps->top = tmp_top;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
701
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
702 ps->image = image;
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5602
diff changeset
703 ps->pal = pal;
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
704 ps->sub = sub;
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
705 ps->xmin = x + bb_offset_x;
7617
efa2262af59e (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7601
diff changeset
706 ps->xmax = x + max(bb_offset_x, w) - 1;
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
707
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
708 ps->ymin = y + bb_offset_y;
7617
efa2262af59e (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7601
diff changeset
709 ps->ymax = y + max(bb_offset_y, h) - 1;
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
710
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
711 ps->zmin = z + bb_offset_z;
7617
efa2262af59e (svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7601
diff changeset
712 ps->zmax = z + max(bb_offset_z, dz) - 1;
7580
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
713
8ae764721b47 (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 <rubidium@openttd.org>
parents: 7579
diff changeset
714 ps->comparison_done = false;
9534
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
715 ps->first_child = -1;
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
716
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
717 _vd.last_child = &ps->first_child;
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
718
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
719 if (_vd.combine_sprites == SPRITE_COMBINE_PENDING) _vd.combine_sprites = SPRITE_COMBINE_ACTIVE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
720 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
721
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
722 /**
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
723 * Starts a block of sprites, which are "combined" into a single bounding box.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
724 *
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
725 * Subsequent calls to #AddSortableSpriteToDraw will be drawn into the same bounding box.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
726 * That is: The first sprite that is not clipped by the viewport defines the bounding box, and
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
727 * the following sprites will be child sprites to that one.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
728 *
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
729 * That implies:
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
730 * - The drawing order is definite. No other sprites will be sorted between those of the block.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
731 * - You have to provide a valid bounding box for all sprites,
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
732 * as you won't know which one is the first non-clipped one.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
733 * Preferable you use the same bounding box for all.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
734 * - You cannot use #AddChildSpriteScreen inside the block, as its result will be indefinite.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
735 *
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
736 * The block is terminated by #EndSpriteCombine.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
737 *
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
738 * You cannot nest "combined" blocks.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
739 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
740 void StartSpriteCombine()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
741 {
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
742 assert(_vd.combine_sprites == SPRITE_COMBINE_NONE);
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
743 _vd.combine_sprites = SPRITE_COMBINE_PENDING;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
744 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
745
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
746 /**
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
747 * Terminates a block of sprites started by #StartSpriteCombine.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
748 * Take a look there for details.
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
749 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
750 void EndSpriteCombine()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
751 {
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
752 assert(_vd.combine_sprites != SPRITE_COMBINE_NONE);
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
753 _vd.combine_sprites = SPRITE_COMBINE_NONE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
754 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
755
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
756 /**
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
757 * Add a child sprite to a parent sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
758 *
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
759 * @param image the image to draw.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
760 * @param pal the provided palette.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
761 * @param x sprite x-offset (screen coordinates) relative to parent sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
762 * @param y sprite y-offset (screen coordinates) relative to parent sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
763 * @param transparent if true, switch the palette between the provided palette and the transparent palette,
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
764 * @param sub Only draw a part of the sprite.
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
765 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
766 void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
767 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
768 assert((image & SPRITE_MASK) < MAX_SPRITES);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
769
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
770 /* If the ParentSprite was clipped by the viewport bounds, do not draw the ChildSprites either */
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
771 if (_vd.last_child == NULL) return;
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
772
7659
03747e97c53b (svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium <rubidium@openttd.org>
parents: 7643
diff changeset
773 /* make the sprites transparent with the right palette */
03747e97c53b (svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium <rubidium@openttd.org>
parents: 7643
diff changeset
774 if (transparent) {
7931
44ff7a6d801f (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7929
diff changeset
775 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
7659
03747e97c53b (svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium <rubidium@openttd.org>
parents: 7643
diff changeset
776 pal = PALETTE_TO_TRANSPARENT;
03747e97c53b (svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium <rubidium@openttd.org>
parents: 7643
diff changeset
777 }
03747e97c53b (svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium <rubidium@openttd.org>
parents: 7643
diff changeset
778
9553
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
779 *_vd.last_child = _vd.child_screen_sprites_to_draw.Length();
9534
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
780
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
781 ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
782 cs->image = image;
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5602
diff changeset
783 cs->pal = pal;
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
784 cs->sub = sub;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
785 cs->x = x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
786 cs->y = y;
9534
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
787 cs->next = -1;
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
788
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
789 /* Append the sprite to the active ChildSprite list.
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
790 * If the active ParentSprite is a foundation, update last_foundation_child as well.
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
791 * Note: ChildSprites of foundations are NOT sequential in the vector, as selection sprites are added at last. */
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
792 if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = &cs->next;
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
793 if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = &cs->next;
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
794 _vd.last_child = &cs->next;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
795 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
796
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
797 static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
798 {
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
799 assert(width != 0);
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
800 StringSpriteToDraw *ss = _vd.string_sprites_to_draw.Append();
8949
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
801 ss->string = string;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
802 ss->x = x;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
803 ss->y = y;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
804 ss->params[0] = params_1;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
805 ss->params[1] = params_2;
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
806 ss->width = width;
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11082
diff changeset
807 ss->colour = colour;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
808 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
809
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
810
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
811 /**
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
812 * Draws sprites between ground sprite and everything above.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
813 *
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
814 * The sprite is either drawn as TileSprite or as ChildSprite of the active foundation.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
815 *
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
816 * @param image the image to draw.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
817 * @param pal the provided palette.
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
818 * @param ti TileInfo Tile that is being drawn
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
819 * @param z_offset Z offset relative to the groundsprite. Only used for the sprite position, not for sprite sorting.
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
820 * @param foundation_part Foundation part the sprite belongs to.
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
821 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
822 static void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
823 {
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
824 /* FIXME: This is not totally valid for some autorail highlights, that extent over the edges of the tile. */
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
825 if (_vd.foundation[foundation_part] == -1) {
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
826 /* draw on real ground */
14154
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
827 AddTileSpriteToDraw(image, pal, ti->x, ti->y, ti->z + z_offset);
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
828 } else {
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
829 /* draw on top of foundation */
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
830 AddChildSpriteToFoundation(image, pal, NULL, foundation_part, 0, -z_offset);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
831 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
832 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
833
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
834 /**
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
835 * Draws a selection rectangle on a tile.
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
836 *
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
837 * @param ti TileInfo Tile that is being drawn
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
838 * @param pal Palette to apply.
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
839 */
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
840 static void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal)
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
841 {
10815
8966b7fa7a24 (svn r15150) -Fix: Don't highlight tiles outside the visible map.
Yexo <Yexo@openttd.org>
parents: 10732
diff changeset
842 if (!IsValidTile(ti->tile)) return;
8966b7fa7a24 (svn r15150) -Fix: Don't highlight tiles outside the visible map.
Yexo <Yexo@openttd.org>
parents: 10732
diff changeset
843
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
844 SpriteID sel;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
845 if (IsHalftileSlope(ti->tileh)) {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
846 Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
847 SpriteID sel2 = SPR_HALFTILE_SELECTION_FLAT + halftile_corner;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
848 DrawSelectionSprite(sel2, pal, ti, 7 + TILE_HEIGHT, FOUNDATION_PART_HALFTILE);
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
849
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
850 Corner opposite_corner = OppositeCorner(halftile_corner);
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
851 if (IsSteepSlope(ti->tileh)) {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
852 sel = SPR_HALFTILE_SELECTION_DOWN;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
853 } else {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
854 sel = ((ti->tileh & SlopeWithOneCornerRaised(opposite_corner)) != 0 ? SPR_HALFTILE_SELECTION_UP : SPR_HALFTILE_SELECTION_FLAT);
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
855 }
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
856 sel += opposite_corner;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
857 } else {
15528
8e6b5d370794 (svn r20187) -Codechange: move _tileh_to_sprite into a function in a more logical place and with a more descriptive name
rubidium <rubidium@openttd.org>
parents: 15470
diff changeset
858 sel = SPR_SELECT_TILE + SlopeToSpriteOffset(ti->tileh);
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
859 }
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
860 DrawSelectionSprite(sel, pal, ti, 7, FOUNDATION_PART_NORMAL);
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
861 }
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
862
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
863 static bool IsPartOfAutoLine(int px, int py)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
864 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
865 px -= _thd.selstart.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
866 py -= _thd.selstart.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
867
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
868 if ((_thd.drawstyle & ~HT_DIR_MASK) != HT_LINE) return false;
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
869
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
870 switch (_thd.drawstyle & HT_DIR_MASK) {
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
871 case HT_DIR_X: return py == 0; // x direction
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
872 case HT_DIR_Y: return px == 0; // y direction
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
873 case HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
874 case HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
875 case HT_DIR_VL: return px == py || px == py + 16; // vertical left
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
876 case HT_DIR_VR: return px == py || px == py - 16; // vertical right
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
877 default:
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
878 NOT_REACHED();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
879 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
880 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
881
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
882 /* [direction][side] */
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
883 static const HighLightStyle _autorail_type[6][2] = {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
884 { HT_DIR_X, HT_DIR_X },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
885 { HT_DIR_Y, HT_DIR_Y },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
886 { HT_DIR_HU, HT_DIR_HL },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
887 { HT_DIR_HL, HT_DIR_HU },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
888 { HT_DIR_VL, HT_DIR_VR },
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
889 { HT_DIR_VR, HT_DIR_VL }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
890 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
891
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
892 #include "table/autorail.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
893
7078
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
894 /**
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
895 * Draws autorail highlights.
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
896 *
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
897 * @param *ti TileInfo Tile that is being drawn
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
898 * @param autorail_type Offset into _AutorailTilehSprite[][]
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
899 */
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
900 static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type)
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
901 {
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
902 SpriteID image;
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
903 PaletteID pal;
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
904 int offset;
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
905
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
906 FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
8413
5c456105e68a (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch <frosch@openttd.org>
parents: 8270
diff changeset
907 Slope autorail_tileh = RemoveHalftileSlope(ti->tileh);
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
908 if (IsHalftileSlope(ti->tileh)) {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
909 static const uint _lower_rail[4] = { 5U, 2U, 4U, 3U };
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
910 Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
911 if (autorail_type != _lower_rail[halftile_corner]) {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
912 foundation_part = FOUNDATION_PART_HALFTILE;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
913 /* Here we draw the highlights of the "three-corners-raised"-slope. That looks ok to me. */
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
914 autorail_tileh = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
915 }
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
916 }
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
917
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
918 offset = _AutorailTilehSprite[autorail_tileh][autorail_type];
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
919 if (offset >= 0) {
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
920 image = SPR_AUTORAIL_BASE + offset;
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
921 pal = PAL_NONE;
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
922 } else {
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
923 image = SPR_AUTORAIL_BASE - offset;
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
924 pal = PALETTE_SEL_TILE_RED;
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
925 }
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
926
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
927 DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti, 7, foundation_part);
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
928 }
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
929
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
930 /**
7078
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
931 * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
932 * @param *ti TileInfo Tile that is being drawn
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
933 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
934 static void DrawTileSelection(const TileInfo *ti)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
935 {
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
936 /* Draw a red error square? */
10816
35b3e8e25590 (svn r15151) -Fix: tile 0 can now be highlighted as error tile
Yexo <Yexo@openttd.org>
parents: 10815
diff changeset
937 bool is_redsq = _thd.redsq == ti->tile;
8743
d6d6bbb8da9c (svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium <rubidium@openttd.org>
parents: 8585
diff changeset
938 if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
939
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
940 /* no selection active? */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
941 if (_thd.drawstyle == 0) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
942
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
943 /* Inside the inner area? */
7954
38bb7c45688f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7951
diff changeset
944 if (IsInsideBS(ti->x, _thd.pos.x, _thd.size.x) &&
38bb7c45688f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7951
diff changeset
945 IsInsideBS(ti->y, _thd.pos.y, _thd.size.y)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
946 if (_thd.drawstyle & HT_RECT) {
8743
d6d6bbb8da9c (svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium <rubidium@openttd.org>
parents: 8585
diff changeset
947 if (!is_redsq) DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
948 } else if (_thd.drawstyle & HT_POINT) {
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
949 /* Figure out the Z coordinate for the single dot. */
7726
9f29ddfd8351 (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 <rubidium@openttd.org>
parents: 7681
diff changeset
950 byte z = 0;
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
951 FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
952 if (ti->tileh & SLOPE_N) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
953 z += TILE_HEIGHT;
8413
5c456105e68a (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch <frosch@openttd.org>
parents: 8270
diff changeset
954 if (RemoveHalftileSlope(ti->tileh) == SLOPE_STEEP_N) z += TILE_HEIGHT;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
955 }
7769
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
956 if (IsHalftileSlope(ti->tileh)) {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
957 Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
958 if ((halftile_corner == CORNER_W) || (halftile_corner == CORNER_E)) z += TILE_HEIGHT;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
959 if (halftile_corner != CORNER_S) {
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
960 foundation_part = FOUNDATION_PART_HALFTILE;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
961 if (IsSteepSlope(ti->tileh)) z -= TILE_HEIGHT;
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
962 }
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
963 }
ca89a62f72e1 (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 <rubidium@openttd.org>
parents: 7764
diff changeset
964 DrawSelectionSprite(_cur_dpi->zoom <= ZOOM_LVL_DETAIL ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti, z, foundation_part);
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
965 } else if (_thd.drawstyle & HT_RAIL) {
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
966 /* autorail highlight piece under cursor */
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
967 HighLightStyle type = _thd.drawstyle & HT_DIR_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
968 assert(type < HT_DIR_END);
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
969 DrawAutorailSelection(ti, _autorail_type[type][0]);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
970 } else if (IsPartOfAutoLine(ti->x, ti->y)) {
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
971 /* autorail highlighting long line */
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
972 HighLightStyle dir = _thd.drawstyle & HT_DIR_MASK;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
973 uint side;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
974
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
975 if (dir == HT_DIR_X || dir == HT_DIR_Y) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
976 side = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
977 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
978 TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
7970
c49c1607b294 (svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7954
diff changeset
979 side = Delta(Delta(TileX(start), TileX(ti->tile)), Delta(TileY(start), TileY(ti->tile)));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
980 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
981
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
982 DrawAutorailSelection(ti, _autorail_type[dir][side]);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
983 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
984 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
985 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
986
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
987 /* Check if it's inside the outer area? */
8743
d6d6bbb8da9c (svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium <rubidium@openttd.org>
parents: 8585
diff changeset
988 if (!is_redsq && _thd.outersize.x &&
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
989 _thd.size.x < _thd.size.x + _thd.outersize.x &&
7954
38bb7c45688f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7951
diff changeset
990 IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
38bb7c45688f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7951
diff changeset
991 IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
992 /* Draw a blue rect. */
7679
9e222b8c9065 (svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7659
diff changeset
993 DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
994 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
995 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
996 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
997
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
998 static void ViewportAddLandscape()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
999 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1000 int x, y, width, height;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1001 TileInfo ti;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1002 bool direction;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1003
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1004 _cur_ti = &ti;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1005
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
1006 /* Transform into tile coordinates and round to closest full tile */
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1007 x = ((_vd.dpi.top >> 1) - (_vd.dpi.left >> 2)) & ~TILE_UNIT_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1008 y = ((_vd.dpi.top >> 1) + (_vd.dpi.left >> 2) - TILE_SIZE) & ~TILE_UNIT_MASK;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1009
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
1010 /* determine size of area */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1011 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1012 Point pt = RemapCoords(x, y, 241);
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1013 width = (_vd.dpi.left + _vd.dpi.width - pt.x + 95) >> 6;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1014 height = (_vd.dpi.top + _vd.dpi.height - pt.y) >> 5 << 1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1015 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1016
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1017 assert(width > 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1018 assert(height > 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1019
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1020 direction = false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1021
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1022 do {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1023 int width_cur = width;
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
1024 uint x_cur = x;
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
1025 uint y_cur = y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1026
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1027 do {
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1028 TileType tt = MP_VOID;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1029
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1030 ti.x = x_cur;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1031 ti.y = y_cur;
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1032
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1033 ti.z = 0;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1034
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1035 ti.tileh = SLOPE_FLAT;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1036 ti.tile = INVALID_TILE;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1037
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
1038 if (x_cur < MapMaxX() * TILE_SIZE &&
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
1039 y_cur < MapMaxY() * TILE_SIZE) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1040 TileIndex tile = TileVirtXY(x_cur, y_cur);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1041
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1042 if (!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0)) {
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1043 if (x_cur == ((int)MapMaxX() - 1) * TILE_SIZE || y_cur == ((int)MapMaxY() - 1) * TILE_SIZE) {
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1044 uint maxh = max<uint>(TileHeight(tile), 1);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1045 for (uint h = 0; h < maxh; h++) {
14154
e3fe36dfb81e (svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
frosch <frosch@openttd.org>
parents: 14136
diff changeset
1046 AddTileSpriteToDraw(SPR_SHADOW_CELL, PAL_NONE, ti.x, ti.y, h * TILE_HEIGHT);
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1047 }
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1048 }
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1049
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1050 ti.tile = tile;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1051 ti.tileh = GetTileSlope(tile, &ti.z);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1052 tt = GetTileType(tile);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1053 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1054 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1055
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1056 _vd.foundation_part = FOUNDATION_PART_NONE;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1057 _vd.foundation[0] = -1;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1058 _vd.foundation[1] = -1;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1059 _vd.last_foundation_child[0] = NULL;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1060 _vd.last_foundation_child[1] = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1061
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1062 _tile_type_procs[tt]->draw_tile_proc(&ti);
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1063
10864
e10213483b43 (svn r15199) -Fix (r15190): The south point of the south-most tile wasn't highlighted during terraforming.
Yexo <Yexo@openttd.org>
parents: 10855
diff changeset
1064 if ((x_cur == (int)MapMaxX() * TILE_SIZE && IsInsideMM(y_cur, 0, MapMaxY() * TILE_SIZE + 1)) ||
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15533
diff changeset
1065 (y_cur == (int)MapMaxY() * TILE_SIZE && IsInsideMM(x_cur, 0, MapMaxX() * TILE_SIZE + 1))) {
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1066 TileIndex tile = TileVirtXY(x_cur, y_cur);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1067 ti.tile = tile;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1068 ti.tileh = GetTileSlope(tile, &ti.z);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1069 tt = GetTileType(tile);
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1070 }
10815
8966b7fa7a24 (svn r15150) -Fix: Don't highlight tiles outside the visible map.
Yexo <Yexo@openttd.org>
parents: 10732
diff changeset
1071 if (ti.tile != INVALID_TILE) DrawTileSelection(&ti);
10855
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1072
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1073 y_cur += 0x10;
7881d9cd55ab (svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents: 10816
diff changeset
1074 x_cur -= 0x10;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1075 } while (--width_cur);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1076
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1077 if ((direction ^= 1) != 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1078 y += 0x10;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1079 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1080 x += 0x10;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1081 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1082 } while (--height);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1083 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1084
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1085 /**
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1086 * Add a string to draw in the viewport
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1087 * @param dpi current viewport area
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1088 * @param small_from Zoomlevel from when the small font should be used
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1089 * @param sign sign position and dimension
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1090 * @param string_normal String for normal and 2x zoom level
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1091 * @param string_small String for 4x and 8x zoom level
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
1092 * @param string_small_shadow Shadow string for 4x and 8x zoom level; or #STR_NULL if no shadow
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1093 * @param colour colour of the sign background; or 0 if transparent
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1094 */
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1095 void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2, Colours colour)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1096 {
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1097 bool small = dpi->zoom >= small_from;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1098
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1099 int left = dpi->left;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1100 int top = dpi->top;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1101 int right = left + dpi->width;
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1102 int bottom = top + dpi->height;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1103
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1104 int sign_height = ScaleByZoom(VPSM_TOP + FONT_HEIGHT_NORMAL + VPSM_BOTTOM, dpi->zoom);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1105 int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, dpi->zoom);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1106
14071
2c01d0796d1d (svn r18614) -Fix [FS#3412](r18602): too many signs were drawn, causing slowdowns
smatz <smatz@openttd.org>
parents: 14059
diff changeset
1107 if (bottom < sign->top ||
2c01d0796d1d (svn r18614) -Fix [FS#3412](r18602): too many signs were drawn, causing slowdowns
smatz <smatz@openttd.org>
parents: 14059
diff changeset
1108 top > sign->top + sign_height ||
2c01d0796d1d (svn r18614) -Fix [FS#3412](r18602): too many signs were drawn, causing slowdowns
smatz <smatz@openttd.org>
parents: 14059
diff changeset
1109 right < sign->center - sign_half_width ||
2c01d0796d1d (svn r18614) -Fix [FS#3412](r18602): too many signs were drawn, causing slowdowns
smatz <smatz@openttd.org>
parents: 14059
diff changeset
1110 left > sign->center + sign_half_width) {
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1111 return;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1112 }
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1113
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1114 if (!small) {
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1115 AddStringToDraw(sign->center - sign_half_width, sign->top, string_normal, params_1, params_2, colour, sign->width_normal);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1116 } else {
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1117 int shadow_offset = 0;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1118 if (string_small_shadow != STR_NULL) {
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1119 shadow_offset = 4;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1120 AddStringToDraw(sign->center - sign_half_width + shadow_offset, sign->top, string_small_shadow, params_1, params_2, INVALID_COLOUR, sign->width_small);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1121 }
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1122 AddStringToDraw(sign->center - sign_half_width, sign->top - shadow_offset, string_small, params_1, params_2,
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1123 colour, sign->width_small | 0x8000);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1124 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1125 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1126
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1127 static void ViewportAddTownNames(DrawPixelInfo *dpi)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1128 {
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1129 if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) return;
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1130
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1131 const Town *t;
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1132 FOR_ALL_TOWNS(t) {
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1133 ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &t->sign,
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1134 _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN,
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1135 STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK,
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1136 t->index, t->population);
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1137 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1138 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1139
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1140
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1141 static void ViewportAddStationNames(DrawPixelInfo *dpi)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1142 {
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1143 if (!(HasBit(_display_opt, DO_SHOW_STATION_NAMES) || HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)) || _game_mode == GM_MENU) return;
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1144
12513
7f4fa8992bbc (svn r16950) -Codechange: unduplicate waypoint + station sign drawing
rubidium <rubidium@openttd.org>
parents: 12512
diff changeset
1145 const BaseStation *st;
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1146 FOR_ALL_BASE_STATIONS(st) {
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1147 /* Check whether the base station is a station or a waypoint */
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1148 bool is_station = Station::IsExpected(st);
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1149
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1150 /* Don't draw if the display options are disabled */
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1151 if (!HasBit(_display_opt, is_station ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES)) continue;
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1152
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1153 ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &st->sign,
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1154 is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT,
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1155 (is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT) + 1, STR_NULL,
13817
881715964693 (svn r18343) -Fix [FS#3336] (r18243): dark blue signs would be drawn transparent
rubidium <rubidium@openttd.org>
parents: 13721
diff changeset
1156 st->index, st->facilities, (st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1157 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1158 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1159
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1160
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1161 static void ViewportAddSigns(DrawPixelInfo *dpi)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1162 {
8806
104bbcae351d (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents: 8798
diff changeset
1163 /* Signs are turned off or are invisible */
104bbcae351d (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents: 8798
diff changeset
1164 if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS)) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1165
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1166 const Sign *si;
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1167 FOR_ALL_SIGNS(si) {
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1168 ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &si->sign,
13718
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1169 STR_WHITE_SIGN,
141a263aecc4 (svn r18243) -Codechange: Deduplicate code wrt. drawing signs and station/town names.
frosch <frosch@openttd.org>
parents: 13454
diff changeset
1170 IsTransparencySet(TO_SIGNS) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
13817
881715964693 (svn r18343) -Fix [FS#3336] (r18243): dark blue signs would be drawn transparent
rubidium <rubidium@openttd.org>
parents: 13721
diff changeset
1171 si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : _company_colours[si->owner]);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1172 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1173 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1174
12341
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1175 /**
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1176 * Update the position of the viewport sign.
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1177 * @param center the (preferred) center of the viewport sign
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1178 * @param top the new top of the sign
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1179 * @param str the string to show in the sign
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1180 */
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1181 void ViewportSign::UpdatePosition(int center, int top, StringID str)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1182 {
12395
c2eb8db929f0 (svn r16825) -Codechange: unify dirtying when updating the viewport signs.
rubidium <rubidium@openttd.org>
parents: 12345
diff changeset
1183 if (this->width_normal != 0) this->MarkDirty();
c2eb8db929f0 (svn r16825) -Codechange: unify dirtying when updating the viewport signs.
rubidium <rubidium@openttd.org>
parents: 12345
diff changeset
1184
12341
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1185 this->top = top;
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1186
561291e41257 (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
rubidium <rubidium@openttd.org>
parents: 12122
diff changeset
1187 char buffer[DRAW_STRING_BUFFER];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1188
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1189 GetString(buffer, str, lastof(buffer));
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1190 this->width_normal = VPSM_LEFT + Align(GetStringBoundingBox(buffer).width, 2) + VPSM_RIGHT;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1191 this->center = center;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1192
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1193 /* zoomed out version */
15276
04ac3a270667 (svn r19911) -Codechange: Simplify text drawing by eliminating global variables and side effects. This also fixes the 'colour' parameter of DrawStringMultiLine().
frosch <frosch@openttd.org>
parents: 15274
diff changeset
1194 this->width_small = VPSM_LEFT + Align(GetStringBoundingBox(buffer, FS_SMALL).width, 2) + VPSM_RIGHT;
12395
c2eb8db929f0 (svn r16825) -Codechange: unify dirtying when updating the viewport signs.
rubidium <rubidium@openttd.org>
parents: 12345
diff changeset
1195
c2eb8db929f0 (svn r16825) -Codechange: unify dirtying when updating the viewport signs.
rubidium <rubidium@openttd.org>
parents: 12345
diff changeset
1196 this->MarkDirty();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1197 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1198
12344
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1199 /**
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1200 * Mark the sign dirty in all viewports.
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1201 *
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1202 * @ingroup dirty
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1203 */
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1204 void ViewportSign::MarkDirty() const
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1205 {
14136
54dfd3720fa1 (svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents: 14071
diff changeset
1206 /* We use ZOOM_LVL_MAX here, as every viewport can have another zoom,
12344
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1207 * and there is no way for us to know which is the biggest. So make the
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1208 * biggest area dirty, and we are safe for sure.
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1209 * We also add 1 to make sure the whole thing is redrawn. */
12344
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1210 MarkAllViewportsDirty(
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1211 this->center - ScaleByZoom(this->width_normal / 2 + 1, ZOOM_LVL_MAX),
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1212 this->top - ScaleByZoom(1, ZOOM_LVL_MAX),
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1213 this->center + ScaleByZoom(this->width_normal / 2 + 1, ZOOM_LVL_MAX),
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1214 this->top + ScaleByZoom(VPSM_TOP + FONT_HEIGHT_NORMAL + VPSM_BOTTOM + 1, ZOOM_LVL_MAX));
12344
1e953af1fb5f (svn r16764) -Codechange: unify the way viewport signs are marked dirty
rubidium <rubidium@openttd.org>
parents: 12341
diff changeset
1215 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1216
8947
20e58270e32d (svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8946
diff changeset
1217 static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1218 {
8949
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
1219 const TileSpriteToDraw *tsend = tstdv->End();
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
1220 for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) {
12115
6318d41ef9ef (svn r16528) -Fix [FS#2959]: Draw PBS reservation as groundsprite resp. childsprite of foundation/bridgehead.
frosch <frosch@openttd.org>
parents: 11922
diff changeset
1221 DrawSprite(ts->image, ts->pal, ts->x, ts->y, ts->sub);
8947
20e58270e32d (svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8946
diff changeset
1222 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1223 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1224
10233
63a58f4b2607 (svn r14461) -Document: add some doxygen comments (Albert)
rubidium <rubidium@openttd.org>
parents: 10216
diff changeset
1225 /** Sort parent sprites pointer array */
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1226 static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1227 {
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1228 ParentSpriteToDraw **psdvend = psdv->End();
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1229 ParentSpriteToDraw **psd = psdv->Begin();
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1230 while (psd != psdvend) {
8948
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1231 ParentSpriteToDraw *ps = *psd;
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1232
8950
1e8449e9c1ec (svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz <smatz@openttd.org>
parents: 8949
diff changeset
1233 if (ps->comparison_done) {
1e8449e9c1ec (svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz <smatz@openttd.org>
parents: 8949
diff changeset
1234 psd++;
1e8449e9c1ec (svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz <smatz@openttd.org>
parents: 8949
diff changeset
1235 continue;
1e8449e9c1ec (svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz <smatz@openttd.org>
parents: 8949
diff changeset
1236 }
8948
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1237
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1238 ps->comparison_done = true;
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1239
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1240 for (ParentSpriteToDraw **psd2 = psd + 1; psd2 != psdvend; psd2++) {
8948
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1241 ParentSpriteToDraw *ps2 = *psd2;
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1242
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1243 if (ps2->comparison_done) continue;
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1244
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1245 /* Decide which comparator to use, based on whether the bounding
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1246 * boxes overlap
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1247 */
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1248 if (ps->xmax >= ps2->xmin && ps->xmin <= ps2->xmax && // overlap in X?
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1249 ps->ymax >= ps2->ymin && ps->ymin <= ps2->ymax && // overlap in Y?
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1250 ps->zmax >= ps2->zmin && ps->zmin <= ps2->zmax) { // overlap in Z?
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1251 /* Use X+Y+Z as the sorting order, so sprites closer to the bottom of
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1252 * the screen and with higher Z elevation, are drawn in front.
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1253 * Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1254 * i.e. X=(left+right)/2, etc.
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1255 * However, since we only care about order, don't actually divide / 2
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1256 */
8948
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1257 if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <=
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1258 ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) {
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1259 continue;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1260 }
8948
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1261 } else {
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1262 /* We only change the order, if it is definite.
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1263 * I.e. every single order of X, Y, Z says ps2 is behind ps or they overlap.
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1264 * That is: If one partial order says ps behind ps2, do not change the order.
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1265 */
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1266 if (ps->xmax < ps2->xmin ||
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1267 ps->ymax < ps2->ymin ||
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1268 ps->zmax < ps2->zmin) {
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1269 continue;
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1270 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1271 }
8948
6b08c7cd7921 (svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium <rubidium@openttd.org>
parents: 8947
diff changeset
1272
10196
d44af18ae6c7 (svn r14409) -Codechange: Simplify a loop and correct a comment.
frosch <frosch@openttd.org>
parents: 10056
diff changeset
1273 /* Move ps2 in front of ps */
d44af18ae6c7 (svn r14409) -Codechange: Simplify a loop and correct a comment.
frosch <frosch@openttd.org>
parents: 10056
diff changeset
1274 ParentSpriteToDraw *temp = ps2;
d44af18ae6c7 (svn r14409) -Codechange: Simplify a loop and correct a comment.
frosch <frosch@openttd.org>
parents: 10056
diff changeset
1275 for (ParentSpriteToDraw **psd3 = psd2; psd3 > psd; psd3--) {
d44af18ae6c7 (svn r14409) -Codechange: Simplify a loop and correct a comment.
frosch <frosch@openttd.org>
parents: 10056
diff changeset
1276 *psd3 = *(psd3 - 1);
d44af18ae6c7 (svn r14409) -Codechange: Simplify a loop and correct a comment.
frosch <frosch@openttd.org>
parents: 10056
diff changeset
1277 }
d44af18ae6c7 (svn r14409) -Codechange: Simplify a loop and correct a comment.
frosch <frosch@openttd.org>
parents: 10056
diff changeset
1278 *psd = temp;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1279 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1280 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1281 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1282
8952
2a7a810979e0 (svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8951
diff changeset
1283 static void ViewportDrawParentSprites(const ParentSpriteToSortVector *psd, const ChildScreenSpriteToDrawVector *csstdv)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1284 {
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1285 const ParentSpriteToDraw * const *psd_end = psd->End();
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1286 for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1287 const ParentSpriteToDraw *ps = *it;
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
1288 if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1289
9534
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
1290 int child_idx = ps->first_child;
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
1291 while (child_idx >= 0) {
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
1292 const ChildScreenSpriteToDraw *cs = csstdv->Get(child_idx);
564d5fd5a247 (svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch <frosch@openttd.org>
parents: 9510
diff changeset
1293 child_idx = cs->next;
7681
7ab16079f91b (svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7679
diff changeset
1294 DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1295 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1296 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1297 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1298
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1299 /**
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1300 * Draws the bounding boxes of all ParentSprites
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1301 * @param psd Array of ParentSprites
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1302 */
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1303 static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd)
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1304 {
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1305 const ParentSpriteToDraw * const *psd_end = psd->End();
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1306 for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1307 const ParentSpriteToDraw *ps = *it;
7643
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1308 Point pt1 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmax + 1); // top front corner
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1309 Point pt2 = RemapCoords(ps->xmin , ps->ymax + 1, ps->zmax + 1); // top left corner
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1310 Point pt3 = RemapCoords(ps->xmax + 1, ps->ymin , ps->zmax + 1); // top right corner
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1311 Point pt4 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmin ); // bottom front corner
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1312
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1313 DrawBox( pt1.x, pt1.y,
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1314 pt2.x - pt1.x, pt2.y - pt1.y,
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1315 pt3.x - pt1.x, pt3.y - pt1.y,
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1316 pt4.x - pt1.x, pt4.y - pt1.y);
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1317 }
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1318 }
5dadd473fda6 (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 <rubidium@openttd.org>
parents: 7617
diff changeset
1319
8946
402107c0562f (svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8925
diff changeset
1320 static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVector *sstdv)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1321 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1322 DrawPixelInfo dp;
6624
bf5d7b24a7ab (svn r9844) -Codechange: replace zoomlevel with an enum
truelight <truelight@openttd.org>
parents: 6591
diff changeset
1323 ZoomLevel zoom;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1324
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1325 _cur_dpi = &dp;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1326 dp = *dpi;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1327
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1328 zoom = dp.zoom;
6624
bf5d7b24a7ab (svn r9844) -Codechange: replace zoomlevel with an enum
truelight <truelight@openttd.org>
parents: 6591
diff changeset
1329 dp.zoom = ZOOM_LVL_NORMAL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1330
6654
860f3e5f70ec (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight <truelight@openttd.org>
parents: 6653
diff changeset
1331 dp.left = UnScaleByZoom(dp.left, zoom);
860f3e5f70ec (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight <truelight@openttd.org>
parents: 6653
diff changeset
1332 dp.top = UnScaleByZoom(dp.top, zoom);
860f3e5f70ec (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight <truelight@openttd.org>
parents: 6653
diff changeset
1333 dp.width = UnScaleByZoom(dp.width, zoom);
860f3e5f70ec (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight <truelight@openttd.org>
parents: 6653
diff changeset
1334 dp.height = UnScaleByZoom(dp.height, zoom);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1335
8949
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
1336 const StringSpriteToDraw *ssend = sstdv->End();
36b54e6eec1e (svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138 <peter1138@openttd.org>
parents: 8948
diff changeset
1337 for (const StringSpriteToDraw *ss = sstdv->Begin(); ss != ssend; ++ss) {
13012
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1338 TextColour colour = TC_BLACK;
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1339 bool small = HasBit(ss->width, 15);
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1340 int w = GB(ss->width, 0, 15);
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1341 int x = UnScaleByZoom(ss->x, zoom);
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1342 int y = UnScaleByZoom(ss->y, zoom);
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1343 int h = VPSM_TOP + (small ? FONT_HEIGHT_SMALL : FONT_HEIGHT_NORMAL) + VPSM_BOTTOM;
13012
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1344
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1345 SetDParam(0, ss->params[0]);
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1346 SetDParam(1, ss->params[1]);
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1347
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1348 if (ss->colour != INVALID_COLOUR) {
8806
104bbcae351d (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents: 8798
diff changeset
1349 /* Do not draw signs nor station names if they are set invisible */
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12546
diff changeset
1350 if (IsInvisibilitySet(TO_SIGNS) && ss->string != STR_WHITE_SIGN) continue;
8806
104bbcae351d (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents: 8798
diff changeset
1351
13012
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1352 /* if we didn't draw a rectangle, or if transparant building is on,
13454
24547db62b5c (svn r17963) -Codechange: some documentation style
rubidium <rubidium@openttd.org>
parents: 13186
diff changeset
1353 * draw the text in the colour the rectangle would have */
13012
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1354 if (IsTransparencySet(TO_SIGNS) && ss->string != STR_WHITE_SIGN) {
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1355 /* Real colours need the IS_PALETTE_COLOUR flag
13454
24547db62b5c (svn r17963) -Codechange: some documentation style
rubidium <rubidium@openttd.org>
parents: 13186
diff changeset
1356 * otherwise colours from _string_colourmap are assumed. */
13012
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1357 colour = (TextColour)_colour_gradient[ss->colour][6] | IS_PALETTE_COLOUR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1358 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1359
13012
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1360 /* Draw the rectangle if 'tranparent station signs' is off,
fbc1bbc180f9 (svn r17506) -Fix [FS#3191]: signs partly drawn out of the rectangle in 4/8x zoom out.
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1361 * or if we are drawing a general text sign (STR_WHITE_SIGN) */
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12546
diff changeset
1362 if (!IsTransparencySet(TO_SIGNS) || ss->string == STR_WHITE_SIGN) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1363 DrawFrameRect(
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1364 x, y, x + w, y + h, ss->colour,
7849
e6ee8bfd9045 (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents: 7824
diff changeset
1365 IsTransparencySet(TO_SIGNS) ? FR_TRANSPARENT : FR_NONE
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1366 );
6427
2437ed7b277c (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 <peter1138@openttd.org>
parents: 6423
diff changeset
1367 }
11466
e3ea1ff8eb75 (svn r15824) -Fix: determine the actual length of the strings to draw in the viewport
rubidium <rubidium@openttd.org>
parents: 11446
diff changeset
1368 }
11446
188e18645591 (svn r15804) -Fix (r15796): viewport strings weren't properly 'rendered'.
rubidium <rubidium@openttd.org>
parents: 11375
diff changeset
1369
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15301
diff changeset
1370 DrawString(x + VPSM_LEFT, x + w - 1 - VPSM_RIGHT, y + VPSM_TOP, ss->string, colour, SA_HOR_CENTER);
8947
20e58270e32d (svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8946
diff changeset
1371 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1372 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1373
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1374 void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1375 {
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1376 DrawPixelInfo *old_dpi = _cur_dpi;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1377 _cur_dpi = &_vd.dpi;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1378
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1379 _vd.dpi.zoom = vp->zoom;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1380 int mask = ScaleByZoom(-1, vp->zoom);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1381
12546
53d056f3a161 (svn r16984) -Codechange: Document and assertify (Start|End)SpriteCombine.
frosch <frosch@openttd.org>
parents: 12523
diff changeset
1382 _vd.combine_sprites = SPRITE_COMBINE_NONE;
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1383
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1384 _vd.dpi.width = (right - left) & mask;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1385 _vd.dpi.height = (bottom - top) & mask;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1386 _vd.dpi.left = left & mask;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1387 _vd.dpi.top = top & mask;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1388 _vd.dpi.pitch = old_dpi->pitch;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1389 _vd.last_child = NULL;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1390
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1391 int x = UnScaleByZoom(_vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1392 int y = UnScaleByZoom(_vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1393
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1394 _vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1395
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1396 ViewportAddLandscape();
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1397 ViewportAddVehicles(&_vd.dpi);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1398
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1399 ViewportAddTownNames(&_vd.dpi);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1400 ViewportAddStationNames(&_vd.dpi);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1401 ViewportAddSigns(&_vd.dpi);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1402
9847
cc5c11ce4280 (svn r13991) -Codechange: draw text effects after all other signs
smatz <smatz@openttd.org>
parents: 9781
diff changeset
1403 DrawTextEffects(&_vd.dpi);
cc5c11ce4280 (svn r13991) -Codechange: draw text effects after all other signs
smatz <smatz@openttd.org>
parents: 9781
diff changeset
1404
9553
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1405 if (_vd.tile_sprites_to_draw.Length() != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1406
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1407 ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End();
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1408 for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) {
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1409 *_vd.parent_sprites_to_sort.Append() = it;
8951
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1410 }
231bd4dd1f98 (svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium <rubidium@openttd.org>
parents: 8950
diff changeset
1411
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1412 ViewportSortParentSprites(&_vd.parent_sprites_to_sort);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1413 ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1414
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1415 if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(&_vd.parent_sprites_to_sort);
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1416
9553
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1417 if (_vd.string_sprites_to_draw.Length() != 0) ViewportDrawStrings(&_vd.dpi, &_vd.string_sprites_to_draw);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1418
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1419 _cur_dpi = old_dpi;
8953
0f3c6c845c6f (svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium <rubidium@openttd.org>
parents: 8952
diff changeset
1420
9553
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1421 _vd.string_sprites_to_draw.Clear();
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1422 _vd.tile_sprites_to_draw.Clear();
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1423 _vd.parent_sprites_to_draw.Clear();
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1424 _vd.parent_sprites_to_sort.Clear();
0069339d03bf (svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13 <skidd13@openttd.org>
parents: 9534
diff changeset
1425 _vd.child_screen_sprites_to_draw.Clear();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1426 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1427
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1428 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1429 * Make sure we don't draw a too big area at a time.
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
1430 * If we do, the sprite memory will overflow.
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
1431 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1432 static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1433 {
6626
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
1434 if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1435 if ((bottom - top) > (right - left)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1436 int t = (top + bottom) >> 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1437 ViewportDrawChk(vp, left, top, right, t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1438 ViewportDrawChk(vp, left, t, right, bottom);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1439 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1440 int t = (left + right) >> 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1441 ViewportDrawChk(vp, left, top, t, bottom);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1442 ViewportDrawChk(vp, t, top, right, bottom);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1443 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1444 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1445 ViewportDoDraw(vp,
6626
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
1446 ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
1447 ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top,
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
1448 ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left,
f940341a80f0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents: 6624
diff changeset
1449 ScaleByZoom(bottom - vp->top, vp->zoom) + vp->virtual_top
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1450 );
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1451 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1452 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1453
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1454 static inline void ViewportDraw(const ViewPort *vp, int left, int top, int right, int bottom)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1455 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1456 if (right <= vp->left || bottom <= vp->top) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1457
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1458 if (left >= vp->left + vp->width) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1459
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1460 if (left < vp->left) left = vp->left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1461 if (right > vp->left + vp->width) right = vp->left + vp->width;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1462
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1463 if (top >= vp->top + vp->height) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1464
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1465 if (top < vp->top) top = vp->top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1466 if (bottom > vp->top + vp->height) bottom = vp->top + vp->height;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1467
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1468 ViewportDrawChk(vp, left, top, right, bottom);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1469 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1470
10238
12805d675e85 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents: 10233
diff changeset
1471 /**
12805d675e85 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents: 10233
diff changeset
1472 * Draw the viewport of this window.
12805d675e85 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents: 10233
diff changeset
1473 */
9273
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1474 void Window::DrawViewport() const
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1475 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1476 DrawPixelInfo *dpi = _cur_dpi;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1477
9273
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1478 dpi->left += this->left;
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1479 dpi->top += this->top;
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1480
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1481 ViewportDraw(this->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1482
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1483 dpi->left -= this->left;
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9244
diff changeset
1484 dpi->top -= this->top;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1485 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1486
7069
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1487 static inline void ClampViewportToMap(const ViewPort *vp, int &x, int &y)
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1488 {
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1489 /* Centre of the viewport is hot spot */
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1490 x += vp->virtual_width / 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1491 y += vp->virtual_height / 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1492
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1493 /* Convert viewport coordinates to map coordinates
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1494 * Calculation is scaled by 4 to avoid rounding errors */
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1495 int vx = -x + y * 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1496 int vy = x + y * 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1497
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1498 /* clamp to size of map */
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7918
diff changeset
1499 vx = Clamp(vx, 0, MapMaxX() * TILE_SIZE * 4);
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7918
diff changeset
1500 vy = Clamp(vy, 0, MapMaxY() * TILE_SIZE * 4);
7069
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1501
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1502 /* Convert map coordinates to viewport coordinates */
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1503 x = (-vx + vy) / 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1504 y = ( vx + vy) / 4;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1505
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
1506 /* Remove centering */
7069
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1507 x -= vp->virtual_width / 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1508 y -= vp->virtual_height / 2;
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1509 }
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1510
12523
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1511 /**
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1512 * Update the viewport position being displayed.
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1513 * @param w %Window owning the viewport.
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1514 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1515 void UpdateViewportPosition(Window *w)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1516 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1517 const ViewPort *vp = w->viewport;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1518
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1519 if (w->viewport->follow_vehicle != INVALID_VEHICLE) {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11765
diff changeset
1520 const Vehicle *veh = Vehicle::Get(w->viewport->follow_vehicle);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1521 Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1522
10645
d20b89e45634 (svn r14947) -Fix [FS#2519]: vehicle following did not update the location from where to smooth scroll, thus any new viewport center would smooth scroll from the location where you were just before you started following the vehicle
rubidium <rubidium@openttd.org>
parents: 10642
diff changeset
1523 w->viewport->scrollpos_x = pt.x;
d20b89e45634 (svn r14947) -Fix [FS#2519]: vehicle following did not update the location from where to smooth scroll, thus any new viewport center would smooth scroll from the location where you were just before you started following the vehicle
rubidium <rubidium@openttd.org>
parents: 10642
diff changeset
1524 w->viewport->scrollpos_y = pt.y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1525 SetViewportPosition(w, pt.x, pt.y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1526 } else {
7069
6de5150e902f (svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138 <peter1138@openttd.org>
parents: 7056
diff changeset
1527 /* Ensure the destination location is within the map */
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1528 ClampViewportToMap(vp, w->viewport->dest_scrollpos_x, w->viewport->dest_scrollpos_y);
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1529
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1530 int delta_x = w->viewport->dest_scrollpos_x - w->viewport->scrollpos_x;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1531 int delta_y = w->viewport->dest_scrollpos_y - w->viewport->scrollpos_y;
6730
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1532
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1533 if (delta_x != 0 || delta_y != 0) {
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9410
diff changeset
1534 if (_settings_client.gui.smooth_scroll) {
6731
5b13b47b071c (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138 <peter1138@openttd.org>
parents: 6730
diff changeset
1535 int max_scroll = ScaleByMapSize1D(512);
15274
e81d5697d8aa (svn r19909) -Doc: Typo fixes, small doxygen improvements.
alberth <alberth@openttd.org>
parents: 15270
diff changeset
1536 /* Not at our desired position yet... */
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1537 w->viewport->scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll);
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1538 w->viewport->scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll);
6731
5b13b47b071c (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138 <peter1138@openttd.org>
parents: 6730
diff changeset
1539 } else {
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1540 w->viewport->scrollpos_x = w->viewport->dest_scrollpos_x;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1541 w->viewport->scrollpos_y = w->viewport->dest_scrollpos_y;
6731
5b13b47b071c (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138 <peter1138@openttd.org>
parents: 6730
diff changeset
1542 }
6730
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1543 }
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1544
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1545 ClampViewportToMap(vp, w->viewport->scrollpos_x, w->viewport->scrollpos_y);
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1546
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1547 SetViewportPosition(w, w->viewport->scrollpos_x, w->viewport->scrollpos_y);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1548 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1549 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1550
7545
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1551 /**
8992
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1552 * Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1553 * @param vp The viewport to mark as dirty
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1554 * @param left Left edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1555 * @param top Top edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1556 * @param right Right edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1557 * @param bottom Bottom edge of area to repaint
7545
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1558 * @ingroup dirty
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1559 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1560 static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1561 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1562 right -= vp->virtual_left;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1563 if (right <= 0) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1564
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1565 bottom -= vp->virtual_top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1566 if (bottom <= 0) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1567
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1568 left = max(0, left - vp->virtual_left);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1569
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1570 if (left >= vp->virtual_width) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1571
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1572 top = max(0, top - vp->virtual_top);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1573
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1574 if (top >= vp->virtual_height) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1575
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1576 SetDirtyBlocks(
10549
dd9cc2c7c5be (svn r14806) -Fix: MarkAllViewportsDirty() didn't mark dirty whole area when zoomed out, visible by aircraft leaving trails sometimes
smatz <smatz@openttd.org>
parents: 10532
diff changeset
1577 UnScaleByZoomLower(left, vp->zoom) + vp->left,
dd9cc2c7c5be (svn r14806) -Fix: MarkAllViewportsDirty() didn't mark dirty whole area when zoomed out, visible by aircraft leaving trails sometimes
smatz <smatz@openttd.org>
parents: 10532
diff changeset
1578 UnScaleByZoomLower(top, vp->zoom) + vp->top,
dd9cc2c7c5be (svn r14806) -Fix: MarkAllViewportsDirty() didn't mark dirty whole area when zoomed out, visible by aircraft leaving trails sometimes
smatz <smatz@openttd.org>
parents: 10532
diff changeset
1579 UnScaleByZoom(right, vp->zoom) + vp->left + 1,
dd9cc2c7c5be (svn r14806) -Fix: MarkAllViewportsDirty() didn't mark dirty whole area when zoomed out, visible by aircraft leaving trails sometimes
smatz <smatz@openttd.org>
parents: 10532
diff changeset
1580 UnScaleByZoom(bottom, vp->zoom) + vp->top + 1
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1581 );
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1582 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1583
8992
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1584 /**
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1585 * Mark all viewports that display an area as dirty (in need of repaint).
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1586 * @param left Left edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1587 * @param top Top edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1588 * @param right Right edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1589 * @param bottom Bottom edge of area to repaint
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1590 * @ingroup dirty
c0e03990caf0 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8979
diff changeset
1591 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1592 void MarkAllViewportsDirty(int left, int top, int right, int bottom)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1593 {
10597
b9297d5178c0 (svn r14880) -Codechange: make it clear which way the FOR_ALL_WINDOWS goes (from back to front or vice versa) and make it iterate over the Window* instead of Window**.
rubidium <rubidium@openttd.org>
parents: 10571
diff changeset
1594 Window *w;
b9297d5178c0 (svn r14880) -Codechange: make it clear which way the FOR_ALL_WINDOWS goes (from back to front or vice versa) and make it iterate over the Window* instead of Window**.
rubidium <rubidium@openttd.org>
parents: 10571
diff changeset
1595 FOR_ALL_WINDOWS_FROM_BACK(w) {
b9297d5178c0 (svn r14880) -Codechange: make it clear which way the FOR_ALL_WINDOWS goes (from back to front or vice versa) and make it iterate over the Window* instead of Window**.
rubidium <rubidium@openttd.org>
parents: 10571
diff changeset
1596 ViewPort *vp = w->viewport;
8957
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
1597 if (vp != NULL) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1598 assert(vp->width != 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1599 MarkViewportDirty(vp, left, top, right, bottom);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1600 }
8957
484f482e54fa (svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium <rubidium@openttd.org>
parents: 8953
diff changeset
1601 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1602 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1603
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1604 void MarkTileDirtyByTile(TileIndex tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1605 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1606 Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1607 MarkAllViewportsDirty(
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1608 pt.x - 31,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1609 pt.y - 122,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1610 pt.x - 31 + 67,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1611 pt.y - 122 + 154
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1612 );
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1613 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1614
7545
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1615 /**
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1616 * Marks the selected tiles as dirty.
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1617 *
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1618 * This function marks the selected tiles as dirty for repaint
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1619 *
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1620 * @ingroup dirty
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7497
diff changeset
1621 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
1622 static void SetSelectionTilesDirty()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1623 {
11756
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1624 int x_start = _thd.pos.x;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1625 int y_start = _thd.pos.y;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1626
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1627 int x_size = _thd.size.x;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1628 int y_size = _thd.size.y;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1629
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1630 if (_thd.outersize.x != 0) {
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1631 x_size += _thd.outersize.x;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1632 x_start += _thd.offs.x;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1633 y_size += _thd.outersize.y;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1634 y_start += _thd.offs.y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1635 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1636
11756
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1637 x_size -= TILE_SIZE;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1638 y_size -= TILE_SIZE;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1639
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1640 assert(x_size >= 0);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1641 assert(y_size >= 0);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1642
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1643 int x_end = Clamp(x_start + x_size, 0, MapSizeX() * TILE_SIZE - TILE_SIZE);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1644 int y_end = Clamp(y_start + y_size, 0, MapSizeY() * TILE_SIZE - TILE_SIZE);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1645
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1646 x_start = Clamp(x_start, 0, MapSizeX() * TILE_SIZE - TILE_SIZE);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1647 y_start = Clamp(y_start, 0, MapSizeY() * TILE_SIZE - TILE_SIZE);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1648
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1649 /* make sure everything is multiple of TILE_SIZE */
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1650 assert((x_end | y_end | x_start | y_start) % TILE_SIZE == 0);
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1651
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1652 /* How it works:
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1653 * Suppose we have to mark dirty rectangle of 3x4 tiles:
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1654 * x
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1655 * xxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1656 * xxxxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1657 * xxxxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1658 * xxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1659 * x
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1660 * This algorithm marks dirty columns of tiles, so it is done in 3+4-1 steps:
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1661 * 1) x 2) x
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1662 * xxx Oxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1663 * Oxxxx xOxxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1664 * xxxxx Oxxxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1665 * xxx xxx
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1666 * x x
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1667 * And so forth...
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1668 */
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1669
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1670 int top_x = x_end; // coordinates of top dirty tile
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1671 int top_y = y_start;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1672 int bot_x = top_x; // coordinates of bottom dirty tile
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1673 int bot_y = top_y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1674
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1675 do {
11756
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1676 Point top = RemapCoords2(top_x, top_y); // topmost dirty point
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1677 Point bot = RemapCoords2(bot_x + TILE_SIZE - 1, bot_y + TILE_SIZE - 1); // bottommost point
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1678
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1679 /* the 'x' coordinate of 'top' and 'bot' is the same (and always in the same distance from tile middle),
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1680 * tile height/slope affects only the 'y' on-screen coordinate! */
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1681
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1682 int l = top.x - (TILE_PIXELS - 2); // 'x' coordinate of left side of dirty rectangle
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1683 int t = top.y; // 'y' coordinate of top side -//-
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1684 int r = top.x + (TILE_PIXELS - 2); // right side of dirty rectangle
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1685 int b = bot.y; // bottom -//-
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1686
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1687 static const int OVERLAY_WIDTH = 4; // part of selection sprites is drawn outside the selected area
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1688
12122
d530190c9171 (svn r16536) -Fix (r16535): W != S
frosch <frosch@openttd.org>
parents: 12121
diff changeset
1689 /* For halftile foundations on SLOPE_STEEP_S the sprite extents some more towards the top */
12121
da26b364cc6a (svn r16535) -Fix (r16146): In one case a too small portion of the screen was marked dirty, when (un-)drawing selections.
frosch <frosch@openttd.org>
parents: 12115
diff changeset
1690 MarkAllViewportsDirty(l - OVERLAY_WIDTH, t - OVERLAY_WIDTH - TILE_HEIGHT, r + OVERLAY_WIDTH, b + OVERLAY_WIDTH);
11756
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1691
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1692 /* haven't we reached the topmost tile yet? */
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1693 if (top_x != x_start) {
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1694 top_x -= TILE_SIZE;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1695 } else {
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1696 top_y += TILE_SIZE;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1697 }
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1698
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1699 /* the way the bottom tile changes is different when we reach the bottommost tile */
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1700 if (bot_y != y_end) {
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1701 bot_y += TILE_SIZE;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1702 } else {
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1703 bot_x -= TILE_SIZE;
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1704 }
49713788741d (svn r16146) -Codechange: use faster algorithm in SetSelectionTilesDirty(). Up to 1000 times faster when large area is selected
smatz <smatz@openttd.org>
parents: 11746
diff changeset
1705 } while (bot_x >= top_x);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1706 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1707
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1708
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1709 void SetSelectionRed(bool b)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1710 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1711 _thd.make_square_red = b;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1712 SetSelectionTilesDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1713 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1714
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1715 /**
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1716 * Test whether a sign is below the mouse
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1717 * @param vp the clicked viewport
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1718 * @param x X position of click
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1719 * @param y Y position of click
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1720 * @param sign the sign to check
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1721 * @return true if the sign was hit
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1722 */
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1723 static bool CheckClickOnViewportSign(const ViewPort *vp, int x, int y, const ViewportSign *sign)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1724 {
14059
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1725 bool small = (vp->zoom >= ZOOM_LVL_OUT_4X);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1726 int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, vp->zoom);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1727 int sign_height = ScaleByZoom(VPSM_TOP + (small ? FONT_HEIGHT_SMALL : FONT_HEIGHT_NORMAL) + VPSM_BOTTOM, vp->zoom);
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1728
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1729 x = ScaleByZoom(x - vp->left, vp->zoom) + vp->virtual_left;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1730 y = ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top;
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1731
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1732 return
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1733 y >= sign->top &&
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1734 y < sign->top + sign_height &&
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1735 x >= sign->center - sign_half_width &&
76db067696bb (svn r18602) -Codechange: unify the viewport sign and text effect drawing
rubidium <rubidium@openttd.org>
parents: 13825
diff changeset
1736 x < sign->center + sign_half_width;
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1737 }
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1738
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1739 static bool CheckClickOnTown(const ViewPort *vp, int x, int y)
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1740 {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1741 if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES)) return false;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1742
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1743 const Town *t;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1744 FOR_ALL_TOWNS(t) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1745 if (CheckClickOnViewportSign(vp, x, y, &t->sign)) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1746 ShowTownViewWindow(t->index);
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1747 return true;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1748 }
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1749 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1750
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1751 return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1752 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1753
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1754 static bool CheckClickOnStation(const ViewPort *vp, int x, int y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1755 {
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1756 if (!(HasBit(_display_opt, DO_SHOW_STATION_NAMES) || HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)) || IsInvisibilitySet(TO_SIGNS)) return false;
12513
7f4fa8992bbc (svn r16950) -Codechange: unduplicate waypoint + station sign drawing
rubidium <rubidium@openttd.org>
parents: 12512
diff changeset
1757
7f4fa8992bbc (svn r16950) -Codechange: unduplicate waypoint + station sign drawing
rubidium <rubidium@openttd.org>
parents: 12512
diff changeset
1758 const BaseStation *st;
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1759 FOR_ALL_BASE_STATIONS(st) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1760 /* Check whether the base station is a station or a waypoint */
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1761 bool is_station = Station::IsExpected(st);
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1762
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1763 /* Don't check if the display options are disabled */
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1764 if (!HasBit(_display_opt, is_station ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES)) continue;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1765
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1766 if (CheckClickOnViewportSign(vp, x, y, &st->sign)) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1767 if (is_station) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1768 ShowStationViewWindow(st->index);
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1769 } else {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1770 ShowWaypointWindow(Waypoint::From(st));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1771 }
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1772 return true;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1773 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1774 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1775
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1776 return false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1777 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1778
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1779
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1780 static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1781 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10196
diff changeset
1782 /* Signs are turned off, or they are transparent and invisibility is ON, or company is a spectator */
15116
aaaa44870ac4 (svn r19745) -Fix: The GUI is controlled by _local_company, not _current_company.
frosch <frosch@openttd.org>
parents: 15088
diff changeset
1783 if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS) || _local_company == COMPANY_SPECTATOR) return false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1784
13720
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1785 const Sign *si;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1786 FOR_ALL_SIGNS(si) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1787 if (CheckClickOnViewportSign(vp, x, y, &si->sign)) {
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1788 HandleClickOnSign(si);
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1789 return true;
18cbb884f0a0 (svn r18245) -Codechange: Deduplicate code wrt. clicking on signs and station/town names.
frosch <frosch@openttd.org>
parents: 13718
diff changeset
1790 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1791 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1792
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1793 return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1794 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1795
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1796
10532
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1797 static bool CheckClickOnLandscape(const ViewPort *vp, int x, int y)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1798 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1799 Point pt = TranslateXYToTileCoord(vp, x, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1800
10532
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1801 if (pt.x != -1) return ClickTile(TileVirtXY(pt.x, pt.y));
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1802 return true;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1803 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1804
16068
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1805 static void PlaceObject()
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1806 {
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1807 Point pt;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1808 Window *w;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1809
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1810 pt = GetTileBelowCursor();
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1811 if (pt.x == -1) return;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1812
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1813 if (_thd.place_mode == HT_POINT) {
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1814 pt.x += 8;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1815 pt.y += 8;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1816 }
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1817
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1818 _tile_fract_coords.x = pt.x & TILE_UNIT_MASK;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1819 _tile_fract_coords.y = pt.y & TILE_UNIT_MASK;
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1820
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1821 w = GetCallbackWnd();
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1822 if (w != NULL) w->OnPlaceObject(pt, TileVirtXY(pt.x, pt.y));
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1823 }
75bd5a94eab3 (svn r20761) -Codechange: make PlaceObject() static
smatz <smatz@openttd.org>
parents: 16067
diff changeset
1824
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1825
10532
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1826 bool HandleViewportClicked(const ViewPort *vp, int x, int y)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1827 {
16060
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1828 const Vehicle *v = CheckClickOnVehicle(vp, x, y);
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1829
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1830 if (_thd.place_mode & HT_VEHICLE) {
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1831 if (v != NULL && VehicleClicked(v)) return true;
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1832 }
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1833
16066
a49f518668dd (svn r20759) -Fix (r20753): it wasn't possible to build anything when left button scrolling was active
smatz <smatz@openttd.org>
parents: 16060
diff changeset
1834 if (_thd.place_mode & HT_DRAG_MASK) {
a49f518668dd (svn r20759) -Fix (r20753): it wasn't possible to build anything when left button scrolling was active
smatz <smatz@openttd.org>
parents: 16060
diff changeset
1835 PlaceObject();
a49f518668dd (svn r20759) -Fix (r20753): it wasn't possible to build anything when left button scrolling was active
smatz <smatz@openttd.org>
parents: 16060
diff changeset
1836 return true;
a49f518668dd (svn r20759) -Fix (r20753): it wasn't possible to build anything when left button scrolling was active
smatz <smatz@openttd.org>
parents: 16060
diff changeset
1837 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1838
10532
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1839 if (CheckClickOnTown(vp, x, y)) return true;
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1840 if (CheckClickOnStation(vp, x, y)) return true;
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1841 if (CheckClickOnSign(vp, x, y)) return true;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1842 CheckClickOnLandscape(vp, x, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1843
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1844 if (v != NULL) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1845 DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v);
15088
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1846 if (IsCompanyBuildableVehicleType(v)) {
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1847 v = v->First();
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1848 if (_ctrl_pressed && v->owner == _local_company) {
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1849 StartStopVehicle(v, true);
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1850 } else {
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1851 ShowVehicleViewWindow(v);
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1852 }
a63b4234140f (svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents: 15050
diff changeset
1853 }
10532
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1854 return true;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1855 }
10532
d33755b6159a (svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
1856 return CheckClickOnLandscape(vp, x, y);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1857 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1858
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1859
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1860 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1861 * Scrolls the viewport in a window to a given location.
12523
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1862 * @param x Desired x location of the map to scroll to (world coordinate).
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1863 * @param y Desired y location of the map to scroll to (world coordinate).
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1864 * @param z Desired z location of the map to scroll to (world coordinate). Use \c -1 to scroll to the height of the map at the \a x, \a y location.
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1865 * @param w %Window containing the viewport.
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1866 * @param instant Jump to the location instead of slowly moving to it.
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1867 * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
499566607266 (svn r16960) -Doc: Added some viewport and vehicle type doxygen strings.
alberth <alberth@openttd.org>
parents: 12513
diff changeset
1868 */
11375
1d342902ac94 (svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
smatz <smatz@openttd.org>
parents: 11368
diff changeset
1869 bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1870 {
8473
75c79ef760e8 (svn r12044) -Fix [FS#1741]: crash when centering on a vehicle (aircraft) that is outside of the map.
rubidium <rubidium@openttd.org>
parents: 8413
diff changeset
1871 /* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
11375
1d342902ac94 (svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
smatz <smatz@openttd.org>
parents: 11368
diff changeset
1872 if (z == -1) z = GetSlopeZ(Clamp(x, 0, MapSizeX() * TILE_SIZE - 1), Clamp(y, 0, MapSizeY() * TILE_SIZE - 1));
1d342902ac94 (svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
smatz <smatz@openttd.org>
parents: 11368
diff changeset
1873
1d342902ac94 (svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
smatz <smatz@openttd.org>
parents: 11368
diff changeset
1874 Point pt = MapXYZToViewport(w->viewport, x, y, z);
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1875 w->viewport->follow_vehicle = INVALID_VEHICLE;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1876
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15533
diff changeset
1877 if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1878
6731
5b13b47b071c (svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138 <peter1138@openttd.org>
parents: 6730
diff changeset
1879 if (instant) {
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1880 w->viewport->scrollpos_x = pt.x;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1881 w->viewport->scrollpos_y = pt.y;
6730
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1882 }
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1883
9184
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1884 w->viewport->dest_scrollpos_x = pt.x;
a7020e34c67b (svn r13047) -Codechange: remove vp_d
glx <glx@openttd.org>
parents: 9166
diff changeset
1885 w->viewport->dest_scrollpos_y = pt.y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1886 return true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1887 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1888
16310
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1889 /**
16312
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1890 * Scrolls the viewport in a window to a given location.
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1891 * @param tile Desired tile to center on.
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1892 * @param w %Window containing the viewport.
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1893 * @param instant Jump to the location instead of slowly moving to it.
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1894 * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1895 */
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1896 bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1897 {
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1898 return ScrollWindowTo(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, -1, w, instant);
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1899 }
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1900
e19d6bb9ff88 (svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
alberth <alberth@openttd.org>
parents: 16310
diff changeset
1901 /**
16310
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1902 * Scrolls the viewport of the main window to a given location.
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1903 * @param tile Desired tile to center on.
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1904 * @param instant Jump to the location instead of slowly moving to it.
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1905 * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1906 */
6730
0b56358a0e3d (svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138 <peter1138@openttd.org>
parents: 6669
diff changeset
1907 bool ScrollMainWindowToTile(TileIndex tile, bool instant)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1908 {
11375
1d342902ac94 (svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
smatz <smatz@openttd.org>
parents: 11368
diff changeset
1909 return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, -1, instant);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1910 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1911
16310
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1912 /**
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1913 * Set a tile to display a red error square.
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1914 * @param tile Tile that should show the red error square.
cced8cded106 (svn r21018) -Doc: Add Doxygen comments to some function.
alberth <alberth@openttd.org>
parents: 16309
diff changeset
1915 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1916 void SetRedErrorSquare(TileIndex tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1917 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1918 TileIndex old;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1919
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1920 old = _thd.redsq;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1921 _thd.redsq = tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1922
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1923 if (tile != old) {
10816
35b3e8e25590 (svn r15151) -Fix: tile 0 can now be highlighted as error tile
Yexo <Yexo@openttd.org>
parents: 10815
diff changeset
1924 if (tile != INVALID_TILE) MarkTileDirtyByTile(tile);
35b3e8e25590 (svn r15151) -Fix: tile 0 can now be highlighted as error tile
Yexo <Yexo@openttd.org>
parents: 10815
diff changeset
1925 if (old != INVALID_TILE) MarkTileDirtyByTile(old);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1926 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1927 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1928
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1929 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1930 * Highlight \a w by \a h tiles at the cursor.
12708
f1e888f0b9e1 (svn r17171) -Doc: Additions and corrections of various doxygen strings.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
1931 * @param w Width of the highlighted tiles rectangle.
f1e888f0b9e1 (svn r17171) -Doc: Additions and corrections of various doxygen strings.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
1932 * @param h Height of the highlighted tiles rectangle.
f1e888f0b9e1 (svn r17171) -Doc: Additions and corrections of various doxygen strings.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
1933 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1934 void SetTileSelectSize(int w, int h)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1935 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1936 _thd.new_size.x = w * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1937 _thd.new_size.y = h * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1938 _thd.new_outersize.x = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1939 _thd.new_outersize.y = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1940 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1941
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1942 void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1943 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1944 _thd.offs.x = ox * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1945 _thd.offs.y = oy * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1946 _thd.new_outersize.x = sx * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1947 _thd.new_outersize.y = sy * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1948 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1949
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
1950 /** returns the best autorail highlight type from map coordinates */
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
1951 static HighLightStyle GetAutorailHT(int x, int y)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1952 {
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1953 return HT_RAIL | _autorail_piece[x & TILE_UNIT_MASK][y & TILE_UNIT_MASK];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1954 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1955
7078
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1956 /**
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1957 * Updates tile highlighting for all cases.
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1958 * Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1959 * Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice,
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1960 * Once for the old and once for the new selection.
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1961 * _thd is TileHighlightData, found in viewport.h
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
1962 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
1963 void UpdateTileSelection()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1964 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1965 int x1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1966 int y1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1967
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1968 _thd.new_drawstyle = HT_NONE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1969
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
1970 if (_thd.place_mode == HT_SPECIAL) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1971 x1 = _thd.selend.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1972 y1 = _thd.selend.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1973 if (x1 != -1) {
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1974 int x2 = _thd.selstart.x & ~TILE_UNIT_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1975 int y2 = _thd.selstart.y & ~TILE_UNIT_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1976 x1 &= ~TILE_UNIT_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1977 y1 &= ~TILE_UNIT_MASK;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1978
6106
230764f1a316 (svn r8841) -Fix
tron <tron@openttd.org>
parents: 6075
diff changeset
1979 if (x1 >= x2) Swap(x1, x2);
230764f1a316 (svn r8841) -Fix
tron <tron@openttd.org>
parents: 6075
diff changeset
1980 if (y1 >= y2) Swap(y1, y2);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1981 _thd.new_pos.x = x1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1982 _thd.new_pos.y = y1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1983 _thd.new_size.x = x2 - x1 + TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1984 _thd.new_size.y = y2 - y1 + TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1985 _thd.new_drawstyle = _thd.next_drawstyle;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1986 }
16060
f814822627f3 (svn r20753) -Feature [FS#3999]: make it possible to select vehicle to clone and vehicle to clone orders from directly from vehicle lists and depot window
smatz <smatz@openttd.org>
parents: 15944
diff changeset
1987 } else if ((_thd.place_mode & HT_DRAG_MASK) != HT_NONE) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1988 Point pt = GetTileBelowCursor();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1989 x1 = pt.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1990 y1 = pt.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1991 if (x1 != -1) {
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
1992 switch (_thd.place_mode & HT_DRAG_MASK) {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
1993 case HT_RECT:
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1994 _thd.new_drawstyle = HT_RECT;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1995 break;
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
1996 case HT_POINT:
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1997 _thd.new_drawstyle = HT_POINT;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1998 x1 += TILE_SIZE / 2;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
1999 y1 += TILE_SIZE / 2;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2000 break;
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2001 case HT_RAIL:
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2002 /* Draw one highlighted tile in any direction */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2003 _thd.new_drawstyle = GetAutorailHT(pt.x, pt.y);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2004 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2005 case HT_LINE:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2006 switch (_thd.place_mode & HT_DIR_MASK) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2007 case HT_DIR_X: _thd.new_drawstyle = HT_LINE | HT_DIR_X; break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2008 case HT_DIR_Y: _thd.new_drawstyle = HT_LINE | HT_DIR_Y; break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2009
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2010 case HT_DIR_HU:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2011 case HT_DIR_HL:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2012 _thd.new_drawstyle = (pt.x & TILE_UNIT_MASK) + (pt.y & TILE_UNIT_MASK) <= TILE_SIZE ? HT_LINE | HT_DIR_HU : HT_LINE | HT_DIR_HL;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2013 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2014
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2015 case HT_DIR_VL:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2016 case HT_DIR_VR:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2017 _thd.new_drawstyle = (pt.x & TILE_UNIT_MASK) > (pt.y & TILE_UNIT_MASK) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2018 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2019
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2020 default: NOT_REACHED();
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2021 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2022 _thd.selstart.x = x1 & ~TILE_UNIT_MASK;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2023 _thd.selstart.y = y1 & ~TILE_UNIT_MASK;
7918
7a122ebfa7cf (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz <smatz@openttd.org>
parents: 7912
diff changeset
2024 break;
7a122ebfa7cf (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz <smatz@openttd.org>
parents: 7912
diff changeset
2025 default:
7a122ebfa7cf (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz <smatz@openttd.org>
parents: 7912
diff changeset
2026 NOT_REACHED();
7a122ebfa7cf (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz <smatz@openttd.org>
parents: 7912
diff changeset
2027 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2028 }
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2029 _thd.new_pos.x = x1 & ~TILE_UNIT_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2030 _thd.new_pos.y = y1 & ~TILE_UNIT_MASK;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2031 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2032 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2033
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2034 /* redraw selection */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2035 if (_thd.drawstyle != _thd.new_drawstyle ||
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2036 _thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2037 _thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y ||
7078
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
2038 _thd.outersize.x != _thd.new_outersize.x ||
c4d51d528cd2 (svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas <belugas@openttd.org>
parents: 7069
diff changeset
2039 _thd.outersize.y != _thd.new_outersize.y) {
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2040 /* clear the old selection? */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2041 if (_thd.drawstyle) SetSelectionTilesDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2042
11072
19fd43d5975d (svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
2043 _thd.drawstyle = _thd.new_drawstyle;
19fd43d5975d (svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
2044 _thd.pos = _thd.new_pos;
19fd43d5975d (svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
2045 _thd.size = _thd.new_size;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2046 _thd.outersize = _thd.new_outersize;
11072
19fd43d5975d (svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
2047 _thd.dirty = 0xff;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2048
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2049 /* draw the new selection? */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2050 if (_thd.new_drawstyle) SetSelectionTilesDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2051 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2052 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2053
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2054 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2055 * Displays the measurement tooltips when selecting multiple tiles
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2056 * @param str String to be displayed
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2057 * @param paramcount number of params to deal with
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2058 * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
16191
7065c54bda2c (svn r20891) -Fix [FS#4145]: Measurement tooltips for docks and tunnels were closed after a hover event.
terkhen <terkhen@openttd.org>
parents: 16068
diff changeset
2059 * @param close_cond Condition for closing this tooltip.
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2060 */
16191
7065c54bda2c (svn r20891) -Fix [FS#4145]: Measurement tooltips for docks and tunnels were closed after a hover event.
terkhen <terkhen@openttd.org>
parents: 16068
diff changeset
2061 static inline void ShowMeasurementTooltips(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_cond = TCC_LEFT_CLICK)
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2062 {
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2063 if (!_settings_client.gui.measure_tooltip) return;
16191
7065c54bda2c (svn r20891) -Fix [FS#4145]: Measurement tooltips for docks and tunnels were closed after a hover event.
terkhen <terkhen@openttd.org>
parents: 16068
diff changeset
2064 GuiShowTooltips(str, paramcount, params, close_cond);
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2065 }
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2066
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2067 /** highlighting tiles while only going over them with the mouse */
9147
6c9755fab091 (svn r13009) -Codechange: move more tile highlighting related functions/types to tilehighlight_*.h.
rubidium <rubidium@openttd.org>
parents: 9127
diff changeset
2068 void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2069 {
6669
66456dace92f (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros <maedhros@openttd.org>
parents: 6654
diff changeset
2070 _thd.select_method = method;
66456dace92f (svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros <maedhros@openttd.org>
parents: 6654
diff changeset
2071 _thd.select_proc = process;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2072 _thd.selend.x = TileX(tile) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2073 _thd.selstart.x = TileX(tile) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2074 _thd.selend.y = TileY(tile) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2075 _thd.selstart.y = TileY(tile) * TILE_SIZE;
7912
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2076
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2077 /* Needed so several things (road, autoroad, bridges, ...) are placed correctly.
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2078 * In effect, placement starts from the centre of a tile
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2079 */
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2080 if (method == VPM_X_OR_Y || method == VPM_FIX_X || method == VPM_FIX_Y) {
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2081 _thd.selend.x += TILE_SIZE / 2;
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2082 _thd.selend.y += TILE_SIZE / 2;
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2083 _thd.selstart.x += TILE_SIZE / 2;
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2084 _thd.selstart.y += TILE_SIZE / 2;
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2085 }
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2086
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2087 if (_thd.place_mode == HT_RECT) {
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2088 _thd.place_mode = HT_SPECIAL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2089 _thd.next_drawstyle = HT_RECT;
11746
5078e0598a60 (svn r16136) -Fix (r16095)[FS#2858]: sometimes autorail wouldn't work; seems to be primarily for OSX users though
rubidium <rubidium@openttd.org>
parents: 11730
diff changeset
2090 } else if (_thd.place_mode & (HT_RAIL | HT_LINE)) {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2091 _thd.place_mode = HT_SPECIAL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2092 _thd.next_drawstyle = _thd.drawstyle;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2093 } else {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2094 _thd.place_mode = HT_SPECIAL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2095 _thd.next_drawstyle = HT_POINT;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2096 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2097 _special_mouse_mode = WSM_SIZING;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2098 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2099
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2100 void VpSetPlaceSizingLimit(int limit)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2101 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2102 _thd.sizelimit = limit;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2103 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2104
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2105 /**
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11239
diff changeset
2106 * Highlights all tiles between a set of two tiles. Used in dock and tunnel placement
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11239
diff changeset
2107 * @param from TileIndex of the first tile to highlight
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2108 * @param to TileIndex of the last tile to highlight
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2109 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2110 void VpSetPresizeRange(TileIndex from, TileIndex to)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2111 {
7006
933d3ee6d37d (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 <rubidium@openttd.org>
parents: 6937
diff changeset
2112 uint64 distance = DistanceManhattan(from, to) + 1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2113
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2114 _thd.selend.x = TileX(to) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2115 _thd.selend.y = TileY(to) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2116 _thd.selstart.x = TileX(from) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2117 _thd.selstart.y = TileY(from) * TILE_SIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2118 _thd.next_drawstyle = HT_RECT;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2119
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2120 /* show measurement only if there is any length to speak of */
16191
7065c54bda2c (svn r20891) -Fix [FS#4145]: Measurement tooltips for docks and tunnels were closed after a hover event.
terkhen <terkhen@openttd.org>
parents: 16068
diff changeset
2121 if (distance > 1) ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1, &distance, TCC_HOVER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2122 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2123
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
2124 static void VpStartPreSizing()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2125 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2126 _thd.selend.x = -1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2127 _special_mouse_mode = WSM_PRESIZE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2128 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2129
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2130 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2131 * returns information about the 2x1 piece to be build.
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2132 * The lower bits (0-3) are the track type.
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2133 */
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2134 static HighLightStyle Check2x1AutoRail(int mode)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2135 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2136 int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2137 int sxpy = (_thd.selend.x & TILE_UNIT_MASK) + (_thd.selend.y & TILE_UNIT_MASK);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2138 int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2139 int sxmy = (_thd.selend.x & TILE_UNIT_MASK) - (_thd.selend.y & TILE_UNIT_MASK);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2140
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2141 switch (mode) {
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2142 default: NOT_REACHED();
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2143 case 0: // end piece is lower right
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2144 if (fxpy >= 20 && sxpy <= 12) return HT_DIR_HL;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2145 if (fxmy < -3 && sxmy > 3) return HT_DIR_VR;
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2146 return HT_DIR_Y;
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2147
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2148 case 1:
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2149 if (fxmy > 3 && sxmy < -3) return HT_DIR_VL;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2150 if (fxpy <= 12 && sxpy >= 20) return HT_DIR_HU;
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2151 return HT_DIR_Y;
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2152
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2153 case 2:
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2154 if (fxmy > 3 && sxmy < -3) return HT_DIR_VL;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2155 if (fxpy >= 20 && sxpy <= 12) return HT_DIR_HL;
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2156 return HT_DIR_X;
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2157
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2158 case 3:
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2159 if (fxmy < -3 && sxmy > 3) return HT_DIR_VR;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2160 if (fxpy <= 12 && sxpy >= 20) return HT_DIR_HU;
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2161 return HT_DIR_X;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2162 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2163 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2164
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2165 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2166 * Check if the direction of start and end tile should be swapped based on
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2167 * the dragging-style. Default directions are:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2168 * in the case of a line (HT_RAIL, HT_LINE): DIR_NE, DIR_NW, DIR_N, DIR_E
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2169 * in the case of a rect (HT_RECT, HT_POINT): DIR_S, DIR_E
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2170 * For example dragging a rectangle area from south to north should be swapped to
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2171 * north-south (DIR_S) to obtain the same results with less code. This is what
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2172 * the return value signifies.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2173 * @param style HighLightStyle dragging style
6484
17fdaec13730 (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas <belugas@openttd.org>
parents: 6453
diff changeset
2174 * @param start_tile start tile of drag
17fdaec13730 (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas <belugas@openttd.org>
parents: 6453
diff changeset
2175 * @param end_tile end tile of drag
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2176 * @return boolean value which when true means start/end should be swapped
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2177 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2178 static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2179 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2180 uint start_x = TileX(start_tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2181 uint start_y = TileY(start_tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2182 uint end_x = TileX(end_tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2183 uint end_y = TileY(end_tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2184
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2185 switch (style & HT_DRAG_MASK) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2186 case HT_RAIL:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2187 case HT_LINE: return (end_x > start_x || (end_x == start_x && end_y > start_y));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2188
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2189 case HT_RECT:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2190 case HT_POINT: return (end_x != start_x && end_y < start_y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2191 default: NOT_REACHED();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2192 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2193
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2194 return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2195 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2196
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2197 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
2198 * Calculates height difference between one tile and another.
15138
9ce158e1d59e (svn r19767) -Fix [FS#3808]: Height in smallmap was different from measured heights (ChillCore).
alberth <alberth@openttd.org>
parents: 15136
diff changeset
2199 * Multiplies the result to suit the standard given by #TILE_HEIGHT_STEP.
9ce158e1d59e (svn r19767) -Fix [FS#3808]: Height in smallmap was different from measured heights (ChillCore).
alberth <alberth@openttd.org>
parents: 15136
diff changeset
2200 *
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11239
diff changeset
2201 * To correctly get the height difference we need the direction we are dragging
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11239
diff changeset
2202 * in, as well as with what kind of tool we are dragging. For example a horizontal
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11239
diff changeset
2203 * autorail tool that starts in bottom and ends at the top of a tile will need the
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11239
diff changeset
2204 * maximum of SW, S and SE, N corners respectively. This is handled by the lookup table below
15136
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2205 * See #_tileoffs_by_dir in map.cpp for the direction enums if you can't figure out the values yourself.
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2206 * @param style Highlighting style of the drag. This includes direction and style (autorail, rect, etc.)
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2207 * @param distance Number of tiles dragged, important for horizontal/vertical drags, ignored for others.
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2208 * @param start_tile Start tile of the drag operation.
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2209 * @param end_tile End tile of the drag operation.
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2210 * @return Height difference between two tiles. The tile measurement tool utilizes this value in its tooltip.
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2211 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2212 static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2213 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2214 bool swap = SwapDirection(style, start_tile, end_tile);
15136
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2215 uint h0, h1; // Start height and end height.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2216
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2217 if (start_tile == end_tile) return 0;
5733
0b9175cb534a (svn r8276) -Fix
tron <tron@openttd.org>
parents: 5673
diff changeset
2218 if (swap) Swap(start_tile, end_tile);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2219
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2220 switch (style & HT_DRAG_MASK) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2221 case HT_RECT: {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2222 static const TileIndexDiffC heightdiff_area_by_dir[] = {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2223 /* Start */ {1, 0}, /* Dragging east */ {0, 0}, // Dragging south
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2224 /* End */ {0, 1}, /* Dragging east */ {1, 1} // Dragging south
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2225 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2226
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2227 /* In the case of an area we can determine whether we were dragging south or
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2228 * east by checking the X-coordinates of the tiles */
15136
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2229 byte style_t = (byte)(TileX(end_tile) > TileX(start_tile));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2230 start_tile = TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_area_by_dir[style_t]));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2231 end_tile = TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_area_by_dir[2 + style_t]));
15626
33d3500b2a62 (svn r20289) -Codechange: Unify fall through coding style.
terkhen <terkhen@openttd.org>
parents: 15623
diff changeset
2232 /* FALL THROUGH */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2233 }
15626
33d3500b2a62 (svn r20289) -Codechange: Unify fall through coding style.
terkhen <terkhen@openttd.org>
parents: 15623
diff changeset
2234
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2235 case HT_POINT:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2236 h0 = TileHeight(start_tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2237 h1 = TileHeight(end_tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2238 break;
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2239 default: { // All other types, this is mostly only line/autorail
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2240 static const HighLightStyle flip_style_direction[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2241 HT_DIR_X, HT_DIR_Y, HT_DIR_HL, HT_DIR_HU, HT_DIR_VR, HT_DIR_VL
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2242 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2243 static const TileIndexDiffC heightdiff_line_by_dir[] = {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2244 /* Start */ {1, 0}, {1, 1}, /* HT_DIR_X */ {0, 1}, {1, 1}, // HT_DIR_Y
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2245 /* Start */ {1, 0}, {0, 0}, /* HT_DIR_HU */ {1, 0}, {1, 1}, // HT_DIR_HL
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2246 /* Start */ {1, 0}, {1, 1}, /* HT_DIR_VL */ {0, 1}, {1, 1}, // HT_DIR_VR
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2247
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2248 /* Start */ {0, 1}, {0, 0}, /* HT_DIR_X */ {1, 0}, {0, 0}, // HT_DIR_Y
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2249 /* End */ {0, 1}, {0, 0}, /* HT_DIR_HU */ {1, 1}, {0, 1}, // HT_DIR_HL
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2250 /* End */ {1, 0}, {0, 0}, /* HT_DIR_VL */ {0, 0}, {0, 1}, // HT_DIR_VR
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2251 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2252
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2253 distance %= 2; // we're only interested if the distance is even or uneven
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2254 style &= HT_DIR_MASK;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2255
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2256 /* To handle autorail, we do some magic to be able to use a lookup table.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2257 * Firstly if we drag the other way around, we switch start&end, and if needed
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2258 * also flip the drag-position. Eg if it was on the left, and the distance is even
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2259 * that means the end, which is now the start is on the right */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2260 if (swap && distance == 0) style = flip_style_direction[style];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2261
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2262 /* Use lookup table for start-tile based on HighLightStyle direction */
15136
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2263 byte style_t = style * 2;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2264 assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2265 h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t])));
15136
519a23c09115 (svn r19765) -Codechange: Apply a bit of code style and a bit of comment shuffling to CalcHeightdiff.
alberth <alberth@openttd.org>
parents: 15116
diff changeset
2266 uint ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1])));
5601
ca6b459bf488 (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 <celestar@openttd.org>
parents: 5587
diff changeset
2267 h0 = max(h0, ht);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2268
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2269 /* Use lookup table for end-tile based on HighLightStyle direction
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2270 * flip around side (lower/upper, left/right) based on distance */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2271 if (distance == 0) style_t = flip_style_direction[style] * 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2272 assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2273 h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t])));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2274 ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1])));
5601
ca6b459bf488 (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 <celestar@openttd.org>
parents: 5587
diff changeset
2275 h1 = max(h1, ht);
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15579
diff changeset
2276 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15579
diff changeset
2277 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2278 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2279
5733
0b9175cb534a (svn r8276) -Fix
tron <tron@openttd.org>
parents: 5673
diff changeset
2280 if (swap) Swap(h0, h1);
15138
9ce158e1d59e (svn r19767) -Fix [FS#3808]: Height in smallmap was different from measured heights (ChillCore).
alberth <alberth@openttd.org>
parents: 15136
diff changeset
2281 return (int)(h1 - h0) * TILE_HEIGHT_STEP;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2282 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2283
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2284 static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF};
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2285
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2286 /**
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2287 * Check for underflowing the map.
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2288 * @param test the variable to test for underflowing
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2289 * @param other the other variable to update to keep the line
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2290 * @param mult the constant to multiply the difference by for \c other
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2291 */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2292 static void CheckUnderflow(int &test, int &other, int mult)
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2293 {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2294 if (test >= 0) return;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2295
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2296 other += mult * test;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2297 test = 0;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2298 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2299
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2300 /**
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2301 * Check for overflowing the map.
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2302 * @param test the variable to test for overflowing
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2303 * @param other the other variable to update to keep the line
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2304 * @param max the maximum value for the \c test variable
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2305 * @param mult the constant to multiply the difference by for \c other
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2306 */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2307 static void CheckOverflow(int &test, int &other, int max, int mult)
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2308 {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2309 if (test <= max) return;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2310
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2311 other += mult * (test - max);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2312 test = max;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2313 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2314
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2315 /** while dragging */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2316 static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2317 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2318 HighLightStyle b;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2319
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2320 int dx = thd->selstart.x - (thd->selend.x & ~TILE_UNIT_MASK);
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2321 int dy = thd->selstart.y - (thd->selend.y & ~TILE_UNIT_MASK);
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2322 uint w = abs(dx) + TILE_SIZE;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2323 uint h = abs(dy) + TILE_SIZE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2324
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2325 if (method & ~(VPM_RAILDIRS | VPM_SIGNALDIRS)) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2326 /* We 'force' a selection direction; first four rail buttons. */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2327 method &= ~(VPM_RAILDIRS | VPM_SIGNALDIRS);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2328 int raw_dx = thd->selstart.x - thd->selend.x;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2329 int raw_dy = thd->selstart.y - thd->selend.y;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2330 switch (method) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2331 case VPM_FIX_X:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2332 b = HT_LINE | HT_DIR_Y;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2333 x = thd->selstart.x;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2334 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2335
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2336 case VPM_FIX_Y:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2337 b = HT_LINE | HT_DIR_X;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2338 y = thd->selstart.y;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2339 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2340
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2341 case VPM_FIX_HORIZONTAL:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2342 if (dx == -dy) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2343 /* We are on a straight horizontal line. Determine the 'rail'
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2344 * to build based the sub tile location. */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2345 b = (x & TILE_UNIT_MASK) + (y & TILE_UNIT_MASK) >= TILE_SIZE ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2346 } else {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2347 /* We are not on a straight line. Determine the rail to build
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2348 * based on whether we are above or below it. */
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2349 b = dx + dy >= (int)TILE_SIZE ? HT_LINE | HT_DIR_HU : HT_LINE | HT_DIR_HL;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2350
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2351 /* Calculate where a horizontal line through the start point and
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2352 * a vertical line from the selected end point intersect and
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2353 * use that point as the end point. */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2354 int offset = (raw_dx - raw_dy) / 2;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2355 x = thd->selstart.x - (offset & ~TILE_UNIT_MASK);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2356 y = thd->selstart.y + (offset & ~TILE_UNIT_MASK);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2357
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2358 /* 'Build' the last half rail tile if needed */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2359 if ((offset & TILE_UNIT_MASK) > (TILE_SIZE / 2)) {
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2360 if (dx + dy >= (int)TILE_SIZE) {
15236
ebd4e1b1fcb3 (svn r19870) -Codechange: silence some of GCC 3.3 warnings
smatz <smatz@openttd.org>
parents: 15188
diff changeset
2361 x += (dx + dy < 0) ? (int)TILE_SIZE : -(int)TILE_SIZE;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2362 } else {
15236
ebd4e1b1fcb3 (svn r19870) -Codechange: silence some of GCC 3.3 warnings
smatz <smatz@openttd.org>
parents: 15188
diff changeset
2363 y += (dx + dy < 0) ? (int)TILE_SIZE : -(int)TILE_SIZE;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2364 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2365 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2366
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2367 /* Make sure we do not overflow the map! */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2368 CheckUnderflow(x, y, 1);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2369 CheckUnderflow(y, x, 1);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2370 CheckOverflow(x, y, (MapMaxX() - 1) * TILE_SIZE, 1);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2371 CheckOverflow(y, x, (MapMaxY() - 1) * TILE_SIZE, 1);
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2372 assert(x >= 0 && y >= 0 && x <= (int)(MapMaxX() * TILE_SIZE) && y <= (int)(MapMaxY() * TILE_SIZE));
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2373 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2374 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2375
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2376 case VPM_FIX_VERTICAL:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2377 if (dx == dy) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2378 /* We are on a straight vertical line. Determine the 'rail'
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2379 * to build based the sub tile location. */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2380 b = (x & TILE_UNIT_MASK) > (y & TILE_UNIT_MASK) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2381 } else {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2382 /* We are not on a straight line. Determine the rail to build
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2383 * based on whether we are left or right from it. */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2384 b = dx < dy ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2385
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2386 /* Calculate where a vertical line through the start point and
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2387 * a horizontal line from the selected end point intersect and
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2388 * use that point as the end point. */
15301
df3ff675fdd4 (svn r19942) -Fix [FS#3871](r19816): Vertical dragging of rail was broken.
frosch <frosch@openttd.org>
parents: 15276
diff changeset
2389 int offset = (raw_dx + raw_dy + (int)TILE_SIZE) / 2;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2390 x = thd->selstart.x - (offset & ~TILE_UNIT_MASK);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2391 y = thd->selstart.y - (offset & ~TILE_UNIT_MASK);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2392
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2393 /* 'Build' the last half rail tile if needed */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2394 if ((offset & TILE_UNIT_MASK) > (TILE_SIZE / 2)) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2395 if (dx - dy < 0) {
15236
ebd4e1b1fcb3 (svn r19870) -Codechange: silence some of GCC 3.3 warnings
smatz <smatz@openttd.org>
parents: 15188
diff changeset
2396 y += (dx > dy) ? (int)TILE_SIZE : -(int)TILE_SIZE;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2397 } else {
15236
ebd4e1b1fcb3 (svn r19870) -Codechange: silence some of GCC 3.3 warnings
smatz <smatz@openttd.org>
parents: 15188
diff changeset
2398 x += (dx < dy) ? (int)TILE_SIZE : -(int)TILE_SIZE;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2399 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2400 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2401
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2402 /* Make sure we do not overflow the map! */
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2403 CheckUnderflow(x, y, -1);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2404 CheckUnderflow(y, x, -1);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2405 CheckOverflow(x, y, (MapMaxX() - 1) * TILE_SIZE, -1);
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2406 CheckOverflow(y, x, (MapMaxY() - 1) * TILE_SIZE, -1);
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2407 assert(x >= 0 && y >= 0 && x <= (int)(MapMaxX() * TILE_SIZE) && y <= (int)(MapMaxY() * TILE_SIZE));
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2408 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2409 break;
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2410
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2411 default:
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2412 NOT_REACHED();
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2413 }
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2414 } else if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2415 if (method & VPM_RAILDIRS) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2416 b = GetAutorailHT(x, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2417 } else { // rect for autosignals on one tile
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2418 b = HT_RECT;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2419 }
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2420 } else if (h == TILE_SIZE) { // Is this in X direction?
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2421 if (dx == (int)TILE_SIZE) { // 2x1 special handling
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2422 b = (Check2x1AutoRail(3)) | HT_LINE;
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2423 } else if (dx == -(int)TILE_SIZE) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2424 b = (Check2x1AutoRail(2)) | HT_LINE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2425 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2426 b = HT_LINE | HT_DIR_X;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2427 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2428 y = thd->selstart.y;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2429 } else if (w == TILE_SIZE) { // Or Y direction?
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2430 if (dy == (int)TILE_SIZE) { // 2x1 special handling
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2431 b = (Check2x1AutoRail(1)) | HT_LINE;
15187
03033976eab9 (svn r19816) -Codechange: use static const uint for the unnamed 'tile consts' enum as well
rubidium <rubidium@openttd.org>
parents: 15138
diff changeset
2432 } else if (dy == -(int)TILE_SIZE) { // 2x1 other direction
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2433 b = (Check2x1AutoRail(0)) | HT_LINE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2434 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2435 b = HT_LINE | HT_DIR_Y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2436 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2437 x = thd->selstart.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2438 } else if (w > h * 2) { // still count as x dir?
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2439 b = HT_LINE | HT_DIR_X;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2440 y = thd->selstart.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2441 } else if (h > w * 2) { // still count as y dir?
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2442 b = HT_LINE | HT_DIR_Y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2443 x = thd->selstart.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2444 } else { // complicated direction
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2445 int d = w - h;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2446 thd->selend.x = thd->selend.x & ~TILE_UNIT_MASK;
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2447 thd->selend.y = thd->selend.y & ~TILE_UNIT_MASK;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2448
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2449 /* four cases. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2450 if (x > thd->selstart.x) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2451 if (y > thd->selstart.y) {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2452 /* south */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2453 if (d == 0) {
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2454 b = (x & TILE_UNIT_MASK) > (y & TILE_UNIT_MASK) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2455 } else if (d >= 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2456 x = thd->selstart.x + h;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2457 b = HT_LINE | HT_DIR_VL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2458 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2459 y = thd->selstart.y + w;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2460 b = HT_LINE | HT_DIR_VR;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2461 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2462 } else {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2463 /* west */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2464 if (d == 0) {
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2465 b = (x & TILE_UNIT_MASK) + (y & TILE_UNIT_MASK) >= TILE_SIZE ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2466 } else if (d >= 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2467 x = thd->selstart.x + h;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2468 b = HT_LINE | HT_DIR_HL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2469 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2470 y = thd->selstart.y - w;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2471 b = HT_LINE | HT_DIR_HU;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2472 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2473 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2474 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2475 if (y > thd->selstart.y) {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2476 /* east */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2477 if (d == 0) {
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2478 b = (x & TILE_UNIT_MASK) + (y & TILE_UNIT_MASK) >= TILE_SIZE ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2479 } else if (d >= 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2480 x = thd->selstart.x - h;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2481 b = HT_LINE | HT_DIR_HU;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2482 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2483 y = thd->selstart.y + w;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2484 b = HT_LINE | HT_DIR_HL;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2485 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2486 } else {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2487 /* north */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2488 if (d == 0) {
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2489 b = (x & TILE_UNIT_MASK) > (y & TILE_UNIT_MASK) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2490 } else if (d >= 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2491 x = thd->selstart.x - h;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2492 b = HT_LINE | HT_DIR_VR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2493 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2494 y = thd->selstart.y - w;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2495 b = HT_LINE | HT_DIR_VL;
11700
5cb273d3151b (svn r16086) -Codechange: magic numbers substitutes by enums and some type safety
rubidium <rubidium@openttd.org>
parents: 11545
diff changeset
2496 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2497 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2498 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2499 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2500
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9410
diff changeset
2501 if (_settings_client.gui.measure_tooltip) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2502 TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2503 TileIndex t1 = TileVirtXY(x, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2504 uint distance = DistanceManhattan(t0, t1) + 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2505 byte index = 0;
7006
933d3ee6d37d (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 <rubidium@openttd.org>
parents: 6937
diff changeset
2506 uint64 params[2];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2507
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2508 if (distance != 1) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2509 int heightdiff = CalcHeightdiff(b, distance, t0, t1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2510 /* If we are showing a tooltip for horizontal or vertical drags,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2511 * 2 tiles have a length of 1. To bias towards the ceiling we add
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2512 * one before division. It feels more natural to count 3 lengths as 2 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2513 if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) {
15050
73f4e0e490b7 (svn r19670) -Codechange: Add CeilDiv() and RoundDiv() to simplify integer divisions with rounding.
frosch <frosch@openttd.org>
parents: 15002
diff changeset
2514 distance = CeilDiv(distance, 2);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2515 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2516
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2517 params[index++] = distance;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2518 if (heightdiff != 0) params[index++] = heightdiff;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2519 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2520
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2521 ShowMeasurementTooltips(measure_strings_length[index], index, params);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2522 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2523
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2524 thd->selend.x = x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2525 thd->selend.y = y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2526 thd->next_drawstyle = b;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2527 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2528
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2529 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2530 * Selects tiles while dragging
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2531 * @param x X coordinate of end of selection
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2532 * @param y Y coordinate of end of selection
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2533 * @param method modifies the way tiles are selected. Possible
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2534 * methods are VPM_* in viewport.h
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
2535 */
7888
194fee5b8120 (svn r11439) -Codechange: replace some magic numbers by a ViewportPlaceMethod enumified constant. Patch by SmatZ.
rubidium <rubidium@openttd.org>
parents: 7849
diff changeset
2536 void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2537 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2538 int sx, sy;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2539 HighLightStyle style;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2540
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2541 if (x == -1) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2542 _thd.selend.x = -1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2543 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2544 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2545
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2546 /* Special handling of drag in any (8-way) direction */
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2547 if (method & (VPM_RAILDIRS | VPM_SIGNALDIRS)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2548 _thd.selend.x = x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2549 _thd.selend.y = y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2550 CalcRaildirsDrawstyle(&_thd, x, y, method);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2551 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2552 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2553
7912
357db556fc02 (svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz <smatz@openttd.org>
parents: 7905
diff changeset
2554 /* Needed so level-land is placed correctly */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2555 if (_thd.next_drawstyle == HT_POINT) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2556 x += TILE_SIZE / 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2557 y += TILE_SIZE / 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2558 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2559
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2560 sx = _thd.selstart.x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2561 sy = _thd.selstart.y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2562
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2563 int limit = 0;
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2564
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2565 switch (method) {
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2566 case VPM_X_OR_Y: // drag in X or Y direction
7923
504d4b2ecc6c (svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13 <skidd13@openttd.org>
parents: 7922
diff changeset
2567 if (abs(sy - y) < abs(sx - x)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2568 y = sy;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2569 style = HT_DIR_X;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2570 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2571 x = sx;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2572 style = HT_DIR_Y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2573 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2574 goto calc_heightdiff_single_direction;
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2575
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2576 case VPM_X_LIMITED: // Drag in X direction (limited size).
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2577 limit = (_thd.sizelimit - 1) * TILE_SIZE;
15579
5f128be91f59 (svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents: 15552
diff changeset
2578 /* FALL THROUGH */
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2579
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2580 case VPM_FIX_X: // drag in Y direction
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2581 x = sx;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2582 style = HT_DIR_Y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2583 goto calc_heightdiff_single_direction;
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2584
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2585 case VPM_Y_LIMITED: // Drag in Y direction (limited size).
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2586 limit = (_thd.sizelimit - 1) * TILE_SIZE;
15579
5f128be91f59 (svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents: 15552
diff changeset
2587 /* FALL THROUGH */
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2588
11368
82c90cd591ab (svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
2589 case VPM_FIX_Y: // drag in X direction
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2590 y = sy;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2591 style = HT_DIR_X;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2592
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2593 calc_heightdiff_single_direction:;
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2594 if (limit > 0) {
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2595 x = sx + Clamp(x - sx, -limit, limit);
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2596 y = sy + Clamp(y - sy, -limit, limit);
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2597 }
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9410
diff changeset
2598 if (_settings_client.gui.measure_tooltip) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2599 TileIndex t0 = TileVirtXY(sx, sy);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2600 TileIndex t1 = TileVirtXY(x, y);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2601 uint distance = DistanceManhattan(t0, t1) + 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2602 byte index = 0;
7006
933d3ee6d37d (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 <rubidium@openttd.org>
parents: 6937
diff changeset
2603 uint64 params[2];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2604
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2605 if (distance != 1) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2606 /* With current code passing a HT_LINE style to calculate the height
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2607 * difference is enough. However if/when a point-tool is created
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2608 * with this method, function should be called with new_style (below)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2609 * instead of HT_LINE | style case HT_POINT is handled specially
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2610 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2611 int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2612
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2613 params[index++] = distance;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2614 if (heightdiff != 0) params[index++] = heightdiff;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2615 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2616
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2617 ShowMeasurementTooltips(measure_strings_length[index], index, params);
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15579
diff changeset
2618 }
15692
450d0cb8bf5f (svn r20358) -Fix [FS#4008]: (r20281) crash when building some stuff when the measurement tooltip is disabled
rubidium <rubidium@openttd.org>
parents: 15626
diff changeset
2619 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2620
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2621 case VPM_X_AND_Y_LIMITED: // Drag an X by Y constrained rect area.
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2622 limit = (_thd.sizelimit - 1) * TILE_SIZE;
7922
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7918
diff changeset
2623 x = sx + Clamp(x - sx, -limit, limit);
ff1975ced735 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents: 7918
diff changeset
2624 y = sy + Clamp(y - sy, -limit, limit);
15579
5f128be91f59 (svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents: 15552
diff changeset
2625 /* FALL THROUGH */
14427
368b198b010a (svn r18984) -Add: Viewport place methods for dragging a line with limited size.
terkhen <terkhen@openttd.org>
parents: 14319
diff changeset
2626
15692
450d0cb8bf5f (svn r20358) -Fix [FS#4008]: (r20281) crash when building some stuff when the measurement tooltip is disabled
rubidium <rubidium@openttd.org>
parents: 15626
diff changeset
2627 case VPM_X_AND_Y: // drag an X by Y area
11072
19fd43d5975d (svn r15413) -Fix [FS#2529/2533]: inconsistencies between station and bridge building w.r.t. tile selection and when the window should be closed.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
2628 if (_settings_client.gui.measure_tooltip) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2629 static const StringID measure_strings_area[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2630 STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2631 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2632
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2633 TileIndex t0 = TileVirtXY(sx, sy);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2634 TileIndex t1 = TileVirtXY(x, y);
7970
c49c1607b294 (svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7954
diff changeset
2635 uint dx = Delta(TileX(t0), TileX(t1)) + 1;
c49c1607b294 (svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13 <skidd13@openttd.org>
parents: 7954
diff changeset
2636 uint dy = Delta(TileY(t0), TileY(t1)) + 1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2637 byte index = 0;
7006
933d3ee6d37d (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 <rubidium@openttd.org>
parents: 6937
diff changeset
2638 uint64 params[3];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2639
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2640 /* If dragging an area (eg dynamite tool) and it is actually a single
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2641 * row/column, change the type to 'line' to get proper calculation for height */
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
2642 style = (HighLightStyle)_thd.next_drawstyle;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2643 if (style & HT_RECT) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2644 if (dx == 1) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2645 style = HT_LINE | HT_DIR_Y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2646 } else if (dy == 1) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2647 style = HT_LINE | HT_DIR_X;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2648 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2649 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2650
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2651 if (dx != 1 || dy != 1) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2652 int heightdiff = CalcHeightdiff(style, 0, t0, t1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2653
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2654 params[index++] = dx;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2655 params[index++] = dy;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2656 if (heightdiff != 0) params[index++] = heightdiff;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2657 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2658
9781
5ab8b1b156bb (svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch <frosch@openttd.org>
parents: 9755
diff changeset
2659 ShowMeasurementTooltips(measure_strings_area[index], index, params);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2660 }
15692
450d0cb8bf5f (svn r20358) -Fix [FS#4008]: (r20281) crash when building some stuff when the measurement tooltip is disabled
rubidium <rubidium@openttd.org>
parents: 15626
diff changeset
2661 break;
450d0cb8bf5f (svn r20358) -Fix [FS#4008]: (r20281) crash when building some stuff when the measurement tooltip is disabled
rubidium <rubidium@openttd.org>
parents: 15626
diff changeset
2662
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2663 default: NOT_REACHED();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2664 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2665
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2666 _thd.selend.x = x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2667 _thd.selend.y = y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2668 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2669
9314
93a764ca7ec7 (svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 9274
diff changeset
2670 /**
93a764ca7ec7 (svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 9274
diff changeset
2671 * Handle the mouse while dragging for placement/resizing.
15270
e2fcc8072ae6 (svn r19905) -Codechange: Use EventState for mouse handling routines.
alberth <alberth@openttd.org>
parents: 15236
diff changeset
2672 * @return State of handling the event.
9314
93a764ca7ec7 (svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 9274
diff changeset
2673 */
15270
e2fcc8072ae6 (svn r19905) -Codechange: Use EventState for mouse handling routines.
alberth <alberth@openttd.org>
parents: 15236
diff changeset
2674 EventState VpHandlePlaceSizingDrag()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2675 {
15270
e2fcc8072ae6 (svn r19905) -Codechange: Use EventState for mouse handling routines.
alberth <alberth@openttd.org>
parents: 15236
diff changeset
2676 if (_special_mouse_mode != WSM_SIZING) return ES_NOT_HANDLED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2677
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2678 /* stop drag mode if the window has been closed */
9166
45b1388fe9ba (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium <rubidium@openttd.org>
parents: 9147
diff changeset
2679 Window *w = FindWindowById(_thd.window_class, _thd.window_number);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2680 if (w == NULL) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2681 ResetObjectToPlace();
15270
e2fcc8072ae6 (svn r19905) -Codechange: Use EventState for mouse handling routines.
alberth <alberth@openttd.org>
parents: 15236
diff changeset
2682 return ES_HANDLED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2683 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2684
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2685 /* while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2686 if (_left_button_down) {
9166
45b1388fe9ba (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium <rubidium@openttd.org>
parents: 9147
diff changeset
2687 w->OnPlaceDrag(_thd.select_method, _thd.select_proc, GetTileBelowCursor());
15270
e2fcc8072ae6 (svn r19905) -Codechange: Use EventState for mouse handling routines.
alberth <alberth@openttd.org>
parents: 15236
diff changeset
2688 return ES_HANDLED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2689 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2690
6423
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2691 /* mouse button released..
72ac8bfaa32f (svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents: 6248
diff changeset
2692 * keep the selected tool, but reset it to the original mode. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2693 _special_mouse_mode = WSM_NONE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2694 if (_thd.next_drawstyle == HT_RECT) {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2695 _thd.place_mode = HT_RECT;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2696 } else if (_thd.select_method & VPM_SIGNALDIRS) {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2697 _thd.place_mode = HT_RECT;
11709
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2698 } else if (_thd.select_method & VPM_RAILDIRS) {
886f2a4f8cba (svn r16095) -Change/Feature-ish: make the first 4 rail building tools behave more like autorail
rubidium <rubidium@openttd.org>
parents: 11702
diff changeset
2699 _thd.place_mode = (_thd.select_method & ~VPM_RAILDIRS) ? _thd.next_drawstyle : HT_RAIL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2700 } else {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2701 _thd.place_mode = HT_POINT;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2702 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2703 SetTileSelectSize(1, 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2704
9166
45b1388fe9ba (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium <rubidium@openttd.org>
parents: 9147
diff changeset
2705 w->OnPlaceMouseUp(_thd.select_method, _thd.select_proc, _thd.selend, TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2706
15270
e2fcc8072ae6 (svn r19905) -Codechange: Use EventState for mouse handling routines.
alberth <alberth@openttd.org>
parents: 15236
diff changeset
2707 return ES_HANDLED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2708 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2709
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2710 void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2711 {
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5602
diff changeset
2712 SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2713 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2714
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2715 #include "table/animcursors.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2716
14319
72cb3c72d619 (svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2717 void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2718 {
8585
2880bcf43f14 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz <smatz@openttd.org>
parents: 8562
diff changeset
2719 /* undo clicking on button and drag & drop */
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2720 if (_thd.place_mode != HT_NONE || _special_mouse_mode == WSM_DRAGDROP) {
9244
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2721 Window *w = FindWindowById(_thd.window_class, _thd.window_number);
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2722 if (w != NULL) {
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2723 /* Call the abort function, but set the window class to something
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2724 * that will never be used to avoid infinite loops. Setting it to
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2725 * the 'next' window class must not be done because recursion into
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2726 * this function might in some cases reset the newly set object to
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2727 * place or not properly reset the original selection. */
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2728 _thd.window_class = WC_INVALID;
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2729 w->OnPlaceObjectAbort();
07d38b0d61ce (svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium <rubidium@openttd.org>
parents: 9238
diff changeset
2730 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2731 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2732
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2733 SetTileSelectSize(1, 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2734
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2735 _thd.make_square_red = false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2736
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2737 if (mode == HT_DRAG) { // HT_DRAG is for dragdropping trains in the depot window
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2738 mode = HT_NONE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2739 _special_mouse_mode = WSM_DRAGDROP;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2740 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2741 _special_mouse_mode = WSM_NONE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2742 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2743
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2744 _thd.place_mode = mode;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2745 _thd.window_class = window_class;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2746 _thd.window_number = window_num;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2747
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15533
diff changeset
2748 if (mode == HT_SPECIAL) { // special tools, like tunnels or docks start with presizing mode
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2749 VpStartPreSizing();
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15533
diff changeset
2750 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2751
14448
a80dd44ffa0d (svn r19005) -Codechange: make animated cursors have a bit set instead of using negative numbers that are passed as uints, then cast again to be compared as ints before being inverted to be actually used. Also fixes a couple of 'integer conversion resulted in truncation' warnings ICC spewed.
rubidium <rubidium@openttd.org>
parents: 14427
diff changeset
2752 if ((icon & ANIMCURSOR_FLAG) != 0) {
a80dd44ffa0d (svn r19005) -Codechange: make animated cursors have a bit set instead of using negative numbers that are passed as uints, then cast again to be compared as ints before being inverted to be actually used. Also fixes a couple of 'integer conversion resulted in truncation' warnings ICC spewed.
rubidium <rubidium@openttd.org>
parents: 14427
diff changeset
2753 SetAnimatedMouseCursor(_animcursors[icon & ~ANIMCURSOR_FLAG]);
9238
cef3cbdc68c6 (svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium <rubidium@openttd.org>
parents: 9192
diff changeset
2754 } else {
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5602
diff changeset
2755 SetMouseCursor(icon, pal);
9238
cef3cbdc68c6 (svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium <rubidium@openttd.org>
parents: 9192
diff changeset
2756 }
cef3cbdc68c6 (svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium <rubidium@openttd.org>
parents: 9192
diff changeset
2757
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2758 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2759
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6117
diff changeset
2760 void ResetObjectToPlace()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2761 {
11702
cdaad565efe5 (svn r16088) -Codechange: merge HighLightStyle and ViewportHighlightMode as they are basically the same thing
rubidium <rubidium@openttd.org>
parents: 11700
diff changeset
2762 SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2763 }