Change: Use Rect helpers for widget drawing.
This replaces repetitive and sometimes unwieldy use of constants.
This commit is contained in:
@@ -1214,8 +1214,9 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SM_MAP: {
|
||||
Rect ir = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
|
||||
DrawPixelInfo new_dpi;
|
||||
if (!FillDrawPixelInfo(&new_dpi, r.left + 1, r.top + 1, r.Width(), r.Height())) return;
|
||||
if (!FillDrawPixelInfo(&new_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return;
|
||||
this->DrawSmallMap(&new_dpi);
|
||||
break;
|
||||
}
|
||||
@@ -1224,17 +1225,13 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
|
||||
uint columns = this->GetNumberColumnsLegend(r.Width());
|
||||
uint number_of_rows = this->GetNumberRowsLegend(columns);
|
||||
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 i = 0; // Row counter for industry legend.
|
||||
uint row_height = FONT_HEIGHT_SMALL;
|
||||
int padding = ScaleFontTrad(1);
|
||||
|
||||
uint text_left = rtl ? 0 : this->legend_width + WD_FRAMERECT_LEFT;
|
||||
uint text_right = this->column_width - padding - (rtl ? this->legend_width + WD_FRAMERECT_RIGHT : 0);
|
||||
uint blob_left = rtl ? this->column_width - padding - this->legend_width : 0;
|
||||
uint blob_right = rtl ? this->column_width - padding : this->legend_width;
|
||||
Rect origin = r.WithWidth(this->column_width, rtl).Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM).WithHeight(row_height);
|
||||
Rect text = origin.Indent(this->legend_width + padding, rtl);
|
||||
Rect icon = origin.WithWidth(this->legend_width, rtl).Shrink(0, padding, 0, 0);
|
||||
|
||||
StringID string = STR_NULL;
|
||||
switch (this->map_type) {
|
||||
@@ -1255,8 +1252,10 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
|
||||
if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) {
|
||||
/* 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;
|
||||
int x = rtl ? -(int)this->column_width : this->column_width;
|
||||
int y = origin.top - text.top;
|
||||
text = text.Translate(x, y);
|
||||
icon = icon.Translate(x, y);
|
||||
i = 1;
|
||||
}
|
||||
|
||||
@@ -1283,10 +1282,10 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
|
||||
if (!tbl->show_on_map) {
|
||||
/* Simply draw the string, not the black border of the legend colour.
|
||||
* This will enforce the idea of the disabled item */
|
||||
DrawString(x + text_left, x + text_right, y, string, TC_GREY);
|
||||
DrawString(text, string, TC_GREY);
|
||||
} else {
|
||||
DrawString(x + text_left, x + text_right, y, string, TC_BLACK);
|
||||
GfxFillRect(x + blob_left, y + padding, x + blob_right, y + row_height - 1, PC_BLACK); // Outer border of the legend colour
|
||||
DrawString(text, string, TC_BLACK);
|
||||
GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1295,13 +1294,14 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
|
||||
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 + padding, x + blob_right, y + row_height - 1, PC_BLACK);
|
||||
DrawString(x + text_left, x + text_right, y, tbl->legend);
|
||||
GfxFillRect(icon, PC_BLACK);
|
||||
DrawString(text, tbl->legend);
|
||||
break;
|
||||
}
|
||||
GfxFillRect(x + blob_left + 1, y + padding + 1, x + blob_right - 1, y + row_height - 2, legend_colour); // Legend colour
|
||||
GfxFillRect(icon.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), legend_colour); // Legend colour
|
||||
|
||||
y += row_height;
|
||||
text = text.Translate(0, row_height);
|
||||
icon = icon.Translate(0, row_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user