* Determines the mouse position on the legend. * @param pt Mouse position. * @return Legend item under the mouse. */
| 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() |
no test coverage detected