tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" truelight@4356: #include "functions.h" tron@3234: #include "bridge_map.h" tron@3144: #include "clear_map.h" peter1138@3391: #include "industry_map.h" tron@3338: #include "station_map.h" tron@507: #include "table/strings.h" Darkvater@1918: #include "table/sprites.h" tron@679: #include "map.h" tron@1209: #include "tile.h" darkvater@152: #include "gui.h" tron@3144: #include "tree_map.h" tron@3180: #include "tunnel_map.h" truelight@0: #include "window.h" truelight@0: #include "gfx.h" truelight@0: #include "viewport.h" truelight@0: #include "player.h" truelight@0: #include "vehicle.h" truelight@0: #include "town.h" tron@337: #include "sound.h" tron@2159: #include "variables.h" truelight@0: truelight@867: static const Widget _smallmap_widgets[] = { peter1138@2725: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, Darkvater@1918: { WWT_CAPTION, RESIZE_RIGHT, 13, 11, 433, 0, 13, STR_00B0_MAP, STR_018C_WINDOW_TITLE_DRAG_THIS}, Darkvater@1918: { WWT_STICKYBOX, RESIZE_LR, 13, 434, 445, 0, 13, 0x0, STR_STICKY_BUTTON}, Darkvater@2907: { WWT_PANEL, RESIZE_RB, 13, 0, 445, 14, 257, 0x0, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_RB, 13, 2, 443, 16, 255, 0x0, STR_NULL}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 380, 401, 258, 279, SPR_IMG_SHOW_COUNTOURS, STR_0191_SHOW_LAND_CONTOURS_ON_MAP}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 402, 423, 258, 279, SPR_IMG_SHOW_VEHICLES, STR_0192_SHOW_VEHICLES_ON_MAP}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 424, 445, 258, 279, SPR_IMG_INDUSTRY, STR_0193_SHOW_INDUSTRIES_ON_MAP}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 380, 401, 280, 301, SPR_IMG_SHOW_ROUTES, STR_0194_SHOW_TRANSPORT_ROUTES_ON}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 402, 423, 280, 301, SPR_IMG_PLANTTREES, STR_0195_SHOW_VEGETATION_ON_MAP}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 424, 445, 280, 301, SPR_IMG_COMPANY_GENERAL, STR_0196_SHOW_LAND_OWNERS_ON_MAP}, truelight@4339: { WWT_IMGBTN, RESIZE_LRTB, 13, 358, 379, 258, 279, SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER}, Darkvater@1918: { WWT_IMGBTN, RESIZE_LRTB, 13, 358, 379, 280, 301, SPR_IMG_TOWN, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF}, Darkvater@4938: { WWT_PANEL, RESIZE_RTB, 13, 0, 357, 258, 301, 0x0, STR_NULL}, Darkvater@1918: { WWT_PANEL, RESIZE_RTB, 13, 0, 433, 302, 313, 0x0, STR_NULL}, Darkvater@1918: { WWT_RESIZEBOX, RESIZE_LRTB, 13, 434, 445, 302, 313, 0x0, STR_RESIZE_BUTTON}, Darkvater@1918: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static int _smallmap_type; truelight@0: static bool _smallmap_show_towns = true; truelight@0: Darkvater@1918: #define MK(a,b) a, b Darkvater@1918: #define MKEND() 0xFFFF Darkvater@1918: #define MS(a,b) (a | 0x100), b truelight@0: Darkvater@1918: /* Legend text giving the colours to look for on the minimap */ truelight@0: static const uint16 _legend_land_contours[] = { rubidium@4344: MK(0x5A, STR_00F0_100M), rubidium@4344: MK(0x5C, STR_00F1_200M), rubidium@4344: MK(0x5E, STR_00F2_300M), rubidium@4344: MK(0x1F, STR_00F3_400M), rubidium@4344: MK(0x27, STR_00F4_500M), truelight@193: rubidium@4344: MS(0xD7, STR_00EB_ROADS), rubidium@4344: MK(0x0A, STR_00EC_RAILROADS), rubidium@4344: MK(0x98, STR_00ED_STATIONS_AIRPORTS_DOCKS), rubidium@4344: MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES), rubidium@4344: MK(0x0F, STR_00EF_VEHICLES), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_vehicles[] = { rubidium@4344: MK(0xB8, STR_00F5_TRAINS), rubidium@4344: MK(0xBF, STR_00F6_ROAD_VEHICLES), rubidium@4344: MK(0x98, STR_00F7_SHIPS), rubidium@4344: MK(0x0F, STR_00F8_AIRCRAFT), rubidium@4344: MS(0xD7, STR_00F9_TRANSPORT_ROUTES), rubidium@4344: MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_normal[] = { rubidium@4344: MK(0xD7, STR_00FA_COAL_MINE), rubidium@4344: MK(0xB8, STR_00FB_POWER_STATION), rubidium@4344: MK(0x56, STR_00FC_FOREST), rubidium@4344: MK(0xC2, STR_00FD_SAWMILL), rubidium@4344: MK(0xBF, STR_00FE_OIL_REFINERY), rubidium@4344: MK(0x0F, STR_0105_BANK), truelight@0: rubidium@4344: MS(0x30, STR_00FF_FARM), rubidium@4344: MK(0xAE, STR_0100_FACTORY), rubidium@4344: MK(0x98, STR_0102_OIL_WELLS), rubidium@4344: MK(0x37, STR_0103_IRON_ORE_MINE), rubidium@4344: MK(0x0A, STR_0104_STEEL_MILL), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_hilly[] = { rubidium@4344: MK(0xD7, STR_00FA_COAL_MINE), rubidium@4344: MK(0xB8, STR_00FB_POWER_STATION), rubidium@4344: MK(0x56, STR_00FC_FOREST), rubidium@4344: MK(0x0A, STR_0106_PAPER_MILL), rubidium@4344: MK(0xBF, STR_00FE_OIL_REFINERY), rubidium@4344: MK(0x37, STR_0108_FOOD_PROCESSING_PLANT), rubidium@4344: MS(0x30, STR_00FF_FARM), truelight@0: rubidium@4344: MK(0xAE, STR_0101_PRINTING_WORKS), rubidium@4344: MK(0x98, STR_0102_OIL_WELLS), rubidium@4344: MK(0xC2, STR_0107_GOLD_MINE), rubidium@4344: MK(0x0F, STR_0105_BANK), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_desert[] = { rubidium@4344: MK(0xBF, STR_00FE_OIL_REFINERY), rubidium@4344: MK(0x98, STR_0102_OIL_WELLS), rubidium@4344: MK(0x0F, STR_0105_BANK), rubidium@4344: MK(0xB8, STR_0109_DIAMOND_MINE), rubidium@4344: MK(0x37, STR_0108_FOOD_PROCESSING_PLANT), rubidium@4344: MK(0x0A, STR_010A_COPPER_ORE_MINE), rubidium@4344: MK(0x30, STR_00FF_FARM), rubidium@4344: MS(0x56, STR_010B_FRUIT_PLANTATION), truelight@0: rubidium@4344: MK(0x27, STR_010C_RUBBER_PLANTATION), rubidium@4344: MK(0x25, STR_010D_WATER_SUPPLY), rubidium@4344: MK(0xD0, STR_010E_WATER_TOWER), rubidium@4344: MK(0xAE, STR_0100_FACTORY), rubidium@4344: MK(0xC2, STR_010F_LUMBER_MILL), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_candy[] = { rubidium@4344: MK(0x30, STR_0110_COTTON_CANDY_FOREST), rubidium@4344: MK(0xAE, STR_0111_CANDY_FACTORY), rubidium@4344: MK(0x27, STR_0112_BATTERY_FARM), rubidium@4344: MK(0x37, STR_0113_COLA_WELLS), rubidium@4344: MK(0xD0, STR_0114_TOY_SHOP), rubidium@4344: MK(0x0A, STR_0115_TOY_FACTORY), rubidium@4344: MS(0x25, STR_0116_PLASTIC_FOUNTAINS), truelight@0: rubidium@4344: MK(0xB8, STR_0117_FIZZY_DRINK_FACTORY), rubidium@4344: MK(0x98, STR_0118_BUBBLE_GENERATOR), rubidium@4344: MK(0xC2, STR_0119_TOFFEE_QUARRY), rubidium@4344: MK(0x0F, STR_011A_SUGAR_MINE), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_routes[] = { rubidium@4344: MK(0xD7, STR_00EB_ROADS), rubidium@4344: MK(0x0A, STR_00EC_RAILROADS), rubidium@4344: MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES), rubidium@4344: MS(0x56, STR_011B_RAILROAD_STATION), truelight@0: rubidium@4344: MK(0xC2, STR_011C_TRUCK_LOADING_BAY), rubidium@4344: MK(0xBF, STR_011D_BUS_STATION), rubidium@4344: MK(0xB8, STR_011E_AIRPORT_HELIPORT), rubidium@4344: MK(0x98, STR_011F_DOCK), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_vegetation[] = { rubidium@4344: MK(0x52, STR_0120_ROUGH_LAND), rubidium@4344: MK(0x54, STR_0121_GRASS_LAND), rubidium@4344: MK(0x37, STR_0122_BARE_LAND), rubidium@4344: MK(0x25, STR_0123_FIELDS), rubidium@4344: MK(0x57, STR_0124_TREES), rubidium@4344: MK(0xD0, STR_00FC_FOREST), rubidium@4344: MS(0x0A, STR_0125_ROCKS), truelight@0: rubidium@4344: MK(0xC2, STR_012A_DESERT), rubidium@4344: MK(0x98, STR_012B_SNOW), rubidium@4344: MK(0xD7, STR_00F9_TRANSPORT_ROUTES), rubidium@4344: MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_land_owners[] = { rubidium@4344: MK(0xCA, STR_0126_WATER), rubidium@4344: MK(0x54, STR_0127_NO_OWNER), rubidium@4344: MK(0xB4, STR_0128_TOWNS), rubidium@4344: MK(0x20, STR_0129_INDUSTRIES), truelight@0: MKEND() truelight@0: }; truelight@0: #undef MK truelight@0: #undef MS truelight@0: #undef MKEND truelight@0: truelight@0: truelight@0: enum { IND_OFFS = 6 }; truelight@0: static const uint16 * const _legend_table[] = { truelight@0: _legend_land_contours, truelight@0: _legend_vehicles, truelight@0: NULL, truelight@0: _legend_routes, truelight@0: _legend_vegetation, truelight@0: _legend_land_owners, truelight@0: truelight@0: _legend_industries_normal, truelight@0: _legend_industries_hilly, truelight@0: _legend_industries_desert, truelight@0: _legend_industries_candy, truelight@0: }; truelight@0: Darkvater@2966: #if defined(OTTD_ALIGNMENT) tron@2062: static inline void WRITE_PIXELS(Pixel* d, uint32 val) truelight@0: { truelight@0: # if defined(TTD_BIG_ENDIAN) tron@2635: d[0] = GB(val, 24, 8); tron@2635: d[1] = GB(val, 16, 8); tron@2635: d[2] = GB(val, 8, 8); tron@2635: d[3] = GB(val, 0, 8); truelight@0: # elif defined(TTD_LITTLE_ENDIAN) tron@2635: d[0] = GB(val, 0, 8); tron@2635: d[1] = GB(val, 8, 8); tron@2635: d[2] = GB(val, 16, 8); tron@2635: d[3] = GB(val, 24, 8); truelight@0: # endif truelight@0: } truelight@0: truelight@0: /* need to use OR, otherwise we will overwrite the wrong pixels at the edges :( */ belugas@4171: static inline void WRITE_PIXELS_OR(Pixel *d, uint32 val) truelight@0: { truelight@0: # if defined(TTD_BIG_ENDIAN) tron@2635: d[0] |= GB(val, 24, 8); tron@2635: d[1] |= GB(val, 16, 8); tron@2635: d[2] |= GB(val, 8, 8); tron@2635: d[3] |= GB(val, 0, 8); truelight@0: # elif defined(TTD_LITTLE_ENDIAN) tron@2635: d[0] |= GB(val, 0, 8); tron@2635: d[1] |= GB(val, 8, 8); tron@2635: d[2] |= GB(val, 16, 8); tron@2635: d[3] |= GB(val, 24, 8); truelight@0: # endif truelight@0: } truelight@0: #else rubidium@4549: # define WRITE_PIXELS(dst, val) *(uint32*)(dst) = (val); rubidium@4549: # define WRITE_PIXELS_OR(dst,val) *(uint32*)(dst) |= (val); truelight@0: #endif truelight@0: Darkvater@2984: #define MKCOLOR(x) TO_LE32X(x) truelight@0: Darkvater@1918: /* Height encodings; 16 levels XXX - needs updating for more/finer heights! */ truelight@0: static const uint32 _map_height_bits[16] = { truelight@0: MKCOLOR(0x5A5A5A5A), truelight@0: MKCOLOR(0x5A5B5A5B), truelight@0: MKCOLOR(0x5B5B5B5B), truelight@0: MKCOLOR(0x5B5C5B5C), truelight@0: MKCOLOR(0x5C5C5C5C), truelight@0: MKCOLOR(0x5C5D5C5D), truelight@0: MKCOLOR(0x5D5D5D5D), truelight@0: MKCOLOR(0x5D5E5D5E), truelight@0: MKCOLOR(0x5E5E5E5E), truelight@0: MKCOLOR(0x5E5F5E5F), truelight@0: MKCOLOR(0x5F5F5F5F), truelight@0: MKCOLOR(0x5F1F5F1F), truelight@0: MKCOLOR(0x1F1F1F1F), truelight@0: MKCOLOR(0x1F271F27), truelight@0: MKCOLOR(0x27272727), truelight@0: MKCOLOR(0x27272727), truelight@0: }; truelight@0: tron@1511: typedef struct AndOr { tron@1511: uint32 mor; tron@1511: uint32 mand; tron@1511: } AndOr; tron@1511: belugas@4171: static inline uint32 ApplyMask(uint32 colour, const AndOr *mask) tron@1511: { tron@1511: return (colour & mask->mand) | mask->mor; tron@1511: } tron@1511: Darkvater@1918: tron@1511: static const AndOr _smallmap_contours_andor[] = { rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x000A0A00), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x98989898), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0xCACACACA), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0xB5B5B5B5), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x000A0A00), MKCOLOR(0xFF0000FF)}, truelight@0: }; truelight@0: tron@1511: static const AndOr _smallmap_vehicles_andor[] = { rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0xCACACACA), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0xB5B5B5B5), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, truelight@0: }; truelight@0: tron@1511: static const AndOr _smallmap_vegetation_andor[] = { rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00575700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0xCACACACA), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0xB5B5B5B5), MKCOLOR(0x00000000)}, rubidium@4344: {MKCOLOR(0x00000000), MKCOLOR(0xFFFFFFFF)}, rubidium@4344: {MKCOLOR(0x00B5B500), MKCOLOR(0xFF0000FF)}, rubidium@4344: {MKCOLOR(0x00D7D700), MKCOLOR(0xFF0000FF)}, truelight@0: }; truelight@0: Darkvater@1918: typedef uint32 GetSmallMapPixels(TileIndex tile); // typedef callthrough function Darkvater@1918: Darkvater@1918: /** Darkvater@1918: * Draws one column of the small map in a certain mode onto the screen buffer. This Darkvater@1918: * function looks exactly the same for all types Darkvater@1918: * Darkvater@1918: * @param dst Pointer to a part of the screen buffer to write to. Darkvater@1918: * @param xc The X coordinate of the first tile in the column. Darkvater@1918: * @param yc The Y coordinate of the first tile in the column Darkvater@1918: * @param pitch Number of pixels to advance in the screen buffer each time a pixel is written. Darkvater@1918: * @param reps Number of lines to draw Darkvater@1918: * @param mask ? Darkvater@1918: * @param proc Pointer to the colour function Darkvater@1918: * @see GetSmallMapPixels(TileIndex) Darkvater@1918: */ tron@2062: static void DrawSmallMapStuff(Pixel *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc) Darkvater@1918: { tron@2062: Pixel *dst_ptr_end = _screen.dst_ptr + _screen.width * _screen.height - _screen.width; Darkvater@1918: Darkvater@1918: do { Darkvater@1918: // check if the tile (xc,yc) is within the map range Darkvater@1919: if (xc < MapMaxX() && yc < MapMaxY()) { Darkvater@1918: // check if the dst pointer points to a pixel inside the screen buffer Darkvater@1918: if (dst > _screen.dst_ptr && dst < dst_ptr_end) tron@1981: WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask); Darkvater@1918: } Darkvater@1918: // switch to next tile in the column Darkvater@1918: } while (xc++, yc++, dst += pitch, --reps != 0); Darkvater@1918: } Darkvater@1918: tron@1516: tron@1516: static inline TileType GetEffectiveTileType(TileIndex tile) truelight@0: { celestar@5590: switch (GetTileType(tile)) { celestar@5590: case MP_STREET_BRIDGE: return MP_STREET; celestar@5590: case MP_RAILWAY_BRIDGE: return MP_RAILWAY; celestar@5590: case MP_TUNNEL: celestar@5590: if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) return MP_RAILWAY; celestar@5590: return MP_STREET; celestar@5590: default: return GetTileType(tile); truelight@0: } tron@1516: } tron@1516: Darkvater@1918: /** Darkvater@1918: * Return the color a tile would be displayed with in the small map in mode "Contour". Darkvater@1918: * @param tile The tile of which we would like to get the color. Darkvater@1918: * @return The color of tile in the small map in mode "Contour" Darkvater@1918: */ tron@1516: static inline uint32 GetSmallMapContoursPixels(TileIndex tile) tron@1516: { tron@1516: TileType t = GetEffectiveTileType(tile); truelight@0: tron@1511: return tron@1511: ApplyMask(_map_height_bits[TileHeight(tile)], &_smallmap_contours_andor[t]); truelight@0: } truelight@0: Darkvater@1918: /** Darkvater@1918: * Return the color a tile would be displayed with in the small map in mode "Vehicles". Darkvater@1918: * Darkvater@1918: * @param t The tile of which we would like to get the color. Darkvater@1918: * @return The color of tile in the small map in mode "Vehicles" Darkvater@1918: */ tron@1515: static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile) truelight@0: { tron@1516: TileType t = GetEffectiveTileType(tile); truelight@0: tron@1511: return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]); truelight@0: } truelight@0: Darkvater@1918: /* Industry colours... a total of 175 gfx - XXX - increase if more industries */ truelight@0: static const byte _industry_smallmap_colors[175] = { rubidium@4344: 215, 215, 215, 215, 215, 215, 215, 184, rubidium@4344: 184, 184, 184, 194, 194, 194, 194, 194, rubidium@4344: 86, 86, 191, 191, 191, 191, 191, 191, rubidium@4344: 152, 152, 152, 152, 152, 152, 152, 152, rubidium@4344: 152, 48, 48, 48, 48, 48, 48, 174, rubidium@4344: 174, 174, 174, 174, 174, 174, 174, 10, rubidium@4344: 10, 10, 10, 10, 10, 10, 10, 10, rubidium@4344: 10, 10, 15, 15, 55, 55, 55, 55, rubidium@4344: 10, 10, 10, 10, 10, 10, 10, 10, rubidium@4344: 194, 194, 194, 194, 194, 194, 194, 194, rubidium@4344: 194, 194, 194, 194, 194, 194, 194, 194, rubidium@4344: 194, 15, 15, 184, 184, 184, 184, 184, rubidium@4344: 184, 184, 184, 184, 55, 55, 55, 55, rubidium@4344: 55, 55, 55, 55, 55, 55, 55, 55, rubidium@4344: 55, 55, 55, 55, 86, 39, 37, 37, rubidium@4344: 208, 174, 174, 174, 174, 194, 194, 194, rubidium@4344: 194, 48, 48, 174, 174, 174, 174, 39, rubidium@4344: 39, 55, 208, 208, 208, 208, 10, 10, rubidium@4344: 10, 10, 10, 10, 37, 37, 37, 37, rubidium@4344: 37, 37, 37, 37, 184, 184, 184, 184, rubidium@4344: 152, 152, 152, 152, 194, 194, 194, 15, rubidium@4344: 15, 15, 15, 15, 15, 15, 15, truelight@0: }; truelight@0: Darkvater@1918: /** Darkvater@1918: * Return the color a tile would be displayed with in the small map in mode "Industries". Darkvater@1918: * Darkvater@1918: * @param tile The tile of which we would like to get the color. Darkvater@1918: * @return The color of tile in the small map in mode "Industries" Darkvater@1918: */ tron@1515: static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile) truelight@0: { tron@1516: TileType t = GetEffectiveTileType(tile); truelight@0: truelight@0: if (t == MP_INDUSTRY) { tron@4481: return _industry_smallmap_colors[GetIndustryGfx(tile)] * 0x01010101; truelight@0: } Darkvater@1918: Darkvater@1918: return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]); truelight@0: } truelight@0: Darkvater@1918: /** Darkvater@1918: * Return the color a tile would be displayed with in the small map in mode "Routes". Darkvater@1918: * Darkvater@1918: * @param t The tile of which we would like to get the color. Darkvater@1918: * @return The color of tile in the small map in mode "Routes" Darkvater@1918: */ tron@1515: static inline uint32 GetSmallMapRoutesPixels(TileIndex tile) truelight@0: { tron@1516: TileType t = GetEffectiveTileType(tile); truelight@0: uint32 bits; truelight@0: truelight@0: if (t == MP_STATION) { tron@3338: switch (GetStationType(tile)) { tron@3338: case STATION_RAIL: bits = MKCOLOR(0x56565656); break; tron@3338: case STATION_AIRPORT: bits = MKCOLOR(0xB8B8B8B8); break; tron@3338: case STATION_TRUCK: bits = MKCOLOR(0xC2C2C2C2); break; tron@3338: case STATION_BUS: bits = MKCOLOR(0xBFBFBFBF); break; tron@3338: case STATION_DOCK: bits = MKCOLOR(0x98989898); break; tron@3338: default: bits = MKCOLOR(0xFFFFFFFF); break; tron@3338: } truelight@0: } else { truelight@0: // ground color tron@1511: bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]); truelight@0: } truelight@0: return bits; truelight@0: } truelight@0: truelight@0: tron@2955: static const uint32 _vegetation_clear_bits[] = { Darkvater@1918: MKCOLOR(0x54545454), ///< full grass Darkvater@1918: MKCOLOR(0x52525252), ///< rough land Darkvater@1918: MKCOLOR(0x0A0A0A0A), ///< rocks Darkvater@1918: MKCOLOR(0x25252525), ///< fields Darkvater@1918: MKCOLOR(0x98989898), ///< snow Darkvater@1918: MKCOLOR(0xC2C2C2C2), ///< desert Darkvater@1918: MKCOLOR(0x54545454), ///< unused Darkvater@1918: MKCOLOR(0x54545454), ///< unused truelight@0: }; truelight@0: tron@1515: static inline uint32 GetSmallMapVegetationPixels(TileIndex tile) truelight@0: { tron@1516: TileType t = GetEffectiveTileType(tile); truelight@0: uint32 bits; truelight@0: tron@1515: switch (t) { tron@1515: case MP_CLEAR: tron@3447: if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) < 3) { tron@2955: bits = MKCOLOR(0x37373737); tron@2955: } else { tron@2955: bits = _vegetation_clear_bits[GetClearGround(tile)]; tron@2955: } tron@1515: break; tron@1515: tron@1515: case MP_INDUSTRY: belugas@3499: bits = GetIndustryType(tile) == IT_FOREST ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5); tron@1515: break; tron@1515: tron@1515: case MP_TREES: tron@3441: if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT) { tron@1515: bits = (_opt.landscape == LT_HILLY) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2); tron@2951: } else { tron@1515: bits = MKCOLOR(0x54575754); tron@2951: } tron@1515: break; tron@1515: tron@1515: default: tron@1515: bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]); tron@1515: break; truelight@0: } truelight@0: truelight@0: return bits; truelight@0: } truelight@0: truelight@0: Darkvater@4846: static uint32 _owner_colors[OWNER_END + 1]; truelight@0: Darkvater@1918: /** Darkvater@1918: * Return the color a tile would be displayed with in the small map in mode "Owner". Darkvater@1918: * Darkvater@1918: * @param t The tile of which we would like to get the color. Darkvater@1918: * @return The color of tile in the small map in mode "Owner" Darkvater@1918: */ tron@1515: static inline uint32 GetSmallMapOwnerPixels(TileIndex tile) truelight@0: { tron@2368: Owner o; truelight@0: tron@2368: switch (GetTileType(tile)) { Darkvater@4846: case MP_INDUSTRY: o = OWNER_END; break; tron@2368: case MP_HOUSE: o = OWNER_TOWN; break; tron@2368: default: o = GetTileOwner(tile); break; truelight@0: } truelight@0: tron@2368: return _owner_colors[o]; truelight@0: } truelight@0: truelight@0: truelight@0: static const uint32 _smallmap_mask_left[3] = { truelight@0: MKCOLOR(0xFF000000), truelight@0: MKCOLOR(0xFFFF0000), truelight@0: MKCOLOR(0xFFFFFF00), truelight@0: }; truelight@0: tron@1515: static const uint32 _smallmap_mask_right[] = { truelight@0: MKCOLOR(0x000000FF), truelight@0: MKCOLOR(0x0000FFFF), truelight@0: MKCOLOR(0x00FFFFFF), truelight@0: }; truelight@0: truelight@0: /* each tile has 4 x pixels and 1 y pixel */ truelight@0: Darkvater@1918: static GetSmallMapPixels *_smallmap_draw_procs[] = { Darkvater@1918: GetSmallMapContoursPixels, Darkvater@1918: GetSmallMapVehiclesPixels, Darkvater@1918: GetSmallMapIndustriesPixels, Darkvater@1918: GetSmallMapRoutesPixels, Darkvater@1918: GetSmallMapVegetationPixels, Darkvater@1918: GetSmallMapOwnerPixels, truelight@0: }; truelight@0: truelight@0: static const byte _vehicle_type_colors[6] = { truelight@0: 184, 191, 152, 15, 215, 184 truelight@0: }; truelight@0: truelight@0: truelight@0: static void DrawVertMapIndicator(int x, int y, int x2, int y2) truelight@0: { tron@2951: GfxFillRect(x, y, x2, y + 3, 69); tron@2951: GfxFillRect(x, y2 - 3, x2, y2, 69); truelight@0: } truelight@0: truelight@0: static void DrawHorizMapIndicator(int x, int y, int x2, int y2) truelight@0: { tron@2951: GfxFillRect(x, y, x + 3, y2, 69); tron@2951: GfxFillRect(x2 - 3, y, x2, y2, 69); truelight@0: } truelight@0: Darkvater@1918: /** Darkvater@1918: * Draws the small map. Darkvater@1918: * Darkvater@1918: * Basically, the small map is draw column of pixels by column of pixels. The pixels Darkvater@1918: * are drawn directly into the screen buffer. The final map is drawn in multiple passes. Darkvater@1918: * The passes are: Darkvater@1918: *
  1. The colors of tiles in the different modes.
  2. Darkvater@1918: *
  3. Town names (optional)
  4. Darkvater@1918: * Darkvater@1918: * @param dpi pointer to pixel to write onto Darkvater@1918: * @param w pointer to Window struct Darkvater@1918: * @param type type of map requested (vegetation, owners, routes, etc) Darkvater@1918: * @param show_towns true if the town names should be displayed, false if not. Darkvater@1918: */ truelight@0: static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns) truelight@0: { truelight@0: DrawPixelInfo *old_dpi; truelight@0: int dx,dy, x, y, x2, y2; tron@2062: Pixel *ptr; tron@1515: int tile_x; tron@1515: int tile_y; truelight@0: ViewPort *vp; truelight@0: truelight@0: old_dpi = _cur_dpi; truelight@0: _cur_dpi = dpi; truelight@0: truelight@0: /* clear it */ truelight@0: GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, 0); truelight@0: truelight@0: /* setup owner table */ truelight@0: if (type == 5) { belugas@4171: const Player *p; truelight@193: truelight@0: /* fill with some special colors */ tron@2368: _owner_colors[OWNER_TOWN] = MKCOLOR(0xB4B4B4B4); truelight@2332: _owner_colors[OWNER_NONE] = MKCOLOR(0x54545454); truelight@2332: _owner_colors[OWNER_WATER] = MKCOLOR(0xCACACACA); Darkvater@4847: _owner_colors[OWNER_END] = MKCOLOR(0x20202020); /* industry */ truelight@0: truelight@0: /* now fill with the player colors */ truelight@0: FOR_ALL_PLAYERS(p) { tron@2951: if (p->is_active) { tron@1092: _owner_colors[p->index] = tron@4455: _colour_gradient[p->player_color][5] * 0x01010101; tron@2951: } truelight@193: } truelight@0: } truelight@0: celestar@3421: tile_x = WP(w,smallmap_d).scroll_x / TILE_SIZE; celestar@3421: tile_y = WP(w,smallmap_d).scroll_y / TILE_SIZE; truelight@0: truelight@0: dx = dpi->left + WP(w,smallmap_d).subscroll; tron@1515: tile_x -= dx / 4; tron@1515: tile_y += dx / 4; truelight@0: dx &= 3; truelight@0: truelight@0: dy = dpi->top; tron@1515: tile_x += dy / 2; tron@1515: tile_y += dy / 2; truelight@0: truelight@0: if (dy & 1) { truelight@0: tile_x++; truelight@0: dx += 2; truelight@0: if (dx > 3) { truelight@0: dx -= 4; truelight@0: tile_x--; truelight@0: tile_y++; truelight@0: } truelight@0: } truelight@0: truelight@0: ptr = dpi->dst_ptr - dx - 4; truelight@0: x = - dx - 4; truelight@0: y = 0; truelight@0: tron@2952: for (;;) { tron@2989: uint32 mask = 0xFFFFFFFF; tron@1515: int reps; tron@1515: int t; tron@1515: truelight@0: /* distance from left edge */ truelight@0: if (x < 0) { truelight@0: if (x < -3) goto skip_column; truelight@0: /* mask to use at the left edge */ truelight@0: mask = _smallmap_mask_left[x + 3]; truelight@0: } truelight@0: truelight@0: /* distance from right edge */ truelight@0: t = dpi->width - x; truelight@0: if (t < 4) { tron@2951: if (t <= 0) break; /* exit loop */ truelight@0: /* mask to use at the right edge */ tron@1515: mask &= _smallmap_mask_right[t - 1]; truelight@0: } truelight@0: truelight@0: /* number of lines */ tron@1515: reps = (dpi->height - y + 1) / 2; truelight@0: if (reps > 0) { truelight@0: // assert(ptr >= dpi->dst_ptr); belugas@4171: DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[type]); truelight@0: } truelight@0: truelight@193: skip_column: truelight@0: if (y == 0) { truelight@0: tile_y++; truelight@0: y++; truelight@0: ptr += dpi->pitch; truelight@0: } else { truelight@0: tile_x--; truelight@0: y--; truelight@0: ptr -= dpi->pitch; truelight@0: } truelight@0: ptr += 2; truelight@0: x += 2; truelight@0: } truelight@0: truelight@0: /* draw vehicles? */ truelight@0: if (type == 0 || type == 1) { truelight@0: Vehicle *v; truelight@0: bool skip; truelight@0: byte color; truelight@0: truelight@0: FOR_ALL_VEHICLES(v) { truelight@4346: if (v->type != VEH_Special && tron@1515: (v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) { truelight@0: // Remap into flat coordinates. truelight@0: Point pt = RemapCoords( KUDr@5096: v->x_pos / TILE_SIZE - WP(w,smallmap_d).scroll_x / TILE_SIZE, // divide each one separately because (a-b)/c != a/c-b/c in integer world KUDr@5096: v->y_pos / TILE_SIZE - WP(w,smallmap_d).scroll_y / TILE_SIZE, // dtto truelight@0: 0); truelight@0: x = pt.x; truelight@0: y = pt.y; truelight@0: truelight@0: // Check if y is out of bounds? truelight@0: y -= dpi->top; tron@1515: if (!IS_INT_INSIDE(y, 0, dpi->height)) continue; truelight@0: truelight@0: // Default is to draw both pixels. truelight@0: skip = false; truelight@0: truelight@0: // Offset X coordinate truelight@0: x -= WP(w,smallmap_d).subscroll + 3 + dpi->left; truelight@0: truelight@0: if (x < 0) { truelight@0: // if x+1 is 0, that means we're on the very left edge, truelight@0: // and should thus only draw a single pixel tron@2951: if (++x != 0) continue; truelight@0: skip = true; truelight@0: } else if (x >= dpi->width - 1) { truelight@0: // Check if we're at the very right edge, and if so draw only a single pixel tron@2951: if (x != dpi->width - 1) continue; truelight@0: skip = true; truelight@0: } truelight@193: truelight@0: // Calculate pointer to pixel and the color truelight@0: ptr = dpi->dst_ptr + y * dpi->pitch + x; truelight@0: color = (type == 1) ? _vehicle_type_colors[v->type-0x10] : 0xF; truelight@193: truelight@0: // And draw either one or two pixels depending on clipping truelight@0: ptr[0] = color; tron@2951: if (!skip) ptr[1] = color; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: if (show_towns) { Darkvater@1918: const Town *t; tron@1515: truelight@0: FOR_ALL_TOWNS(t) { truelight@4346: // Remap the town coordinate truelight@4346: Point pt = RemapCoords( truelight@4346: (int)(TileX(t->xy) * TILE_SIZE - WP(w, smallmap_d).scroll_x) / TILE_SIZE, truelight@4346: (int)(TileY(t->xy) * TILE_SIZE - WP(w, smallmap_d).scroll_y) / TILE_SIZE, truelight@4346: 0); truelight@4346: x = pt.x - WP(w,smallmap_d).subscroll + 3 - (t->sign.width_2 >> 1); truelight@4346: y = pt.y; truelight@193: truelight@4346: // Check if the town sign is within bounds truelight@4346: if (x + t->sign.width_2 > dpi->left && truelight@4346: x < dpi->left + dpi->width && truelight@4346: y + 6 > dpi->top && truelight@4346: y < dpi->top + dpi->height) { truelight@4346: // And draw it. truelight@4346: SetDParam(0, t->index); truelight@4346: DrawString(x, y, STR_2056, 12); truelight@0: } truelight@0: } truelight@193: } truelight@0: truelight@0: // Draw map indicators truelight@0: { truelight@0: Point pt; truelight@0: truelight@0: // Find main viewport. truelight@0: vp = FindWindowById(WC_MAIN_WINDOW,0)->viewport; truelight@193: tron@1515: pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w, smallmap_d).scroll_y, 0); truelight@0: truelight@0: x = vp->virtual_left - pt.x; truelight@0: y = vp->virtual_top - pt.y; celestar@3421: x2 = (x + vp->virtual_width) / TILE_SIZE; celestar@3421: y2 = (y + vp->virtual_height) / TILE_SIZE; celestar@3421: x /= TILE_SIZE; celestar@3421: y /= TILE_SIZE; truelight@0: truelight@0: x -= WP(w,smallmap_d).subscroll; truelight@0: x2 -= WP(w,smallmap_d).subscroll; truelight@0: truelight@0: DrawVertMapIndicator(x, y, x, y2); truelight@0: DrawVertMapIndicator(x2, y, x2, y2); truelight@0: truelight@0: DrawHorizMapIndicator(x, y, x2, y); truelight@0: DrawHorizMapIndicator(x, y2, x2, y2); truelight@0: } truelight@0: _cur_dpi = old_dpi; truelight@0: } truelight@0: truelight@4339: void SmallMapCenterOnCurrentPos(Window *w) truelight@4339: { truelight@4339: int x, y; truelight@4339: ViewPort *vp; truelight@4339: vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; truelight@4339: truelight@4339: x = ((vp->virtual_width - (w->widget[4].right - w->widget[4].left) * TILE_SIZE) / 2 + vp->virtual_left) / 4; truelight@4339: y = ((vp->virtual_height - (w->widget[4].bottom - w->widget[4].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2; truelight@4339: WP(w, smallmap_d).scroll_x = (y - x) & ~0xF; truelight@4339: WP(w, smallmap_d).scroll_y = (x + y) & ~0xF; truelight@4339: SetWindowDirty(w); truelight@4339: } truelight@4339: truelight@0: static void SmallMapWindowProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@1918: switch (e->event) { belugas@4435: case WE_PAINT: { belugas@4435: const uint16 *tbl; belugas@4435: int x, y, y_org; belugas@4435: DrawPixelInfo new_dpi; truelight@0: belugas@4435: /* draw the window */ belugas@4435: SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); belugas@4435: DrawWindowWidgets(w); truelight@0: belugas@4435: /* draw the legend */ belugas@4435: tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; belugas@4435: x = 4; belugas@4435: y_org = w->height - 44 - 11; belugas@4435: y = y_org; belugas@4435: for (;;) { belugas@4435: GfxFillRect(x, y + 1, x + 8, y + 5, 0); belugas@4435: GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]); belugas@4435: DrawString(x + 11, y, tbl[1], 0); truelight@0: belugas@4435: tbl += 2; belugas@4435: y += 6; truelight@4339: belugas@4435: if (tbl[0] == 0xFFFF) { belugas@4435: break; belugas@4435: } else if (tbl[0] & 0x100) { belugas@4435: x += 123; belugas@4435: y = y_org; belugas@4435: } truelight@4339: } truelight@4339: belugas@4435: if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11)) belugas@4435: return; belugas@4435: belugas@4435: DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns); truelight@0: } break; truelight@0: belugas@4435: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { belugas@4435: case 4: { // Map window belugas@4435: Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); belugas@4435: Point pt; Darkvater@5127: Darkvater@5127: /* Darkvater@5127: * XXX: scrolling with the left mouse button is done by subsequently Darkvater@5127: * clicking with the left mouse button; clicking once centers the Darkvater@5127: * large map at the selected point. So by unclicking the left mouse Darkvater@5127: * button here, it gets reclicked during the next inputloop, which Darkvater@5127: * would make it look like the mouse is being dragged, while it is Darkvater@5127: * actually being (virtually) clicked every inputloop. Darkvater@5127: */ Darkvater@5127: _left_button_clicked = false; truelight@0: belugas@4435: pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); Darkvater@5127: WP(w2, vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); Darkvater@5127: WP(w2, vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); belugas@4435: belugas@4435: SetWindowDirty(w); belugas@4435: } break; belugas@4435: belugas@4435: case 5: // Show land contours belugas@4435: case 6: // Show vehicles belugas@4435: case 7: // Show industries belugas@4435: case 8: // Show transport routes belugas@4435: case 9: // Show vegetation belugas@4435: case 10: // Show land owners belugas@4719: RaiseWindowWidget(w, _smallmap_type + 5); belugas@4634: _smallmap_type = e->we.click.widget - 5; belugas@4719: LowerWindowWidget(w, _smallmap_type + 5); belugas@4435: belugas@4435: SetWindowDirty(w); belugas@4435: SndPlayFx(SND_15_BEEP); belugas@4435: break; belugas@4435: belugas@4435: case 11: // Center the smallmap again belugas@4435: SmallMapCenterOnCurrentPos(w); belugas@4435: belugas@4435: SetWindowDirty(w); belugas@4435: SndPlayFx(SND_15_BEEP); belugas@4435: break; belugas@4435: belugas@4435: case 12: // Toggle town names belugas@4719: ToggleWidgetLoweredState(w, 12); belugas@4719: _smallmap_show_towns = IsWindowWidgetLowered(w, 12); belugas@4435: belugas@4435: SetWindowDirty(w); belugas@4435: SndPlayFx(SND_15_BEEP); belugas@4435: break; belugas@4435: } truelight@0: break; truelight@0: belugas@4435: case WE_RCLICK: belugas@4634: if (e->we.click.widget == 4) { belugas@4435: if (_scrolling_viewport) return; belugas@4435: _scrolling_viewport = true; belugas@4435: _cursor.delta.x = 0; belugas@4435: _cursor.delta.y = 0; belugas@4435: } truelight@4339: break; truelight@4339: belugas@4435: case WE_MOUSELOOP: belugas@4435: /* update the window every now and then */ belugas@4435: if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); truelight@0: break; truelight@4335: truelight@4335: case WE_SCROLL: { truelight@4335: int x; truelight@4335: int y; truelight@4335: int sub; truelight@4335: int hx; truelight@4335: int hy; truelight@4335: int hvx; truelight@4335: int hvy; truelight@4335: truelight@4335: _cursor.fix_at = true; truelight@4335: truelight@4335: x = WP(w, smallmap_d).scroll_x; truelight@4335: y = WP(w, smallmap_d).scroll_y; truelight@4335: belugas@4634: sub = WP(w, smallmap_d).subscroll + e->we.scroll.delta.x; truelight@4335: truelight@4335: x -= (sub >> 2) << 4; truelight@4335: y += (sub >> 2) << 4; truelight@4335: sub &= 3; truelight@4335: belugas@4634: x += (e->we.scroll.delta.y >> 1) << 4; belugas@4634: y += (e->we.scroll.delta.y >> 1) << 4; truelight@4335: belugas@4634: if (e->we.scroll.delta.y & 1) { truelight@4335: x += TILE_SIZE; truelight@4335: sub += 2; truelight@4335: if (sub > 3) { truelight@4335: sub -= 4; truelight@4335: x -= TILE_SIZE; truelight@4335: y += TILE_SIZE; truelight@4335: } truelight@4335: } truelight@4335: truelight@4335: hx = (w->widget[4].right - w->widget[4].left) / 2; truelight@4335: hy = (w->widget[4].bottom - w->widget[4].top ) / 2; truelight@4335: hvx = hx * -4 + hy * 8; truelight@4335: hvy = hx * 4 + hy * 8; truelight@4335: if (x < -hvx) { truelight@4335: x = -hvx; truelight@4335: sub = 0; truelight@4335: } truelight@4335: if (x > (int)MapMaxX() * TILE_SIZE - hvx) { truelight@4335: x = MapMaxX() * TILE_SIZE - hvx; truelight@4335: sub = 0; truelight@4335: } truelight@4335: if (y < -hvy) { truelight@4335: y = -hvy; truelight@4335: sub = 0; truelight@4335: } truelight@4335: if (y > (int)MapMaxY() * TILE_SIZE - hvy) { truelight@4335: y = MapMaxY() * TILE_SIZE - hvy; truelight@4335: sub = 0; truelight@4335: } truelight@4335: truelight@4335: WP(w, smallmap_d).scroll_x = x; truelight@4335: WP(w, smallmap_d).scroll_y = y; truelight@4335: WP(w, smallmap_d).subscroll = sub; truelight@4335: truelight@4335: SetWindowDirty(w); truelight@4335: } break; truelight@0: } truelight@0: } truelight@0: truelight@867: static const WindowDesc _smallmap_desc = { Darkvater@5070: WDP_AUTO, WDP_AUTO, 446, 314, truelight@0: WC_SMALLMAP,0, truelight@867: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@867: _smallmap_widgets, truelight@0: SmallMapWindowProc truelight@0: }; truelight@0: tron@1093: void ShowSmallMap(void) truelight@0: { truelight@0: Window *w; truelight@0: truelight@867: w = AllocateWindowDescFront(&_smallmap_desc, 0); truelight@4339: if (w == NULL) return; truelight@193: belugas@4719: LowerWindowWidget(w, _smallmap_type + 5); belugas@4727: SetWindowWidgetLoweredState(w, 12, _smallmap_show_towns); truelight@4339: w->resize.width = 350; truelight@4339: w->resize.height = 250; truelight@0: truelight@4339: SmallMapCenterOnCurrentPos(w); truelight@0: } truelight@0: darkvater@152: /* Extra ViewPort Window Stuff */ truelight@867: static const Widget _extra_view_port_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 287, 0, 13, STR_EXTRA_VIEW_PORT_TITLE, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_STICKYBOX, RESIZE_LR, 14, 288, 299, 0, 13, 0x0, STR_STICKY_BUTTON}, rubidium@4344: { WWT_PANEL, RESIZE_RB, 14, 0, 299, 14, 233, 0x0, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_RB, 14, 2, 297, 16, 231, 0x0, STR_NULL}, Darkvater@5036: { WWT_PUSHIMGBTN, RESIZE_TB, 14, 0, 21, 234, 255, SPR_IMG_ZOOMIN, STR_017F_ZOOM_THE_VIEW_IN}, Darkvater@5036: { WWT_PUSHIMGBTN, RESIZE_TB, 14, 22, 43, 234, 255, SPR_IMG_ZOOMOUT, STR_0180_ZOOM_THE_VIEW_OUT}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 44, 171, 234, 255, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 172, 298, 234, 255, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT}, rubidium@4344: { WWT_PANEL, RESIZE_RTB, 14, 299, 299, 234, 255, 0x0, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_RTB, 14, 0, 287, 256, 267, 0x0, STR_NULL}, rubidium@4344: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 288, 299, 256, 267, 0x0, STR_RESIZE_BUTTON}, darkvater@176: { WIDGETS_END}, darkvater@152: }; darkvater@152: darkvater@152: static void ExtraViewPortWndProc(Window *w, WindowEvent *e) darkvater@152: { Darkvater@1815: switch (e->event) { Darkvater@1815: case WE_CREATE: /* Disable zoom in button */ belugas@4709: DisableWindowWidget(w, 5); Darkvater@1815: break; tron@4000: Darkvater@1815: case WE_PAINT: darkvater@152: // set the number in the title bar tron@4000: SetDParam(0, w->window_number + 1); darkvater@152: darkvater@152: DrawWindowWidgets(w); darkvater@152: DrawWindowViewport(w); Darkvater@1815: break; darkvater@152: tron@4000: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { tron@4000: case 5: DoZoomInOutWindow(ZOOM_IN, w); break; tron@4000: case 6: DoZoomInOutWindow(ZOOM_OUT, w); break; tron@4000: Darkvater@1815: case 7: { /* location button (move main view to same spot as this view) 'Paste Location' */ Darkvater@1815: Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); Darkvater@1815: int x = WP(w, vp_d).scrollpos_x; // Where is the main looking at Darkvater@1815: int y = WP(w, vp_d).scrollpos_y; darkvater@152: darkvater@152: // set this view to same location. Based on the center, adjusting for zoom Darkvater@1815: WP(w2, vp_d).scrollpos_x = x - (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; Darkvater@1815: WP(w2, vp_d).scrollpos_y = y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; darkvater@152: } break; tron@4000: Darkvater@1815: case 8: { /* inverse location button (move this view to same spot as main view) 'Copy Location' */ belugas@4171: const Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); tron@2548: int x = WP(w2, const vp_d).scrollpos_x; tron@2548: int y = WP(w2, const vp_d).scrollpos_y; darkvater@152: Darkvater@1815: WP(w, vp_d).scrollpos_x = x + (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; Darkvater@1815: WP(w, vp_d).scrollpos_y = y + (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; darkvater@152: } break; truelight@193: } tron@4000: break; Darkvater@1815: Darkvater@1815: case WE_RESIZE: belugas@4634: w->viewport->width += e->we.sizing.diff.x; belugas@4634: w->viewport->height += e->we.sizing.diff.y; belugas@4634: w->viewport->virtual_width += e->we.sizing.diff.x; belugas@4634: w->viewport->virtual_height += e->we.sizing.diff.y; Darkvater@1815: break; truelight@4335: truelight@4335: case WE_SCROLL: { truelight@4335: ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); truelight@4335: truelight@4335: if (vp == NULL) { truelight@4335: _cursor.fix_at = false; truelight@4335: _scrolling_viewport = false; truelight@4335: } truelight@4335: belugas@4634: WP(w, vp_d).scrollpos_x += e->we.scroll.delta.x << vp->zoom; belugas@4634: WP(w, vp_d).scrollpos_y += e->we.scroll.delta.y << vp->zoom; truelight@4335: } break; truelight@4337: truelight@4337: case WE_MOUSEWHEEL: belugas@4634: ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w); truelight@4337: break; Darkvater@5045: Darkvater@5045: Darkvater@5045: case WE_MESSAGE: Darkvater@5045: /* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */ Darkvater@5045: if (e->we.message.wparam != w->window_number) break; Darkvater@5045: HandleZoomMessage(w, w->viewport, 5, 6); Darkvater@5045: break; darkvater@152: } darkvater@152: } darkvater@152: darkvater@152: static const WindowDesc _extra_view_port_desc = { Darkvater@5070: WDP_AUTO, WDP_AUTO, 300, 268, darkvater@152: WC_EXTRA_VIEW_PORT,0, truelight@867: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, darkvater@152: _extra_view_port_widgets, darkvater@152: ExtraViewPortWndProc darkvater@152: }; darkvater@152: tron@1093: void ShowExtraViewPortWindow(void) darkvater@152: { darkvater@152: Window *w, *v; darkvater@152: int i = 0; truelight@193: darkvater@152: // find next free window number for extra viewport tron@2989: while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++; darkvater@152: truelight@867: w = AllocateWindowDescFront(&_extra_view_port_desc, i); tron@2989: if (w != NULL) { truelight@867: int x, y; darkvater@152: // the main window with the main view truelight@193: v = FindWindowById(WC_MAIN_WINDOW, 0); truelight@193: // New viewport start ats (zero,zero) darkvater@152: AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0); darkvater@152: darkvater@152: // center on same place as main window (zoom is maximum, no adjustment needed) Darkvater@1815: x = WP(v, vp_d).scrollpos_x; Darkvater@1815: y = WP(v, vp_d).scrollpos_y; Darkvater@1815: WP(w, vp_d).scrollpos_x = x + (v->viewport->virtual_width - (294)) / 2; Darkvater@1815: WP(w, vp_d).scrollpos_y = y + (v->viewport->virtual_height - (214)) / 2; darkvater@152: } darkvater@152: }