94#include <forward_list>
99#include "table/strings.h"
104Point _tile_fract_coords;
107ViewportSignKdtree _viewport_sign_kdtree{};
108static int _viewport_sign_maxwidth = 0;
120 ViewportStringFlags flags;
161typedef std::vector<TileSpriteToDraw> TileSpriteToDrawVector;
162typedef std::vector<StringSpriteToDraw> StringSpriteToDrawVector;
163typedef std::vector<ParentSpriteToDraw> ParentSpriteToDrawVector;
164typedef std::vector<ChildScreenSpriteToDraw> ChildScreenSpriteToDrawVector;
173 StringSpriteToDrawVector string_sprites_to_draw;
174 TileSpriteToDrawVector tile_sprites_to_draw;
175 ParentSpriteToDrawVector parent_sprites_to_draw;
177 ChildScreenSpriteToDrawVector child_screen_sprites_to_draw;
195bool _draw_bounding_boxes =
false;
196bool _draw_dirty_blocks =
false;
197uint _dirty_block_colour = 0;
200static Point MapXYZToViewport(
const Viewport &vp,
int x,
int y,
int z)
219 int width,
int height, std::variant<TileIndex, VehicleID> focus,
ZoomLevel zoom)
223 auto vp = std::make_unique<ViewportData>();
225 vp->left = x + w->
left;
226 vp->top = y + w->
top;
237 if (std::holds_alternative<VehicleID>(focus)) {
240 vp->follow_vehicle = std::get<VehicleID>(focus);
244 TileIndex tile = std::get<TileIndex>(focus);
251 pt.
x -= vp->virtual_width / 2;
253 pt.
y -= vp->virtual_height / 2;
259 vp->follow_vehicle = VehicleID::Invalid();
262 vp->scrollpos_x = pt.
x;
263 vp->scrollpos_y = pt.
y;
264 vp->dest_scrollpos_x = pt.
x;
265 vp->dest_scrollpos_y = pt.
y;
267 vp->overlay =
nullptr;
269 vp->virtual_left = 0;
275static Point _vp_move_offs;
279 for (; !it.IsEnd(); ++it) {
281 if (left + width > w->
left &&
283 top + height > w->
top &&
286 if (left < w->left) {
287 DoSetViewportPosition(it, left, top, w->
left - left, height);
288 DoSetViewportPosition(it, left + (w->
left - left), top, width - (w->
left - left), height);
293 DoSetViewportPosition(it, left, top, (w->
left + w->
width - left), height);
294 DoSetViewportPosition(it, left + (w->
left + w->
width - left), top, width - (w->
left + w->
width - left), height);
299 DoSetViewportPosition(it, left, top, width, (w->
top - top));
300 DoSetViewportPosition(it, left, top + (w->
top - top), width, height - (w->
top - top));
305 DoSetViewportPosition(it, left, top, width, (w->
top + w->
height - top));
306 DoSetViewportPosition(it, left, top + (w->
top + w->
height - top), width, height - (w->
top + w->
height - top));
315 int xo = _vp_move_offs.x;
316 int yo = _vp_move_offs.y;
318 if (
abs(xo) >= width ||
abs(yo) >= height) {
324 GfxScroll(left, top, width, height, xo, yo);
343static void SetViewportPosition(
Window *w,
int x,
int y)
349 int left, top, width, height;
365 if (old_top == 0 && old_left == 0)
return;
367 _vp_move_offs.x = old_left;
368 _vp_move_offs.y = old_top;
380 i = left + width - _screen.width;
381 if (i >= 0) width -= i;
389 i = top + height - _screen.height;
390 if (i >= 0) height -= i;
395 DoSetViewportPosition(it, left, top, width, height);
410 if (w->
viewport ==
nullptr)
return nullptr;
433 Point pt = { -1, -1 };
445static Point GetTileFromScreenXY(
int x,
int y,
int zoom_x,
int zoom_y)
456Point GetTileBelowCursor()
458 return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y);
468 x = ((_cursor.pos.x - vp.
left) >> 1) + (vp.
width >> 2);
469 y = ((_cursor.pos.y - vp.
top) >> 1) + (vp.
height >> 2);
471 x = vp.
width - (_cursor.pos.x - vp.
left);
472 y = vp.
height - (_cursor.pos.y - vp.
top);
475 return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp.
left, y + vp.
top);
516 ts.
x = pt.
x + extra_offs_x;
517 ts.
y = pt.
y + extra_offs_y;
534 assert(
IsInsideMM(foundation_part, 0, FOUNDATION_PART_END));
535 assert(_vd.foundation[foundation_part] != -1);
536 Point offs = _vd.foundation_offset[foundation_part];
539 AutoRestoreBackup backup(_vd.last_child, _vd.last_foundation_child[foundation_part]);
561 if (_vd.foundation[_vd.foundation_part] != -1) {
565 AddTileSpriteToDraw(image, pal, _cur_ti.x + x, _cur_ti.y + y, _cur_ti.z + z, sub, extra_offs_x * ZOOM_BASE, extra_offs_y * ZOOM_BASE);
594 switch (_vd.foundation_part) {
601 default: NOT_REACHED();
605 if (_vd.last_child !=
LAST_CHILD_NONE) _vd.foundation[_vd.foundation_part] =
static_cast<uint
>(_vd.parent_sprites_to_draw.size()) - 1;
607 _vd.foundation_offset[_vd.foundation_part].x = x * ZOOM_BASE;
608 _vd.foundation_offset[_vd.foundation_part].y = y * ZOOM_BASE;
609 _vd.last_foundation_child[_vd.foundation_part] = _vd.last_child;
628 if (pt.
x + spr->
x_offs >= _vd.dpi.left + _vd.dpi.width ||
630 pt.
y + spr->
y_offs >= _vd.dpi.top + _vd.dpi.height ||
660 int32_t left, right, top, bottom;
683 int tmp_left, tmp_top, tmp_x = pt.
x, tmp_y = pt.
y;
686 if (image == SPR_EMPTY_BOUNDING_BOX) {
693 left = tmp_left = (pt.
x += spr->
x_offs);
694 right = (pt.
x + spr->
width );
695 top = tmp_top = (pt.
y += spr->
y_offs);
699 if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
708 if (left >= _vd.dpi.left + _vd.dpi.width ||
709 right <= _vd.dpi.left ||
710 top >= _vd.dpi.top + _vd.dpi.height ||
711 bottom <= _vd.dpi.top) {
787 if (begin > end) std::swap(begin, end);
788 return begin <= check && check <= end;
799 int dist_a = (_thd.size.x + _thd.size.y);
800 int dist_b = (_thd.size.x - _thd.size.y);
801 int a = ((x - _thd.pos.x) + (y - _thd.pos.y));
802 int b = ((x - _thd.pos.x) - (y - _thd.pos.y));
833 int32_t child_id =
static_cast<int32_t
>(_vd.child_screen_sprites_to_draw.size());
835 _vd.child_screen_sprites_to_draw[_vd.last_child].next = child_id;
837 _vd.parent_sprites_to_draw.back().first_child = child_id;
844 cs.x = scale ? x * ZOOM_BASE : x;
845 cs.y = scale ? y * ZOOM_BASE : y;
846 cs.relative = relative;
852 if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = child_id;
853 if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = child_id;
854 _vd.last_child = child_id;
866static std::string &
AddStringToDraw(
int x,
int y, Colours colour, ViewportStringFlags flags, uint16_t width)
895 if (_vd.foundation[foundation_part] == -1) {
917 SpriteID sel2 = SPR_HALFTILE_SELECTION_FLAT + halftile_corner;
922 sel = SPR_HALFTILE_SELECTION_DOWN;
926 sel += opposite_corner;
933static bool IsPartOfAutoLine(
int px,
int py)
935 px -= _thd.selstart.x;
936 py -= _thd.selstart.y;
943 case HT_DIR_HU:
return px == -py || px == -py - 16;
944 case HT_DIR_HL:
return px == -py || px == -py + 16;
945 case HT_DIR_VL:
return px == py || px == py + 16;
946 case HT_DIR_VR:
return px == py || px == py - 16;
979 static const uint _lower_rail[4] = { 5U, 2U, 4U, 3U };
981 if (autorail_type != _lower_rail[halftile_corner]) {
990 image = SPR_AUTORAIL_BASE + offset;
993 image = SPR_AUTORAIL_BASE - offset;
1000enum TileHighlightType : uint8_t {
1044 TileHighlightType type = THT_RED;
1047 if (st->TileIsInCatchment(t))
return THT_BLUE;
1071 case THT_NONE:
break;
1086 if (_town_local_authority_kdtree.Count() == 0)
return;
1090 if (!Town::GetByTile(ti->
tile)->show_zone)
return;
1097 TownID tid = _town_local_authority_kdtree.FindNearest(
TileX(ti->
tile),
TileY(ti->
tile));
1122 bool is_redsq = _thd.redsq == ti->
tile;
1131 if (_thd.diagonal) {
1140 if (_thd.drawstyle &
HT_RECT) {
1142 }
else if (_thd.drawstyle &
HT_POINT) {
1152 if ((halftile_corner == CORNER_W) || (halftile_corner == CORNER_E)) z +=
TILE_HEIGHT;
1153 if (halftile_corner != CORNER_S) {
1159 }
else if (_thd.drawstyle &
HT_RAIL) {
1164 }
else if (IsPartOfAutoLine(ti->
x, ti->
y)) {
1182 if (!is_redsq && (tht == THT_NONE || tht == THT_RED) && _thd.outersize.x > 0 &&
1183 IsInsideBS(ti->
x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
1184 IsInsideBS(ti->
y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
1208 assert(_vd.dpi.top <= _vd.dpi.top + _vd.dpi.height);
1209 assert(_vd.dpi.left <= _vd.dpi.left + _vd.dpi.width);
1227 int left_column = (upper_left.
y - upper_left.
x) / (
int)
TILE_SIZE - 2;
1228 int right_column = (upper_right.
y - upper_right.
x) / (
int)
TILE_SIZE + 2;
1236 int row = (upper_left.
x + upper_left.
y) / (
int)
TILE_SIZE - 2;
1237 bool last_row =
false;
1238 for (; !last_row; row++) {
1240 for (
int column = left_column; column <= right_column; column++) {
1242 if ((row + column) % 2 != 0)
continue;
1245 tilecoord.
x = (row - column) / 2;
1246 tilecoord.
y = (row + column) / 2;
1247 assert(column == tilecoord.
y - tilecoord.
x);
1248 assert(row == tilecoord.
y + tilecoord.
x);
1256 _cur_ti.tile =
TileXY(tilecoord.
x, tilecoord.
y);
1280 int min_visible_height = viewport_y - (_vd.dpi.top + _vd.dpi.height);
1281 bool tile_visible = min_visible_height <= 0;
1300 if ((tilecoord.
x <= 0 || tilecoord.
y <= 0) && min_visible_height < potential_bridge_height +
MAX_TILE_EXTENT_TOP) last_row =
false;
1306 _vd.foundation[0] = -1;
1307 _vd.foundation[1] = -1;
1328 int left = dpi->left;
1330 int right = left + dpi->width;
1331 int bottom = top + dpi->height;
1337 if (bottom < sign->top ||
1338 top > sign->
top + sign_height ||
1339 right < sign->center - sign_half_width ||
1340 left > sign->
center + sign_half_width) {
1350 const int max_tw = _viewport_sign_maxwidth / 2 + 1;
1355 r.right += expand_x;
1357 r.bottom += expand_y;
1370 ViewportStringFlags flags{};
1373 StringID stringid_town = !small &&
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_TOWN_NAME;
1374 StringID stringid_town_city = stringid_town;
1376 stringid_town_city =
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_CITY_POP : STR_VIEWPORT_TOWN_CITY;
1379 for (
const Town *t : towns) {
1380 std::string *str =
ViewportAddString(dpi, &t->cache.sign, flags, INVALID_COLOUR);
1381 if (str ==
nullptr)
continue;
1383 if (t->larger_town) {
1384 *str =
GetString(stringid_town_city, t->index, t->cache.population);
1386 *str =
GetString(stringid_town, t->index, t->cache.population);
1399 ViewportStringFlags flags{};
1403 ViewportStringFlags deity_flags{ flags };
1408 for (
const Sign *si : signs) {
1411 const Colours deity_colour = si->text_colour == COLOUR_WHITE ? INVALID_COLOUR : si->text_colour;
1415 if (str ==
nullptr)
continue;
1417 *str =
GetString(STR_SIGN_NAME, si->index);
1435 if (str ==
nullptr)
continue;
1438 *str =
GetString(small ? STR_STATION_NAME : STR_VIEWPORT_STATION, st->index, st->facilities);
1440 *str =
GetString(STR_WAYPOINT_NAME, st->index);
1447 Rect search_rect{ dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height };
1448 search_rect = ExpandRectWithViewportSignMargins(search_rect, dpi->zoom);
1457 std::vector<const BaseStation *> stations;
1458 std::vector<const Town *> towns;
1459 std::vector<const Sign *> signs;
1461 _viewport_sign_kdtree.FindContained(search_rect.left, search_rect.top, search_rect.right, search_rect.bottom, [&](
const ViewportSignKdtreeItem & item) {
1462 switch (item.type) {
1463 case ViewportSignKdtreeItem::VKI_STATION: {
1464 if (!show_stations) break;
1465 const BaseStation *st = BaseStation::Get(std::get<StationID>(item.id));
1468 StationFacilities facilities = st->facilities;
1469 if (facilities.None()) facilities = STATION_FACILITY_GHOST;
1471 if (!facilities.Any(_facility_display_opt)) break;
1474 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
1476 stations.push_back(st);
1480 case ViewportSignKdtreeItem::VKI_WAYPOINT: {
1481 if (!show_waypoints) break;
1482 const BaseStation *st = BaseStation::Get(std::get<StationID>(item.id));
1485 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
1487 stations.push_back(st);
1491 case ViewportSignKdtreeItem::VKI_TOWN:
1492 if (!show_towns) break;
1493 towns.push_back(Town::Get(std::get<TownID>(item.id)));
1496 case ViewportSignKdtreeItem::VKI_SIGN: {
1497 if (!show_signs) break;
1498 const Sign *si = Sign::Get(std::get<SignID>(item.id));
1503 if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break;
1505 signs.push_back(si);
1545 if (str_small.empty()) str_small = str;
1573 if (w->
viewport ==
nullptr)
continue;
1576 if (vp.
zoom <= maxzoom) {
1577 assert(vp.
width != 0);
1584static void ViewportDrawTileSprites(
const TileSpriteToDrawVector *tstdv)
1597 if (psdv->size() < 2)
return;
1606 const uint32_t ORDER_COMPARED = UINT32_MAX;
1607 const uint32_t ORDER_RETURNED = UINT32_MAX - 1;
1608 std::stack<ParentSpriteToDraw *> sprite_order;
1609 uint32_t next_order = 0;
1611 std::forward_list<std::pair<int64_t, ParentSpriteToDraw *>> sprite_list;
1614 for (
auto p = psdv->rbegin(); p != psdv->rend(); p++) {
1615 sprite_list.emplace_front((*p)->xmin + (*p)->ymin, *p);
1616 sprite_order.push(*p);
1617 (*p)->order = next_order++;
1622 std::vector<ParentSpriteToDraw *> preceding;
1623 auto preceding_prev = sprite_list.begin();
1624 auto out = psdv->begin();
1626 while (!sprite_order.empty()) {
1628 auto s = sprite_order.top();
1632 if (s->order == ORDER_RETURNED)
continue;
1635 if (s->order == ORDER_COMPARED) {
1637 s->order = ORDER_RETURNED;
1651 auto ssum = std::max(s->xmax, s->xmin) + std::max(s->ymax, s->ymin);
1652 auto prev = sprite_list.before_begin();
1653 auto x = sprite_list.begin();
1654 while (x != sprite_list.end() && x->first <= ssum) {
1658 x = sprite_list.erase_after(prev);
1665 if (s->xmax < p->xmin || s->ymax < p->ymin || s->zmax < p->zmin)
continue;
1666 if (s->xmin <= p->xmax &&
1667 s->ymin <= p->ymax &&
1668 s->zmin <= p->zmax) {
1669 if (s->xmin + s->xmax + s->ymin + s->ymax + s->zmin + s->zmax <=
1670 p->xmin + p->xmax + p->ymin + p->ymax + p->zmin + p->zmax) {
1674 preceding.push_back(p);
1675 preceding_prev = p_prev;
1678 if (preceding.empty()) {
1681 s->order = ORDER_RETURNED;
1686 if (preceding.size() == 1) {
1687 auto p = preceding[0];
1689 if (p->xmax <= s->xmax && p->ymax <= s->ymax && p->zmax <= s->zmax) {
1690 p->order = ORDER_RETURNED;
1691 s->order = ORDER_RETURNED;
1692 sprite_list.erase_after(preceding_prev);
1701 return a->order > b->order;
1704 s->order = ORDER_COMPARED;
1705 sprite_order.push(s);
1707 for (
auto p: preceding) {
1708 p->order = next_order++;
1709 sprite_order.push(p);
1715static void ViewportDrawParentSprites(
const ParentSpriteToSortVector *psd,
const ChildScreenSpriteToDrawVector *csstdv)
1718 if (ps->image != SPR_EMPTY_BOUNDING_BOX)
DrawSpriteViewport(ps->image, ps->pal, ps->x, ps->y, ps->sub);
1720 int child_idx = ps->first_child;
1721 while (child_idx >= 0) {
1723 child_idx = cs->
next;
1746 pt2.
x - pt1.
x, pt2.
y - pt1.
y,
1747 pt3.
x - pt1.
x, pt3.
y - pt1.
y,
1748 pt4.
x - pt1.
x, pt4.
y - pt1.
y);
1767 uint8_t bo =
UnScaleByZoom(dpi->left + dpi->top, dpi->zoom) & 1;
1769 for (
int i = (bo ^= 1); i < right; i += 2) blitter->
SetPixel(dst, i, 0, colour);
1770 dst = blitter->
MoveTo(dst, 0, 1);
1771 }
while (--bottom > 0);
1774static void ViewportDrawStrings(
ZoomLevel zoom,
const StringSpriteToDrawVector *sstdv)
1785 if (ss.colour != INVALID_COLOUR)
DrawFrameRect(x, y, x + w - 1, y + h - 1, ss.colour, {});
1792 if (ss.colour != INVALID_COLOUR) colour =
GetColourGradient(ss.colour, SHADE_LIGHTER).ToTextColour();
1799 int shadow_offset = 0;
1810void ViewportDoDraw(
const Viewport &vp,
int left,
int top,
int right,
int bottom)
1812 _vd.dpi.zoom = vp.
zoom;
1817 _vd.dpi.width = (right - left) & mask;
1818 _vd.dpi.height = (bottom - top) & mask;
1819 _vd.dpi.left = left & mask;
1820 _vd.dpi.top = top & mask;
1821 _vd.dpi.pitch = _cur_dpi->pitch;
1833 ViewportAddKdtreeSigns(&_vd.dpi);
1835 DrawTextEffects(&_vd.dpi);
1837 if (!_vd.tile_sprites_to_draw.empty()) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
1839 for (
auto &psd : _vd.parent_sprites_to_draw) {
1840 _vd.parent_sprites_to_sort.push_back(&psd);
1843 _vp_sprite_sorter(&_vd.parent_sprites_to_sort);
1844 ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw);
1856 if (vp.overlay !=
nullptr && vp.overlay->GetCargoMask() != 0 && vp.overlay->GetCompanyMask().Any()) {
1860 vp.overlay->Draw(&dp);
1863 if (!_vd.string_sprites_to_draw.empty()) {
1867 ViewportDrawStrings(zoom, &_vd.string_sprites_to_draw);
1870 _vd.string_sprites_to_draw.clear();
1871 _vd.tile_sprites_to_draw.clear();
1872 _vd.parent_sprites_to_draw.clear();
1873 _vd.parent_sprites_to_sort.clear();
1874 _vd.child_screen_sprites_to_draw.clear();
1877static inline void ViewportDraw(
const Viewport &vp,
int left,
int top,
int right,
int bottom)
1879 if (right <= vp.
left || bottom <= vp.
top)
return;
1883 if (left < vp.
left) left = vp.
left;
1888 if (top < vp.
top) top = vp.
top;
1908 dpi->left += this->left;
1909 dpi->top += this->top;
1911 ViewportDraw(*this->
viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
1913 dpi->left -= this->left;
1914 dpi->top -= this->top;
1959static void ClampSmoothScroll(uint32_t delta_ms, int64_t delta_hi, int64_t delta_lo,
int &delta_hi_clamped,
int &delta_lo_clamped)
1962 constexpr int PIXELS_PER_TILE =
TILE_PIXELS * 2 * ZOOM_BASE;
1964 assert(delta_hi != 0);
1967 int64_t delta_left = delta_hi * std::pow(0.75, delta_ms / 30.0);
1972 delta_hi_clamped =
Clamp(delta_hi - delta_left, -max_scroll, max_scroll);
1974 delta_lo_clamped = delta_lo * delta_hi_clamped / delta_hi;
1977 if (delta_hi_clamped == 0) {
1978 delta_hi_clamped = delta_hi > 0 ? 1 : -1;
1997 SetViewportPosition(w, pt.
x, pt.
y);
2008 bool update_overlay =
false;
2009 if (delta_x != 0 || delta_y != 0) {
2011 int delta_x_clamped;
2012 int delta_y_clamped;
2014 if (
abs(delta_x) >
abs(delta_y)) {
2015 ClampSmoothScroll(delta_ms, delta_x, delta_y, delta_x_clamped, delta_y_clamped);
2017 ClampSmoothScroll(delta_ms, delta_y, delta_x, delta_y_clamped, delta_x_clamped);
2040 if (update_overlay) RebuildViewportOverlay(w);
2061 if (right <= 0)
return false;
2064 if (bottom <= 0)
return false;
2098 if (w->viewport !=
nullptr) {
2099 assert(w->viewport->width != 0);
2107void ConstrainAllViewportsZoom()
2110 if (w->viewport ==
nullptr)
continue;
2113 if (zoom != w->viewport->zoom) {
2146 int x_size = _thd.size.x;
2147 int y_size = _thd.size.y;
2149 if (!_thd.diagonal) {
2150 int x_start = _thd.pos.x;
2151 int y_start = _thd.pos.y;
2153 if (_thd.outersize.x != 0) {
2154 x_size += _thd.outersize.x;
2155 x_start += _thd.offs.x;
2156 y_size += _thd.outersize.y;
2157 y_start += _thd.offs.y;
2163 assert(x_size >= 0);
2164 assert(y_size >= 0);
2173 assert((x_end | y_end | x_start | y_start) %
TILE_SIZE == 0);
2194 int top_y = y_start;
2215 static const int OVERLAY_WIDTH = 4 * ZOOM_BASE;
2221 if (top_x != x_start) {
2228 if (bot_y != y_end) {
2233 }
while (bot_x >= top_x);
2236 int a_size = x_size + y_size, b_size = x_size - y_size;
2241 for (
int a = -interval_a; a != a_size + interval_a; a += interval_a) {
2242 for (
int b = -interval_b; b != b_size + interval_b; b += interval_b) {
2243 uint x = (_thd.pos.x + (a + b) / 2) /
TILE_SIZE;
2244 uint y = (_thd.pos.y + (a - b) / 2) /
TILE_SIZE;
2255void SetSelectionRed(
bool b)
2257 _thd.make_square_red = b;
2275 return y >= sign->
top && y < sign->
top + sign_height &&
2276 x >= sign->
center - sign_half_width && x < sign->
center + sign_half_width;
2289 if (_game_mode == GM_MENU)
return false;
2294 Rect search_rect{ x - 1, y - 1, x + 1, y + 1 };
2295 search_rect = ExpandRectWithViewportSignMargins(search_rect, vp.
zoom);
2305 Town *t =
nullptr, *last_t =
nullptr;
2306 Sign *si =
nullptr, *last_si =
nullptr;
2309 _viewport_sign_kdtree.FindContained(search_rect.left, search_rect.top, search_rect.right, search_rect.bottom, [&](
const ViewportSignKdtreeItem & item) {
2310 switch (item.type) {
2311 case ViewportSignKdtreeItem::VKI_STATION: {
2312 if (!show_stations) break;
2313 st = BaseStation::Get(std::get<StationID>(item.id));
2314 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
2316 StationFacilities facilities = st->facilities;
2317 if (facilities.None()) facilities = STATION_FACILITY_GHOST;
2318 if (!facilities.Any(_facility_display_opt)) break;
2320 if (CheckClickOnViewportSign(vp, x, y, &st->sign)) last_st = st;
2324 case ViewportSignKdtreeItem::VKI_WAYPOINT:
2325 if (!show_waypoints) break;
2326 st = BaseStation::Get(std::get<StationID>(item.id));
2327 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
2328 if (CheckClickOnViewportSign(vp, x, y, &st->sign)) last_st = st;
2331 case ViewportSignKdtreeItem::VKI_TOWN:
2332 if (!show_towns) break;
2333 t = Town::Get(std::get<TownID>(item.id));
2334 if (CheckClickOnViewportSign(vp, x, y, &t->cache.sign)) last_t = t;
2337 case ViewportSignKdtreeItem::VKI_SIGN:
2338 if (!show_signs) break;
2339 si = Sign::Get(std::get<SignID>(item.id));
2340 if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break;
2341 if (CheckClickOnViewportSign(vp, x, y, &si->sign)) last_si = si;
2350 if (last_st !=
nullptr) {
2357 }
else if (last_t !=
nullptr) {
2358 ShowTownViewWindow(last_t->index);
2360 }
else if (last_si !=
nullptr) {
2371 ViewportSignKdtreeItem item;
2372 item.type = VKI_STATION;
2388 ViewportSignKdtreeItem item;
2389 item.type = VKI_WAYPOINT;
2405 ViewportSignKdtreeItem item;
2406 item.type = VKI_TOWN;
2422 ViewportSignKdtreeItem item;
2423 item.type = VKI_SIGN;
2428 item.center = sign->sign.
center;
2429 item.top = sign->sign.
top;
2432 _viewport_sign_maxwidth = std::max<int>({_viewport_sign_maxwidth, sign->sign.
width_normal, sign->sign.
width_small});
2437void RebuildViewportKdtree()
2440 _viewport_sign_maxwidth = 0;
2442 std::vector<ViewportSignKdtreeItem> items;
2446 if (st->
sign.
kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeStation(st->index));
2450 if (wp->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
2458 if (sign->sign.
kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeSign(sign->index));
2461 _viewport_sign_kdtree.Build(items.begin(), items.end());
2465static bool CheckClickOnLandscape(
const Viewport &vp,
int x,
int y)
2473static void PlaceObject()
2478 pt = GetTileBelowCursor();
2479 if (pt.
x == -1)
return;
2489 w = _thd.GetCallbackWnd();
2494bool HandleViewportClicked(
const Viewport &vp,
int x,
int y)
2509 bool result = CheckClickOnLandscape(vp, x, y);
2512 Debug(misc, 2,
"Vehicle {} (index {}) at {}", v->
unitnumber, v->index, fmt::ptr(v));
2526void RebuildViewportOverlay(
Window *w)
2528 if (w->
viewport->overlay !=
nullptr &&
2529 w->
viewport->overlay->GetCompanyMask().Any() &&
2530 w->
viewport->overlay->GetCargoMask() != 0) {
2560 if (w->
viewport->dest_scrollpos_x == pt.
x && w->
viewport->dest_scrollpos_y == pt.
y)
return false;
2565 RebuildViewportOverlay(w);
2622 _thd.new_outersize.x = 0;
2623 _thd.new_outersize.y = 0;
2626void SetTileSelectBigSize(
int ox,
int oy,
int sx,
int sy)
2683 if (_thd.freeze)
return;
2686 bool new_diagonal =
false;
2697 if (_thd.IsDraggingDiagonal()) {
2698 new_diagonal =
true;
2700 if (x1 >= x2) std::swap(x1, x2);
2701 if (y1 >= y2) std::swap(y1, y2);
2703 _thd.new_pos.x = x1;
2704 _thd.new_pos.y = y1;
2705 _thd.new_size.x = x2 - x1;
2706 _thd.new_size.y = y2 - y1;
2707 if (!new_diagonal) {
2711 new_drawstyle = _thd.next_drawstyle;
2714 Point pt = GetTileBelowCursor();
2746 default: NOT_REACHED();
2760 if (_thd.drawstyle != new_drawstyle ||
2761 _thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
2762 _thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y ||
2763 _thd.outersize.x != _thd.new_outersize.x ||
2764 _thd.outersize.y != _thd.new_outersize.y ||
2765 _thd.diagonal != new_diagonal) {
2769 _thd.drawstyle = new_drawstyle;
2770 _thd.pos = _thd.new_pos;
2771 _thd.size = _thd.new_size;
2772 _thd.outersize = _thd.new_outersize;
2773 _thd.diagonal = new_diagonal;
2788 GuiShowTooltips(_thd.GetCallbackWnd(), std::move(text), TCC_EXIT_VIEWPORT);
2791static void HideMeasurementTooltips()
2799 _thd.select_method = method;
2800 _thd.select_proc = process;
2819 _thd.next_drawstyle =
HT_RECT | others;
2822 _thd.next_drawstyle = _thd.drawstyle | others;
2825 _thd.next_drawstyle =
HT_POINT | others;
2837 _thd.select_proc = process;
2838 _thd.selstart.x = 0;
2839 _thd.selstart.y = 0;
2840 _thd.next_drawstyle =
HT_RECT;
2845void VpSetPlaceSizingLimit(
int limit)
2847 _thd.sizelimit = limit;
2863 _thd.next_drawstyle =
HT_RECT;
2869 HideMeasurementTooltips();
2873static void VpStartPreSizing()
2888 int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
2890 int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
2893 switch (direction) {
2894 default: NOT_REACHED();
2896 if (fxpy >= 20 && sxpy <= 12)
return HT_DIR_HL;
2897 if (fxmy < -3 && sxmy > 3)
return HT_DIR_VR;
2901 if (fxmy > 3 && sxmy < -3)
return HT_DIR_VL;
2902 if (fxpy <= 12 && sxpy >= 20)
return HT_DIR_HU;
2906 if (fxmy > 3 && sxmy < -3)
return HT_DIR_VL;
2907 if (fxpy >= 20 && sxpy <= 12)
return HT_DIR_HL;
2911 if (fxmy < -3 && sxmy > 3)
return HT_DIR_VR;
2912 if (fxpy <= 12 && sxpy >= 20)
return HT_DIR_HU;
2932 uint start_x =
TileX(start_tile);
2933 uint start_y =
TileY(start_tile);
2934 uint end_x =
TileX(end_tile);
2935 uint end_y =
TileY(end_tile);
2939 case HT_LINE:
return (end_x > start_x || (end_x == start_x && end_y > start_y));
2942 case HT_POINT:
return (end_x != start_x && end_y < start_y);
2943 default: NOT_REACHED();
2969 if (start_tile == end_tile)
return 0;
2970 if (swap) std::swap(start_tile, end_tile);
2994 static const std::pair<TileIndexDiffC, TileIndexDiffC> start_heightdiff_line_by_dir[] = {
3002 static const std::pair<TileIndexDiffC, TileIndexDiffC> end_heightdiff_line_by_dir[] = {
3010 static_assert(std::size(start_heightdiff_line_by_dir) ==
HT_DIR_END);
3011 static_assert(std::size(end_heightdiff_line_by_dir) ==
HT_DIR_END);
3021 if (swap && distance == 0) style = flip_style_direction[style];
3024 auto get_height = [](
auto &tile,
auto &heightdiffs) {
3031 h0 = get_height(start_tile, start_heightdiff_line_by_dir[style]);
3035 if (distance == 0) style = flip_style_direction[style];
3036 h1 = get_height(end_tile, end_heightdiff_line_by_dir[style]);
3041 if (swap) std::swap(h0, h1);
3053 if (test >= 0)
return;
3055 other += mult * test;
3068 if (test <= max)
return;
3070 other += mult * (test - max);
3087 int raw_dx = _thd.selstart.x - _thd.selend.x;
3088 int raw_dy = _thd.selstart.y - _thd.selend.y;
3092 x = _thd.selstart.x;
3097 y = _thd.selstart.y;
3113 int offset = (raw_dx - raw_dy) / 2;
3148 int offset = (raw_dx + raw_dy + (int)
TILE_SIZE) / 2;
3187 y = _thd.selstart.y;
3196 x = _thd.selstart.x;
3197 }
else if (w > h * 2) {
3199 y = _thd.selstart.y;
3200 }
else if (h > w * 2) {
3202 x = _thd.selstart.x;
3209 if (x > _thd.selstart.x) {
3210 if (y > _thd.selstart.y) {
3214 }
else if (d >= 0) {
3215 x = _thd.selstart.x + h;
3218 y = _thd.selstart.y + w;
3225 }
else if (d >= 0) {
3226 x = _thd.selstart.x + h;
3229 y = _thd.selstart.y - w;
3234 if (y > _thd.selstart.y) {
3238 }
else if (d >= 0) {
3239 x = _thd.selstart.x - h;
3242 y = _thd.selstart.y + w;
3249 }
else if (d >= 0) {
3250 x = _thd.selstart.x - h;
3253 y = _thd.selstart.y - w;
3265 if (distance == 1) {
3266 HideMeasurementTooltips();
3273 distance =
CeilDiv(distance, 2);
3276 if (heightdiff == 0) {
3286 _thd.next_drawstyle = b;
3320 sx = _thd.selstart.x;
3321 sy = _thd.selstart.y;
3327 if (
abs(sy - y) <
abs(sx - x)) {
3334 goto calc_heightdiff_single_direction;
3337 limit = (_thd.sizelimit - 1) *
TILE_SIZE;
3343 goto calc_heightdiff_single_direction;
3346 limit = (_thd.sizelimit - 1) *
TILE_SIZE;
3353calc_heightdiff_single_direction:;
3355 x = sx +
Clamp(x - sx, -limit, limit);
3356 y = sy +
Clamp(y - sy, -limit, limit);
3363 if (distance == 1) {
3364 HideMeasurementTooltips();
3373 if (heightdiff == 0) {
3383 limit = (_thd.sizelimit - 1) *
TILE_SIZE;
3384 x = sx +
Clamp(x - sx, -limit, limit);
3385 y = sy +
Clamp(y - sy, -limit, limit);
3398 if (_thd.IsDraggingDiagonal()) {
3411 int a_max = dist_x + dist_y;
3412 int b_max = dist_y - dist_x;
3416 a_max =
abs(a_max + (a_max > 0 ? 2 : -2)) / 2;
3417 b_max =
abs(b_max + (b_max > 0 ? 2 : -2)) / 2;
3423 if (a_max != 1 || b_max != 1) {
3430 }
else if (dy == 1) {
3435 if (dx != 1 || dy != 1) {
3441 if (heightdiff == 0) {
3450 default: NOT_REACHED();
3466 Window *w = _thd.GetCallbackWnd();
3476 if (_thd.new_pos.x == _thd.selstart.x && _thd.new_pos.y == _thd.selstart.y)
return ES_HANDLED;
3477 _thd.selstart.x = _thd.new_pos.x;
3478 _thd.selstart.y = _thd.new_pos.y;
3481 w->
OnPlaceDrag(_thd.select_method, _thd.select_proc, GetTileBelowCursor());
3492 _thd.place_mode =
HT_RECT | others;
3494 _thd.place_mode =
HT_RECT | others;
3496 _thd.place_mode = (_thd.select_method &
~VPM_RAILDIRS) ? _thd.next_drawstyle : (
HT_RAIL | others);
3498 _thd.place_mode =
HT_POINT | others;
3502 HideMeasurementTooltips();
3534 Window *w = _thd.GetCallbackWnd();
3543 HideMeasurementTooltips();
3552 _thd.make_square_red =
false;
3561 _thd.place_mode = mode;
3562 _thd.window_class = window_class;
3563 _thd.window_number = window_num;
3599 { &ViewportSortParentSpritesSSE41Checker, &ViewportSortParentSpritesSSE41 },
3608 if (sprite_sorter.fct_checker()) {
3609 _vp_sprite_sorter = sprite_sorter.fct_sorter;
3613 assert(_vp_sprite_sorter !=
nullptr);
3647void MarkCatchmentTilesDirty()
3688static void SetWindowDirtyForViewportCatchment()
3697static void ClearViewportCatchment()
3699 MarkCatchmentTilesDirty();
3715 SetWindowDirtyForViewportCatchment();
3718 ClearViewportCatchment();
3720 MarkCatchmentTilesDirty();
3723 MarkCatchmentTilesDirty();
3738 SetWindowDirtyForViewportCatchment();
3741 ClearViewportCatchment();
3743 MarkCatchmentTilesDirty();
3746 MarkCatchmentTilesDirty();
3761 SetWindowDirtyForViewportCatchment();
3764 ClearViewportCatchment();
3766 MarkCatchmentTilesDirty();
3769 MarkCatchmentTilesDirty();
3784 SetWindowDirtyForViewportCatchment();
3787 ClearViewportCatchment();
3789 MarkCatchmentTilesDirty();
3792 MarkCatchmentTilesDirty();
3807 SetWindowDirtyForViewportCatchment();
3810 ClearViewportCatchment();
This file defines all the the animated cursors.
Highlight/sprite information for autorail.
static const int _AutorailTilehSprite[][6]
Table maps each of the six rail directions and tileh combinations to a sprite.
static const HighLightStyle _autorail_piece[][16]
Maps each pixel of a tile (16x16) to a selection type (0,0) is the top corner, (16,...
Class for backupping variables and making sure they are restored later.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Map accessor functions for bridges.
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
virtual void SetPixel(void *video, int x, int y, PixelColour colour)=0
Draw a pixel with a given colour on the video-buffer.
Common return value for all commands.
Container for an encoded string, created by GetEncodedString.
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Execute
execute the given command
Definition of stuff that is very close to a company, like the company struct itself.
TypedIndexContainer< std::array< Colours, MAX_COMPANIES >, CompanyID > _company_colours
NOSAVE: can be determined from company structs.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
static constexpr Owner OWNER_NONE
The tile has no ownership.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Factory to 'query' all available blitters.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Types for recording game performance data.
@ PFE_DRAWWORLD
Time spent drawing world viewports in GUI.
bool _left_button_down
Is left mouse button pressed?
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
void SetCursor(CursorID icon, PaletteID pal)
Assign an animation or a non-animated sprite to the cursor.
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
Draw a sprite in a viewport.
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
Draws the projection of a parallelepiped.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ Normal
The most basic (normal) sprite.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
uint32_t CursorID
The number of the cursor (sprite).
@ SA_HOR_CENTER
Horizontally center the text.
uint32_t PaletteID
The number of the palette.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
bool MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
void MarkDirty(ZoomLevel maxzoom=ZoomLevel::Max) const
Mark the sign dirty in all viewports.
static bool MarkViewportDirty(const Viewport &vp, int left, int top, int right, int bottom)
Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void RedrawScreenRect(int left, int top, int right, int bottom)
Repaints a specific rectangle of the screen.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static void SetSelectionTilesDirty()
Marks the selected tiles as dirty.
const EnumClassIndexContainer< std::array< const TileTypeProcs *, to_underlying(TileType::MaxSize)>, TileType > _tile_type_procs
Tile callback functions for each type of tile.
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Functions related to OTTD's landscape.
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Declaration of linkgraph overlay GUI.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
ClientID _network_own_client_id
Our client identifier.
Network functions used by other parts of OpenTTD.
ClientID
'Unique' identifier to be given to clients
@ DO_SHOW_TOWN_NAMES
Display town names.
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
@ DO_SHOW_SIGNS
Display signs.
@ DO_SHOW_WAYPOINT_NAMES
Display waypoint names.
@ DO_SHOW_STATION_NAMES
Display station names.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
Functions related to signs.
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
PoolID< uint16_t, struct SignIDTag, 64000, 0xFFFF > SignID
The type of the IDs of signs.
Slope SlopeWithThreeCornersRaised(Corner corner)
Returns the slope with all except one corner raised.
Corner OppositeCorner(Corner corner)
Returns the opposite corner.
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
static constexpr Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
Corner
Enumeration of tile corners.
Slope
Enumeration for the slope-type.
@ SLOPE_N
the north corner of the tile is raised
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
@ Town
Source/destination is a town.
static constexpr uint32_t MAX_SPRITES
Masks needed for sprite operations.
static const PaletteID PALETTE_TILE_RED_PULSATING
pulsating red tile drawn if you try to build a wrong tunnel or raise/lower land where it is not possi...
static const PaletteID PALETTE_SEL_TILE_RED
makes a square red. is used when removing rails or other stuff
static constexpr uint32_t SPRITE_MASK
The mask to for the main sprite.
static constexpr uint8_t PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
static const PaletteID PALETTE_SEL_TILE_BLUE
This draws a blueish square (catchment areas for example).
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Base classes/functions for stations.
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition of base types and functions in a cross-platform compatible way.
The colour translation of GRF's strings.
static constexpr PixelColour _string_colourmap[17]
Colour mapping for TextColour.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Base class for all station-ish types.
TileIndex xy
Base tile of the station.
Owner owner
The owner of this station.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
int next
next child to draw (-1 at the end)
const SubSprite * sub
only draw a rectangular part of the sprite
Data about how and where to blit pixels.
static uint SizeX()
Get the size of the map along the X.
static uint SizeY()
Get the size of the map along the Y.
static uint ScaleBySize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Parent sprite that should be drawn.
const SubSprite * sub
only draw a rectangular part of the sprite
int32_t zmin
minimal world Z coordinate of bounding box
SpriteID image
sprite to draw
int32_t xmax
maximal world X coordinate of bounding box
int32_t ymax
maximal world Y coordinate of bounding box
int32_t x
screen X coordinate of sprite
int32_t y
screen Y coordinate of sprite
int32_t first_child
the first child to draw.
int32_t zmax
maximal world Z coordinate of bounding box
int32_t xmin
minimal world X coordinate of bounding box
int32_t ymin
minimal world Y coordinate of bounding box
PaletteID pal
palette to use
int32_t left
minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
int32_t top
minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
Colour for pixel/line drawing.
static Pool::IterateWrapper< Town > Iterate(size_t from=0)
static Vehicle * Get(auto index)
static size_t GetNumItems()
Specification of a rectangle with absolute coordinates of all edges.
static bool IsExpected(const BaseStation *st)
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
static Station * Get(auto index)
static Waypoint * From(BaseStation *st)
Coord3D< int8_t > offset
Relative position of sprite from bounding box.
Coord3D< int8_t > origin
Position of northern corner within tile.
Coord3D< uint8_t > extent
Size of bounding box.
Data structure describing a sprite.
uint16_t width
Width of the sprite.
uint16_t height
Height of the sprite.
int16_t y_offs
Number of pixels to shift the sprite downwards.
int16_t x_offs
Number of pixels to shift the sprite to the right.
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
bool PtInExtendedRect(int x, int y, int distance=0) const
Determines whether a given point (x, y) is within a certain distance of the station rectangle.
Used to only draw a part of the sprite.
Metadata about the current highlighting.
Point new_pos
New value for pos; used to determine whether to redraw the selection.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
bool IsDraggingDiagonal()
Is the user dragging a 'diagonal rectangle'?
HighLightStyle place_mode
Method which is used to place the selection.
WindowClass window_class
The WindowClass of the window that is responsible for the selection mode.
Point pos
Location, in tile "units", of the northern tile of the selected area.
void Reset()
Reset tile highlighting.
WindowNumber window_number
The WindowNumber of the window that is responsible for the selection mode.
Tile information, used while rendering the tile.
Slope tileh
Slope of the tile.
TileIndex tile
Tile index.
int32_t y
screen Y coordinate of sprite
int32_t x
screen X coordinate of sprite
const SubSprite * sub
only draw a rectangular part of the sprite
TrackedViewportSign sign
Location of name sign, UpdateVirtCoord updates this.
TileIndex xy
town center tile
TownCache cache
Container for all cacheable data.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
int32_t z_pos
z coordinate.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
Owner owner
Which company owns the vehicle?
UnitID unitnumber
unit number, for display purposes only
Data structure for a window viewport.
void CancelFollow(const Window &viewport_window)
Cancel viewport vehicle following, and raise follow location widget if needed.
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, VehicleID::Invalid() otherwise.
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Data structure storing rendering information.
int foundation[FOUNDATION_PART_END]
Foundation sprites (index into parent_sprites_to_draw).
int last_foundation_child[FOUNDATION_PART_END]
Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw).
ParentSpriteToSortVector parent_sprites_to_sort
Parent sprite pointer array used for sorting.
Point foundation_offset[FOUNDATION_PART_END]
Pixel offset for ground sprites on the foundations.
SpriteCombineMode combine_sprites
Current mode of "sprite combining".
FoundationPart foundation_part
Currently active foundation for ground sprite drawing.
Helper class for getting the best sprite sorter.
VpSorterChecker fct_checker
The check function.
VpSpriteSorter fct_sorter
The sorting function.
Location information about a sign as seen on the viewport.
int32_t center
The center position of the sign.
uint16_t width_small
The width when zoomed out (small font).
uint16_t width_normal
The width when not zoomed out (normal font).
void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small={})
Update the position of the viewport sign.
int32_t top
The top of the sign.
Data structure for viewport, display of a part of the world.
int top
Screen coordinate top edge of the viewport.
int width
Screen width of the viewport.
ZoomLevel zoom
The zoom level of the viewport.
int virtual_top
Virtual top coordinate.
int virtual_left
Virtual left coordinate.
int virtual_width
width << zoom
int left
Screen coordinate left edge of the viewport.
int height
Screen height of the viewport.
int virtual_height
height << zoom
Representation of a waypoint.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
WindowClass window_class
Window class.
void DrawViewport() const
Draw the viewport of this window.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
WindowIterator< false > IteratorToFront
Iterate in Z order towards front.
int left
x position of left edge of the window
int top
y position of top edge of the window
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
The user is dragging over the map when the tile highlight mode has been set.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
int height
Height of the window (number of pixels down in y direction).
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
std::tuple< Slope, int > GetTilePixelSlopeOutsideMap(int x, int y)
Return the slope of a given tile, also for tiles outside the map (virtual "black" tiles).
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static uint TileHeight(Tile tile)
Returns the height of a tile.
int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
uint TilePixelHeight(Tile tile)
Returns the height of a tile in pixels.
uint TilePixelHeightOutsideMap(int x, int y)
Returns the height of a tile in pixels, also for tiles outside the map (virtual "black" tiles).
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
uint TileHeightOutsideMap(int x, int y)
Returns the height of a tile, also for tiles outside the map (virtual "black" tiles).
static constexpr uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
static constexpr uint MAX_BUILDING_PIXELS
Maximum height of a building in pixels in ZOOM_BASE. (Also applies to "bridge buildings" on the bridg...
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static constexpr uint TILE_SIZE
Tile size in world coordinates.
static constexpr uint TILE_PIXELS
Pixel distance between tile columns/rows in ZOOM_BASE.
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
TileType
The different types of tiles.
@ Station
A tile of a station or airport.
@ Void
Invisible tiles at the SW and SE border.
@ House
A house by a town.
Functions related to tile highlights.
HighLightStyle
Highlighting draw styles.
@ HT_LINE
used for autorail highlighting (longer stretches), lower bits: direction
@ HT_DIR_HL
horizontal lower
@ HT_DIR_HU
horizontal upper
@ HT_DRAG
dragging items in the depot windows
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_POINT
point (lower land, raise land, level land, ...)
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_DIR_MASK
masks the drag-direction
@ HT_RAIL
autorail (one piece), lower bits: direction
@ HT_DRAG_MASK
Mask for the tile drag-type modes.
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
@ HT_DIR_VR
vertical right
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Declarations for accessing the k-d tree of towns.
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
uint8_t _display_opt
What do we want to draw/do?
bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
void ViewportAddVehicles(DrawPixelInfo *dpi)
Add the vehicle sprites that should be drawn at a part of the screen.
Vehicle * CheckClickOnVehicle(const Viewport &vp, int x, int y)
Find the vehicle close to the clicked coordinates.
Base class for all vehicles.
Functions related to vehicles.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
void StartStopVehicle(const Vehicle *v, bool texteffect)
Executes Commands::StartStopVehicle for given vehicle.
Functions related to the vehicle's GUIs.
static void HighlightTownLocalAuthorityTiles(const TileInfo *ti)
Highlights tiles inside local authority of selected towns.
std::string * ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sign, ViewportStringFlags flags, Colours colour)
Add a string to draw in the current viewport.
static void CheckOverflow(int &test, int &other, int max, int mult)
Check for overflowing the map.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
FoundationPart
Enumeration of multi-part foundations.
@ FOUNDATION_PART_NONE
Neither foundation nor groundsprite drawn yet.
@ FOUNDATION_PART_HALFTILE
Second part (halftile foundation).
@ FOUNDATION_PART_NORMAL
First part (normal foundation or no foundation).
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
CommandCost CmdScrollViewport(DoCommandFlags flags, TileIndex tile, ViewportScrollTarget target, uint32_t ref)
Scroll players main viewport.
static void ViewportAddStationStrings(DrawPixelInfo *dpi, const std::vector< const BaseStation * > &stations, bool small)
Add station strings to a viewport.
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
constexpr int LAST_CHILD_NONE
There is no last_child to fill.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
static void ViewportAddSignStrings(DrawPixelInfo *dpi, const std::vector< const Sign * > &signs, bool small)
Add sign strings to a viewport.
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
constexpr int LAST_CHILD_PARENT
Fill last_child of the most recent parent sprite.
static const int MAX_TILE_EXTENT_TOP
Maximum top extent of tile relative to north corner (not considering bridges).
void SetViewportStationRect(const Station *st, bool sel)
Select or deselect station for rectangle area highlight.
static void ShowMeasurementTooltips(EncodedString &&text)
Displays the measurement tooltips when selecting multiple tiles.
static const int MAX_TILE_EXTENT_LEFT
Maximum left extent of tile relative to north corner.
bool IsInsideRotatedRectangle(int x, int y)
Checks whether a point is inside the selected a diagonal rectangle given by _thd.size and _thd....
static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile)
Calculates height difference between one tile and another.
static void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal)
Draws a selection rectangle on a tile.
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
void InitializeSpriteSorter()
Choose the "best" sprite sorter and set _vp_sprite_sorter.
static const ViewportSSCSS _vp_sprite_sorters[]
List of sorters ordered from best to worst.
static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z, const SubSprite *sub)
Adds a child sprite to a parent sprite.
static int GetViewportY(Point tile)
Returns the y coordinate in the viewport coordinate system where the given tile is painted.
static void AddChildSpriteToFoundation(SpriteID image, PaletteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y)
Adds a child sprite to the active foundation.
static HighLightStyle GetAutorailHT(int x, int y)
returns the best autorail highlight type from map coordinates
static void ClampSmoothScroll(uint32_t delta_ms, int64_t delta_hi, int64_t delta_lo, int &delta_hi_clamped, int &delta_lo_clamped)
Clamp the smooth scroll to a maxmimum speed and distance based on time elapsed.
static void DrawTileSelection(const TileInfo *ti)
Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
static TileHighlightType GetTileHighlightType(TileIndex t)
Get tile highlight type of coverage area for a given tile.
static bool IsInRangeInclusive(int begin, int end, int check)
Check if the parameter "check" is inside the interval between begin and end, including both begin and...
const Waypoint * _viewport_highlight_waypoint_rect
Currently selected waypoint for rectangle highlight.
Point TranslateXYToTileCoord(const Viewport &vp, int x, int y, bool clamp_to_map)
Translate screen coordinate in a viewport to underlying tile coordinate.
static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type)
Draws autorail highlights.
SpriteCombineMode
Mode of "sprite combining".
@ SPRITE_COMBINE_PENDING
Sprite combining will start with the next unclipped sprite.
@ SPRITE_COMBINE_ACTIVE
Sprite combining is active. AddSortableSpriteToDraw outputs child sprites.
@ SPRITE_COMBINE_NONE
Every AddSortableSpriteToDraw start its own bounding box.
static void DrawTileHighlightType(const TileInfo *ti, TileHighlightType tht)
Draw tile highlight for coverage area highlight.
static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd)
Draws the bounding boxes of all ParentSprites.
static void ViewportAddTownStrings(DrawPixelInfo *dpi, const std::vector< const Town * > &towns, bool small)
Add town strings to a viewport.
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
Sort parent sprites pointer array replicating the way original sorter did it.
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
static HighLightStyle Check2x1AutoRail(DiagDirection direction)
What would be the highlight style when trying to build a 2 tile long piece of rail.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
EventState VpHandlePlaceSizingDrag()
Handle the mouse while dragging for placement/resizing.
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
static const int MAX_TILE_EXTENT_RIGHT
Maximum right extent of tile relative to north corner.
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale, bool relative)
Add a child sprite to a parent sprite.
static void CheckUnderflow(int &test, int &other, int mult)
Check for underflowing the map.
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32_t x, int32_t y, int z, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite at a specific world-coordinate relative to the current tile.
void VpStartDragging(ViewportDragDropSelectionProcess process)
Drag over the map while holding the left mouse down.
void UpdateTileSelection()
Updates tile highlighting for all cases.
static void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part, int extra_offs_x=0, int extra_offs_y=0)
Draws sprites between ground sprite and everything above.
static const int MAX_TILE_EXTENT_BOTTOM
Maximum bottom extent of tile relative to north corner (worst case: SLOPE_STEEP_N).
static bool CheckClickOnViewportSign(const Viewport &vp, int x, int y, const ViewportSign *sign)
Test whether a sign is below the mouse.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile)
Check if the direction of start and end tile should be swapped based on the dragging-style.
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize viewport of the window for use.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
static void CalcRaildirsDrawstyle(int x, int y, int method)
while dragging
void SetViewportWaypointRect(const Waypoint *wp, bool sel)
Select or deselect waypoint for rectangle area highlight.
static void ViewportDrawDirtyBlocks()
Draw/colour the blocks that have been redrawn.
void HandleZoomMessage(Window *w, const Viewport &vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out)
Update the status of the zoom-buttons according to the zoom-level of the viewport.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
const Station * _viewport_highlight_station_rect
Currently selected station for rectangle highlight.
static void ClampViewportToMap(const Viewport &vp, int *scroll_x, int *scroll_y)
Ensure that a given viewport has a valid scroll position.
static void AddTileSpriteToDraw(SpriteID image, PaletteID pal, int32_t x, int32_t y, int z, const SubSprite *sub=nullptr, int extra_offs_x=0, int extra_offs_y=0)
Schedules a tile sprite for drawing.
static void ViewportAddLandscape()
Add the landscape to the viewport, i.e.
static std::string & AddStringToDraw(int x, int y, Colours colour, ViewportStringFlags flags, uint16_t width)
Add a string to draw to a viewport.
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
const Waypoint * _viewport_highlight_waypoint
Currently selected waypoint for coverage area highlight.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Command definitions related to viewports.
Functions related to (drawing on) viewports.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Declarations for accessing the k-d tree of viewports.
Types related to sprite sorting.
bool(* VpSorterChecker)()
Type for method for checking whether a viewport sprite sorter exists.
void(* VpSpriteSorter)(ParentSpriteToSortVector *psd)
Type for the actual viewport sprite sorter.
ViewportScrollTarget
Target of the viewport scrolling GS method.
@ VST_EVERYONE
All players.
@ VST_COMPANY
All players in specific company.
@ VST_CLIENT
Single player.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects).
@ VPM_FIX_Y
drag only in Y axis
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
@ VPM_X_AND_Y_LIMITED
area of land of limited size
@ VPM_FIX_VERTICAL
drag only in vertical direction
@ VPM_X_LIMITED
Drag only in X axis with limited size.
@ VPM_X_AND_Y
area of land in X and Y directions
@ VPM_FIX_HORIZONTAL
drag only in horizontal direction
@ VPM_FIX_X
drag only in X axis
@ VPM_SIGNALDIRS
similar to VMP_RAILDIRS, but with different cursor
@ VPM_X_OR_Y
drag in X or Y direction
@ VPM_RAILDIRS
all rail directions
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_OUT
Zoom out (get helicopter view).
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ ColourRect
Draw a colour rect around the sign.
@ Small
Draw using the small font.
@ Shadow
Draw an extra text shadow. Should only be used with ViewportStringFlag::Small, as normal font already...
@ TransparentRect
Draw a transparent rect around the sign.
@ TextColour
Draw text in colour.
Functions related to waypoints.
void ShowWaypointWindow(const Waypoint *wp)
Show the window for the given waypoint.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window * GetMainWindow()
Get the main window, i.e.
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Transparent
Makes the background transparent if set.
@ WSM_DRAGDROP
Drag&drop an object.
@ WSM_DRAGGING
Dragging mode (trees).
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
@ WSM_NONE
No special mouse mode.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_INVALID
Invalid window.
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
@ WC_STATION_VIEW
Station view; Window numbers:
@ WC_MAIN_WINDOW
Main window; Window numbers:
@ WC_TOWN_VIEW
Town view; Window numbers:
@ WC_TOOLTIPS
Tooltip window; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ Waypoint
waypoint encountered (could be a target next time)
@ Station
station encountered (could be a target next time)
Functions related to zooming.
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZoomLevel::Min) When shifting right,...
int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZoomLevel::Min).
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZoomLevel::Min) When shifting right,...
ZoomLevel
All zoom levels we know.
@ Begin
Begin for iteration.
@ Out4x
Zoomed 4 times out.