src/smallmap_gui.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10322 1a2a97853c0c
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9094
diff changeset
     3
/** @file smallmap_gui.cpp GUI that shows a small map of the world with metadata like owner or height. */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6357
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1815
diff changeset
     6
#include "openttd.h"
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3184
diff changeset
     7
#include "bridge_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 2989
diff changeset
     8
#include "clear_map.h"
3391
3c8a6643ed15 (svn r4199) - Codechange: Use industry map accessors to get industry graphics type.
peter1138
parents: 3338
diff changeset
     9
#include "industry_map.h"
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
    10
#include "industry.h"
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
    11
#include "station_map.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6441
diff changeset
    12
#include "landscape.h"
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
    13
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    14
#include "window_gui.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 2989
diff changeset
    15
#include "tree_map.h"
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3144
diff changeset
    16
#include "tunnel_map.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8157
diff changeset
    17
#include "viewport_func.h"
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8157
diff changeset
    18
#include "gfx_func.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    19
#include "company_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "town.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2062
diff changeset
    21
#include "variables.h"
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
    22
#include "blitter/factory.hpp"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8082
diff changeset
    23
#include "tunnelbridge_map.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8108
diff changeset
    24
#include "strings_func.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    25
#include "zoom_func.h"
8132
f4c7a8e4f25a (svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents: 8131
diff changeset
    26
#include "core/endian_func.hpp"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    27
#include "vehicle_base.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
    28
#include "sound_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    29
#include "settings_type.h"
9117
87f472043e9e (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 9116
diff changeset
    30
#include "window_func.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8082
diff changeset
    31
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    32
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    33
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 856
diff changeset
    35
static const Widget _smallmap_widgets[] = {
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    36
{  WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_BROWN,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    37
{   WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_BROWN,    11,   337,     0,    13, STR_00B0_MAP,            STR_018C_WINDOW_TITLE_DRAG_THIS},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    38
{ WWT_STICKYBOX,     RESIZE_LR,  COLOUR_BROWN,   338,   349,     0,    13, 0x0,                     STR_STICKY_BUTTON},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    39
{     WWT_PANEL,     RESIZE_RB,  COLOUR_BROWN,     0,   349,    14,   157, 0x0,                     STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    40
{     WWT_INSET,     RESIZE_RB,  COLOUR_BROWN,     2,   347,    16,   155, 0x0,                     STR_NULL},
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
    41
{     WWT_PANEL,    RESIZE_RTB,  COLOUR_BROWN,     0,   261,   158,   201, 0x0,                     STR_NULL},
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
    42
{     WWT_PANEL,   RESIZE_LRTB,  COLOUR_BROWN,   262,   349,   158,   158, 0x0,                     STR_NULL},
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    43
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   284,   305,   158,   179, SPR_IMG_SHOW_COUNTOURS,  STR_0191_SHOW_LAND_CONTOURS_ON_MAP},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    44
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   306,   327,   158,   179, SPR_IMG_SHOW_VEHICLES,   STR_0192_SHOW_VEHICLES_ON_MAP},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    45
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   328,   349,   158,   179, SPR_IMG_INDUSTRY,        STR_0193_SHOW_INDUSTRIES_ON_MAP},
9835
b40b96c9b74b (svn r13978) -Fix: Incorrect widget size.
peter1138
parents: 9832
diff changeset
    46
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   284,   305,   180,   201, SPR_IMG_SHOW_ROUTES,     STR_0194_SHOW_TRANSPORT_ROUTES_ON},
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    47
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   306,   327,   180,   201, SPR_IMG_PLANTTREES,      STR_0195_SHOW_VEGETATION_ON_MAP},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    48
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   328,   349,   180,   201, SPR_IMG_COMPANY_GENERAL, STR_0196_SHOW_LAND_OWNERS_ON_MAP},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    49
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   262,   283,   158,   179, SPR_IMG_SMALLMAP,        STR_SMALLMAP_CENTER},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    50
{    WWT_IMGBTN,   RESIZE_LRTB,  COLOUR_BROWN,   262,   283,   180,   201, SPR_IMG_TOWN,            STR_0197_TOGGLE_TOWN_NAMES_ON_OFF},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    51
{     WWT_PANEL,    RESIZE_RTB,  COLOUR_BROWN,     0,   337,   202,   213, 0x0,                     STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    52
{   WWT_TEXTBTN,     RESIZE_TB,  COLOUR_BROWN,     0,    99,   202,   213, STR_MESSAGES_ENABLE_ALL, STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    53
{   WWT_TEXTBTN,     RESIZE_TB,  COLOUR_BROWN,   100,   201,   202,   213, STR_MESSAGES_DISABLE_ALL,STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
    54
{ WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_BROWN,   338,   349,   202,   213, 0x0,                     STR_RESIZE_BUTTON},
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
    55
{  WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
    58
/* number of used industries */
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
    59
static int _smallmap_industry_count;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    61
/** Macro for ordinary entry of LegendAndColor */
7933
b2bb6a4aafd4 (svn r11486) -Fix [FS#1457]: industry count was wrong in smallmap
glx
parents: 7921
diff changeset
    62
#define MK(a,b) {a, b, INVALID_INDUSTRYTYPE, true, false, false}
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    63
/** Macro for end of list marker in arrays of LegendAndColor */
7933
b2bb6a4aafd4 (svn r11486) -Fix [FS#1457]: industry count was wrong in smallmap
glx
parents: 7921
diff changeset
    64
#define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, true, true, false}
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    65
/** Macro for break marker in arrays of LegendAndColor.
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    66
 * It will have valid data, though */
7933
b2bb6a4aafd4 (svn r11486) -Fix [FS#1457]: industry count was wrong in smallmap
glx
parents: 7921
diff changeset
    67
#define MS(a,b) {a, b, INVALID_INDUSTRYTYPE, true, false, true}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    69
/** Structure for holding relevant data for legends in small map */
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    70
struct LegendAndColour {
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    71
	uint16 colour;     ///< color of the item on the map
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    72
	StringID legend;   ///< string corresponding to the colored item
7933
b2bb6a4aafd4 (svn r11486) -Fix [FS#1457]: industry count was wrong in smallmap
glx
parents: 7921
diff changeset
    73
	IndustryType type; ///< type of industry
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
    74
	bool show_on_map;  ///< for filtering industries, if true is shown on map in color
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
    75
	bool end;          ///< this is the end of the list
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
    76
	bool col_break;    ///< perform a break and go one collumn further
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    77
};
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    78
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    79
/** Legend text giving the colours to look for on the minimap */
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    80
static const LegendAndColour _legend_land_contours[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    81
	MK(0x5A, STR_00F0_100M),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    82
	MK(0x5C, STR_00F1_200M),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    83
	MK(0x5E, STR_00F2_300M),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    84
	MK(0x1F, STR_00F3_400M),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    85
	MK(0x27, STR_00F4_500M),
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    86
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    87
	MS(0xD7, STR_00EB_ROADS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    88
	MK(0x0A, STR_00EC_RAILROADS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    89
	MK(0x98, STR_00ED_STATIONS_AIRPORTS_DOCKS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    90
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    91
	MK(0x0F, STR_00EF_VEHICLES),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	MKEND()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
    95
static const LegendAndColour _legend_vehicles[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    96
	MK(0xB8, STR_00F5_TRAINS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    97
	MK(0xBF, STR_00F6_ROAD_VEHICLES),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    98
	MK(0x98, STR_00F7_SHIPS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
    99
	MK(0x0F, STR_00F8_AIRCRAFT),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   100
	MS(0xD7, STR_00F9_TRANSPORT_ROUTES),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   101
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	MKEND()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
   105
static const LegendAndColour _legend_routes[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   106
	MK(0xD7, STR_00EB_ROADS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   107
	MK(0x0A, STR_00EC_RAILROADS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   108
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   109
	MS(0x56, STR_011B_RAILROAD_STATION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   111
	MK(0xC2, STR_011C_TRUCK_LOADING_BAY),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   112
	MK(0xBF, STR_011D_BUS_STATION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   113
	MK(0xB8, STR_011E_AIRPORT_HELIPORT),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   114
	MK(0x98, STR_011F_DOCK),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	MKEND()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
   118
static const LegendAndColour _legend_vegetation[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   119
	MK(0x52, STR_0120_ROUGH_LAND),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   120
	MK(0x54, STR_0121_GRASS_LAND),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   121
	MK(0x37, STR_0122_BARE_LAND),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   122
	MK(0x25, STR_0123_FIELDS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   123
	MK(0x57, STR_0124_TREES),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   124
	MK(0xD0, STR_00FC_FOREST),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   125
	MS(0x0A, STR_0125_ROCKS),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   127
	MK(0xC2, STR_012A_DESERT),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   128
	MK(0x98, STR_012B_SNOW),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   129
	MK(0xD7, STR_00F9_TRANSPORT_ROUTES),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   130
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	MKEND()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
   134
static const LegendAndColour _legend_land_owners[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   135
	MK(0xCA, STR_0126_WATER),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   136
	MK(0x54, STR_0127_NO_OWNER),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   137
	MK(0xB4, STR_0128_TOWNS),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   138
	MK(0x20, STR_0129_INDUSTRIES),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	MKEND()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
#undef MK
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
#undef MS
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
#undef MKEND
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   145
/** Allow room for all industries, plus a terminator entry
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   146
 * This is required in order to have the indutry slots all filled up */
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   147
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES+1];
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   148
/* For connecting industry type to position in industries list(small map legend) */
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   149
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   151
/**
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   152
 * Fills an array for the industries legends.
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   153
 */
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   154
void BuildIndustriesLegend()
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   155
{
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   156
	const IndustrySpec *indsp;
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   157
	uint j = 0;
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   158
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   159
	/* Add each name */
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   160
	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   161
		indsp = GetIndustrySpec(i);
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6730
diff changeset
   162
		if (indsp->enabled) {
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   163
			_legend_from_industries[j].legend = indsp->name;
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   164
			_legend_from_industries[j].colour = indsp->map_colour;
7933
b2bb6a4aafd4 (svn r11486) -Fix [FS#1457]: industry count was wrong in smallmap
glx
parents: 7921
diff changeset
   165
			_legend_from_industries[j].type = i;
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   166
			_legend_from_industries[j].show_on_map = true;
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   167
			_legend_from_industries[j].col_break = false;
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   168
			_legend_from_industries[j].end = false;
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   169
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   170
			/* Store widget number for this industry type */
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   171
			_industry_to_list_pos[i] = j;
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   172
			j++;
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   173
		}
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   174
	}
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   175
	/* Terminate the list */
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   176
	_legend_from_industries[j].end = true;
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   177
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   178
	/* Store number of enabled industries */
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   179
	_smallmap_industry_count = j;
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   180
}
6475
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
   181
b7dce828b7a1 (svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
belugas
parents: 6453
diff changeset
   182
static const LegendAndColour * const _legend_table[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	_legend_land_contours,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	_legend_vehicles,
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6488
diff changeset
   185
	_legend_from_industries,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	_legend_routes,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	_legend_vegetation,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	_legend_land_owners,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
2984
f9d92e013486 (svn r3559) - CodeChange: simplify MKCOLOR(x) macro for smallmap_gui.c by adding a TO_LE32X() macro next to TO_BE32X(). The 'X' signifies them as macros and not-inline functions so they can be used in variable declarations.
Darkvater
parents: 2981
diff changeset
   191
#define MKCOLOR(x) TO_LE32X(x)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
7313
a36dc43afcb5 (svn r10665) -Codechange: replace magic 15 with MAX_TILE_HEIGHT (bilbo)
truelight
parents: 7266
diff changeset
   193
/**
a36dc43afcb5 (svn r10665) -Codechange: replace magic 15 with MAX_TILE_HEIGHT (bilbo)
truelight
parents: 7266
diff changeset
   194
 * Height encodings; MAX_TILE_HEIGHT + 1 levels, from 0 to MAX_TILE_HEIGHT
a36dc43afcb5 (svn r10665) -Codechange: replace magic 15 with MAX_TILE_HEIGHT (bilbo)
truelight
parents: 7266
diff changeset
   195
 */
a36dc43afcb5 (svn r10665) -Codechange: replace magic 15 with MAX_TILE_HEIGHT (bilbo)
truelight
parents: 7266
diff changeset
   196
static const uint32 _map_height_bits[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	MKCOLOR(0x5A5A5A5A),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	MKCOLOR(0x5A5B5A5B),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	MKCOLOR(0x5B5B5B5B),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	MKCOLOR(0x5B5C5B5C),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	MKCOLOR(0x5C5C5C5C),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	MKCOLOR(0x5C5D5C5D),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	MKCOLOR(0x5D5D5D5D),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	MKCOLOR(0x5D5E5D5E),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	MKCOLOR(0x5E5E5E5E),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	MKCOLOR(0x5E5F5E5F),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	MKCOLOR(0x5F5F5F5F),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	MKCOLOR(0x5F1F5F1F),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	MKCOLOR(0x1F1F1F1F),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	MKCOLOR(0x1F271F27),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	MKCOLOR(0x27272727),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	MKCOLOR(0x27272727),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
};
7313
a36dc43afcb5 (svn r10665) -Codechange: replace magic 15 with MAX_TILE_HEIGHT (bilbo)
truelight
parents: 7266
diff changeset
   214
assert_compile(lengthof(_map_height_bits) == MAX_TILE_HEIGHT + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   216
struct AndOr {
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   217
	uint32 mor;
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   218
	uint32 mand;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   219
};
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   220
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4000
diff changeset
   221
static inline uint32 ApplyMask(uint32 colour, const AndOr *mask)
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   222
{
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   223
	return (colour & mask->mand) | mask->mor;
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   224
}
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   225
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   226
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   227
static const AndOr _smallmap_contours_andor[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   228
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   229
	{MKCOLOR(0x000A0A00), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   230
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   231
	{MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   232
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   233
	{MKCOLOR(0x98989898), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   234
	{MKCOLOR(0xCACACACA), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   235
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   236
	{MKCOLOR(0xB5B5B5B5), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   237
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   238
	{MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   239
	{MKCOLOR(0x000A0A00), MKCOLOR(0xFF0000FF)},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   242
static const AndOr _smallmap_vehicles_andor[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   243
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   244
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   245
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   246
	{MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   247
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   248
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   249
	{MKCOLOR(0xCACACACA), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   250
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   251
	{MKCOLOR(0xB5B5B5B5), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   252
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   253
	{MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   254
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   257
static const AndOr _smallmap_vegetation_andor[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   258
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   259
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   260
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   261
	{MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   262
	{MKCOLOR(0x00575700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   263
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   264
	{MKCOLOR(0xCACACACA), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   265
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   266
	{MKCOLOR(0xB5B5B5B5), MKCOLOR(0x00000000)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   267
	{MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   268
	{MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4339
diff changeset
   269
	{MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   272
typedef uint32 GetSmallMapPixels(TileIndex tile); // typedef callthrough function
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   273
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   274
/**
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   275
 * Draws one column of the small map in a certain mode onto the screen buffer. This
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   276
 * function looks exactly the same for all types
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   277
 *
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   278
 * @param dst Pointer to a part of the screen buffer to write to.
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   279
 * @param xc The X coordinate of the first tile in the column.
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   280
 * @param yc The Y coordinate of the first tile in the column
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   281
 * @param pitch Number of pixels to advance in the screen buffer each time a pixel is written.
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   282
 * @param reps Number of lines to draw
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   283
 * @param mask ?
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   284
 * @param proc Pointer to the colour function
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   285
 * @see GetSmallMapPixels(TileIndex)
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   286
 */
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6757
diff changeset
   287
static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   288
{
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
   289
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
7489
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   290
	void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   291
	void *dst_ptr_end = blitter->MoveTo(dst_ptr_abs_end, -4, 0);
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   292
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   293
	do {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6357
diff changeset
   294
		/* check if the tile (xc,yc) is within the map range */
1919
ca41cc314d40 (svn r2425) - Fix (regression): wrong sprite for level-land cursor (thx Tron)
Darkvater
parents: 1918
diff changeset
   295
		if (xc < MapMaxX() && yc < MapMaxY()) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6357
diff changeset
   296
			/* check if the dst pointer points to a pixel inside the screen buffer */
7489
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   297
			if (dst < _screen.dst_ptr) continue;
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   298
			if (dst >= dst_ptr_abs_end) continue;
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   299
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   300
			uint32 val = proc(TileXY(xc, yc)) & mask;
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   301
			uint8 *val8 = (uint8 *)&val;
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   302
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   303
			if (dst <= dst_ptr_end) {
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   304
				blitter->SetPixelIfEmpty(dst, 0, 0, val8[0]);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   305
				blitter->SetPixelIfEmpty(dst, 1, 0, val8[1]);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   306
				blitter->SetPixelIfEmpty(dst, 2, 0, val8[2]);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   307
				blitter->SetPixelIfEmpty(dst, 3, 0, val8[3]);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   308
			} else {
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   309
				/* It happens that there are only 1, 2 or 3 pixels left to fill, so in that special case, write till the end of the video-buffer */
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   310
				int i = 0;
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   311
				do {
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   312
					blitter->SetPixelIfEmpty(dst, 0, 0, val8[i]);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   313
				} while (i++, dst = blitter->MoveTo(dst, 1, 0), dst < dst_ptr_abs_end);
71e233b9a937 (svn r11000) -Fix r10121: when introducing the new blitter system, smallmap regained an old bug: buffer-overflow when moving window to far bottom-right.
truelight
parents: 7370
diff changeset
   314
			}
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   315
		}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6357
diff changeset
   316
	/* switch to next tile in the column */
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
   317
	} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   318
}
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   319
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   320
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   321
static inline TileType GetEffectiveTileType(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
{
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   323
	TileType t = GetTileType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	if (t == MP_TUNNELBRIDGE) {
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
   326
		TransportType tt = GetTunnelBridgeTransportType(tile);
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3144
diff changeset
   327
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3144
diff changeset
   328
		switch (tt) {
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3144
diff changeset
   329
			case TRANSPORT_RAIL: t = MP_RAILWAY; break;
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7369
diff changeset
   330
			case TRANSPORT_ROAD: t = MP_ROAD;    break;
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3144
diff changeset
   331
			default:             t = MP_WATER;   break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	}
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   334
	return t;
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   335
}
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   336
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   337
/**
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   338
 * Return the color a tile would be displayed with in the small map in mode "Contour".
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   339
 * @param tile The tile of which we would like to get the color.
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   340
 * @return The color of tile in the small map in mode "Contour"
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   341
 */
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   342
static inline uint32 GetSmallMapContoursPixels(TileIndex tile)
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   343
{
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   344
	TileType t = GetEffectiveTileType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   346
	return
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   347
		ApplyMask(_map_height_bits[TileHeight(tile)], &_smallmap_contours_andor[t]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   350
/**
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   351
 * Return the color a tile would be displayed with in the small map in mode "Vehicles".
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   352
 *
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6476
diff changeset
   353
 * @param tile The tile of which we would like to get the color.
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   354
 * @return The color of tile in the small map in mode "Vehicles"
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   355
 */
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   356
static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
{
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   358
	TileType t = GetEffectiveTileType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
1511
5917a04566df (svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
tron
parents: 1350
diff changeset
   360
	return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   363
/**
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   364
 * Return the color a tile would be displayed with in the small map in mode "Industries".
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   365
 *
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   366
 * @param tile The tile of which we would like to get the color.
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   367
 * @return The color of tile in the small map in mode "Industries"
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   368
 */
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   369
static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
{
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   371
	TileType t = GetEffectiveTileType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	if (t == MP_INDUSTRY) {
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   374
		/* If industry is allowed to be seen, use its color on the map */
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   375
		if (_legend_from_industries[_industry_to_list_pos[GetIndustryByTile(tile)->type]].show_on_map) {
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   376
			return GetIndustrySpec(GetIndustryByTile(tile)->type)->map_colour * 0x01010101;
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   377
		} else {
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   378
			/* otherwise, return the color of the clear tiles, which will make it disappear */
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   379
			return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[MP_CLEAR]);
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   380
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	}
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   382
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   383
	return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   386
/**
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   387
 * Return the color a tile would be displayed with in the small map in mode "Routes".
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   388
 *
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6476
diff changeset
   389
 * @param tile The tile of which we would like to get the color.
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   390
 * @return The color of tile  in the small map in mode "Routes"
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   391
 */
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   392
static inline uint32 GetSmallMapRoutesPixels(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
{
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   394
	TileType t = GetEffectiveTileType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	uint32 bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	if (t == MP_STATION) {
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   398
		switch (GetStationType(tile)) {
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   399
			case STATION_RAIL:    bits = MKCOLOR(0x56565656); break;
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   400
			case STATION_AIRPORT: bits = MKCOLOR(0xB8B8B8B8); break;
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   401
			case STATION_TRUCK:   bits = MKCOLOR(0xC2C2C2C2); break;
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   402
			case STATION_BUS:     bits = MKCOLOR(0xBFBFBFBF); break;
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   403
			case STATION_DOCK:    bits = MKCOLOR(0x98989898); break;
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   404
			default:              bits = MKCOLOR(0xFFFFFFFF); break;
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3326
diff changeset
   405
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	} else {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6357
diff changeset
   407
		/* ground color */
10322
1a2a97853c0c (svn r14567) -Revert (part of 14566): don't commit testing stuff...
rubidium
parents: 10321
diff changeset
   408
		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	return bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   414
static const uint32 _vegetation_clear_bits[] = {
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   415
	MKCOLOR(0x54545454), ///< full grass
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   416
	MKCOLOR(0x52525252), ///< rough land
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   417
	MKCOLOR(0x0A0A0A0A), ///< rocks
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   418
	MKCOLOR(0x25252525), ///< fields
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   419
	MKCOLOR(0x98989898), ///< snow
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   420
	MKCOLOR(0xC2C2C2C2), ///< desert
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   421
	MKCOLOR(0x54545454), ///< unused
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   422
	MKCOLOR(0x54545454), ///< unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   425
static inline uint32 GetSmallMapVegetationPixels(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
{
1516
dc914162ad01 (svn r2020) Reduce code duplication in the minimap code a bit
tron
parents: 1515
diff changeset
   427
	TileType t = GetEffectiveTileType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	uint32 bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   430
	switch (t) {
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   431
		case MP_CLEAR:
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   432
			if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) < 3) {
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   433
				bits = MKCOLOR(0x37373737);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   434
			} else {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   435
				bits = _vegetation_clear_bits[GetClearGround(tile)];
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   436
			}
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   437
			break;
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   438
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   439
		case MP_INDUSTRY:
6757
385cb1bf2ba9 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 6748
diff changeset
   440
			bits = GetIndustrySpec(GetIndustryByTile(tile)->type)->check_proc == CHECK_FOREST ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5);
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   441
			break;
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   442
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   443
		case MP_TREES:
3441
fead68bcb6a3 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3421
diff changeset
   444
			if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT) {
9413
7042a8ec3fa8 (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
parents: 9412
diff changeset
   445
				bits = (_settings_game.game_creation.landscape == LT_ARCTIC) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2907
diff changeset
   446
			} else {
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   447
				bits = MKCOLOR(0x54575754);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2907
diff changeset
   448
			}
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   449
			break;
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   450
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   451
		default:
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   452
			bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   453
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	return bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
4846
8cf926d11bfa (svn r6772) -Codechange: Do not abuse OWNER_SPECTATOR as the "owner" of the industry for
Darkvater
parents: 4727
diff changeset
   460
static uint32 _owner_colors[OWNER_END + 1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   462
/**
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   463
 * Return the color a tile would be displayed with in the small map in mode "Owner".
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   464
 *
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6476
diff changeset
   465
 * @param tile The tile of which we would like to get the color.
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   466
 * @return The color of tile in the small map in mode "Owner"
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   467
 */
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   468
static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
{
2368
cb44b5c6953d (svn r2894) Simplify colouring in owner-mode in the minimap regarding towns and get rid of some magic numbers
tron
parents: 2332
diff changeset
   470
	Owner o;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
2368
cb44b5c6953d (svn r2894) Simplify colouring in owner-mode in the minimap regarding towns and get rid of some magic numbers
tron
parents: 2332
diff changeset
   472
	switch (GetTileType(tile)) {
4846
8cf926d11bfa (svn r6772) -Codechange: Do not abuse OWNER_SPECTATOR as the "owner" of the industry for
Darkvater
parents: 4727
diff changeset
   473
		case MP_INDUSTRY: o = OWNER_END;          break;
2368
cb44b5c6953d (svn r2894) Simplify colouring in owner-mode in the minimap regarding towns and get rid of some magic numbers
tron
parents: 2332
diff changeset
   474
		case MP_HOUSE:    o = OWNER_TOWN;         break;
cb44b5c6953d (svn r2894) Simplify colouring in owner-mode in the minimap regarding towns and get rid of some magic numbers
tron
parents: 2332
diff changeset
   475
		default:          o = GetTileOwner(tile); break;
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9317
diff changeset
   476
		/* FIXME: For MP_ROAD there are multiple owners.
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9317
diff changeset
   477
		 * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9317
diff changeset
   478
		 * even if there are no ROADTYPE_ROAD bits on the tile.
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9317
diff changeset
   479
		 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
2368
cb44b5c6953d (svn r2894) Simplify colouring in owner-mode in the minimap regarding towns and get rid of some magic numbers
tron
parents: 2332
diff changeset
   482
	return _owner_colors[o];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
static const uint32 _smallmap_mask_left[3] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	MKCOLOR(0xFF000000),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
	MKCOLOR(0xFFFF0000),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	MKCOLOR(0xFFFFFF00),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   492
static const uint32 _smallmap_mask_right[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	MKCOLOR(0x000000FF),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	MKCOLOR(0x0000FFFF),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	MKCOLOR(0x00FFFFFF),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
/* each tile has 4 x pixels and 1 y pixel */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
1918
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   500
static GetSmallMapPixels *_smallmap_draw_procs[] = {
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   501
	GetSmallMapContoursPixels,
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   502
	GetSmallMapVehiclesPixels,
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   503
	GetSmallMapIndustriesPixels,
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   504
	GetSmallMapRoutesPixels,
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   505
	GetSmallMapVegetationPixels,
fb72133270ac (svn r2424) - Fix: backport the smallmap_gui.c changes from the map/ branch into trunk. This also implicitely fixes the bug where the game would crash in certain resolutions with certain minimap masks when dragged partly outside the game-area.
Darkvater
parents: 1901
diff changeset
   506
	GetSmallMapOwnerPixels,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
static const byte _vehicle_type_colors[6] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	184, 191, 152, 15, 215, 184
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
static void DrawVertMapIndicator(int x, int y, int x2, int y2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
{
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2907
diff changeset
   516
	GfxFillRect(x, y,      x2, y + 3, 69);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2907
diff changeset
   517
	GfxFillRect(x, y2 - 3, x2, y2,    69);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
static void DrawHorizMapIndicator(int x, int y, int x2, int y2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
{
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2907
diff changeset
   522
	GfxFillRect(x,      y, x + 3, y2, 69);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2907
diff changeset
   523
	GfxFillRect(x2 - 3, y, x2,    y2, 69);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
7919
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   526
enum SmallMapWindowWidgets {
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   527
	SM_WIDGET_MAP_BORDER = 3,
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   528
	SM_WIDGET_MAP,
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   529
	SM_WIDGET_LEGEND,
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   530
	SM_WIDGET_BUTTONSPANEL,
7919
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   531
	SM_WIDGET_CONTOUR,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   532
	SM_WIDGET_VEHICLES,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   533
	SM_WIDGET_INDUSTRIES,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   534
	SM_WIDGET_ROUTES,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   535
	SM_WIDGET_VEGETATION,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   536
	SM_WIDGET_OWNERS,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   537
	SM_WIDGET_CENTERMAP,
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   538
	SM_WIDGET_TOGGLETOWNNAME,
7921
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   539
	SM_WIDGET_BOTTOMPANEL,
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   540
	SM_WIDGET_ENABLEINDUSTRIES,
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   541
	SM_WIDGET_DISABLEINDUSTRIES,
3437fdd5c0a8 (svn r11474) -Feature: Allow to resize on creation the smallmap gui in order to show all the types industry available.
belugas
parents: 7920
diff changeset
   542
	SM_WIDGET_RESIZEBOX,
7919
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   543
};
a8b61d51832e (svn r11472) -Codechange: Give enuma for both the widget numbers and the used smallmap currently used type
belugas
parents: 7824
diff changeset
   544
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   545
class SmallMapWindow : public Window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
{
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   547
	enum SmallMapType {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   548
		SMT_CONTOUR,
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   549
		SMT_VEHICLES,
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   550
		SMT_INDUSTRY,
9856
19d70a7250ee (svn r14000) -Codechange: Missing enum entries kind of defeat the point of the enum
peter1138
parents: 9843
diff changeset
   551
		SMT_ROUTES,
19d70a7250ee (svn r14000) -Codechange: Missing enum entries kind of defeat the point of the enum
peter1138
parents: 9843
diff changeset
   552
		SMT_VEGETATION,
19d70a7250ee (svn r14000) -Codechange: Missing enum entries kind of defeat the point of the enum
peter1138
parents: 9843
diff changeset
   553
		SMT_OWNER,
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   554
	};
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   555
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   556
	static SmallMapType map_type;
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   557
	static bool show_towns;
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   558
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   559
	int32 scroll_x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   560
	int32 scroll_y;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   561
	int32 subscroll;
9412
163c465bf250 (svn r13323) -Codechange: scrollbars are not refresh counters
peter1138
parents: 9358
diff changeset
   562
	uint8 refresh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   564
	static const int COLUMN_WIDTH = 119;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   565
	static const int MIN_LEGEND_HEIGHT = 6 * 7;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   566
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   567
public:
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   568
	/**
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   569
	 * Draws the small map.
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   570
	 *
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   571
	 * Basically, the small map is draw column of pixels by column of pixels. The pixels
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   572
	 * are drawn directly into the screen buffer. The final map is drawn in multiple passes.
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   573
	 * The passes are:
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   574
	 * <ol><li>The colors of tiles in the different modes.</li>
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   575
	 * <li>Town names (optional)</li></ol>
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   576
	 *
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   577
	 * @param dpi pointer to pixel to write onto
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   578
	 * @param w pointer to Window struct
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   579
	 * @param type type of map requested (vegetation, owners, routes, etc)
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   580
	 * @param show_towns true if the town names should be displayed, false if not.
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   581
	 */
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   582
	void DrawSmallMap(DrawPixelInfo *dpi)
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   583
	{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   584
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   585
		DrawPixelInfo *old_dpi;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   586
		int dx,dy, x, y, x2, y2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   587
		void *ptr;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   588
		int tile_x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   589
		int tile_y;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   590
		ViewPort *vp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   592
		old_dpi = _cur_dpi;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   593
		_cur_dpi = dpi;
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   594
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   595
		/* clear it */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   596
		GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, 0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   597
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   598
		/* setup owner table */
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   599
		if (this->map_type == SMT_OWNER) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10075
diff changeset
   600
			const Company *c;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   601
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   602
			/* fill with some special colors */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   603
			_owner_colors[OWNER_TOWN] = MKCOLOR(0xB4B4B4B4);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   604
			_owner_colors[OWNER_NONE] = MKCOLOR(0x54545454);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   605
			_owner_colors[OWNER_WATER] = MKCOLOR(0xCACACACA);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   606
			_owner_colors[OWNER_END]   = MKCOLOR(0x20202020); /* industry */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   607
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10075
diff changeset
   608
			/* now fill with the company colours */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10075
diff changeset
   609
			FOR_ALL_COMPANIES(c) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10075
diff changeset
   610
				_owner_colors[c->index] =
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10075
diff changeset
   611
					_colour_gradient[c->colour][5] * 0x01010101;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   612
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   615
		tile_x = this->scroll_x / TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   616
		tile_y = this->scroll_y / TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   618
		dx = dpi->left + this->subscroll;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   619
		tile_x -= dx / 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   620
		tile_y += dx / 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   621
		dx &= 3;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   622
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   623
		dy = dpi->top;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   624
		tile_x += dy / 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   625
		tile_y += dy / 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   626
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   627
		if (dy & 1) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   628
			tile_x++;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   629
			dx += 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   630
			if (dx > 3) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   631
				dx -= 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   632
				tile_x--;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   633
				tile_y++;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   634
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   637
		ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   638
		x = - dx - 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   639
		y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   641
		for (;;) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   642
			uint32 mask = 0xFFFFFFFF;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   643
			int reps;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   644
			int t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   646
			/* distance from left edge */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   647
			if (x < 0) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   648
				if (x < -3) goto skip_column;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   649
				/* mask to use at the left edge */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   650
				mask = _smallmap_mask_left[x + 3];
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   651
			}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   652
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   653
			/* distance from right edge */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   654
			t = dpi->width - x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   655
			if (t < 4) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   656
				if (t <= 0) break; /* exit loop */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   657
				/* mask to use at the right edge */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   658
				mask &= _smallmap_mask_right[t - 1];
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   659
			}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   660
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   661
			/* number of lines */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   662
			reps = (dpi->height - y + 1) / 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   663
			if (reps > 0) {
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   664
				DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[this->map_type]);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   665
			}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   666
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   667
	skip_column:
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   668
			if (y == 0) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   669
				tile_y++;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   670
				y++;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   671
				ptr = blitter->MoveTo(ptr, 0, 1);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   672
			} else {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   673
				tile_x--;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   674
				y--;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   675
				ptr = blitter->MoveTo(ptr, 0, -1);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   676
			}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   677
			ptr = blitter->MoveTo(ptr, 2, 0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   678
			x += 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   679
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   680
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   681
		/* draw vehicles? */
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   682
		if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) {
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   683
			Vehicle *v;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   684
			bool skip;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   685
			byte color;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   686
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   687
			FOR_ALL_VEHICLES(v) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   688
				if (v->type != VEH_EFFECT &&
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   689
						(v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   690
					/* Remap into flat coordinates. */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   691
					Point pt = RemapCoords(
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   692
						v->x_pos / TILE_SIZE - this->scroll_x / TILE_SIZE, // divide each one separately because (a-b)/c != a/c-b/c in integer world
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   693
						v->y_pos / TILE_SIZE - this->scroll_y / TILE_SIZE, //    dtto
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   694
						0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   695
					x = pt.x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   696
					y = pt.y;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   697
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   698
					/* Check if y is out of bounds? */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   699
					y -= dpi->top;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   700
					if (!IsInsideMM(y, 0, dpi->height)) continue;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   701
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   702
					/* Default is to draw both pixels. */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   703
					skip = false;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   704
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   705
					/* Offset X coordinate */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   706
					x -= this->subscroll + 3 + dpi->left;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   707
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   708
					if (x < 0) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   709
						/* if x+1 is 0, that means we're on the very left edge,
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   710
						 *  and should thus only draw a single pixel */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   711
						if (++x != 0) continue;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   712
						skip = true;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   713
					} else if (x >= dpi->width - 1) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   714
						/* Check if we're at the very right edge, and if so draw only a single pixel */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   715
						if (x != dpi->width - 1) continue;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   716
						skip = true;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   717
					}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   718
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   719
					/* Calculate pointer to pixel and the color */
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   720
					color = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colors[v->type] : 0xF;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   721
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   722
					/* And draw either one or two pixels depending on clipping */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   723
					blitter->SetPixel(dpi->dst_ptr, x, y, color);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   724
					if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, color);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   725
				}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   726
			}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   727
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   728
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   729
		if (this->show_towns) {
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   730
			const Town *t;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   731
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   732
			FOR_ALL_TOWNS(t) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   733
				/* Remap the town coordinate */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
				Point pt = RemapCoords(
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   735
					(int)(TileX(t->xy) * TILE_SIZE - this->scroll_x) / TILE_SIZE,
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   736
					(int)(TileY(t->xy) * TILE_SIZE - this->scroll_y) / TILE_SIZE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
					0);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   738
				x = pt.x - this->subscroll + 3 - (t->sign.width_2 >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
				y = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   741
				/* Check if the town sign is within bounds */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   742
				if (x + t->sign.width_2 > dpi->left &&
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   743
						x < dpi->left + dpi->width &&
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   744
						y + 6 > dpi->top &&
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   745
						y < dpi->top + dpi->height) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   746
					/* And draw it. */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   747
					SetDParam(0, t->index);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   748
					DrawString(x, y, STR_2056, TC_WHITE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		}
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   752
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   753
		/* Draw map indicators */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   754
		{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   755
			Point pt;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   756
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   757
			/* Find main viewport. */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   758
			vp = FindWindowById(WC_MAIN_WINDOW,0)->viewport;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   759
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   760
			pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   761
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   762
			x = vp->virtual_left - pt.x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   763
			y = vp->virtual_top - pt.y;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   764
			x2 = (x + vp->virtual_width) / TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   765
			y2 = (y + vp->virtual_height) / TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   766
			x /= TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   767
			y /= TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   768
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   769
			x -= this->subscroll;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   770
			x2 -= this->subscroll;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   771
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   772
			DrawVertMapIndicator(x, y, x, y2);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   773
			DrawVertMapIndicator(x2, y, x2, y2);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   774
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   775
			DrawHorizMapIndicator(x, y, x2, y);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   776
			DrawHorizMapIndicator(x, y2, x2, y2);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   777
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   778
		_cur_dpi = old_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   781
	void SmallMapCenterOnCurrentPos()
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   782
	{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   783
		int x, y;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   784
		ViewPort *vp;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   785
		vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
1515
071fe1565cb8 (svn r2019) Miscellaneous cleanups, like uint -> TileIndex, >> -> /, if cascade -> switch
tron
parents: 1511
diff changeset
   786
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   787
		x  = ((vp->virtual_width  - (this->widget[SM_WIDGET_MAP].right  - this->widget[SM_WIDGET_MAP].left) * TILE_SIZE) / 2 + vp->virtual_left) / 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   788
		y  = ((vp->virtual_height - (this->widget[SM_WIDGET_MAP].bottom - this->widget[SM_WIDGET_MAP].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   789
		this->scroll_x = (y - x) & ~0xF;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   790
		this->scroll_y = (x + y) & ~0xF;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   791
		this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   792
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   793
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   794
	void ResizeLegend()
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   795
	{
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   796
		Widget *legend = &this->widget[SM_WIDGET_LEGEND];
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   797
		int rows = (legend->bottom - legend->top) - 1;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   798
		int columns = (legend->right - legend->left) / COLUMN_WIDTH;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   799
		int new_rows = (this->map_type == SMT_INDUSTRY) ? ((_smallmap_industry_count + columns - 1) / columns) * 6 : MIN_LEGEND_HEIGHT;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   800
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   801
		new_rows = max(new_rows, MIN_LEGEND_HEIGHT);
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   802
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   803
		if (new_rows != rows) {
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   804
			this->SetDirty();
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   805
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   806
			/* The legend widget needs manual adjustment as by default
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   807
			 * it lays outside the filler widget's bounds. */
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   808
			legend->top--;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   809
			/* Resize the filler widget, and move widgets below it. */
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   810
			ResizeWindowForWidget(this, SM_WIDGET_BUTTONSPANEL, 0, new_rows - rows);
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   811
			legend->top++;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   812
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   813
			/* Resize map border widget so the window stays the same size */
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   814
			ResizeWindowForWidget(this, SM_WIDGET_MAP_BORDER, 0, rows - new_rows);
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   815
			/* Manually adjust the map widget as it lies completely within
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   816
			 * the map border widget */
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   817
			this->widget[SM_WIDGET_MAP].bottom += rows - new_rows;
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   818
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   819
			this->SetDirty();
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   820
		}
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   821
	}
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   822
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9193
diff changeset
   823
	SmallMapWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number)
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   824
	{
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   825
		this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   826
		this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   827
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   828
		this->SmallMapCenterOnCurrentPos();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   829
		this->FindWindowPlacementAndResize(desc);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   830
	}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   831
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   832
	virtual void OnPaint()
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   833
	{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   834
		DrawPixelInfo new_dpi;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   835
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   836
		/* Hide Enable all/Disable all buttons if is not industry type small map*/
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   837
		this->SetWidgetHiddenState(SM_WIDGET_ENABLEINDUSTRIES, this->map_type != SMT_INDUSTRY);
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   838
		this->SetWidgetHiddenState(SM_WIDGET_DISABLEINDUSTRIES, this->map_type != SMT_INDUSTRY);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   839
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   840
		/* draw the window */
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   841
		SetDParam(0, STR_00E5_CONTOURS + this->map_type);
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9203
diff changeset
   842
		this->DrawWidgets();
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   843
9841
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   844
		const Widget *legend = &this->widget[SM_WIDGET_LEGEND];
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   845
9841
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   846
		int y_org = legend->top + 1;
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   847
		int x = 4;
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   848
		int y = y_org;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   849
9837
8d4c9e463e5e (svn r13980) -Codechange: Turn small map legend while loop into a for-loop.
peter1138
parents: 9836
diff changeset
   850
		for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
9841
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   851
			if (tbl->col_break || y >= legend->bottom) {
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   852
				/* Column break needed, continue at top, COLUMN_WIDTH pixels
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   853
				 * (one "row") to the right. */
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   854
				x += COLUMN_WIDTH;
9837
8d4c9e463e5e (svn r13980) -Codechange: Turn small map legend while loop into a for-loop.
peter1138
parents: 9836
diff changeset
   855
				y = y_org;
8d4c9e463e5e (svn r13980) -Codechange: Turn small map legend while loop into a for-loop.
peter1138
parents: 9836
diff changeset
   856
			}
8d4c9e463e5e (svn r13980) -Codechange: Turn small map legend while loop into a for-loop.
peter1138
parents: 9836
diff changeset
   857
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   858
			if (this->map_type == SMT_INDUSTRY) {
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   859
				/* Industry name must be formated, since it's not in tiny font in the specs.
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   860
				 * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font.*/
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   861
				SetDParam(0, tbl->legend);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   862
				assert(tbl->type < NUM_INDUSTRYTYPES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   863
				SetDParam(1, _industry_counts[tbl->type]);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   864
				if (!tbl->show_on_map) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   865
					/* Simply draw the string, not the black border of the legend color.
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   866
					 * This will enforce the idea of the disabled item */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   867
					DrawString(x + 11, y, STR_SMALLMAP_INDUSTRY, TC_GREY);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   868
				} else {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   869
					DrawString(x + 11, y, STR_SMALLMAP_INDUSTRY, TC_BLACK);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   870
					GfxFillRect(x, y + 1, x + 8, y + 5, 0); // outer border of the legend color
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   871
				}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   872
			} else {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   873
				/* Anything that is not an industry is using normal process */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   874
				GfxFillRect(x, y + 1, x + 8, y + 5, 0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   875
				DrawString(x + 11, y, tbl->legend, TC_FROMSTRING);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   876
			}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   877
			GfxFillRect(x + 1, y + 2, x + 7, y + 4, tbl->colour); // legend color
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   878
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   879
			y += 6;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   880
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   881
9836
aa56bba741a2 (svn r13979) -Codechange: Use widget dimensions instead of magic number incantations for limiting small map area.
peter1138
parents: 9835
diff changeset
   882
		const Widget *wi = &this->widget[SM_WIDGET_MAP];
aa56bba741a2 (svn r13979) -Codechange: Use widget dimensions instead of magic number incantations for limiting small map area.
peter1138
parents: 9835
diff changeset
   883
		if (!FillDrawPixelInfo(&new_dpi, wi->left + 1, wi->top + 1, wi->right - wi->left - 1, wi->bottom - wi->top - 1)) return;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   884
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   885
		this->DrawSmallMap(&new_dpi);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   886
	}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   887
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   888
	virtual void OnClick(Point pt, int widget)
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   889
	{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   890
		switch (widget) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   891
			case SM_WIDGET_MAP: { // Map window
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   892
				/*
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   893
				 * XXX: scrolling with the left mouse button is done by subsequently
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   894
				 * clicking with the left mouse button; clicking once centers the
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   895
				 * large map at the selected point. So by unclicking the left mouse
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   896
				 * button here, it gets reclicked during the next inputloop, which
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   897
				 * would make it look like the mouse is being dragged, while it is
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   898
				 * actually being (virtually) clicked every inputloop.
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   899
				 */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   900
				_left_button_clicked = false;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   901
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   902
				Point pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   903
				Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
10075
38e5b4db10d9 (svn r14243) -Fix [FS#2269]: clicking on the smallmap didn't break the "follow vehicle in main viewport".
rubidium
parents: 9856
diff changeset
   904
				w->viewport->follow_vehicle = INVALID_VEHICLE;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   905
				w->viewport->dest_scrollpos_x = pt.x + ((_cursor.pos.x - this->left + 2) << 4) - (w->viewport->virtual_width >> 1);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   906
				w->viewport->dest_scrollpos_y = pt.y + ((_cursor.pos.y - this->top - 16) << 4) - (w->viewport->virtual_height >> 1);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   907
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   908
				this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   909
			} break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   910
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   911
			case SM_WIDGET_CONTOUR:    // Show land contours
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   912
			case SM_WIDGET_VEHICLES:   // Show vehicles
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   913
			case SM_WIDGET_INDUSTRIES: // Show industries
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   914
			case SM_WIDGET_ROUTES:     // Show transport routes
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   915
			case SM_WIDGET_VEGETATION: // Show vegetation
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   916
			case SM_WIDGET_OWNERS:     // Show land owners
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   917
				this->RaiseWidget(this->map_type + SM_WIDGET_CONTOUR);
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   918
				this->map_type = (SmallMapType)(widget - SM_WIDGET_CONTOUR);
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   919
				this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   920
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   921
				this->ResizeLegend();
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   922
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   923
				this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   924
				SndPlayFx(SND_15_BEEP);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   925
				break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   926
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   927
			case SM_WIDGET_CENTERMAP: // Center the smallmap again
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   928
				this->SmallMapCenterOnCurrentPos();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   929
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   930
				this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   931
				SndPlayFx(SND_15_BEEP);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   932
				break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   933
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   934
			case SM_WIDGET_TOGGLETOWNNAME: // Toggle town names
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   935
				this->show_towns = !this->show_towns;
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   936
				this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   937
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   938
				this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   939
				SndPlayFx(SND_15_BEEP);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   940
				break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   941
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   942
			case SM_WIDGET_LEGEND: // Legend
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   943
				/* if industry type small map*/
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
   944
				if (this->map_type == SMT_INDUSTRY) {
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   945
					/* if click on industries label, find right industry type and enable/disable it */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   946
					Widget *wi = &this->widget[SM_WIDGET_LEGEND]; // label panel
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
   947
					uint column = (pt.x - 4) / COLUMN_WIDTH;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   948
					uint line = (pt.y - wi->top - 2) / 6;
9841
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   949
					int rows_per_column = (wi->bottom - wi->top) / 6;
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   950
9841
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   951
					/* check if click is on industry label*/
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   952
					int industry_pos = (column * rows_per_column) + line;
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   953
					if (industry_pos < _smallmap_industry_count) {
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   954
						_legend_from_industries[industry_pos].show_on_map = !_legend_from_industries[industry_pos].show_on_map;
2583c4c8d095 (svn r13984) -Codechange: Simplify industry legend on small map, by automatically splitting columns based on widget height.
peter1138
parents: 9837
diff changeset
   955
					}
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   956
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   957
					/* Raise the two buttons "all", as we have done a specific choice */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   958
					this->RaiseWidget(SM_WIDGET_ENABLEINDUSTRIES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   959
					this->RaiseWidget(SM_WIDGET_DISABLEINDUSTRIES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   960
					this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   961
				}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   962
				break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   963
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   964
			case SM_WIDGET_ENABLEINDUSTRIES: // Enable all industries
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   965
				for (int i = 0; i != _smallmap_industry_count; i++) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   966
					_legend_from_industries[i].show_on_map = true;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   967
				}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   968
				/* toggle appeareance indicating the choice */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   969
				this->LowerWidget(SM_WIDGET_ENABLEINDUSTRIES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   970
				this->RaiseWidget(SM_WIDGET_DISABLEINDUSTRIES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   971
				this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   972
				break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   973
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   974
			case SM_WIDGET_DISABLEINDUSTRIES: // disable all industries
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   975
				for (int i = 0; i != _smallmap_industry_count; i++) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   976
					_legend_from_industries[i].show_on_map = false;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   977
				}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   978
				/* toggle appeareance indicating the choice */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   979
				this->RaiseWidget(SM_WIDGET_ENABLEINDUSTRIES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   980
				this->LowerWidget(SM_WIDGET_DISABLEINDUSTRIES);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   981
				this->SetDirty();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   982
				break;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   983
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   984
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   986
	virtual void OnRightClick(Point pt, int widget)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	{
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   988
		if (widget == SM_WIDGET_MAP) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   989
			if (_scrolling_viewport) return;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   990
			_scrolling_viewport = true;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   991
			_cursor.delta.x = 0;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   992
			_cursor.delta.y = 0;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   993
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
	}
4435
40eff4363774 (svn r6205) -CodeChange : use a switch case instead of a cascade of if
belugas
parents: 4429
diff changeset
   995
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   996
	virtual void OnTick()
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   997
	{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
   998
		/* update the window every now and then */
9412
163c465bf250 (svn r13323) -Codechange: scrollbars are not refresh counters
peter1138
parents: 9358
diff changeset
   999
		if ((++this->refresh & 0x1F) == 0) this->SetDirty();
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1000
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1002
	virtual void OnScroll(Point delta)
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1003
	{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1004
		_cursor.fix_at = true;
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1005
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1006
		int x = this->scroll_x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1007
		int y = this->scroll_y;
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1008
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1009
		int sub = this->subscroll + delta.x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1010
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1011
		x -= (sub >> 2) << 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1012
		y += (sub >> 2) << 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1013
		sub &= 3;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1014
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1015
		x += (delta.y >> 1) << 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1016
		y += (delta.y >> 1) << 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1017
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1018
		if (delta.y & 1) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1019
			x += TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1020
			sub += 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1021
			if (sub > 3) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1022
				sub -= 4;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1023
				x -= TILE_SIZE;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1024
				y += TILE_SIZE;
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1025
			}
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1026
		}
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1027
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1028
		int hx = (this->widget[SM_WIDGET_MAP].right  - this->widget[SM_WIDGET_MAP].left) / 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1029
		int hy = (this->widget[SM_WIDGET_MAP].bottom - this->widget[SM_WIDGET_MAP].top ) / 2;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1030
		int hvx = hx * -4 + hy * 8;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1031
		int hvy = hx *  4 + hy * 8;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1032
		if (x < -hvx) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1033
			x = -hvx;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1034
			sub = 0;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1035
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1036
		if (x > (int)MapMaxX() * TILE_SIZE - hvx) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1037
			x = MapMaxX() * TILE_SIZE - hvx;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1038
			sub = 0;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1039
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1040
		if (y < -hvy) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1041
			y = -hvy;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1042
			sub = 0;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1043
		}
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1044
		if (y > (int)MapMaxY() * TILE_SIZE - hvy) {
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1045
			y = MapMaxY() * TILE_SIZE - hvy;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1046
			sub = 0;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1047
		}
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1048
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1049
		this->scroll_x = x;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1050
		this->scroll_y = y;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1051
		this->subscroll = sub;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1052
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1053
		this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	}
9843
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
  1055
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
  1056
	virtual void OnResize(Point new_size, Point delta)
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
  1057
	{
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
  1058
		if (delta.x != 0 && this->map_type == SMT_INDUSTRY) this->ResizeLegend();
96b2f22e54da (svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents: 9841
diff changeset
  1059
	}
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1060
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
9832
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
  1062
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
  1063
bool SmallMapWindow::show_towns = true;
200ded94a1c3 (svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
peter1138
parents: 9780
diff changeset
  1064
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 856
diff changeset
  1065
static const WindowDesc _smallmap_desc = {
7345
9770fd47a675 (svn r10708) -Codechange: allow automatic downsizing of the smallmap window in case of low resolutions; one could already make the window smaller, but the resize button was unreachable.
rubidium
parents: 7341
diff changeset
  1066
	WDP_AUTO, WDP_AUTO, 350, 214, 446, 314,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5584
diff changeset
  1067
	WC_SMALLMAP, WC_NONE,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 856
diff changeset
  1068
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 856
diff changeset
  1069
	_smallmap_widgets,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5955
diff changeset
  1072
void ShowSmallMap()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
{
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1074
	AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1077
/* Extra ViewPort Window Stuff */
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 856
diff changeset
  1078
static const Widget _extra_view_port_widgets[] = {
9764
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1079
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,    0,   13, STR_00C5,                         STR_018B_CLOSE_WINDOW},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1080
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_GREY,    11,   287,    0,   13, STR_EXTRA_VIEW_PORT_TITLE,        STR_018C_WINDOW_TITLE_DRAG_THIS},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1081
{  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_GREY,   288,   299,    0,   13, 0x0,                              STR_STICKY_BUTTON},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1082
{      WWT_PANEL,     RESIZE_RB,  COLOUR_GREY,     0,   299,   14,   33, 0x0,                              STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1083
{      WWT_INSET,     RESIZE_RB,  COLOUR_GREY,     2,   297,   16,   31, 0x0,                              STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1084
{ WWT_PUSHIMGBTN,     RESIZE_TB,  COLOUR_GREY,     0,    21,   34,   55, SPR_IMG_ZOOMIN,                   STR_017F_ZOOM_THE_VIEW_IN},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1085
{ WWT_PUSHIMGBTN,     RESIZE_TB,  COLOUR_GREY,    22,    43,   34,   55, SPR_IMG_ZOOMOUT,                  STR_0180_ZOOM_THE_VIEW_OUT},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1086
{ WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_GREY,    44,   171,   34,   55, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1087
{ WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_GREY,   172,   298,   34,   55, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1088
{      WWT_PANEL,    RESIZE_RTB,  COLOUR_GREY,   299,   299,   34,   55, 0x0,                              STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1089
{      WWT_PANEL,    RESIZE_RTB,  COLOUR_GREY,     0,   287,   56,   67, 0x0,                              STR_NULL},
9b21f847d91c (svn r13900) -Codechange: Replace numbers with Colours enum on settings, smallmaps, stations and signs guis.
belugas
parents: 9659
diff changeset
  1090
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_GREY,   288,   299,   56,   67, 0x0,                              STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 154
diff changeset
  1091
{   WIDGETS_END},
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1092
};
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1093
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1094
class ExtraViewportWindow : public Window
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1095
{
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1096
	enum ExtraViewportWindowWidgets {
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1097
		EVW_CLOSE,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1098
		EVW_CAPTION,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1099
		EVW_STICKY,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1100
		EVW_BACKGROUND,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1101
		EVW_VIEWPORT,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1102
		EVW_ZOOMIN,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1103
		EVW_ZOOMOUT,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1104
		EVW_MAIN_TO_VIEW,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1105
		EVW_VIEW_TO_MAIN,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1106
		EVW_SPACER1,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1107
		EVW_SPACER2,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1108
		EVW_RESIZE,
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1109
	};
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3882
diff changeset
  1110
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1111
public:
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9193
diff changeset
  1112
	ExtraViewportWindow(const WindowDesc *desc, int window_number, TileIndex tile) : Window(desc, window_number)
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1113
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1114
		/* New viewport start at (zero,zero) */
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1115
		InitializeWindowViewport(this, 3, 17, this->widget[EVW_VIEWPORT].right - this->widget[EVW_VIEWPORT].left - 1, this->widget[EVW_VIEWPORT].bottom - this->widget[EVW_VIEWPORT].top - 1, 0, ZOOM_LVL_VIEWPORT);
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1116
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1117
		this->DisableWidget(EVW_ZOOMIN);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1118
		this->FindWindowPlacementAndResize(desc);
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4171
diff changeset
  1119
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1120
		Point pt;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1121
		if (tile == INVALID_TILE) {
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1122
			/* the main window with the main view */
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1123
			const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1124
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1125
			/* center on same place as main window (zoom is maximum, no adjustment needed) */
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1126
			pt.x = w->viewport->scrollpos_x + w->viewport->virtual_height / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1127
			pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1128
		} else {
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1129
			pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile));
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1130
		}
5045
846098142ffe (svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents: 5036
diff changeset
  1131
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1132
		this->viewport->scrollpos_x = pt.x - ((this->widget[EVW_VIEWPORT].right - this->widget[EVW_VIEWPORT].left) - 1) / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1133
		this->viewport->scrollpos_y = pt.y - ((this->widget[EVW_VIEWPORT].bottom - this->widget[EVW_VIEWPORT].top) - 1) / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1134
		this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1135
		this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1136
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1137
	}
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1138
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1139
	virtual void OnPaint()
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1140
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1141
		/* set the number in the title bar */
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1142
		SetDParam(0, this->window_number + 1);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1143
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9203
diff changeset
  1144
		this->DrawWidgets();
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9203
diff changeset
  1145
		this->DrawViewport();
9193
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1146
	}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1147
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1148
	virtual void OnClick(Point pt, int widget)
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1149
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1150
		switch (widget) {
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1151
			case EVW_ZOOMIN: DoZoomInOutWindow(ZOOM_IN,  this); break;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1152
			case EVW_ZOOMOUT: DoZoomInOutWindow(ZOOM_OUT, this); break;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1153
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1154
			case EVW_MAIN_TO_VIEW: { // location button (move main view to same spot as this view) 'Paste Location'
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1155
				Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1156
				int x = this->viewport->scrollpos_x; // Where is the main looking at
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1157
				int y = this->viewport->scrollpos_y;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1158
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1159
				/* set this view to same location. Based on the center, adjusting for zoom */
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1160
				w->viewport->dest_scrollpos_x =  x - (w->viewport->virtual_width -  this->viewport->virtual_width) / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1161
				w->viewport->dest_scrollpos_y =  y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1162
			} break;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1163
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1164
			case EVW_VIEW_TO_MAIN: { // inverse location button (move this view to same spot as main view) 'Copy Location'
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1165
				const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1166
				int x = w->viewport->scrollpos_x;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1167
				int y = w->viewport->scrollpos_y;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1168
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1169
				this->viewport->dest_scrollpos_x =  x + (w->viewport->virtual_width -  this->viewport->virtual_width) / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1170
				this->viewport->dest_scrollpos_y =  y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1171
			} break;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1172
		}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1173
	}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1174
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1175
	virtual void OnResize(Point new_size, Point delta)
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1176
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1177
		this->viewport->width          += delta.x;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1178
		this->viewport->height         += delta.y;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1179
		this->viewport->virtual_width  += delta.x;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1180
		this->viewport->virtual_height += delta.y;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1181
	}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1182
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1183
	virtual void OnScroll(Point delta)
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1184
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1185
		ViewPort *vp = IsPtInWindowViewport(this, _cursor.pos.x, _cursor.pos.y);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1186
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1187
		if (vp == NULL) {
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1188
			_cursor.fix_at = false;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1189
			_scrolling_viewport = false;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1190
		}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1191
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1192
		this->viewport->scrollpos_x += ScaleByZoom(delta.x, vp->zoom);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1193
		this->viewport->scrollpos_y += ScaleByZoom(delta.y, vp->zoom);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1194
		this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1195
		this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1196
	}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1197
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1198
	virtual void OnMouseWheel(int wheel)
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1199
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1200
		ZoomInOrOutToCursorWindow(wheel < 0, this);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1201
	}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1202
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1203
	virtual void OnInvalidateData(int data = 0)
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1204
	{
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1205
		/* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1206
		HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT);
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1207
	}
972346754b84 (svn r13058) -Codechange: make a class of the ExtraViewportWindow.
glx
parents: 9192
diff changeset
  1208
};
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1209
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1210
static const WindowDesc _extra_view_port_desc = {
7369
2bfadb828304 (svn r10732) -Codechange: lower the minimum size for the extra viewport window.
rubidium
parents: 7345
diff changeset
  1211
	WDP_AUTO, WDP_AUTO, 300, 68, 300, 268,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5584
diff changeset
  1212
	WC_EXTRA_VIEW_PORT, WC_NONE,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 856
diff changeset
  1213
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1214
	_extra_view_port_widgets,
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1215
};
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1216
9094
48004fcef409 (svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
peter1138
parents: 9008
diff changeset
  1217
void ShowExtraViewPortWindow(TileIndex tile)
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1218
{
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1219
	int i = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1220
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6357
diff changeset
  1221
	/* find next free window number for extra viewport */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2984
diff changeset
  1222
	while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1223
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9193
diff changeset
  1224
	new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 12
diff changeset
  1225
}
9192
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1226
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1227
bool ScrollMainWindowTo(int x, int y, bool instant)
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1228
{
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1229
	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0), instant);
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1230
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1231
	/* If a user scrolls to a tile (via what way what so ever) and already is on
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1232
	 *  that tile (e.g.: pressed twice), move the smallmap to that location,
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1233
	 *  so you directly see where you are on the smallmap. */
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1234
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1235
	if (res) return res;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1236
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1237
	SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1238
	if (w != NULL) w->SmallMapCenterOnCurrentPos();
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1239
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1240
	return res;
769df96220cd (svn r13055) -Codechange: make a class of SmallMapWindow.
glx
parents: 9184
diff changeset
  1241
}