OpenTTD Source: src/tilehighlight_func.h File Reference

OpenTTD Source 15.3

Functions | Variables
tilehighlight_func.h File Reference

Functions related to tile highlights. More...

`#include "gfx_type.h"`
`#include "tilehighlight_type.h"`

Go to the source code of this file.

## Functions
void | PlaceProc_DemolishArea (TileIndex tile)
| Start a drag for demolishing an area.
bool | GUIPlaceProcDragXY (ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
| A central place to handle all X_AND_Y dragged GUI functions.
bool | HandlePlacePushButton (Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
| This code is shared for the majority of the pushbuttons.
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 area selection, object placement, etc.
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 area selection, object placement, etc.
void | ResetObjectToPlace ()
| Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void | VpSelectTilesWithMethod (int x, int y, ViewportPlaceMethod method)
| Selects tiles while dragging.
void | VpStartDragging (ViewportDragDropSelectionProcess process)
| Drag over the map while holding the left mouse down.
void | VpStartPlaceSizing (TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
| highlighting tiles while only going over them with the mouse
void | VpSetPresizeRange (TileIndex from, TileIndex to)
| Highlights all tiles between a set of two tiles.
void | VpSetPlaceSizingLimit (int limit)
void | UpdateTileSelection ()
| Updates tile highlighting for all cases.

## Variables
TileHighlightData | _thd

## Detailed Description

Functions related to tile highlights.

Definition in file tilehighlight_func.h.

## Function Documentation

## ◆ GUIPlaceProcDragXY()

bool GUIPlaceProcDragXY | ( | ViewportDragDropSelectionProcess | proc,
|  | TileIndex | start_tile,
|  | TileIndex | end_tile
| ) |  |

A central place to handle all X_AND_Y dragged GUI functions.

Parameters

  proc | Procedure related to the dragging
  start_tile | Begin of the dragging
  end_tile | End of the dragging

Returns
  Returns true if the action was found and handled, and false otherwise. This allows for additional implements that are more local. For example X_Y drag of convertrail which belongs in rail_gui.cpp and not terraform_gui.cpp

Definition at line 112 of file terraform_gui.cpp.

References _ctrl_pressed, _settings_game, GameSettings::construction, DDSP_CREATE_DESERT, DDSP_CREATE_ROCKS, DDSP_DEMOLISH_AREA, DDSP_LEVEL_AREA, DDSP_LOWER_AND_LEVEL_AREA, DDSP_RAISE_AND_LEVEL_AREA, ConstructionSettings::freeform_edges, GenerateDesertArea(), GenerateRockyArea(), LM_LEVEL, LM_LOWER, LM_RAISE, Map::MaxX(), Map::MaxY(), TileDiffXY(), TileX(), and TileY().

Referenced by BuildAirToolbarWindow::OnPlaceMouseUp(), BuildDocksToolbarWindow::OnPlaceMouseUp(), BuildRailToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceMouseUp(), and ScenarioEditorLandscapeGenerationWindow::OnPlaceMouseUp().

## ◆ HandlePlacePushButton()

bool HandlePlacePushButton | ( | Window * | w,
|  | WidgetID | widget,
|  | CursorID | cursor,
|  | HighLightStyle | mode
| ) |  |

This code is shared for the majority of the pushbuttons.

Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters

Parameters

  w | Window which called the function
  widget | ID of the widget (=button) that called this function
  cursor | How should the cursor image change? E.g. cursor with depot image in it
  mode | Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground

Returns
  true if the button is clicked, false if it's unclicked

Definition at line 63 of file main_gui.cpp.

References Window::IsWidgetDisabled(), Window::IsWidgetLowered(), Window::LowerWidget(), ResetObjectToPlace(), Window::SetDirty(), SetObjectToPlace(), SndClickBeep(), Window::window_class, and Window::window_number.

Referenced by BuildAirToolbarWindow::OnClick(), BuildDocksToolbarWindow::OnClick(), BuildIndustryWindow::OnClick(), QueryStringWindow::OnClick(), BuildRailToolbarWindow::OnClick(), BuildRoadToolbarWindow::OnClick(), SignWindow::OnClick(), TerraformToolbarWindow::OnClick(), ScenarioEditorLandscapeGenerationWindow::OnClick(), and FoundTownWindow::OnClick().

## ◆ PlaceProc_DemolishArea()

void PlaceProc_DemolishArea | ( | TileIndex | tile | ) |

Start a drag for demolishing an area.

Parameters

  tile | Position of one corner.

Definition at line 151 of file terraform_gui.cpp.

References DDSP_DEMOLISH_AREA, VPM_X_AND_Y, and VpStartPlaceSizing().

Referenced by BuildAirToolbarWindow::OnPlaceObject(), BuildDocksToolbarWindow::OnPlaceObject(), BuildRailToolbarWindow::OnPlaceObject(), BuildRoadToolbarWindow::OnPlaceObject(), TerraformToolbarWindow::OnPlaceObject(), and ScenarioEditorLandscapeGenerationWindow::OnPlaceObject().

## ◆ ResetObjectToPlace()

void ResetObjectToPlace | ( |  | ) |

Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).

Definition at line 3573 of file viewport.cpp.

References HT_NONE, SetObjectToPlace(), SPR_CURSOR_MOUSE, and WC_MAIN_WINDOW.

Referenced by _GenerateWorld(), CcBuildRailTunnel(), CcBuildRoadTunnel(), CcMoveStationName(), CcMoveWaypointName(), CcPlaceSign(), CcRoadStop(), Window::Close(), PickerWindowBase::Close(), CmdScrollViewport(), DeleteDepotHighlightOfVehicle(), HandleMouseDragDrop(), HandlePlacePushButton(), CompanyWindow::OnClick(), DepotWindow::OnClick(), BuildIndustryWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnClick(), StatusBarWindow::OnClick(), NewGRFWindow::OnDragDrop(), OrdersWindow::OnDragDrop(), NewGRFWindow::OnDropdownSelect(), MainWindow::OnHotkey(), StoryBookWindow::OnPageElementClick(), BuildRailToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), CompanyWindow::OnPlaceObject(), BuildIndustryWindow::OnPlaceObject(), OrdersWindow::OnPlaceObject(), StoryBookWindow::OnPlaceObject(), DepotWindow::OnVehicleSelect(), StoryBookWindow::RefreshSelectedPage(), StoryBookWindow::SetSelectedPage(), ShowSelectBaseStationIfNeeded(), VehicleGroupWindow::UnselectVehicle(), BuildTreesWindow::UpdateMode(), and VpHandlePlaceSizingDrag().

## ◆ SetObjectToPlace()

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 area selection, object placement, etc.

Parameters

  icon | New shape of the mouse cursor.
  pal | Palette to use.
  mode | Mode to perform.
  window_class | Window class of the window requesting the mode change.
  window_num | Number of the window in its class requesting the mode change.

Definition at line 3525 of file viewport.cpp.

References _animcursors, _special_mouse_mode, ANIMCURSOR_FLAG, TileHighlightData::drawstyle, TileHighlightData::GetCallbackWnd(), HT_DRAG, HT_DRAG_MASK, HT_NONE, HT_SPECIAL, TileHighlightData::make_square_red, Window::OnPlaceObjectAbort(), TileHighlightData::place_mode, SetAnimatedMouseCursor(), SetMouseCursor(), SetSelectionTilesDirty(), SetTileSelectSize(), WC_INVALID, TileHighlightData::window_class, TileHighlightData::window_number, WSM_DRAGDROP, and WSM_NONE.

Referenced by _GenerateWorld(), GenerateWorld(), HandlePlacePushButton(), ResetObjectToPlace(), SetObjectToPlaceWnd(), and BuildTreesWindow::UpdateMode().

## ◆ SetObjectToPlaceWnd()

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 area selection, object placement, etc.

Parameters

  icon | New shape of the mouse cursor.
  pal | Palette to use.
  mode | Mode to perform.
  w | Window requesting the mode change.

Definition at line 3510 of file viewport.cpp.

References SetObjectToPlace(), Window::window_class, and Window::window_number.

Referenced by DepotWindow::DepotClick(), CompanyWindow::OnClick(), DepotWindow::OnClick(), VehicleGroupWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnClick(), RefitWindow::OnClick(), StoryBookWindow::OnPageElementClick(), and OrdersWindow::OrderClick_Goto().

## ◆ UpdateTileSelection()

void UpdateTileSelection | ( |  | ) |

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

Definition at line 2679 of file viewport.cpp.

References TileHighlightData::diagonal, TileHighlightData::dirty, TileHighlightData::drawstyle, TileHighlightData::freeze, GetAutorailHT(), HT_DIR_HL, HT_DIR_HU, HT_DIR_MASK, HT_DIR_VL, HT_DIR_VR, HT_DIR_X, HT_DIR_Y, HT_DRAG_MASK, HT_LINE, HT_NONE, HT_POINT, HT_RAIL, HT_RECT, HT_SPECIAL, TileHighlightData::IsDraggingDiagonal(), TileHighlightData::new_outersize, TileHighlightData::new_pos, TileHighlightData::new_size, TileHighlightData::next_drawstyle, TileHighlightData::outersize, TileHighlightData::place_mode, TileHighlightData::pos, TileHighlightData::selend, TileHighlightData::selstart, SetSelectionTilesDirty(), TileHighlightData::size, TILE_SIZE, TILE_UNIT_MASK, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by StationJoinerNeeded().

## ◆ VpSelectTilesWithMethod()

void VpSelectTilesWithMethod | ( | int | x,
|  | int | y,
|  | ViewportPlaceMethod | method
| ) |  |

Selects tiles while dragging.

Parameters

  x | X coordinate of end of selection
  y | Y coordinate of end of selection
  method | modifies the way tiles are selected. Possible methods are VPM_* in viewport.h

Definition at line 3291 of file viewport.cpp.

References _settings_client, abs(), CalcHeightdiff(), CalcRaildirsDrawstyle(), Clamp(), Delta(), DistanceManhattan(), GetEncodedString(), ClientSettings::gui, HT_DIR_X, HT_DIR_Y, HT_DRAG_MASK, HT_LINE, HT_POINT, HT_RECT, TileHighlightData::IsDraggingDiagonal(), GUISettings::measure_tooltip, TileHighlightData::next_drawstyle, TileHighlightData::selend, TileHighlightData::selstart, ShowMeasurementTooltips(), TileHighlightData::sizelimit, TILE_SIZE, TileVirtXY(), TileX(), TileY(), VPM_FIX_X, VPM_FIX_Y, VPM_RAILDIRS, VPM_SIGNALDIRS, VPM_X_AND_Y, VPM_X_AND_Y_LIMITED, VPM_X_LIMITED, VPM_X_OR_Y, VPM_Y_LIMITED, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by BuildAirToolbarWindow::OnPlaceDrag(), BuildDocksToolbarWindow::OnPlaceDrag(), BuildObjectWindow::OnPlaceDrag(), BuildRailToolbarWindow::OnPlaceDrag(), BuildRoadToolbarWindow::OnPlaceDrag(), TerraformToolbarWindow::OnPlaceDrag(), ScenarioEditorLandscapeGenerationWindow::OnPlaceDrag(), and BuildTreesWindow::OnPlaceDrag().

## ◆ VpSetPlaceSizingLimit()

void VpSetPlaceSizingLimit | ( | int | limit | ) |

Definition at line 2843 of file viewport.cpp.

## ◆ VpSetPresizeRange()

void VpSetPresizeRange | ( | TileIndex | from,
|  | TileIndex | to
| ) |  |

Highlights all tiles between a set of two tiles.

Used in dock and tunnel placement

Parameters

  from | TileIndex of the first tile to highlight
  to | TileIndex of the last tile to highlight

Definition at line 2853 of file viewport.cpp.

References DistanceManhattan(), GetEncodedString(), HT_RECT, TileHighlightData::next_drawstyle, TileHighlightData::selend, TileHighlightData::selstart, ShowMeasurementTooltips(), TILE_SIZE, TileX(), TileY(), Coord2D< T >::x, and Coord2D< T >::y.

Referenced by BuildRailToolbarWindow::OnPlacePresize(), BuildRoadToolbarWindow::OnPlacePresize(), and BuildDocksToolbarWindow::OnPlacePresize().

## ◆ VpStartDragging()

void VpStartDragging | ( | ViewportDragDropSelectionProcess | process | ) |

Drag over the map while holding the left mouse down.

Definition at line 2832 of file viewport.cpp.

References _special_mouse_mode, HT_RECT, TileHighlightData::next_drawstyle, TileHighlightData::select_method, TileHighlightData::select_proc, TileHighlightData::selstart, VPM_X_AND_Y, WSM_DRAGGING, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by BuildTreesWindow::OnPlaceObject().

## ◆ VpStartPlaceSizing()

void VpStartPlaceSizing | ( | TileIndex | tile,
|  | ViewportPlaceMethod | method,
|  | ViewportDragDropSelectionProcess | process
| ) |  |

highlighting tiles while only going over them with the mouse

Definition at line 2798 of file viewport.cpp.

References _special_mouse_mode, TileHighlightData::drawstyle, HT_DIR_MASK, HT_DRAG_MASK, HT_LINE, HT_POINT, HT_RAIL, HT_RECT, HT_SPECIAL, TileHighlightData::next_drawstyle, TileHighlightData::place_mode, TileHighlightData::select_method, TileHighlightData::select_proc, TileHighlightData::selend, TileHighlightData::selstart, TILE_SIZE, TileX(), TileY(), VPM_FIX_X, VPM_FIX_Y, VPM_X_OR_Y, WSM_SIZING, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by BuildDocksToolbarWindow::OnPlaceObject(), BuildObjectWindow::OnPlaceObject(), BuildRailToolbarWindow::OnPlaceObject(), BuildRoadToolbarWindow::OnPlaceObject(), TerraformToolbarWindow::OnPlaceObject(), ScenarioEditorLandscapeGenerationWindow::OnPlaceObject(), BuildTreesWindow::OnPlaceObject(), PlaceProc_DemolishArea(), PlaceRail_Bridge(), PlaceRail_Station(), PlaceRail_Waypoint(), PlaceRoad_Bridge(), PlaceRoad_BusStation(), PlaceRoad_TruckStation(), and PlaceRoad_Waypoint().

## Variable Documentation

## ◆ _thd

TileHighlightData _thd
| extern

Definition at line 193 of file viewport.cpp.