diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index b4137038fc..1d566255d6 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1046,7 +1046,10 @@ void SmallMapWindow::SetupWidgetData() this->GetWidget(WID_SM_SELECT_BUTTONS)->SetDisplayedPlane(plane); } -SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc), refresh(FORCE_REFRESH_PERIOD) +SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : + Window(desc), + row_height(GetMinSizing(NWST_STEP, FONT_HEIGHT_SMALL)), + refresh(FORCE_REFRESH_PERIOD) { _smallmap_industry_highlight = INVALID_INDUSTRYTYPE; this->overlay = new LinkGraphOverlay(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1); @@ -1156,9 +1159,8 @@ SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(des bool rtl = _current_text_dir == TD_RTL; uint y_org = r.top + WD_FRAMERECT_TOP; uint x = rtl ? r.right - this->column_width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT; - uint y = y_org; + uint y = Center(y_org, this->row_height, FONT_HEIGHT_SMALL); uint i = 0; // Row counter for industry legend. - uint row_height = FONT_HEIGHT_SMALL; uint text_left = rtl ? 0 : LEGEND_BLOB_WIDTH + WD_FRAMERECT_LEFT; uint text_right = this->column_width - 1 - (rtl ? LEGEND_BLOB_WIDTH + WD_FRAMERECT_RIGHT : 0); @@ -1185,7 +1187,7 @@ SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(des /* Column break needed, continue at top, COLUMN_WIDTH pixels * (one "row") to the right. */ x += rtl ? -(int)this->column_width : this->column_width; - y = y_org; + y = Center(y_org, this->row_height, FONT_HEIGHT_SMALL); i = 1; } @@ -1213,7 +1215,7 @@ SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(des DrawString(x + text_left, x + text_right, y, string, TC_GREY); } else { DrawString(x + text_left, x + text_right, y, string, TC_BLACK); - GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, PC_BLACK); // Outer border of the legend colour + GfxFillRect(x + blob_left, y + 1, x + blob_right, y + FONT_HEIGHT_SMALL - 1, PC_BLACK); // Outer border of the legend colour } break; } @@ -1221,13 +1223,13 @@ SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(des default: if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP); /* Anything that is not an industry or a company is using normal process */ - GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, PC_BLACK); + GfxFillRect(x + blob_left, y + 1, x + blob_right, y + FONT_HEIGHT_SMALL - 1, PC_BLACK); DrawString(x + text_left, x + text_right, y, tbl->legend); break; } - GfxFillRect(x + blob_left + 1, y + 2, x + blob_right - 1, y + row_height - 2, legend_colour); // Legend colour + GfxFillRect(x + blob_left + 1, y + 2, x + blob_right - 1, y + FONT_HEIGHT_SMALL - 2, legend_colour); // Legend colour - y += row_height; + y += this->row_height; } } } @@ -1319,7 +1321,7 @@ void SmallMapWindow::SetOverlayCargoMask() int SmallMapWindow::GetPositionOnLegend(Point pt) { const NWidgetBase *wi = this->GetWidget(WID_SM_LEGEND); - uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL; + uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / this->row_height; uint columns = this->GetNumberColumnsLegend(wi->current_x); uint number_of_rows = this->GetNumberRowsLegend(columns); if (line >= number_of_rows) return -1; diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h index 6652f83d8c..d54969d915 100644 --- a/src/smallmap_gui.h +++ b/src/smallmap_gui.h @@ -72,6 +72,7 @@ protected: uint min_number_of_columns; ///< Minimal number of columns in legends. uint min_number_of_fixed_rows; ///< Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY). uint column_width; ///< Width of a column in the #WID_SM_LEGEND widget. + const uint row_height; ///< Heigth of each row in the #WID_SM_LEGEND widget. int32 scroll_x; ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display. int32 scroll_y; ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display. @@ -133,7 +134,7 @@ protected: inline uint GetLegendHeight(uint num_columns) const { return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + - this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL; + this->GetNumberRowsLegend(num_columns) * this->row_height; } /**