summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeterN <peter1138@openttd.org>2021-04-22 16:42:40 +0100
committerGitHub <noreply@github.com>2021-04-22 16:42:40 +0100
commit9fa38f5d0f3b1bd67028a8d9d5ff06eed1a31cdf (patch)
treecde44e47c059974ec05000db729f706789748b44 /src
parent994ffaa382ab14c9b80c5a0a5d704fa53b85d4d2 (diff)
downloadopenttd-9fa38f5d0f3b1bd67028a8d9d5ff06eed1a31cdf.tar.xz
Codechange: Scale rating minigraphs on station window list. (#9075)
Minigraphs did not adjust size to accomodate large text, either by font size or font zoom, leading to cropped labels. Minigraphs and spacing are now scaled by font zoom, as this seems to behave better than gui zoom in this instance.
Diffstat (limited to 'src')
-rw-r--r--src/station_gui.cpp113
1 files changed, 60 insertions, 53 deletions
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index d21ba5f73..98b44c6f9 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -153,9 +153,6 @@ void CheckRedrawStationCoverage(const Window *w)
* @param type Cargo type
* @param amount Cargo amount
* @param rating ratings data for that particular cargo
- *
- * @note Each cargo-bar is 16 pixels wide and 6 pixels high
- * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
*/
static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
{
@@ -165,32 +162,33 @@ static void StationsWndShowStationRating(int left, int right, int y, CargoID typ
const CargoSpec *cs = CargoSpec::Get(type);
if (!cs->IsValid()) return;
+ int padding = ScaleFontTrad(1);
+ int width = right - left;
int colour = cs->rating_colour;
TextColour tc = GetContrastColour(colour);
- uint w = (std::min(amount, units_full) + 5) / 36;
-
- int height = GetCharacterHeight(FS_SMALL);
+ uint w = std::min(amount + 5, units_full) * width / units_full;
- /* Draw total cargo (limited) on station (fits into 16 pixels) */
- if (w != 0) GfxFillRect(left, y, left + w - 1, y + height, colour);
+ int height = GetCharacterHeight(FS_SMALL) + padding - 1;
- /* Draw a one pixel-wide bar of additional cargo meter, useful
- * for stations with only a small amount (<=30) */
- if (w == 0) {
- uint rest = amount / 5;
+ if (amount > 30) {
+ /* Draw total cargo (limited) on station */
+ GfxFillRect(left, y, left + w - 1, y + height, colour);
+ } else {
+ /* Draw a (scaled) one pixel-wide bar of additional cargo meter, useful
+ * for stations with only a small amount (<=30) */
+ uint rest = ScaleFontTrad(amount) / 5;
if (rest != 0) {
- w += left;
- GfxFillRect(w, y + height - rest, w, y + height, colour);
+ GfxFillRect(left, y + height - rest, left + padding - 1, y + height, colour);
}
}
- DrawString(left + 1, right, y, cs->abbrev, tc);
+ DrawString(left + padding, right, y, cs->abbrev, tc);
- /* Draw green/red ratings bar (fits into 14 pixels) */
- y += height + 2;
- GfxFillRect(left + 1, y, left + 14, y, PC_RED);
- rating = std::min<uint>(rating, rating_full) / 16;
- if (rating != 0) GfxFillRect(left + 1, y, left + rating, y, PC_GREEN);
+ /* Draw green/red ratings bar (fits under the waiting bar) */
+ y += height + padding + 1;
+ GfxFillRect(left + padding, y, right - padding - 1, y + padding - 1, PC_RED);
+ w = std::min<uint>(rating, rating_full) * (width - padding - padding) / rating_full;
+ if (w != 0) GfxFillRect(left + padding, y, left + w - 1, y + padding - 1, PC_GREEN);
}
typedef GUIList<const Station*> GUIStationList;
@@ -214,6 +212,7 @@ protected:
GUIStationList stations;
Scrollbar *vscroll;
+ uint rating_width;
/**
* (Re)Build station list
@@ -392,16 +391,17 @@ public:
}
case WID_STL_LIST:
- resize->height = FONT_HEIGHT_NORMAL;
+ resize->height = std::max(FONT_HEIGHT_NORMAL, FONT_HEIGHT_SMALL + ScaleFontTrad(3));
size->height = WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM;
- break;
- case WID_STL_TRAIN:
- case WID_STL_TRUCK:
- case WID_STL_BUS:
- case WID_STL_AIRPLANE:
- case WID_STL_SHIP:
- size->height = std::max<uint>(FONT_HEIGHT_SMALL, 10) + padding.height;
+ /* Determine appropriate width for mini station rating graph */
+ this->rating_width = 0;
+ const CargoSpec *cs;
+ FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
+ this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev).width);
+ }
+ /* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
+ this->rating_width = this->rating_width * 16 / 10;
break;
case WID_STL_CARGOALL:
@@ -445,6 +445,12 @@ public:
bool rtl = _current_text_dir == TD_RTL;
int max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size());
int y = r.top + WD_FRAMERECT_TOP;
+ uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
+ /* Spacing between station name and first rating graph. */
+ int text_spacing = ScaleFontTrad(5);
+ /* Spacing between additional rating graphs. */
+ int rating_spacing = ScaleFontTrad(4);
+
for (int i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner
const Station *st = this->stations[i];
assert(st->xy != INVALID_TILE);
@@ -455,8 +461,8 @@ public:
SetDParam(0, st->index);
SetDParam(1, st->facilities);
- int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_STATION);
- x += rtl ? -5 : 5;
+ int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + (line_height - FONT_HEIGHT_NORMAL) / 2, STR_STATION_LIST_STATION);
+ x += rtl ? -text_spacing : text_spacing;
/* show cargo waiting and station ratings */
for (uint j = 0; j < _sorted_standard_cargo_specs_size; j++) {
@@ -467,17 +473,17 @@ public:
* instead of drawing to the left and then incrementing
* the space. */
if (rtl) {
- x -= 20;
+ x -= rating_width + rating_spacing;
if (x < r.left + WD_FRAMERECT_LEFT) break;
}
- StationsWndShowStationRating(x, x + 16, y, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
+ StationsWndShowStationRating(x, x + rating_width, y, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
if (!rtl) {
- x += 20;
+ x += rating_width + rating_spacing;
if (x > r.right - WD_FRAMERECT_RIGHT) break;
}
}
}
- y += FONT_HEIGHT_NORMAL;
+ y += line_height;
}
if (this->vscroll->GetCount() == 0) { // company has no stations
@@ -488,30 +494,30 @@ public:
}
case WID_STL_NOCARGOWAITING: {
- int cg_ofst = this->IsWidgetLowered(widget) ? 2 : 1;
- DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, STR_ABBREV_NONE, TC_BLACK, SA_HOR_CENTER);
+ int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
+ DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_NONE, TC_BLACK, SA_HOR_CENTER);
break;
}
case WID_STL_CARGOALL: {
- int cg_ofst = this->IsWidgetLowered(widget) ? 2 : 1;
- DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
+ int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
+ DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
break;
}
case WID_STL_FACILALL: {
- int cg_ofst = this->IsWidgetLowered(widget) ? 2 : 1;
- DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
+ int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
+ DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
break;
}
default:
if (widget >= WID_STL_CARGOSTART) {
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
- int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 2 : 1;
- GfxFillRect(r.left + cg_ofst, r.top + cg_ofst, r.right - 2 + cg_ofst, r.bottom - 2 + cg_ofst, cs->rating_colour);
+ int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 1 : 0;
+ GfxFillRect(r.left + cg_ofst + 1, r.top + cg_ofst + 1, r.right - 1 + cg_ofst, r.bottom - 1 + cg_ofst, cs->rating_colour);
TextColour tc = GetContrastColour(cs->rating_colour);
- DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER);
+ DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER);
}
break;
}
@@ -720,7 +726,8 @@ static NWidgetBase *CargoWidgets(int *biggest_index)
for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
- panel->SetMinimalSize(14, 11);
+ panel->SetMinimalSize(14, 0);
+ panel->SetMinimalTextLines(1, 0, FS_NORMAL);
panel->SetResize(0, 0);
panel->SetFill(0, 1);
panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
@@ -739,16 +746,16 @@ static const NWidgetPart _nested_company_stations_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_GREY),
EndContainer(),
NWidget(NWID_HORIZONTAL),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRAIN), SetMinimalSize(14, 11), SetDataTip(STR_TRAIN, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRUCK), SetMinimalSize(14, 11), SetDataTip(STR_LORRY, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_BUS), SetMinimalSize(14, 11), SetDataTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_SHIP), SetMinimalSize(14, 11), SetDataTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_AIRPLANE), SetMinimalSize(14, 11), SetDataTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
- NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 11), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetFill(0, 1),
- NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 11), SetFill(0, 1), EndContainer(),
+ NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRAIN), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_TRAIN, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
+ NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRUCK), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_LORRY, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
+ NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_BUS), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
+ NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_SHIP), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
+ NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_AIRPLANE), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
+ NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetFill(0, 1),
+ NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
NWidgetFunction(CargoWidgets),
- NWidget(WWT_PANEL, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 11), SetDataTip(0x0, STR_STATION_LIST_NO_WAITING_CARGO), SetFill(0, 1), EndContainer(),
- NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 11), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_TYPES), SetFill(0, 1),
+ NWidget(WWT_PANEL, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_NO_WAITING_CARGO), SetFill(0, 1), EndContainer(),
+ NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_TYPES), SetFill(0, 1),
NWidget(WWT_PANEL, COLOUR_GREY), SetDataTip(0x0, STR_NULL), SetResize(1, 0), SetFill(1, 1), EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL),