|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
84 #include "viewport_kdtree.h"
94 #include <forward_list>
97 #include "table/strings.h"
102 Point _tile_fract_coords;
106 static int _viewport_sign_maxwidth = 0;
159 typedef std::vector<TileSpriteToDraw> TileSpriteToDrawVector;
160 typedef std::vector<StringSpriteToDraw> StringSpriteToDrawVector;
161 typedef std::vector<ParentSpriteToDraw> ParentSpriteToDrawVector;
162 typedef std::vector<ChildScreenSpriteToDraw> ChildScreenSpriteToDrawVector;
168 StringSpriteToDrawVector string_sprites_to_draw;
169 TileSpriteToDrawVector tile_sprites_to_draw;
170 ParentSpriteToDrawVector parent_sprites_to_draw;
172 ChildScreenSpriteToDrawVector child_screen_sprites_to_draw;
190 bool _draw_bounding_boxes =
false;
191 bool _draw_dirty_blocks =
false;
192 uint _dirty_block_colour = 0;
195 static Point MapXYZToViewport(
const Viewport *vp,
int x,
int y,
int z)
203 void DeleteWindowViewport(
Window *w)
220 int width,
int height, std::variant<TileIndex, VehicleID> focus,
ZoomLevel zoom)
238 if (std::holds_alternative<VehicleID>(focus)) {
245 TileIndex tile = std::get<TileIndex>(focus);
268 vp->overlay =
nullptr;
275 static 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);
343 static 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);
435 Point pt = { -1, -1 };
447 static Point GetTileFromScreenXY(
int x,
int y,
int zoom_x,
int zoom_y)
461 Point GetTileBelowCursor()
463 return GetTileFromScreenXY(_cursor.
pos.x, _cursor.
pos.y, _cursor.
pos.x, _cursor.
pos.y);
473 x = ((_cursor.
pos.x - vp->
left) >> 1) + (vp->
width >> 2);
474 y = ((_cursor.
pos.y - vp->
top) >> 1) + (vp->
height >> 2);
480 return GetTileFromScreenXY(_cursor.
pos.x, _cursor.
pos.y, x + vp->
left, y + vp->
top);
521 ts.
x = pt.x + extra_offs_x;
522 ts.
y = pt.y + extra_offs_y;
539 assert(
IsInsideMM(foundation_part, 0, FOUNDATION_PART_END));
540 assert(_vd.
foundation[foundation_part] != -1);
544 int *old_child = _vd.last_child;
547 AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y,
false, sub,
false,
false);
550 _vd.last_child = old_child;
575 AddTileSpriteToDraw(image, pal, _cur_ti.
x + x, _cur_ti.
y + y, _cur_ti.
z + z, sub, extra_offs_x * ZOOM_LVL_BASE, extra_offs_y * ZOOM_LVL_BASE);
611 default: NOT_REACHED();
638 if (pt.x + spr->
x_offs >= _vd.dpi.left + _vd.dpi.width ||
640 pt.y + spr->
y_offs >= _vd.dpi.top + _vd.dpi.height ||
673 void AddSortableSpriteToDraw(
SpriteID image,
PaletteID pal,
int x,
int y,
int w,
int h,
int dz,
int z,
bool transparent,
int bb_offset_x,
int bb_offset_y,
int bb_offset_z,
const SubSprite *sub)
675 int32_t left, right, top, bottom;
690 _vd.last_child =
nullptr;
693 int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y;
696 if (image == SPR_EMPTY_BOUNDING_BOX) {
697 left = tmp_left =
RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x;
698 right =
RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1;
699 top = tmp_top =
RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y;
700 bottom =
RemapCoords(x + w , y + h , z + bb_offset_z).y + 1;
703 left = tmp_left = (pt.x += spr->
x_offs);
704 right = (pt.x + spr->
width );
705 top = tmp_top = (pt.y += spr->
y_offs);
706 bottom = (pt.y + spr->
height);
709 if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
711 left = std::min(left ,
RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x);
712 right = std::max(right ,
RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1);
713 top = std::min(top ,
RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y);
714 bottom = std::max(bottom,
RemapCoords(x + w , y + h , z + bb_offset_z).y + 1);
718 if (left >= _vd.dpi.left + _vd.dpi.width ||
719 right <= _vd.dpi.left ||
720 top >= _vd.dpi.top + _vd.dpi.height ||
721 bottom <= _vd.dpi.top) {
735 ps.
xmin = x + bb_offset_x;
736 ps.
xmax = x + std::max(bb_offset_x, w) - 1;
738 ps.
ymin = y + bb_offset_y;
739 ps.
ymax = y + std::max(bb_offset_y, h) - 1;
741 ps.
zmin = z + bb_offset_z;
742 ps.
zmax = z + std::max(bb_offset_z, dz) - 1;
796 if (begin > end)
Swap(begin, end);
797 return begin <= check && check <= end;
808 int dist_a = (_thd.
size.x + _thd.
size.y);
809 int dist_b = (_thd.
size.x - _thd.
size.y);
810 int a = ((x - _thd.
pos.x) + (y - _thd.
pos.y));
811 int b = ((x - _thd.
pos.x) - (y - _thd.
pos.y));
834 if (_vd.last_child ==
nullptr)
return;
842 *_vd.last_child = (uint)_vd.child_screen_sprites_to_draw.size();
848 cs.x = scale ? x * ZOOM_LVL_BASE : x;
849 cs.y = scale ? y * ZOOM_LVL_BASE : y;
850 cs.relative = relative;
858 _vd.last_child = &cs.
next;
861 static void AddStringToDraw(
int x,
int y,
StringID string, Colours colour, uint16_t width)
866 ss.string_id = string;
912 SpriteID sel2 = SPR_HALFTILE_SELECTION_FLAT + halftile_corner;
917 sel = SPR_HALFTILE_SELECTION_DOWN;
921 sel += opposite_corner;
928 static bool IsPartOfAutoLine(
int px,
int py)
938 case HT_DIR_HU:
return px == -py || px == -py - 16;
939 case HT_DIR_HL:
return px == -py || px == -py + 16;
940 case HT_DIR_VL:
return px == py || px == py + 16;
941 case HT_DIR_VR:
return px == py || px == py - 16;
974 static const uint _lower_rail[4] = { 5U, 2U, 4U, 3U };
976 if (autorail_type != _lower_rail[halftile_corner]) {
983 offset = _AutorailTilehSprite[autorail_tileh][autorail_type];
985 image = SPR_AUTORAIL_BASE + offset;
988 image = SPR_AUTORAIL_BASE - offset;
995 enum TileHighlightType {
1024 TileHighlightType type = THT_RED;
1027 if (st->TileIsInCatchment(t))
return THT_BLUE;
1051 case THT_NONE:
break;
1066 if (_town_local_authority_kdtree.
Count() == 0)
return;
1132 if ((halftile_corner == CORNER_W) || (halftile_corner == CORNER_E)) z +=
TILE_HEIGHT;
1133 if (halftile_corner != CORNER_S) {
1144 }
else if (IsPartOfAutoLine(ti->
x, ti->
y)) {
1162 if (!is_redsq && (tht == THT_NONE || tht == THT_RED) && _thd.
outersize.x > 0 &&
1188 assert(_vd.dpi.top <= _vd.dpi.top + _vd.dpi.height);
1189 assert(_vd.dpi.left <= _vd.dpi.left + _vd.dpi.width);
1207 int left_column = (upper_left.y - upper_left.x) / (
int)
TILE_SIZE - 2;
1208 int right_column = (upper_right.y - upper_right.x) / (
int)
TILE_SIZE + 2;
1216 int row = (upper_left.x + upper_left.y) / (
int)
TILE_SIZE - 2;
1217 bool last_row =
false;
1218 for (; !last_row; row++) {
1220 for (
int column = left_column; column <= right_column; column++) {
1222 if ((row + column) % 2 != 0)
continue;
1225 tilecoord.x = (row - column) / 2;
1226 tilecoord.y = (row + column) / 2;
1227 assert(column == tilecoord.y - tilecoord.x);
1228 assert(row == tilecoord.y + tilecoord.x);
1236 _cur_ti.
tile =
TileXY(tilecoord.x, tilecoord.y);
1260 int min_visible_height = viewport_y - (_vd.dpi.top + _vd.dpi.height);
1261 bool tile_visible = min_visible_height <= 0;
1280 if ((tilecoord.x <= 0 || tilecoord.y <= 0) && min_visible_height < potential_bridge_height +
MAX_TILE_EXTENT_TOP) last_row =
false;
1310 bool small = dpi->zoom >= small_from;
1312 int left = dpi->left;
1314 int right = left + dpi->width;
1315 int bottom = top + dpi->height;
1320 if (bottom < sign->top ||
1321 top > sign->
top + sign_height ||
1322 right < sign->center - sign_half_width ||
1323 left > sign->
center + sign_half_width) {
1328 AddStringToDraw(sign->
center - sign_half_width, sign->
top, string_normal, colour, sign->
width_normal);
1330 int shadow_offset = 0;
1331 if (string_small_shadow != STR_NULL) {
1333 AddStringToDraw(sign->
center - sign_half_width + shadow_offset, sign->
top, string_small_shadow, INVALID_COLOUR, sign->
width_small | 0x8000);
1335 AddStringToDraw(sign->
center - sign_half_width, sign->
top - shadow_offset, string_small, colour, sign->
width_small | 0x8000);
1343 const int max_tw = _viewport_sign_maxwidth / 2 + 1;
1348 r.right += expand_x;
1350 r.bottom += expand_y;
1357 Rect search_rect{ dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height };
1358 search_rect = ExpandRectWithViewportSignMargins(search_rect, dpi->zoom);
1367 std::vector<const BaseStation *> stations;
1368 std::vector<const Town *> towns;
1369 std::vector<const Sign *> signs;
1372 switch (item.type) {
1373 case ViewportSignKdtreeItem::VKI_STATION: {
1374 if (!show_stations) break;
1375 const BaseStation *st = BaseStation::Get(item.id.station);
1378 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
1380 stations.push_back(st);
1384 case ViewportSignKdtreeItem::VKI_WAYPOINT: {
1385 if (!show_waypoints) break;
1386 const BaseStation *st = BaseStation::Get(item.id.station);
1389 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
1391 stations.push_back(st);
1395 case ViewportSignKdtreeItem::VKI_TOWN:
1396 if (!show_towns) break;
1397 towns.push_back(Town::Get(item.id.town));
1400 case ViewportSignKdtreeItem::VKI_SIGN: {
1401 if (!show_signs) break;
1402 const Sign *si = Sign::Get(item.id.sign);
1407 if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break;
1409 signs.push_back(si);
1420 for (
const auto *t : towns) {
1425 STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK);
1431 for (
const auto *si : signs) {
1439 for (
const auto *st : stations) {
1445 STR_VIEWPORT_STATION, STR_VIEWPORT_STATION_TINY, STR_NULL,
1450 STR_VIEWPORT_WAYPOINT, STR_VIEWPORT_WAYPOINT_TINY, STR_NULL,
1475 if (str_small != STR_NULL) {
1496 zoomlevels[zoom].top = this->top -
ScaleByZoom(1, zoom);
1503 if (vp !=
nullptr && vp->
zoom <= maxzoom) {
1504 assert(vp->
width != 0);
1511 static void ViewportDrawTileSprites(
const TileSpriteToDrawVector *tstdv)
1527 if (psdv->size() < 2)
return;
1536 const uint32_t ORDER_COMPARED = UINT32_MAX;
1537 const uint32_t ORDER_RETURNED = UINT32_MAX - 1;
1538 std::stack<ParentSpriteToDraw *> sprite_order;
1539 uint32_t next_order = 0;
1541 std::forward_list<std::pair<int64_t, ParentSpriteToDraw *>> sprite_list;
1544 for (
auto p = psdv->rbegin(); p != psdv->rend(); p++) {
1545 sprite_list.push_front(std::make_pair((*p)->xmin + (*p)->ymin, *p));
1546 sprite_order.push(*p);
1547 (*p)->order = next_order++;
1552 std::vector<ParentSpriteToDraw *> preceding;
1553 auto preceding_prev = sprite_list.begin();
1554 auto out = psdv->begin();
1556 while (!sprite_order.empty()) {
1558 auto s = sprite_order.top();
1562 if (s->order == ORDER_RETURNED)
continue;
1565 if (s->order == ORDER_COMPARED) {
1567 s->order = ORDER_RETURNED;
1581 auto ssum = std::max(s->xmax, s->xmin) + std::max(s->ymax, s->ymin);
1582 auto prev = sprite_list.before_begin();
1583 auto x = sprite_list.begin();
1584 while (x != sprite_list.end() && ((*x).first <= ssum)) {
1585 auto p = (*x).second;
1588 x = sprite_list.erase_after(prev);
1595 if (s->xmax < p->xmin || s->ymax < p->ymin || s->zmax < p->zmin)
continue;
1596 if (s->xmin <= p->xmax &&
1597 s->ymin <= p->ymax &&
1598 s->zmin <= p->zmax) {
1599 if (s->xmin + s->xmax + s->ymin + s->ymax + s->zmin + s->zmax <=
1600 p->xmin + p->xmax + p->ymin + p->ymax + p->zmin + p->zmax) {
1604 preceding.push_back(p);
1605 preceding_prev = p_prev;
1608 if (preceding.empty()) {
1611 s->order = ORDER_RETURNED;
1616 if (preceding.size() == 1) {
1617 auto p = preceding[0];
1619 if (p->xmax <= s->xmax && p->ymax <= s->ymax && p->zmax <= s->zmax) {
1620 p->order = ORDER_RETURNED;
1621 s->order = ORDER_RETURNED;
1622 sprite_list.erase_after(preceding_prev);
1631 return a->order > b->order;
1634 s->order = ORDER_COMPARED;
1635 sprite_order.push(s);
1637 for (
auto p: preceding) {
1638 p->order = next_order++;
1639 sprite_order.push(p);
1645 static void ViewportDrawParentSprites(
const ParentSpriteToSortVector *psd,
const ChildScreenSpriteToDrawVector *csstdv)
1648 if (ps->image != SPR_EMPTY_BOUNDING_BOX)
DrawSpriteViewport(ps->image, ps->pal, ps->x, ps->y, ps->sub);
1650 int child_idx = ps->first_child;
1651 while (child_idx >= 0) {
1653 child_idx = cs->
next;
1676 pt2.x - pt1.x, pt2.y - pt1.y,
1677 pt3.x - pt1.x, pt3.y - pt1.y,
1678 pt4.x - pt1.x, pt4.y - pt1.y);
1697 byte bo =
UnScaleByZoom(dpi->left + dpi->top, dpi->zoom) & 1;
1699 for (
int i = (bo ^= 1); i < right; i += 2) blitter->
SetPixel(dst, i, 0, (uint8_t)colour);
1700 dst = blitter->
MoveTo(dst, 0, 1);
1701 }
while (--bottom > 0);
1704 static void ViewportDrawStrings(
ZoomLevel zoom,
const StringSpriteToDrawVector *sstdv)
1708 bool small =
HasBit(ss.width, 15);
1709 int w =
GB(ss.width, 0, 15);
1714 if (ss.colour != INVALID_COLOUR) {
1724 x, y, x + w - 1, y + h - 1, ss.colour,
1734 void ViewportDoDraw(
const Viewport *vp,
int left,
int top,
int right,
int bottom)
1736 _vd.dpi.zoom = vp->
zoom;
1741 _vd.dpi.width = (right - left) & mask;
1742 _vd.dpi.height = (bottom - top) & mask;
1743 _vd.dpi.left = left & mask;
1744 _vd.dpi.top = top & mask;
1745 _vd.dpi.pitch = _cur_dpi->pitch;
1746 _vd.last_child =
nullptr;
1757 ViewportAddKdtreeSigns(&_vd.dpi);
1759 DrawTextEffects(&_vd.dpi);
1761 if (!_vd.tile_sprites_to_draw.empty()) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
1763 for (
auto &psd : _vd.parent_sprites_to_draw) {
1780 if (vp->overlay !=
nullptr && vp->overlay->GetCargoMask() != 0 && vp->overlay->GetCompanyMask() != 0) {
1784 vp->overlay->Draw(&dp);
1787 if (!_vd.string_sprites_to_draw.empty()) {
1791 ViewportDrawStrings(zoom, &_vd.string_sprites_to_draw);
1794 _vd.string_sprites_to_draw.clear();
1795 _vd.tile_sprites_to_draw.clear();
1796 _vd.parent_sprites_to_draw.clear();
1798 _vd.child_screen_sprites_to_draw.clear();
1801 static inline void ViewportDraw(
const Viewport *vp,
int left,
int top,
int right,
int bottom)
1803 if (right <= vp->left || bottom <= vp->top)
return;
1805 if (left >= vp->
left + vp->
width)
return;
1807 if (left < vp->left) left = vp->
left;
1810 if (top >= vp->
top + vp->
height)
return;
1812 if (top < vp->top) top = vp->
top;
1832 dpi->left += this->
left;
1833 dpi->top += this->
top;
1835 ViewportDraw(this->
viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
1837 dpi->left -= this->
left;
1838 dpi->top -= this->
top;
1883 static void ClampSmoothScroll(uint32_t delta_ms, int64_t delta_hi, int64_t delta_lo,
int &delta_hi_clamped,
int &delta_lo_clamped)
1886 constexpr
int PIXELS_PER_TILE =
TILE_PIXELS * 2 * ZOOM_LVL_BASE;
1888 assert(delta_hi != 0);
1891 int64_t delta_left = delta_hi * std::pow(0.75, delta_ms / 30.0);
1896 delta_hi_clamped =
Clamp(delta_hi - delta_left, -max_scroll, max_scroll);
1898 delta_lo_clamped = delta_lo * delta_hi_clamped / delta_hi;
1901 if (delta_hi_clamped == 0) {
1902 delta_hi_clamped = delta_hi > 0 ? 1 : -1;
1920 SetViewportPosition(w, pt.x, pt.y);
1931 bool update_overlay =
false;
1932 if (delta_x != 0 || delta_y != 0) {
1934 int delta_x_clamped;
1935 int delta_y_clamped;
1937 if (
abs(delta_x) >
abs(delta_y)) {
1938 ClampSmoothScroll(delta_ms, delta_x, delta_y, delta_x_clamped, delta_y_clamped);
1940 ClampSmoothScroll(delta_ms, delta_y, delta_x, delta_y_clamped, delta_x_clamped);
1963 if (update_overlay) RebuildViewportOverlay(w);
1980 right += (1 << vp->
zoom) - 1;
1981 bottom += (1 << vp->
zoom) - 1;
1984 if (right <= 0)
return false;
1987 if (bottom <= 0)
return false;
2022 if (vp !=
nullptr) {
2023 assert(vp->
width != 0);
2031 void ConstrainAllViewportsZoom()
2034 if (w->viewport ==
nullptr)
continue;
2037 if (zoom != w->viewport->zoom) {
2070 int x_size = _thd.
size.x;
2071 int y_size = _thd.
size.y;
2074 int x_start = _thd.
pos.x;
2075 int y_start = _thd.
pos.y;
2079 x_start += _thd.
offs.x;
2081 y_start += _thd.
offs.y;
2087 assert(x_size >= 0);
2088 assert(y_size >= 0);
2097 assert((x_end | y_end | x_start | y_start) %
TILE_SIZE == 0);
2118 int top_y = y_start;
2139 static const int OVERLAY_WIDTH = 4 * ZOOM_LVL_BASE;
2145 if (top_x != x_start) {
2152 if (bot_y != y_end) {
2157 }
while (bot_x >= top_x);
2160 int a_size = x_size + y_size, b_size = x_size - y_size;
2165 for (
int a = -interval_a; a != a_size + interval_a; a += interval_a) {
2166 for (
int b = -interval_b; b != b_size + interval_b; b += interval_b) {
2179 void SetSelectionRed(
bool b)
2199 return y >= sign->
top && y < sign->
top + sign_height &&
2200 x >= sign->
center - sign_half_width && x < sign->
center + sign_half_width;
2213 if (_game_mode == GM_MENU)
return false;
2218 Rect search_rect{ x - 1, y - 1, x + 1, y + 1 };
2219 search_rect = ExpandRectWithViewportSignMargins(search_rect, vp->
zoom);
2229 Town *t =
nullptr, *last_t =
nullptr;
2230 Sign *si =
nullptr, *last_si =
nullptr;
2234 switch (item.type) {
2235 case ViewportSignKdtreeItem::VKI_STATION:
2236 if (!show_stations) break;
2237 st = BaseStation::Get(item.id.station);
2238 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
2239 if (CheckClickOnViewportSign(vp, x, y, &st->sign)) last_st = st;
2242 case ViewportSignKdtreeItem::VKI_WAYPOINT:
2243 if (!show_waypoints) break;
2244 st = BaseStation::Get(item.id.station);
2245 if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break;
2246 if (CheckClickOnViewportSign(vp, x, y, &st->sign)) last_st = st;
2249 case ViewportSignKdtreeItem::VKI_TOWN:
2250 if (!show_towns) break;
2251 t = Town::Get(item.id.town);
2252 if (CheckClickOnViewportSign(vp, x, y, &t->cache.sign)) last_t = t;
2255 case ViewportSignKdtreeItem::VKI_SIGN:
2256 if (!show_signs) break;
2257 si = Sign::Get(item.id.sign);
2258 if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break;
2259 if (CheckClickOnViewportSign(vp, x, y, &si->sign)) last_si = si;
2268 if (last_st !=
nullptr) {
2275 }
else if (last_t !=
nullptr) {
2276 ShowTownViewWindow(last_t->index);
2278 }
else if (last_si !=
nullptr) {
2290 item.type = VKI_STATION;
2291 item.id.station = id;
2299 _viewport_sign_maxwidth = std::max<int>(_viewport_sign_maxwidth, st->
sign.
width_normal);
2307 item.type = VKI_WAYPOINT;
2308 item.id.station = id;
2316 _viewport_sign_maxwidth = std::max<int>(_viewport_sign_maxwidth, st->
sign.
width_normal);
2324 item.type = VKI_TOWN;
2341 item.type = VKI_SIGN;
2346 item.center = sign->sign.
center;
2347 item.top = sign->sign.
top;
2350 _viewport_sign_maxwidth = std::max<int>(_viewport_sign_maxwidth, sign->sign.
width_normal);
2355 void RebuildViewportKdtree()
2358 _viewport_sign_maxwidth = 0;
2360 std::vector<ViewportSignKdtreeItem> items;
2364 if (st->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeStation(st->index));
2368 if (wp->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
2372 if (town->cache.sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeTown(town->index));
2376 if (sign->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeSign(sign->index));
2379 _viewport_sign_kdtree.
Build(items.begin(), items.end());
2383 static bool CheckClickOnLandscape(
const Viewport *vp,
int x,
int y)
2387 if (pt.x != -1)
return ClickTile(
TileVirtXY(pt.x, pt.y));
2391 static void PlaceObject()
2396 pt = GetTileBelowCursor();
2397 if (pt.x == -1)
return;
2412 bool HandleViewportClicked(
const Viewport *vp,
int x,
int y)
2427 bool result = CheckClickOnLandscape(vp, x, y);
2444 void RebuildViewportOverlay(
Window *w)
2446 if (w->
viewport->overlay !=
nullptr &&
2447 w->
viewport->overlay->GetCompanyMask() != 0 &&
2448 w->
viewport->overlay->GetCargoMask() != 0) {
2483 RebuildViewportOverlay(w);
2544 void SetTileSelectBigSize(
int ox,
int oy,
int sx,
int sy)
2604 bool new_diagonal =
false;
2616 new_diagonal =
true;
2618 if (x1 >= x2)
Swap(x1, x2);
2619 if (y1 >= y2)
Swap(y1, y2);
2625 if (!new_diagonal) {
2632 Point pt = GetTileBelowCursor();
2664 default: NOT_REACHED();
2710 static void HideMeasurementTooltips()
2761 void VpSetPlaceSizingLimit(
int limit)
2786 HideMeasurementTooltips();
2790 static void VpStartPreSizing()
2802 int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
2804 int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
2808 default: NOT_REACHED();
2810 if (fxpy >= 20 && sxpy <= 12)
return HT_DIR_HL;
2811 if (fxmy < -3 && sxmy > 3)
return HT_DIR_VR;
2815 if (fxmy > 3 && sxmy < -3)
return HT_DIR_VL;
2816 if (fxpy <= 12 && sxpy >= 20)
return HT_DIR_HU;
2820 if (fxmy > 3 && sxmy < -3)
return HT_DIR_VL;
2821 if (fxpy >= 20 && sxpy <= 12)
return HT_DIR_HL;
2825 if (fxmy < -3 && sxmy > 3)
return HT_DIR_VR;
2826 if (fxpy <= 12 && sxpy >= 20)
return HT_DIR_HU;
2846 uint start_x =
TileX(start_tile);
2847 uint start_y =
TileY(start_tile);
2848 uint end_x =
TileX(end_tile);
2849 uint end_y =
TileY(end_tile);
2853 case HT_LINE:
return (end_x > start_x || (end_x == start_x && end_y > start_y));
2856 case HT_POINT:
return (end_x != start_x && end_y < start_y);
2857 default: NOT_REACHED();
2883 if (start_tile == end_tile)
return 0;
2884 if (swap)
Swap(start_tile, end_tile);
2895 byte style_t = (byte)(
TileX(end_tile) >
TileX(start_tile));
2910 {1, 0}, {1, 1}, {0, 1}, {1, 1},
2911 {1, 0}, {0, 0}, {1, 0}, {1, 1},
2912 {1, 0}, {1, 1}, {0, 1}, {1, 1},
2914 {0, 1}, {0, 0}, {1, 0}, {0, 0},
2915 {0, 1}, {0, 0}, {1, 1}, {0, 1},
2916 {1, 0}, {0, 0}, {0, 0}, {0, 1},
2926 if (swap && distance == 0) style = flip_style_direction[style];
2929 byte style_t = style * 2;
2930 assert(style_t <
lengthof(heightdiff_line_by_dir) - 13);
2933 h0 = std::max(h0, ht);
2937 if (distance == 0) style_t = flip_style_direction[style] * 2;
2938 assert(style_t <
lengthof(heightdiff_line_by_dir) - 13);
2941 h1 = std::max(h1, ht);
2946 if (swap)
Swap(h0, h1);
2950 static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF};
2960 if (test >= 0)
return;
2962 other += mult * test;
2975 if (test <= max)
return;
2977 other += mult * (test - max);
3020 int offset = (raw_dx - raw_dy) / 2;
3055 int offset = (raw_dx + raw_dy + (int)
TILE_SIZE) / 2;
3104 }
else if (w > h * 2) {
3107 }
else if (h > w * 2) {
3121 }
else if (d >= 0) {
3132 }
else if (d >= 0) {
3145 }
else if (d >= 0) {
3156 }
else if (d >= 0) {
3173 if (distance != 1) {
3179 distance =
CeilDiv(distance, 2);
3183 if (heightdiff != 0)
SetDParam(index++, heightdiff);
3232 if (
abs(sy - y) <
abs(sx - x)) {
3239 goto calc_heightdiff_single_direction;
3248 goto calc_heightdiff_single_direction;
3258 calc_heightdiff_single_direction:;
3260 x = sx +
Clamp(x - sx, -limit, limit);
3261 y = sy +
Clamp(y - sy, -limit, limit);
3269 if (distance != 1) {
3278 if (heightdiff != 0)
SetDParam(index++, heightdiff);
3287 x = sx +
Clamp(x - sx, -limit, limit);
3288 y = sy +
Clamp(y - sy, -limit, limit);
3293 static const StringID measure_strings_area[] = {
3294 STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
3319 int a_max = dist_x + dist_y;
3320 int b_max = dist_y - dist_x;
3324 a_max =
abs(a_max + (a_max > 0 ? 2 : -2)) / 2;
3325 b_max =
abs(b_max + (b_max > 0 ? 2 : -2)) / 2;
3331 if (a_max != 1 || b_max != 1) {
3338 }
else if (dy == 1) {
3343 if (dx != 1 || dy != 1) {
3348 if (heightdiff != 0)
SetDParam(index++, heightdiff);
3355 default: NOT_REACHED();
3407 HideMeasurementTooltips();
3448 HideMeasurementTooltips();
3509 { &ViewportSortParentSpritesSSE41Checker, &ViewportSortParentSpritesSSE41 },
3523 assert(_vp_sprite_sorter !=
nullptr);
3557 void MarkCatchmentTilesDirty()
3582 static void SetWindowDirtyForViewportCatchment()
3589 static void ClearViewportCatchment()
3591 MarkCatchmentTilesDirty();
3605 SetWindowDirtyForViewportCatchment();
3607 ClearViewportCatchment();
3609 MarkCatchmentTilesDirty();
3611 MarkCatchmentTilesDirty();
3625 SetWindowDirtyForViewportCatchment();
3627 ClearViewportCatchment();
3629 MarkCatchmentTilesDirty();
3631 MarkCatchmentTilesDirty();
3645 SetWindowDirtyForViewportCatchment();
3647 ClearViewportCatchment();
uint16_t height
Height of the sprite.
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
@ ES_HANDLED
The passed event is handled.
Iterator to iterate all valid Windows.
@ HT_DIR_HL
horizontal lower
const Waypoint * _viewport_highlight_waypoint
Currently selected waypoint for coverage area highlight.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ MP_HOUSE
A house by a town.
static void CalcRaildirsDrawstyle(int x, int y, int method)
while dragging
Data structure for a window viewport.
@ SPRITE_MASK
The mask to for the main sprite.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
SpriteID image
sprite to draw
virtual void OnPlaceObject([[maybe_unused]] Point pt, [[maybe_unused]] TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Point foundation_offset[FOUNDATION_PART_END]
Pixel offset for ground sprites on the foundations.
byte sizelimit
Whether the selection is limited in length, and what the maximum length is.
#define TILE_ADD(x, y)
Adds two tiles together.
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 DrawAutorailSelection(const TileInfo *ti, uint autorail_type)
Draws autorail highlights.
Point size
Size, in tile "units", of the white/red selection area.
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
Draws the projection of a parallelepiped.
Point outersize
Size, in tile "units", of the blue coverage area excluding the side of the selected area.
@ WC_INVALID
Invalid window.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static void CheckUnderflow(int &test, int &other, int mult)
Check for underflowing the map.
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
static const PaletteID PALETTE_SEL_TILE_RED
makes a square red. is used when removing rails or other stuff
@ VST_CLIENT
Single player.
@ VPM_FIX_VERTICAL
drag only in vertical direction
static const int MAX_TILE_EXTENT_LEFT
Maximum left extent of tile relative to north corner.
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 SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
int16_t x_offs
Number of pixels to shift the sprite to the right.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
EventState VpHandlePlaceSizingDrag()
Handle the mouse while dragging for placement/resizing.
@ ZOOM_OUT
Zoom out (get helicopter view).
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
static const AnimCursor *const _animcursors[]
This is an array of pointers to all the animated cursor definitions we have above.
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
@ HT_DIR_VR
vertical right
constexpr void Swap(T &a, T &b)
Type safe swap operation.
Slope GetTilePixelSlopeOutsideMap(int x, int y, int *h)
Return the slope of a given tile, also for tiles outside the map (virtual "black" tiles).
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
K-dimensional tree, specialised for 2-dimensional space.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Point offs
Offset, in tile "units", for the blue coverage area from the selected area's northern tile.
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Tile information, used while rendering the tile.
bool _left_button_down
Is left mouse button pressed?
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 debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
const SubSprite * sub
only draw a rectangular part of the sprite
@ ZOOM_LVL_END
End for iteration.
How all blitters should look like.
@ ZOOM_LVL_OUT_16X
Zoomed 16 times out.
static void DrawTileHighlightType(const TileInfo *ti, TileHighlightType tht)
Draw tile highlight for coverage area highlight.
int width
Screen width of the viewport.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
ViewportPlaceMethod select_method
The method which governs how tiles are selected.
static constexpr Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
ViewportData * viewport
Pointer to viewport data, if present.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
int height
Screen height of the viewport.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Point new_size
New value for size; used to determine whether to redraw the selection.
static uint ScaleBySize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
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...
Tindex index
Index of this pool item.
bool IsDraggingDiagonal()
Is the user dragging a 'diagonal rectangle'?
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
int top
Screen coordinate top edge of the viewport.
virtual void SetPixel(void *video, int x, int y, uint8_t colour)=0
Draw a pixel with a given colour on the video-buffer.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Data structure storing rendering information.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
@ FOUNDATION_PART_HALFTILE
Second part (halftile foundation)
Representation of a waypoint.
bool _ctrl_pressed
Is Ctrl pressed?
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
int32_t xmax
maximal world X coordinate of bounding box
static const uint TILE_SIZE
Tile size in world coordinates.
ZoomLevel
All zoom levels we know.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
@ VST_COMPANY
All players in specific company.
static Station * Get(size_t index)
Gets station with given index.
@ VPM_FIX_Y
drag only in Y axis
ClientSettings _settings_client
The current settings for this game.
TileIndex xy
town center tile
int32_t dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
int y
Y position of the tile in unit coordinates.
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
@ WC_STATION_VIEW
Station view; Window numbers:
byte _display_opt
What do we want to draw/do?
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
int virtual_top
Virtual top coordinate.
Owner owner
Which company owns the vehicle?
Location information about a sign as seen on the viewport.
uint16_t SignID
The type of the IDs of signs.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Used to only draw a part of the sprite.
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
uint32_t PaletteID
The number of the palette.
@ FR_TRANSPARENT
Makes the background transparent if set.
ZoomLevel zoom_max
maximum zoom out level
DrawTileProc * draw_tile_proc
Called to render the tile and its contents to the screen.
int32_t y
screen Y coordinate of sprite
Owner owner
The owner of this station.
int32_t top
minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
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.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
DoCommandFlag
List of flags for a command.
size_t Count() const
Get number of elements stored in tree.
static bool CheckClickOnViewportSign(const Viewport *vp, int x, int y, const ViewportSign *sign)
Test whether a sign is below the mouse.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
@ ZOOM_LVL_BEGIN
Begin for iteration.
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.
@ SPRITE_COMBINE_ACTIVE
Sprite combining is active. AddSortableSpriteToDraw outputs child sprites.
static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile)
Calculates height difference between one tile and another.
int32_t x_pos
x coordinate.
@ FOUNDATION_PART_NORMAL
First part (normal foundation or no foundation)
int32_t zmax
maximal world Z coordinate of bounding box
Vehicle * CheckClickOnVehicle(const Viewport *vp, int x, int y)
Find the vehicle close to the clicked coordinates.
Metadata about the current highlighting.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
@ VPM_RAILDIRS
all rail directions
Slope SlopeWithThreeCornersRaised(Corner corner)
Returns the slope with all except one corner raised.
int32_t top
The top of the sign.
Slope tileh
Slope of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
bool measure_tooltip
show a permanent tooltip when dragging tools
int * last_foundation_child[FOUNDATION_PART_END]
Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw)
VpSorterChecker fct_checker
The check function.
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.
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...
int foundation[FOUNDATION_PART_END]
Foundation sprites (index into parent_sprites_to_draw).
Slope
Enumeration for the slope-type.
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
@ ZOOM_IN
Zoom in (get more detailed view).
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
int32_t x
screen X coordinate of sprite
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.
Data structure for viewport, display of a part of the world.
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
int32_t center
The center position of the sign.
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
bool IsInsideRotatedRectangle(int x, int y)
Checks whether a point is inside the selected a diagonal rectangle given by _thd.size and _thd....
Common return value for all commands.
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
FoundationPart foundation_part
Currently active foundation for ground sprite drawing.
PaletteID pal
palette to use
int32_t WindowNumber
Number to differentiate different windows of the same class.
void UpdateTileSelection()
Updates tile highlighting for all cases.
@ FS_NORMAL
Index of the normal font in the font tables.
void StartStopVehicle(const Vehicle *v, bool texteffect)
Executes CMD_START_STOP_VEHICLE for given vehicle.
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
@ MAX_SPRITES
Maximum number of sprites that can be loaded at a given time.
int32_t zmin
minimal world Z coordinate of bounding box
static void SetSelectionTilesDirty()
Marks the selected tiles as dirty.
ParentSpriteToSortVector parent_sprites_to_sort
Parent sprite pointer array used for sorting.
@ VPM_FIX_X
drag only in X axis
static void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal)
Draws a selection rectangle on a tile.
int virtual_left
Virtual left coordinate.
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...
WindowNumber window_number
The WindowNumber of the window that is responsible for the selection mode.
int height
Height of the window (number of pixels down in y direction)
static const CursorID ANIMCURSOR_FLAG
Flag for saying a cursor sprite is an animated cursor.
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
int32_t dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
int left
Screen coordinate left edge of the viewport.
static void AddCombinedSprite(SpriteID image, PaletteID pal, int x, int y, int z, const SubSprite *sub)
Adds a child sprite to a parent sprite.
@ FS_SMALL
Index of the small font in the font tables.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
int32_t first_child
the first child to draw.
bool population_in_label
show the population of a town in its label?
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
bool(* VpSorterChecker)()
Type for method for checking whether a viewport sprite sorter exists.
const SubSprite * sub
only draw a rectangular part of the sprite
virtual void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, [[maybe_unused]] TileIndex start_tile, [[maybe_unused]] TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
static const uint MAX_BUILDING_PIXELS
Maximum height of a building in pixels in #ZOOM_LVL_BASE. (Also applies to "bridge buildings" on the ...
@ ES_NOT_HANDLED
The passed event is not handled.
StationList stations_near
NOSAVE: List of nearby stations.
uint16_t width
Width of the sprite.
Corner
Enumeration of tile corners.
@ HT_RAIL
autorail (one piece), lower bits: direction
byte max_bridge_height
maximum height of bridges
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
int next
next child to draw (-1 at the end)
int32_t scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
virtual void OnPlaceDrag([[maybe_unused]] ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt)
The user is dragging over the map when the tile highlight mode has been set.
static void CheckOverflow(int &test, int &other, int max, int mult)
Check for overflowing the map.
static const byte _string_colourmap[17]
Colour mapping for TextColour.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
static void HighlightTownLocalAuthorityTiles(const TileInfo *ti)
Highlights tiles insede local authority of selected towns.
EconomySettings economy
settings to change the economy
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd)
Draws the bounding boxes of all ParentSprites.
@ DO_SHOW_STATION_NAMES
Display station names.
int left
x position of left edge of the window
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
bool make_square_red
Whether to give a tile a red selection.
uint32_t CursorID
The number of the cursor (sprite)
WindowClass
Window classes.
void RedrawScreenRect(int left, int top, int right, int bottom)
Repaints a specific rectangle of the screen.
int32_t ymax
maximal world Y coordinate of bounding box
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Point pos
Location, in tile "units", of the northern tile of the selected area.
void(* VpSpriteSorter)(ParentSpriteToSortVector *psd)
Type for the actual viewport sprite sorter.
@ SPRITE_COMBINE_NONE
Every AddSortableSpriteToDraw start its own bounding box.
SpriteCombineMode combine_sprites
Current mode of "sprite combining".
Point new_outersize
New value for outersize; used to determine whether to redraw the selection.
int virtual_width
width << zoom
Coordinates of a point in 2D.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
@ WSM_DRAGDROP
Drag&drop an object.
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
static Waypoint * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
@ HT_DIR_MASK
masks the drag-direction
void SetAnimatedMouseCursor(const AnimCursor *table)
Assign an animation to the cursor.
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
WindowNumber window_number
Window number within the window class.
uint16_t width_normal
The width when not zoomed out (normal font)
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
@ SA_HOR_CENTER
Horizontally center the text.
Iterable ensemble of all valid Windows.
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
static void ViewportAddLandscape()
Add the landscape to the viewport, i.e.
int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
int32_t z_pos
z coordinate.
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
int32_t y
screen Y coordinate of sprite
bool IsValidTile(Tile tile)
Checks if a tile is valid.
@ HT_DRAG
dragging items in the depot windows
static HighLightStyle GetAutorailHT(int x, int y)
returns the best autorail highlight type from map coordinates
ClientID _network_own_client_id
Our client identifier.
bool MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
A pair-construct of a TileIndexDiff.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
ZoomLevel zoom_min
minimum zoom out level
static debug_inline uint SizeX()
Get the size of the map along the X.
byte dirty
Whether the build station window needs to redraw due to the changed selection.
byte dist_local_authority
distance for town local authority, default 20
HighLightStyle drawstyle
Lower bits 0-3 are reserved for detailed highlight information.
HighLightStyle place_mode
Method which is used to place the selection.
static const int MAX_TILE_EXTENT_BOTTOM
Maximum bottom extent of tile relative to north corner (worst case: SLOPE_STEEP_N).
void VpStartDragging(ViewportDragDropSelectionProcess process)
Drag over the map while holding the left mouse down.
Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
static void ClampViewportToMap(const Viewport *vp, int *scroll_x, int *scroll_y)
Ensure that a given viewport has a valid scroll position.
uint TilePixelHeight(Tile tile)
Returns the height of a tile in pixels.
Point selstart
The location where the dragging started.
CompanyID _current_company
Company currently doing an action.
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
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...
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Vehicle * First() const
Get the first vehicle of this vehicle chain.
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
ClientID
'Unique' identifier to be given to clients
@ MP_VOID
Invisible tiles at the SW and SE border.
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.
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...
static size_t GetNumItems()
Returns number of valid items in the pool.
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
bool diagonal
Whether the dragged area is a 45 degrees rotated rectangle.
@ SLOPE_N
the north corner of the tile is raised
static void DrawTileSelection(const TileInfo *ti)
Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
TileType
The different types of tiles.
ViewportScrollTarget
Target of the viewport scrolling GS method.
@ HT_LINE
used for autorail highlighting (longer stretches), lower bits: direction
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Window * GetMainWindow()
Get the main window, i.e.
static const PaletteID PALETTE_SEL_TILE_BLUE
This draws a blueish square (catchment areas for example)
TileIndex tile
The base tile of the area.
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...
int16_t y_offs
Number of pixels to shift the sprite downwards.
static ViewportSSCSS _vp_sprite_sorters[]
List of sorters ordered from best to worst.
@ WC_TOOLTIPS
Tooltip window; Window numbers:
int32_t xmin
minimal world X coordinate of bounding box
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static int GetViewportY(Point tile)
Returns the y coordinate in the viewport coordinate system where the given tile is painted.
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.
@ OWNER_NONE
The tile has no ownership.
static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
Sort parent sprites pointer array replicating the way original sorter did it.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
int32_t scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
T FindNearest(CoordT x, CoordT y) const
Find the element closest to given coordinate, in Manhattan distance.
@ MP_STATION
A tile of a station.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TownCache cache
Container for all cacheable data.
EventState
State of handling an event.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
@ HT_RECT
rectangle (stations, depots, ...)
@ VPM_FIX_HORIZONTAL
drag only in horizontal direction
@ VPM_X_AND_Y
area of land in X and Y directions
@ DO_SHOW_SIGNS
Display signs.
uint TileHeightOutsideMap(int x, int y)
Returns the height of a tile, also for tiles outside the map (virtual "black" tiles).
void FindContained(CoordT x1, CoordT y1, CoordT x2, CoordT y2, const Outputter &outputter) const
Find all items contained within the given rectangle.
@ WSM_DRAGGING
Dragging mode (trees).
WindowClass window_class
Window class.
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
static HighLightStyle Check2x1AutoRail(int mode)
returns information about the 2x1 piece to be build.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
@ WC_MAIN_WINDOW
Main window; Window numbers:
TileIndex xy
Base tile of the station.
UnitID unitnumber
unit number, for display purposes only
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
@ HT_DRAG_MASK
Mask for the tile drag-type modes.
Base class for all station-ish types.
@ DO_SHOW_TOWN_NAMES
Display town names.
ViewportDragDropSelectionProcess select_proc
The procedure that has to be called when the selection is done.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, Colours colour)
Add a string to draw in the viewport.
int top
y position of top edge of the window
FoundationPart
Enumeration of multi-part foundations.
int32_t y_pos
y coordinate.
static TileHighlightType GetTileHighlightType(TileIndex t)
Get tile highlight type of coverage area for a given tile.
void DrawViewport() const
Draw the viewport of this window.
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
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.
static void ViewportDrawDirtyBlocks()
Draw/colour the blocks that have been redrawn.
HighLightStyle
Highlighting draw styles.
Parent sprite that should be drawn.
const SubSprite * sub
only draw a rectangular part of the sprite
int32_t left
minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
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.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
@ VPM_X_LIMITED
Drag only in X axis with limited size.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
ZoomLevel zoom
The zoom level of the viewport.
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.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
@ VST_EVERYONE
All players.
WindowClass window_class
The WindowClass of the window that is responsible for the selection mode.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
uint16_t width_small
The width when zoomed out (small font)
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.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
static bool ViewportSortParentSpritesChecker()
This fallback sprite checker always exists.
@ WC_TOWN_VIEW
Town view; Window numbers:
int32_t ymin
minimal world Y coordinate of bounding box
VpSpriteSorter fct_sorter
The sorting function.
int x
X position of the tile in unit coordinates.
@ ZOOM_LVL_NORMAL
The normal zoom level.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
TileIndex tile
Tile index.
static void ShowMeasurementTooltips(StringID str, uint paramcount)
Displays the measurement tooltips when selecting multiple tiles.
ConstructionSettings construction
construction of things in-game
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.
Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
Data structure for an opened window.
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_LVL_BASE.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
uint TilePixelHeightOutsideMap(int x, int y)
Returns the height of a tile in pixels, also for tiles outside the map (virtual "black" tiles).
static const int MAX_TILE_EXTENT_RIGHT
Maximum right extent of tile relative to north corner.
HighLightStyle next_drawstyle
Queued, but not yet drawn style.
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Point TranslateXYToTileCoord(const Viewport *vp, int x, int y, bool clamp_to_map)
Translate screen coordinate in a viewport to underlying tile coordinate.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static const int MAX_TILE_EXTENT_TOP
Maximum top extent of tile relative to north corner (not considering bridges).
void InitializeSpriteSorter()
Choose the "best" sprite sorter and set _vp_sprite_sorter.
int virtual_height
height << zoom
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
@ HT_POINT
point (lower land, raise land, level land, ...)
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
@ VPM_X_AND_Y_LIMITED
area of land of limited size
@ HT_DIR_HU
horizontal upper
SpriteCombineMode
Mode of "sprite combining".
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Data structure describing a sprite.
@ VPM_X_OR_Y
drag in X or Y direction
@ FOUNDATION_PART_NONE
Neither foundation nor groundsprite drawn yet.
@ DO_SHOW_WAYPOINT_NAMES
Display waypoint names.
Point new_pos
New value for pos; used to determine whether to redraw the selection.
int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
void ShowWaypointWindow(const Waypoint *wp)
Show the window for the given waypoint.
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Helper class for getting the best sprite sorter.
CommandCost CmdScrollViewport(DoCommandFlag flags, TileIndex tile, ViewportScrollTarget target, uint32_t ref)
Scroll players main viewport.
void ViewportAddVehicles(DrawPixelInfo *dpi)
Add the vehicle sprites that should be drawn at a part of the screen.
TileIndex redsq
The tile that has to get a red selection.
bool freeze
Freeze highlight in place.
@ VPM_SIGNALDIRS
similar to VMP_RAILDIRS, but with different cursor
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ Normal
The most basic (normal) sprite.
@ PFE_DRAWWORLD
Time spent drawing world viewports in GUI.
@ WSM_NONE
No special mouse mode.
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 uint SizeY()
Get the size of the map along the Y.
bool smooth_scroll
smooth scroll viewports
GUISettings gui
settings related to the GUI
TrackedViewportSign sign
Location of name sign, UpdateVirtCoord updates this.
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 selend
The location where the drag currently ends.
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Data about how and where to blit pixels.
void Reset()
Reset tile highlighting.
Corner OppositeCorner(Corner corner)
Returns the opposite corner.
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
int32_t x
screen X coordinate of sprite
@ SPRITE_COMBINE_PENDING
Sprite combining will start with the next unclipped sprite.
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
Draw a sprite in a viewport.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.