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

Function UpdateTileSelection

src/viewport.cpp:2679–2780  ·  view source on GitHub ↗

* Updates tile highlighting for all cases. * Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size * Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice, * Once for the old and once for the new selection. * _thd is TileHighlightData, found in viewport.h */

Source from the content-addressed store, hash-verified

2677 * _thd is TileHighlightData, found in viewport.h
2678 */
2679void UpdateTileSelection()
2680{
2681 int x1;
2682 int y1;
2683
2684 if (_thd.freeze) return;
2685
2686 HighLightStyle new_drawstyle = HT_NONE;
2687 bool new_diagonal = false;
2688
2689 if ((_thd.place_mode & HT_DRAG_MASK) == HT_SPECIAL) {
2690 x1 = _thd.selend.x;
2691 y1 = _thd.selend.y;
2692 if (x1 != -1) {
2693 int x2 = _thd.selstart.x & ~TILE_UNIT_MASK;
2694 int y2 = _thd.selstart.y & ~TILE_UNIT_MASK;
2695 x1 &= ~TILE_UNIT_MASK;
2696 y1 &= ~TILE_UNIT_MASK;
2697
2698 if (_thd.IsDraggingDiagonal()) {
2699 new_diagonal = true;
2700 } else {
2701 if (x1 >= x2) std::swap(x1, x2);
2702 if (y1 >= y2) std::swap(y1, y2);
2703 }
2704 _thd.new_pos.x = x1;
2705 _thd.new_pos.y = y1;
2706 _thd.new_size.x = x2 - x1;
2707 _thd.new_size.y = y2 - y1;
2708 if (!new_diagonal) {
2709 _thd.new_size.x += TILE_SIZE;
2710 _thd.new_size.y += TILE_SIZE;
2711 }
2712 new_drawstyle = _thd.next_drawstyle;
2713 }
2714 } else if ((_thd.place_mode & HT_DRAG_MASK) != HT_NONE) {
2715 Point pt = GetTileBelowCursor();
2716 x1 = pt.x;
2717 y1 = pt.y;
2718 if (x1 != -1) {
2719 switch (_thd.place_mode & HT_DRAG_MASK) {
2720 case HT_RECT:
2721 new_drawstyle = HT_RECT;
2722 break;
2723 case HT_POINT:
2724 new_drawstyle = HT_POINT;
2725 x1 += TILE_SIZE / 2;
2726 y1 += TILE_SIZE / 2;
2727 break;
2728 case HT_RAIL:
2729 /* Draw one highlighted tile in any direction */
2730 new_drawstyle = GetAutorailHT(pt.x, pt.y);
2731 break;
2732 case HT_LINE:
2733 switch (_thd.place_mode & HT_DIR_MASK) {
2734 case HT_DIR_X: new_drawstyle = HT_LINE | HT_DIR_X; break;
2735 case HT_DIR_Y: new_drawstyle = HT_LINE | HT_DIR_Y; break;
2736

Callers 2

MouseLoopFunction · 0.85
StationJoinerNeededFunction · 0.85

Calls 6

swapFunction · 0.85
GetTileBelowCursorFunction · 0.85
GetAutorailHTFunction · 0.85
NOT_REACHEDFunction · 0.85
SetSelectionTilesDirtyFunction · 0.85
IsDraggingDiagonalMethod · 0.80

Tested by

no test coverage detected