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

Method GetPositionOnLegend

src/smallmap_gui.cpp:1401–1415  ·  view source on GitHub ↗

* Determines the mouse position on the legend. * @param pt Mouse position. * @return Legend item under the mouse. */

Source from the content-addressed store, hash-verified

1399 * @return Legend item under the mouse.
1400 */
1401 int GetPositionOnLegend(Point pt)
1402 {
1403 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_LEGEND);
1404 uint line = (pt.y - wi->pos_y - WidgetDimensions::scaled.framerect.top) / GetCharacterHeight(FS_SMALL);
1405 uint columns = this->GetNumberColumnsLegend(wi->current_x);
1406 uint number_of_rows = this->GetNumberRowsLegend(columns);
1407 if (line >= number_of_rows) return -1;
1408
1409 bool rtl = _current_text_dir == TD_RTL;
1410 int x = pt.x - wi->pos_x;
1411 if (rtl) x = wi->current_x - x;
1412 uint column = (x - WidgetDimensions::scaled.framerect.left) / this->column_width;
1413
1414 return (column * number_of_rows) + line;
1415 }
1416
1417 /** Update all the links on the map. */
1418 void UpdateLinks()

Callers 1

OnClickMethod · 0.95

Calls 4

GetNumberRowsLegendMethod · 0.95
GetCharacterHeightFunction · 0.85

Tested by

no test coverage detected