MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawTileSelection

Function DrawTileSelection

src/viewport.cpp:1120–1193  ·  view source on GitHub ↗

* Checks if the specified tile is selected and if so draws selection using correct selectionstyle. * @param *ti TileInfo Tile that is being drawn */

Source from the content-addressed store, hash-verified

1118 * @param *ti TileInfo Tile that is being drawn
1119 */
1120static void DrawTileSelection(const TileInfo *ti)
1121{
1122 /* Highlight tiles inside local authority of selected towns. */
1123 HighlightTownLocalAuthorityTiles(ti);
1124
1125 /* Draw a red error square? */
1126 bool is_redsq = _thd.redsq == ti->tile;
1127 if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
1128
1129 TileHighlightType tht = GetTileHighlightType(ti->tile);
1130 DrawTileHighlightType(ti, tht);
1131
1132 /* No tile selection active? */
1133 if ((_thd.drawstyle & HT_DRAG_MASK) == HT_NONE) return;
1134
1135 if (_thd.diagonal) { // We're drawing a 45 degrees rotated (diagonal) rectangle
1136 if (IsInsideRotatedRectangle((int)ti->x, (int)ti->y)) goto draw_inner;
1137 return;
1138 }
1139
1140 /* Inside the inner area? */
1141 if (IsInsideBS(ti->x, _thd.pos.x, _thd.size.x) &&
1142 IsInsideBS(ti->y, _thd.pos.y, _thd.size.y)) {
1143draw_inner:
1144 if (_thd.drawstyle & HT_RECT) {
1145 if (!is_redsq) DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
1146 } else if (_thd.drawstyle & HT_POINT) {
1147 /* Figure out the Z coordinate for the single dot. */
1148 int z = 0;
1149 FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
1150 if (ti->tileh & SLOPE_N) {
1151 z += TILE_HEIGHT;
1152 if (RemoveHalftileSlope(ti->tileh) == SLOPE_STEEP_N) z += TILE_HEIGHT;
1153 }
1154 if (IsHalftileSlope(ti->tileh)) {
1155 Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
1156 if ((halftile_corner == CORNER_W) || (halftile_corner == CORNER_E)) z += TILE_HEIGHT;
1157 if (halftile_corner != CORNER_S) {
1158 foundation_part = FOUNDATION_PART_HALFTILE;
1159 if (IsSteepSlope(ti->tileh)) z -= TILE_HEIGHT;
1160 }
1161 }
1162 DrawSelectionSprite(SPR_DOT, PAL_NONE, ti, z, foundation_part);
1163 } else if (_thd.drawstyle & HT_RAIL) {
1164 /* autorail highlight piece under cursor */
1165 HighLightStyle type = _thd.drawstyle & HT_DIR_MASK;
1166 assert(type < HT_DIR_END);
1167 DrawAutorailSelection(ti, _autorail_type[type][0]);
1168 } else if (IsPartOfAutoLine(ti->x, ti->y)) {
1169 /* autorail highlighting long line */
1170 HighLightStyle dir = _thd.drawstyle & HT_DIR_MASK;
1171 uint side;
1172
1173 if (dir == HT_DIR_X || dir == HT_DIR_Y) {
1174 side = 0;
1175 } else {
1176 TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
1177 side = Delta(Delta(TileX(start), TileX(ti->tile)), Delta(TileY(start), TileY(ti->tile)));

Callers 1

ViewportAddLandscapeFunction · 0.85

Calls 15

DrawTileSelectionRectFunction · 0.85
GetTileHighlightTypeFunction · 0.85
DrawTileHighlightTypeFunction · 0.85
IsInsideRotatedRectangleFunction · 0.85
IsInsideBSFunction · 0.85
RemoveHalftileSlopeFunction · 0.85
IsHalftileSlopeFunction · 0.85
GetHalftileSlopeCornerFunction · 0.85
IsSteepSlopeFunction · 0.85
DrawSelectionSpriteFunction · 0.85
DrawAutorailSelectionFunction · 0.85

Tested by

no test coverage detected