summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2021-04-22 21:47:18 +0100
committerPeterN <peter@fuzzle.org>2021-04-30 17:08:15 +0100
commit5434d63f914b38dbffa86fe0e5c651b79816f3f2 (patch)
tree34515b14ce6543fef68f170b4fc4f752121b94e0
parentaf70195e448e1a934fe921efcb9450ead99cb49e (diff)
downloadopenttd-5434d63f914b38dbffa86fe0e5c651b79816f3f2.tar.xz
Fix: Scale smallmap legend 'blob' to fit text.
-rw-r--r--src/smallmap_gui.cpp21
-rw-r--r--src/smallmap_gui.h2
2 files changed, 14 insertions, 9 deletions
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 0e7d313a6..b00cf0e7a 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -22,6 +22,7 @@
#include "window_func.h"
#include "company_base.h"
#include "guitimer_func.h"
+#include "zoom_func.h"
#include "smallmap_gui.h"
@@ -1177,8 +1178,11 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
this->min_number_of_columns = std::max(this->min_number_of_columns, num_columns);
}
+ /* Width of the legend blob. */
+ this->legend_width = (FONT_HEIGHT_SMALL - ScaleFontTrad(1)) * 8 / 5;
+
/* The width of a column is the minimum width of all texts + the size of the blob + some spacing */
- this->column_width = min_width + LEGEND_BLOB_WIDTH + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
+ this->column_width = min_width + this->legend_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
}
/* virtual */ void SmallMapWindow::OnPaint()
@@ -1216,11 +1220,12 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
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 : LEGEND_BLOB_WIDTH + WD_FRAMERECT_LEFT;
- uint text_right = this->column_width - 1 - (rtl ? LEGEND_BLOB_WIDTH + WD_FRAMERECT_RIGHT : 0);
- uint blob_left = rtl ? this->column_width - 1 - LEGEND_BLOB_WIDTH : 0;
- uint blob_right = rtl ? this->column_width - 1 : LEGEND_BLOB_WIDTH;
+ 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;
StringID string = STR_NULL;
switch (this->map_type) {
@@ -1272,7 +1277,7 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
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 + padding, x + blob_right, y + row_height - 1, PC_BLACK); // Outer border of the legend colour
}
break;
}
@@ -1281,11 +1286,11 @@ 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 + 1, x + blob_right, y + row_height - 1, PC_BLACK);
+ 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);
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 + padding + 1, x + blob_right - 1, y + row_height - 2, legend_colour); // Legend colour
y += row_height;
}
diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h
index f1b8ece73..e2fa9074d 100644
--- a/src/smallmap_gui.h
+++ b/src/smallmap_gui.h
@@ -64,7 +64,6 @@ protected:
static bool show_towns; ///< Display town names in the smallmap.
static int map_height_limit; ///< Currently used/cached map height limit.
- static const uint LEGEND_BLOB_WIDTH = 8; ///< Width of the coloured blob in front of a line text in the #WID_SM_LEGEND widget.
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
static const uint FORCE_REFRESH_PERIOD = 930; ///< map is redrawn after that many milliseconds.
static const uint BLINK_PERIOD = 450; ///< highlight blinking interval in milliseconds.
@@ -72,6 +71,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.
+ uint legend_width; ///< Width of legend 'blob'.
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.