Change: Use Rect helpers for widget drawing.

This replaces repetitive and sometimes unwieldy use of constants.
This commit is contained in:
Peter Nelson 2022-10-15 16:55:47 +01:00 committed by PeterN
parent cb10ed1509
commit 6f95e04005
41 changed files with 792 additions and 809 deletions

View File

@ -125,18 +125,18 @@ struct AIListWindow : public Window {
switch (widget) { switch (widget) {
case WID_AIL_LIST: { case WID_AIL_LIST: {
/* Draw a list of all available AIs. */ /* Draw a list of all available AIs. */
int y = this->GetWidget<NWidgetBase>(WID_AIL_LIST)->pos_y; Rect tr = r.Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
/* First AI in the list is hardcoded to random */ /* First AI in the list is hardcoded to random */
if (this->vscroll->IsVisible(0)) { if (this->vscroll->IsVisible(0)) {
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_LEFT, y + WD_MATRIX_TOP, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE); DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
y += this->line_height; tr.top += this->line_height;
} }
int i = 0; int i = 0;
for (const auto &item : *this->info_list) { for (const auto &item : *this->info_list) {
i++; i++;
if (this->vscroll->IsVisible(i)) { if (this->vscroll->IsVisible(i)) {
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE); DrawString(tr, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
y += this->line_height; tr.top += this->line_height;
} }
} }
break; break;
@ -150,20 +150,20 @@ struct AIListWindow : public Window {
} }
/* Some info about the currently selected AI. */ /* Some info about the currently selected AI. */
if (selected_info != nullptr) { if (selected_info != nullptr) {
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM);
SetDParamStr(0, selected_info->GetAuthor()); SetDParamStr(0, selected_info->GetAuthor());
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_AUTHOR); DrawString(tr, STR_AI_LIST_AUTHOR);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; tr.top += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
SetDParam(0, selected_info->GetVersion()); SetDParam(0, selected_info->GetVersion());
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_VERSION); DrawString(tr, STR_AI_LIST_VERSION);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; tr.top += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
if (selected_info->GetURL() != nullptr) { if (selected_info->GetURL() != nullptr) {
SetDParamStr(0, selected_info->GetURL()); SetDParamStr(0, selected_info->GetURL());
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_URL); DrawString(tr, STR_AI_LIST_URL);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; tr.top += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
} }
SetDParamStr(0, selected_info->GetDescription()); SetDParamStr(0, selected_info->GetDescription());
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_FRAMERECT_BOTTOM, STR_JUST_RAW_STRING, TC_WHITE); DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_WHITE);
} }
break; break;
} }
@ -359,11 +359,10 @@ struct AISettingsWindow : public Window {
int i = 0; int i = 0;
for (; !this->vscroll->IsVisible(i); i++) it++; for (; !this->vscroll->IsVisible(i); i++) it++;
Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4; Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8); Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + 8, rtl);
uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
int y = r.top; int y = r.top;
int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2; int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
@ -392,13 +391,13 @@ struct AISettingsWindow : public Window {
} }
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) { if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable); DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON); SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
} else { } else {
if (config_item.complete_labels) { if (config_item.complete_labels) {
DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable); DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
} else { } else {
DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value); DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
} }
if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) { if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
SetDParam(idx++, STR_JUST_RAW_STRING); SetDParam(idx++, STR_JUST_RAW_STRING);
@ -409,7 +408,7 @@ struct AISettingsWindow : public Window {
} }
} }
DrawString(text_left, text_right, y + text_y_offset, str, colour); DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
y += this->line_height; y += this->line_height;
} }
} }
@ -427,8 +426,8 @@ struct AISettingsWindow : public Window {
{ {
switch (widget) { switch (widget) {
case WID_AIS_BACKGROUND: { case WID_AIS_BACKGROUND: {
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND); Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WD_MATRIX_LEFT, 0, WD_MATRIX_RIGHT, 0);
int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition(); int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
if (num >= (int)this->visible_settings.size()) break; if (num >= (int)this->visible_settings.size()) break;
VisibleSettingsList::const_iterator it = this->visible_settings.begin(); VisibleSettingsList::const_iterator it = this->visible_settings.begin();
@ -445,9 +444,8 @@ struct AISettingsWindow : public Window {
bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0; bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
int x = pt.x - wid->pos_x; int x = pt.x - r.left;
if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x; if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
x -= 4;
/* One of the arrows is clicked (or green/red rect in case of bool value) */ /* One of the arrows is clicked (or green/red rect in case of bool value) */
int old_val = this->ai_config->GetSetting(config_item.name); int old_val = this->ai_config->GetSetting(config_item.name);
@ -458,8 +456,7 @@ struct AISettingsWindow : public Window {
this->clicked_dropdown = false; this->clicked_dropdown = false;
this->closing_dropdown = false; this->closing_dropdown = false;
} else { } else {
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND); int rel_y = (pt.y - r.top) % this->line_height;
int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
Rect wi_rect; Rect wi_rect;
wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x); wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
@ -794,7 +791,7 @@ struct AIConfigWindow : public Window {
{ {
switch (widget) { switch (widget) {
case WID_AIC_LIST: { case WID_AIC_LIST: {
int y = r.top; Rect tr = r.Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) { for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
StringID text; StringID text;
@ -806,9 +803,9 @@ struct AIConfigWindow : public Window {
} else { } else {
text = STR_AI_CONFIG_RANDOM_AI; text = STR_AI_CONFIG_RANDOM_AI;
} }
DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text, DrawString(tr, text,
(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER)); (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
y += this->line_height; tr.top += this->line_height;
} }
break; break;
} }

View File

@ -388,15 +388,17 @@ public:
{ {
switch (widget) { switch (widget) {
case WID_AP_AIRPORT_LIST: { case WID_AP_AIRPORT_LIST: {
int y = r.top; Rect row = r.WithHeight(this->line_height).Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
Rect text = r.WithHeight(this->line_height).Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
AirportClass *apclass = AirportClass::Get(_selected_airport_class); AirportClass *apclass = AirportClass::Get(_selected_airport_class);
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) { for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) {
const AirportSpec *as = apclass->GetSpec(i); const AirportSpec *as = apclass->GetSpec(i);
if (!as->IsAvailable()) { if (!as->IsAvailable()) {
GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, PC_BLACK, FILLRECT_CHECKER); GfxFillRect(row, PC_BLACK, FILLRECT_CHECKER);
} }
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK); DrawString(text, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
y += this->line_height; row = row.Translate(0, this->line_height);
text = text.Translate(0, this->line_height);
} }
break; break;
} }

View File

@ -422,7 +422,7 @@ public:
str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED; str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
} }
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_BLACK, SA_HOR_CENTER); DrawString(r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM), str, TC_BLACK, SA_HOR_CENTER);
break; break;
} }
@ -433,7 +433,8 @@ public:
EngineID end = static_cast<EngineID>(std::min<size_t>(this->vscroll[side]->GetCapacity() + start, this->engines[side].size())); EngineID end = static_cast<EngineID>(std::min<size_t>(this->vscroll[side]->GetCapacity() + start, this->engines[side].size()));
/* Do the actual drawing */ /* Do the actual drawing */
DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, const Rect list = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
DrawEngineList((VehicleType)this->window_number, list.left, list.right, list.top,
&this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group); &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
break; break;
} }
@ -485,10 +486,10 @@ public:
ted.cargo = e->GetDefaultCargoType(); ted.cargo = e->GetDefaultCargoType();
ted.capacity = e->GetDisplayDefaultCapacity(&ted.mail_capacity); ted.capacity = e->GetDisplayDefaultCapacity(&ted.mail_capacity);
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS); const Rect r = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS)->GetCurrentRect()
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT, .Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM);
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side], ted); int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine[side], ted);
needed_height = std::max(needed_height, (text_end - (int)nwi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL); needed_height = std::max(needed_height, (text_end - r.top) / FONT_HEIGHT_NORMAL);
} }
} }
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them. if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.

View File

@ -108,7 +108,7 @@ public:
void DrawWidget(const Rect &r, int widget) const override void DrawWidget(const Rect &r, int widget) const override
{ {
if (widget == WID_BEM_MESSAGE) { if (widget == WID_BEM_MESSAGE) {
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMETEXT_BOTTOM, STR_MISSING_GRAPHICS_ERROR, TC_FROMSTRING, SA_CENTER); DrawStringMultiLine(r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM), STR_MISSING_GRAPHICS_ERROR, TC_FROMSTRING, SA_CENTER);
} }
} }
@ -236,7 +236,7 @@ public:
{ {
if (widget != 0) return; if (widget != 0) return;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMETEXT_BOTTOM, STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER); DrawStringMultiLine(r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM), STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER);
} }
void OnClick(Point pt, int widget, int click_count) override void OnClick(Point pt, int widget, int click_count) override

View File

@ -194,10 +194,10 @@ public:
} }
sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field. sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field. text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
resize->height = std::max(sprite_dim.height, text_dim.height) + 2; // Max of both sizes + account for matrix edges. resize->height = std::max(sprite_dim.height, text_dim.height) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; // Max of both sizes + account for matrix edges.
this->bridgetext_offset = WD_MATRIX_LEFT + sprite_dim.width + 1; // Left edge of text, 1 pixel distance from the sprite. this->bridgetext_offset = sprite_dim.width + 1; // Left edge of text, 1 pixel distance from the sprite.
size->width = this->bridgetext_offset + text_dim.width + WD_MATRIX_RIGHT; size->width = WD_MATRIX_LEFT + this->bridgetext_offset + text_dim.width + WD_MATRIX_RIGHT;
size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix. size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
break; break;
} }
@ -222,7 +222,7 @@ public:
break; break;
case WID_BBS_BRIDGE_LIST: { case WID_BBS_BRIDGE_LIST: {
uint y = r.top; Rect tr = r.WithHeight(this->resize.step_height).Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) { for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->at(i).spec; const BridgeSpec *b = this->bridges->at(i).spec;
@ -230,10 +230,10 @@ public:
SetDParam(1, b->speed); SetDParam(1, b->speed);
SetDParam(0, b->material); SetDParam(0, b->material);
DrawSprite(b->sprite, b->pal, r.left + WD_MATRIX_LEFT, y + this->resize.step_height - 1 - GetSpriteSize(b->sprite).height); DrawSprite(b->sprite, b->pal, tr.left, tr.bottom - GetSpriteSize(b->sprite).height);
DrawStringMultiLine(r.left + this->bridgetext_offset, r.right, y + 2, y + this->resize.step_height, DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false),
_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO); _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO);
y += this->resize.step_height; tr = tr.Translate(0, this->resize.step_height);
} }
break; break;
} }

View File

@ -1622,10 +1622,9 @@ struct BuildVehicleWindow : Window {
int needed_height = this->details_height; int needed_height = this->details_height;
/* Draw details panels. */ /* Draw details panels. */
if (this->sel_engine != INVALID_ENGINE) { if (this->sel_engine != INVALID_ENGINE) {
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL); const Rect r = this->GetWidget<NWidgetBase>(WID_BV_PANEL)->GetCurrentRect().Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT, int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine, this->te);
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine, this->te); needed_height = std::max(needed_height, (text_end - r.top) / FONT_HEIGHT_NORMAL);
needed_height = std::max(needed_height, (text_end - (int)nwi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL);
} }
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them. if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
int resize = needed_height - this->details_height; int resize = needed_height - this->details_height;

View File

@ -29,6 +29,7 @@
#include "newgrf.h" #include "newgrf.h"
#include "error.h" #include "error.h"
#include "misc_cmd.h" #include "misc_cmd.h"
#include "core/geometry_func.hpp"
#include "widgets/cheat_widget.h" #include "widgets/cheat_widget.h"
@ -216,33 +217,42 @@ struct CheatWindow : Window {
int clicked; int clicked;
int clicked_widget; int clicked_widget;
uint line_height; uint line_height;
int box_width; Dimension box; ///< Dimension of box sprite
Dimension icon; ///< Dimension of company icon sprite
CheatWindow(WindowDesc *desc) : Window(desc) CheatWindow(WindowDesc *desc) : Window(desc)
{ {
this->box_width = GetSpriteSize(SPR_BOX_EMPTY).width;
this->InitNested(); this->InitNested();
} }
void OnInit() override
{
this->box = maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED));
this->icon = GetSpriteSize(SPR_COMPANY_ICON);
}
void DrawWidget(const Rect &r, int widget) const override void DrawWidget(const Rect &r, int widget) const override
{ {
if (widget != WID_C_PANEL) return; if (widget != WID_C_PANEL) return;
int y = r.top + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL; const Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int y = ir.top;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint box_left = rtl ? r.right - this->box_width - 5 : r.left + 5; uint box_left = rtl ? ir.right - this->box.width - 5 : ir.left + 5;
uint button_left = rtl ? r.right - this->box_width - 10 - SETTING_BUTTON_WIDTH : r.left + this->box_width + 10; uint button_left = rtl ? ir.right - this->box.width - 10 - SETTING_BUTTON_WIDTH : ir.left + this->box.width + 10;
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 20 + this->box_width + SETTING_BUTTON_WIDTH); uint text_left = ir.left + (rtl ? 0 : 20 + this->box.width + SETTING_BUTTON_WIDTH);
uint text_right = r.right - (rtl ? 20 + this->box_width + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT); uint text_right = ir.right - (rtl ? 20 + this->box.width + SETTING_BUTTON_WIDTH : 0);
int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2; int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
int icon_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2; int box_y_offset = (this->line_height - this->box.height) / 2;
int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
int icon_y_offset = (this->line_height - this->icon.height) / 2;
for (int i = 0; i != lengthof(_cheats_ui); i++) { for (int i = 0; i != lengthof(_cheats_ui); i++) {
const CheatEntry *ce = &_cheats_ui[i]; const CheatEntry *ce = &_cheats_ui[i];
DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + icon_y_offset + 2); DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + box_y_offset);
switch (ce->type) { switch (ce->type) {
case SLE_BOOL: { case SLE_BOOL: {
@ -258,7 +268,7 @@ struct CheatWindow : Window {
char buf[512]; char buf[512];
/* Draw [<][>] boxes for settings of an integer-type */ /* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(button_left, y + icon_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true); DrawArrowButtons(button_left, y + button_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
switch (ce->str) { switch (ce->str) {
/* Display date for change date cheat */ /* Display date for change date cheat */
@ -269,7 +279,7 @@ struct CheatWindow : Window {
SetDParam(0, val + 1); SetDParam(0, val + 1);
GetString(buf, STR_CHEAT_CHANGE_COMPANY, lastof(buf)); GetString(buf, STR_CHEAT_CHANGE_COMPANY, lastof(buf));
uint offset = 10 + GetStringBoundingBox(buf).width; uint offset = 10 + GetStringBoundingBox(buf).width;
DrawCompanyIcon(_local_company, rtl ? text_right - offset - 10 : text_left + offset, y + icon_y_offset + 2); DrawCompanyIcon(_local_company, rtl ? text_right - offset - 10 : text_left + offset, y + icon_y_offset);
break; break;
} }
@ -327,15 +337,15 @@ struct CheatWindow : Window {
this->line_height = std::max<uint>(this->line_height, SETTING_BUTTON_HEIGHT); this->line_height = std::max<uint>(this->line_height, SETTING_BUTTON_HEIGHT);
this->line_height = std::max<uint>(this->line_height, FONT_HEIGHT_NORMAL) + WD_PAR_VSEP_NORMAL; this->line_height = std::max<uint>(this->line_height, FONT_HEIGHT_NORMAL) + WD_PAR_VSEP_NORMAL;
size->width = width + 20 + this->box_width + SETTING_BUTTON_WIDTH /* stuff on the left */ + 10 /* extra spacing on right */; size->width = width + 20 + this->box.width + SETTING_BUTTON_WIDTH /* stuff on the left */ + 10 /* extra spacing on right */;
size->height = WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + this->line_height * lengthof(_cheats_ui); size->height = WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + this->line_height * lengthof(_cheats_ui);
} }
void OnClick(Point pt, int widget, int click_count) override void OnClick(Point pt, int widget, int click_count) override
{ {
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_C_PANEL); const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_C_PANEL);
uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - WD_PAR_VSEP_NORMAL) / this->line_height; uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP) / this->line_height;
int x = pt.x - wid->pos_x; uint x = pt.x - wid->pos_x;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
if (rtl) x = wid->current_x - x; if (rtl) x = wid->current_x - x;
@ -345,13 +355,13 @@ struct CheatWindow : Window {
int value = (int32)ReadValue(ce->variable, ce->type); int value = (int32)ReadValue(ce->variable, ce->type);
int oldvalue = value; int oldvalue = value;
if (btn == CHT_CHANGE_DATE && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) { if (btn == CHT_CHANGE_DATE && x >= 20 + this->box.width + SETTING_BUTTON_WIDTH) {
/* Click at the date text directly. */ /* Click at the date text directly. */
clicked_widget = CHT_CHANGE_DATE; clicked_widget = CHT_CHANGE_DATE;
SetDParam(0, value); SetDParam(0, value);
ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
return; return;
} else if (btn == CHT_EDIT_MAX_HL && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) { } else if (btn == CHT_EDIT_MAX_HL && x >= 20 + this->box.width + SETTING_BUTTON_WIDTH) {
clicked_widget = CHT_EDIT_MAX_HL; clicked_widget = CHT_EDIT_MAX_HL;
SetDParam(0, value); SetDParam(0, value);
ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
@ -359,7 +369,7 @@ struct CheatWindow : Window {
} }
/* Not clicking a button? */ /* Not clicking a button? */
if (!IsInsideMM(x, 10 + this->box_width, 10 + this->box_width + SETTING_BUTTON_WIDTH)) return; if (!IsInsideMM(x, 10 + this->box.width, 10 + this->box.width + SETTING_BUTTON_WIDTH)) return;
*ce->been_used = true; *ce->been_used = true;
@ -371,10 +381,10 @@ struct CheatWindow : Window {
default: default:
/* Take whatever the function returns */ /* Take whatever the function returns */
value = ce->proc(value + ((x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1); value = ce->proc(value + ((x >= 10 + this->box.width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 10 + this->box.width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
/* The first cheat (money), doesn't return a different value. */ /* The first cheat (money), doesn't return a different value. */
if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0); if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 10 + this->box.width + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
break; break;
} }

View File

@ -159,16 +159,15 @@ static uint GetMaxCategoriesWidth()
*/ */
static void DrawCategory(const Rect &r, int start_y, ExpensesList list) static void DrawCategory(const Rect &r, int start_y, ExpensesList list)
{ {
int offs_left = _current_text_dir == TD_LTR ? EXP_INDENT : 0; Rect tr = r.Indent(EXP_INDENT, _current_text_dir == TD_RTL);
int offs_right = _current_text_dir == TD_LTR ? 0 : EXP_INDENT;
int y = start_y; tr.top = start_y;
ExpensesType et; ExpensesType et;
for (uint i = 0; i < list.length; i++) { for (uint i = 0; i < list.length; i++) {
et = list.et[i]; et = list.et[i];
DrawString(r.left + offs_left, r.right - offs_right, y, STR_FINANCES_SECTION_CONSTRUCTION + et); DrawString(tr, STR_FINANCES_SECTION_CONSTRUCTION + et);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
} }
} }
@ -608,11 +607,12 @@ public:
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int icon_y = CenterBounds(r.top, r.bottom, 0); int icon_y = CenterBounds(r.top, r.bottom, 0);
int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL); int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL);
Rect tr = r.Shrink(WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_TOP, WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_BOTTOM);
DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + (this->result % COLOUR_END), DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + (this->result % COLOUR_END),
rtl ? r.right - 2 - ScaleGUITrad(14) : r.left + ScaleGUITrad(14) + 2, rtl ? tr.right - ScaleGUITrad(14) : tr.left + ScaleGUITrad(14),
icon_y); icon_y);
DrawString(rtl ? r.left + 2 : r.left + ScaleGUITrad(28) + 4, DrawString(rtl ? tr.left : tr.left + ScaleGUITrad(28) + 2,
rtl ? r.right - ScaleGUITrad(28) - 4 : r.right - 2, rtl ? tr.right - ScaleGUITrad(28) - 2 : tr.right,
text_y, this->String(), sel ? TC_WHITE : TC_BLACK); text_y, this->String(), sel ? TC_WHITE : TC_BLACK);
} }
}; };
@ -917,40 +917,41 @@ public:
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
/* Horizontal coordinates of scheme name column. */ /* Coordinates of scheme name column. */
const NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SCL_SPACER_DROPDOWN); const NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SCL_SPACER_DROPDOWN);
int sch_left = nwi->pos_x; Rect sch = nwi->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int sch_right = sch_left + nwi->current_x - 1; /* Coordinates of first dropdown. */
/* Horizontal coordinates of first dropdown. */
nwi = this->GetWidget<NWidgetBase>(WID_SCL_PRI_COL_DROPDOWN); nwi = this->GetWidget<NWidgetBase>(WID_SCL_PRI_COL_DROPDOWN);
int pri_left = nwi->pos_x; Rect pri = nwi->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int pri_right = pri_left + nwi->current_x - 1; /* Coordinates of second dropdown. */
/* Horizontal coordinates of second dropdown. */
nwi = this->GetWidget<NWidgetBase>(WID_SCL_SEC_COL_DROPDOWN); nwi = this->GetWidget<NWidgetBase>(WID_SCL_SEC_COL_DROPDOWN);
int sec_left = nwi->pos_x; Rect sec = nwi->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int sec_right = sec_left + nwi->current_x - 1;
int text_left = (rtl ? (uint)WD_FRAMERECT_LEFT : (this->square.width + 5)); Rect pri_squ = pri.WithWidth(this->square.width, rtl);
int text_right = (rtl ? (this->square.width + 5) : (uint)WD_FRAMERECT_RIGHT); Rect sec_squ = sec.WithWidth(this->square.width, rtl);
int square_offs = (this->line_height - this->square.height) / 2 + 1; pri = pri.Indent(this->square.width + ScaleGUITrad(2), rtl);
int text_offs = (this->line_height - FONT_HEIGHT_NORMAL) / 2 + 1; sec = sec.Indent(this->square.width + ScaleGUITrad(2), rtl);
int y = r.top; Rect ir = r.WithHeight(this->resize.step_height).Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
int square_offs = (ir.Height() - this->square.height) / 2;
int text_offs = (ir.Height() - FONT_HEIGHT_NORMAL) / 2;
int y = ir.top;
/* Helper function to draw livery info. */ /* Helper function to draw livery info. */
auto draw_livery = [&](StringID str, const Livery &liv, bool sel, bool def, int indent) { auto draw_livery = [&](StringID str, const Livery &liv, bool sel, bool def, int indent) {
/* Livery Label. */ /* Livery Label. */
DrawString(sch_left + WD_FRAMERECT_LEFT + (rtl ? 0 : indent), sch_right - WD_FRAMERECT_RIGHT - (rtl ? indent : 0), y + text_offs, str, sel ? TC_WHITE : TC_BLACK); DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, sel ? TC_WHITE : TC_BLACK);
/* Text below the first dropdown. */ /* Text below the first dropdown. */
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(liv.colour1), (rtl ? pri_right - (this->square.width + 5) + WD_FRAMERECT_RIGHT : pri_left) + WD_FRAMERECT_LEFT, y + square_offs); DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(liv.colour1), pri_squ.left, y + square_offs);
DrawString(pri_left + text_left, pri_right - text_right, y + text_offs, (def || HasBit(liv.in_use, 0)) ? STR_COLOUR_DARK_BLUE + liv.colour1 : STR_COLOUR_DEFAULT, sel ? TC_WHITE : TC_GOLD); DrawString(pri.left, pri.right, y + text_offs, (def || HasBit(liv.in_use, 0)) ? STR_COLOUR_DARK_BLUE + liv.colour1 : STR_COLOUR_DEFAULT, sel ? TC_WHITE : TC_GOLD);
/* Text below the second dropdown. */ /* Text below the second dropdown. */
if (sec_right > sec_left) { // Second dropdown has non-zero size. if (sec.right > sec.left) { // Second dropdown has non-zero size.
DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(liv.colour2), (rtl ? sec_right - (this->square.width + 5) + WD_FRAMERECT_RIGHT : sec_left) + WD_FRAMERECT_LEFT, y + square_offs); DrawSprite(SPR_SQUARE, GENERAL_SPRITE_COLOUR(liv.colour2), sec_squ.left, y + square_offs);
DrawString(sec_left + text_left, sec_right - text_right, y + text_offs, (def || HasBit(liv.in_use, 1)) ? STR_COLOUR_DARK_BLUE + liv.colour2 : STR_COLOUR_DEFAULT, sel ? TC_WHITE : TC_GOLD); DrawString(sec.left, sec.right, y + text_offs, (def || HasBit(liv.in_use, 1)) ? STR_COLOUR_DARK_BLUE + liv.colour2 : STR_COLOUR_DEFAULT, sel ? TC_WHITE : TC_GOLD);
} }
y += this->line_height; y += this->line_height;
@ -1795,7 +1796,7 @@ static const NWidgetPart _nested_company_infrastructure_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_GREY), NWidget(WWT_STICKYBOX, COLOUR_GREY),
EndContainer(), EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_VERTICAL), SetPIP(WD_FRAMERECT_TOP, 4, WD_FRAMETEXT_BOTTOM), NWidget(NWID_VERTICAL), SetPIP(WD_FRAMERECT_TOP, WD_PAR_VSEP_NORMAL * 2, WD_FRAMERECT_BOTTOM),
NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2), NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0), NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_DESC), SetMinimalTextLines(2, 0), SetFill(1, 0),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1), NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_RAIL_COUNT), SetMinimalTextLines(2, 0), SetFill(0, 1),
@ -2025,8 +2026,8 @@ struct CompanyInfrastructureWindow : Window
if (_settings_game.economy.infrastructure_maintenance) { if (_settings_game.economy.infrastructure_maintenance) {
SetDParam(0, monthly_cost * 12); // Convert to per year SetDParam(0, monthly_cost * 12); // Convert to per year
int left = _current_text_dir == TD_RTL ? r.right - this->total_width : r.left; Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
DrawString(left, left + this->total_width, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING, SA_RIGHT); DrawString(tr.left, tr.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING, SA_RIGHT);
} }
} }
@ -2109,11 +2110,11 @@ struct CompanyInfrastructureWindow : Window
case WID_CI_TOTAL: case WID_CI_TOTAL:
if (_settings_game.economy.infrastructure_maintenance) { if (_settings_game.economy.infrastructure_maintenance) {
int left = _current_text_dir == TD_RTL ? r.right - this->total_width : r.left; Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
GfxFillRect(left, y, left + this->total_width, y, PC_WHITE); GfxFillRect(tr.left, y, tr.right, y, PC_WHITE);
y += EXP_LINESPACE; y += EXP_LINESPACE;
SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
DrawString(left, left + this->total_width, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING, SA_RIGHT); DrawString(tr.left, tr.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING, SA_RIGHT);
} }
break; break;

View File

@ -287,8 +287,8 @@ public:
int extra = (r.Height() - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2; int extra = (r.Height() - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2;
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */ /* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
DrawStringMultiLine(r.SetHeight(this->height_summary + extra, false), this->summary_msg, TC_WHITE, SA_CENTER); DrawStringMultiLine(r.WithHeight(this->height_summary + extra, false), this->summary_msg, TC_WHITE, SA_CENTER);
DrawStringMultiLine(r.SetHeight(this->height_detailed + extra, true), this->detailed_msg, TC_WHITE, SA_CENTER); DrawStringMultiLine(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg, TC_WHITE, SA_CENTER);
} }
if (this->textref_stack_size > 0) StopTextRefStackUsage(); if (this->textref_stack_size > 0) StopTextRefStackUsage();

View File

@ -437,18 +437,21 @@ public:
_fios_path_changed = false; _fios_path_changed = false;
} }
Rect ir = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
if (str != STR_ERROR_UNABLE_TO_READ_DRIVE) SetDParam(0, tot); if (str != STR_ERROR_UNABLE_TO_READ_DRIVE) SetDParam(0, tot);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP, str); DrawString(ir.left, ir.right, ir.top + FONT_HEIGHT_NORMAL, str);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, path, TC_BLACK); DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
break; break;
} }
case WID_SL_DRIVES_DIRECTORIES_LIST: { case WID_SL_DRIVES_DIRECTORIES_LIST: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK); const Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
GfxFillRect(br, PC_BLACK);
uint y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_INSET_LEFT, WD_INSET_TOP, WD_INSET_RIGHT, 0).WithHeight(this->resize.step_height);
uint scroll_pos = this->vscroll->GetPosition(); uint scroll_pos = this->vscroll->GetPosition();
for (uint row = 0; row < this->fios_items.size(); row++) { for (uint row = 0; row < this->fios_items.size() && tr.top < br.bottom; row++) {
if (!this->fios_items_shown[row]) { if (!this->fios_items_shown[row]) {
/* The current item is filtered out : we do not show it */ /* The current item is filtered out : we do not show it */
scroll_pos++; scroll_pos++;
@ -458,107 +461,117 @@ public:
const FiosItem *item = &this->fios_items[row]; const FiosItem *item = &this->fios_items[row];
if (item == this->selected) { if (item == this->selected) {
GfxFillRect(r.left + 1, y, r.right - 1, y + this->resize.step_height - 1, PC_DARK_BLUE); GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_DARK_BLUE);
} else if (item == this->highlighted) { } else if (item == this->highlighted) {
GfxFillRect(r.left + 1, y, r.right - 1, y + this->resize.step_height - 1, PC_VERY_DARK_BLUE); GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_VERY_DARK_BLUE);
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[GetDetailedFileType(item->type)]); DrawString(tr, item->title, _fios_colours[GetDetailedFileType(item->type)]);
y += this->resize.step_height; tr = tr.Translate(0, this->resize.step_height);
if (y >= this->vscroll->GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break;
} }
break; break;
} }
case WID_SL_DETAILS: { case WID_SL_DETAILS:
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + FONT_HEIGHT_NORMAL * 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, PC_GREY); this->DrawDetails(r);
DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL / 2 + WD_FRAMERECT_TOP, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
if (this->selected == nullptr) break;
uint y = r.top + FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
uint y_max = r.bottom - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM;
if (y > y_max) break;
if (!_load_check_data.checkable) {
/* Old savegame, no information available */
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
y += FONT_HEIGHT_NORMAL;
} else if (_load_check_data.error != INVALID_STRING_ID) {
/* Incompatible / broken savegame */
SetDParamStr(0, _load_check_data.error_data);
y = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT,
y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.error, TC_RED);
} else {
/* Mapsize */
SetDParam(0, _load_check_data.map_size_x);
SetDParam(1, _load_check_data.map_size_y);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_MAP_SIZE);
y += FONT_HEIGHT_NORMAL;
if (y > y_max) break;
/* Climate */
byte landscape = _load_check_data.settings.game_creation.landscape;
if (landscape < NUM_LANDSCAPE) {
SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_LANDSCAPE);
y += FONT_HEIGHT_NORMAL;
}
y += WD_PAR_VSEP_NORMAL;
if (y > y_max) break;
/* Start date (if available) */
if (_load_check_data.settings.game_creation.starting_year != 0) {
SetDParam(0, ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1));
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_START_DATE);
y += FONT_HEIGHT_NORMAL;
}
if (y > y_max) break;
/* Hide current date for scenarios */
if (this->abstract_filetype != FT_SCENARIO) {
/* Current date */
SetDParam(0, _load_check_data.current_date);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
y += FONT_HEIGHT_NORMAL;
}
/* Hide the NewGRF stuff when saving. We also hide the button. */
if (this->fop == SLO_LOAD && (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO)) {
y += WD_PAR_VSEP_NORMAL;
if (y > y_max) break;
/* NewGrf compatibility */
SetDParam(0, _load_check_data.grfconfig == nullptr ? STR_NEWGRF_LIST_NONE :
STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_GRFSTATUS);
y += FONT_HEIGHT_NORMAL;
}
if (y > y_max) break;
/* Hide the company stuff for scenarios */
if (this->abstract_filetype != FT_SCENARIO) {
y += FONT_HEIGHT_NORMAL;
if (y > y_max) break;
/* Companies / AIs */
for (auto &pair : _load_check_data.companies) {
SetDParam(0, pair.first + 1);
const CompanyProperties &c = *pair.second;
if (!c.name.empty()) {
SetDParam(1, STR_JUST_RAW_STRING);
SetDParamStr(2, c.name);
} else {
SetDParam(1, c.name_1);
SetDParam(2, c.name_2);
}
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
y += FONT_HEIGHT_NORMAL;
if (y > y_max) break;
}
}
}
break; break;
}
}
void DrawDetails(const Rect &r) const
{
/* Header panel */
int HEADER_HEIGHT = FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
Rect tr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
tr.top += HEADER_HEIGHT;
/* Create the nice grayish rectangle at the details top */
GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, 0), PC_GREY);
DrawString(hr.left, hr.right, hr.top, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
if (this->selected == nullptr) return;
/* Details panel */
tr.bottom -= FONT_HEIGHT_NORMAL - 1;
if (tr.top > tr.bottom) return;
if (!_load_check_data.checkable) {
/* Old savegame, no information available */
DrawString(tr, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
tr.top += FONT_HEIGHT_NORMAL;
} else if (_load_check_data.error != INVALID_STRING_ID) {
/* Incompatible / broken savegame */
SetDParamStr(0, _load_check_data.error_data);
tr.top = DrawStringMultiLine(tr, _load_check_data.error, TC_RED);
} else {
/* Mapsize */
SetDParam(0, _load_check_data.map_size_x);
SetDParam(1, _load_check_data.map_size_y);
DrawString(tr, STR_NETWORK_SERVER_LIST_MAP_SIZE);
tr.top += FONT_HEIGHT_NORMAL;
if (tr.top > tr.bottom) return;
/* Climate */
byte landscape = _load_check_data.settings.game_creation.landscape;
if (landscape < NUM_LANDSCAPE) {
SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
DrawString(tr, STR_NETWORK_SERVER_LIST_LANDSCAPE);
tr.top += FONT_HEIGHT_NORMAL;
}
tr.top += WD_PAR_VSEP_WIDE;
if (tr.top > tr.bottom) return;
/* Start date (if available) */
if (_load_check_data.settings.game_creation.starting_year != 0) {
SetDParam(0, ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1));
DrawString(tr, STR_NETWORK_SERVER_LIST_START_DATE);
tr.top += FONT_HEIGHT_NORMAL;
}
if (tr.top > tr.bottom) return;
/* Hide current date for scenarios */
if (this->abstract_filetype != FT_SCENARIO) {
/* Current date */
SetDParam(0, _load_check_data.current_date);
DrawString(tr, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
tr.top += FONT_HEIGHT_NORMAL;
}
/* Hide the NewGRF stuff when saving. We also hide the button. */
if (this->fop == SLO_LOAD && (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO)) {
tr.top += WD_PAR_VSEP_NORMAL;
if (tr.top > tr.bottom) return;
/* NewGrf compatibility */
SetDParam(0, _load_check_data.grfconfig == nullptr ? STR_NEWGRF_LIST_NONE :
STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility);
DrawString(tr, STR_SAVELOAD_DETAIL_GRFSTATUS);
tr.top += FONT_HEIGHT_NORMAL;
}
if (tr.top > tr.bottom) return;
/* Hide the company stuff for scenarios */
if (this->abstract_filetype != FT_SCENARIO) {
tr.top += WD_PAR_VSEP_WIDE;
if (tr.top > tr.bottom) return;
/* Companies / AIs */
for (auto &pair : _load_check_data.companies) {
SetDParam(0, pair.first + 1);
const CompanyProperties &c = *pair.second;
if (!c.name.empty()) {
SetDParam(1, STR_JUST_RAW_STRING);
SetDParamStr(2, c.name);
} else {
SetDParam(1, c.name_1);
SetDParam(2, c.name_2);
}
DrawString(tr, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
tr.top += FONT_HEIGHT_NORMAL;
if (tr.top > tr.bottom) break;
}
} }
} }
} }

View File

@ -186,7 +186,7 @@ struct GSConfigWindow : public Window {
} }
/* There is only one slot, unlike with the GS GUI, so it should never be white */ /* There is only one slot, unlike with the GS GUI, so it should never be white */
DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text, (IsEditable() ? TC_ORANGE : TC_SILVER)); DrawString(r.Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM), text, (IsEditable() ? TC_ORANGE : TC_SILVER));
break; break;
} }
case WID_GSC_SETTINGS: { case WID_GSC_SETTINGS: {
@ -195,11 +195,10 @@ struct GSConfigWindow : public Window {
int i = 0; int i = 0;
for (; !this->vscroll->IsVisible(i); i++) it++; for (; !this->vscroll->IsVisible(i); i++) it++;
Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4; Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8); Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + 8, rtl);
uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
int y = r.top; int y = r.top;
int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2; int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
@ -228,13 +227,13 @@ struct GSConfigWindow : public Window {
} }
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) { if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable); DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON); SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
} else { } else {
if (config_item.complete_labels) { if (config_item.complete_labels) {
DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable); DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
} else { } else {
DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value); DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
} }
if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) { if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
SetDParam(idx++, STR_JUST_RAW_STRING); SetDParam(idx++, STR_JUST_RAW_STRING);
@ -245,7 +244,7 @@ struct GSConfigWindow : public Window {
} }
} }
DrawString(text_left, text_right, y + text_y_offset, str, colour); DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
y += this->line_height; y += this->line_height;
} }
break; break;
@ -289,9 +288,10 @@ struct GSConfigWindow : public Window {
ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_GAME); ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_GAME);
} }
break; break;
case WID_GSC_SETTINGS: { case WID_GSC_SETTINGS: {
const NWidgetBase* wid = this->GetWidget<NWidgetBase>(WID_GSC_SETTINGS); Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WD_MATRIX_LEFT, 0, WD_MATRIX_RIGHT, 0);
int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition(); int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
if (num >= (int)this->visible_settings.size()) break; if (num >= (int)this->visible_settings.size()) break;
VisibleSettingsList::const_iterator it = this->visible_settings.begin(); VisibleSettingsList::const_iterator it = this->visible_settings.begin();
@ -308,9 +308,8 @@ struct GSConfigWindow : public Window {
bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0; bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
int x = pt.x - wid->pos_x; int x = pt.x - r.left;
if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x; if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
x -= 4;
/* One of the arrows is clicked (or green/red rect in case of bool value) */ /* One of the arrows is clicked (or green/red rect in case of bool value) */
int old_val = this->gs_config->GetSetting(config_item.name); int old_val = this->gs_config->GetSetting(config_item.name);
@ -321,8 +320,7 @@ struct GSConfigWindow : public Window {
this->clicked_dropdown = false; this->clicked_dropdown = false;
this->closing_dropdown = false; this->closing_dropdown = false;
} else { } else {
const NWidgetBase* wid = this->GetWidget<NWidgetBase>(WID_GSC_SETTINGS); int rel_y = (pt.y - r.top) % this->line_height;
int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
Rect wi_rect; Rect wi_rect;
wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x); wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);

View File

@ -1422,13 +1422,15 @@ struct GenerateProgressWindow : public Window {
void DrawWidget(const Rect &r, int widget) const override void DrawWidget(const Rect &r, int widget) const override
{ {
switch (widget) { switch (widget) {
case WID_GP_PROGRESS_BAR: case WID_GP_PROGRESS_BAR: {
/* Draw the % complete with a bar and a text */ /* Draw the % complete with a bar and a text */
DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY); DrawFrameRect(r, COLOUR_GREY, FR_BORDERONLY);
DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * _gws.percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE); Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
DrawFrameRect(br.WithWidth(br.Width() * _gws.percent / 100, false), COLOUR_MAUVE, FR_NONE);
SetDParam(0, _gws.percent); SetDParam(0, _gws.percent);
DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER); DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
break; break;
}
case WID_GP_PROGRESS_TEXT: case WID_GP_PROGRESS_TEXT:
/* Tell which class we are generating */ /* Tell which class we are generating */

View File

@ -192,9 +192,7 @@ struct GoalListWindow : public Window {
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
{ {
/* Get column draw area. */ /* Get column draw area. */
int y = wid->pos_y + WD_FRAMERECT_TOP; Rect r = wid->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int x = wid->pos_x + WD_FRAMERECT_LEFT;
int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int pos = -this->vscroll->GetPosition(); int pos = -this->vscroll->GetPosition();
@ -209,7 +207,7 @@ struct GoalListWindow : public Window {
/* Display the goal. */ /* Display the goal. */
SetDParamStr(0, s->text); SetDParamStr(0, s->text);
uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0; uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT); DrawString(r.Indent(width_reduction, !rtl), STR_GOALS_TEXT);
break; break;
} }
@ -217,12 +215,11 @@ struct GoalListWindow : public Window {
if (s->progress != nullptr) { if (s->progress != nullptr) {
SetDParamStr(0, s->progress); SetDParamStr(0, s->progress);
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS; StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
int progress_x = x; DrawString(r.WithWidth(progress_col_width, !rtl), str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
int progress_right = rtl ? x + progress_col_width : right;
DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
} }
break; break;
} }
r.top += FONT_HEIGHT_NORMAL;
} }
pos++; pos++;
num++; num++;
@ -231,9 +228,8 @@ struct GoalListWindow : public Window {
if (num == 0) { if (num == 0) {
if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) { if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE); DrawString(r, STR_GOALS_NONE);
} }
pos++;
} }
} }
@ -297,8 +293,7 @@ static const NWidgetPart _nested_goals_list_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_BROWN), NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(), EndContainer(),
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR), NWidget(WWT_PANEL, COLOUR_BROWN, WID_GOAL_LIST), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR), SetResize(1, 1), SetMinimalTextLines(2, 0),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_GOAL_LIST), SetResize(1, 1), SetMinimalTextLines(2, 0), SetFill(1, 1), SetPadding(WD_FRAMERECT_TOP, 2, WD_FRAMETEXT_BOTTOM, 2),
EndContainer(), EndContainer(),
NWidget(NWID_VERTICAL), NWidget(NWID_VERTICAL),
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR), NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
@ -412,7 +407,7 @@ struct GoalQuestionWindow : public Window {
if (widget != WID_GQ_QUESTION) return; if (widget != WID_GQ_QUESTION) return;
SetDParamStr(0, this->question); SetDParamStr(0, this->question);
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER); DrawStringMultiLine(r, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
} }
}; };

View File

@ -65,12 +65,14 @@ struct GraphLegendWindow : Window {
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
const Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
Dimension d = GetSpriteSize(SPR_COMPANY_ICON); Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, rtl ? r.right - d.width - ScaleGUITrad(2) : r.left + ScaleGUITrad(2), CenterBounds(r.top, r.bottom, d.height)); DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CenterBounds(ir.top, ir.bottom, d.height));
const Rect tr = ir.Indent(d.width + ScaleGUITrad(2), rtl);
SetDParam(0, cid); SetDParam(0, cid);
SetDParam(1, cid); SetDParam(1, cid);
DrawString(r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : (d.width + ScaleGUITrad(4))), r.right - (rtl ? (d.width + ScaleGUITrad(4)) : (uint)WD_FRAMERECT_RIGHT), CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE); DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, FONT_HEIGHT_NORMAL), STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
} }
void OnClick(Point pt, int widget, int click_count) override void OnClick(Point pt, int widget, int click_count) override
@ -943,32 +945,31 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int x = r.left + WD_FRAMERECT_LEFT;
int y = r.top;
uint row_height = FONT_HEIGHT_SMALL;
int padding = ScaleFontTrad(1);
int pos = this->vscroll->GetPosition(); int pos = this->vscroll->GetPosition();
int max = pos + this->vscroll->GetCapacity(); int max = pos + this->vscroll->GetCapacity();
Rect line = r.WithHeight(this->line_height);
for (const CargoSpec *cs : _sorted_standard_cargo_specs) { for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
if (pos-- > 0) continue; if (pos-- > 0) continue;
if (--max < 0) break; if (--max < 0) break;
bool lowered = !HasBit(_legend_excluded_cargo, cs->Index()); bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
/* Redraw box if lowered */ /* Redraw frame if lowered */
if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_BROWN, FR_LOWERED); if (lowered) DrawFrameRect(line, COLOUR_BROWN, FR_LOWERED);
byte clk_dif = lowered ? 1 : 0; const Rect text = line.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM).Translate(lowered ? 1 : 0, lowered ? 1 : 0);
int rect_x = clk_dif + (rtl ? r.right - this->legend_width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT);
GfxFillRect(rect_x, y + padding + clk_dif, rect_x + this->legend_width, y + row_height - 1 + clk_dif, PC_BLACK); /* Cargo-colour box with outline */
GfxFillRect(rect_x + 1, y + padding + 1 + clk_dif, rect_x + this->legend_width - 1, y + row_height - 2 + clk_dif, cs->legend_colour); const Rect cargo = text.WithWidth(this->legend_width, rtl);
GfxFillRect(cargo, PC_BLACK);
GfxFillRect(cargo.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), cs->legend_colour);
/* Cargo name */
SetDParam(0, cs->name); SetDParam(0, cs->name);
DrawString(rtl ? r.left : x + this->legend_width + 4 + clk_dif, (rtl ? r.right - this->legend_width - 4 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO); DrawString(text.Indent(this->legend_width + 4, rtl), STR_GRAPH_CARGO_PAYMENT_CARGO);
y += this->line_height; line = line.Translate(0, this->line_height);
} }
} }
@ -1132,8 +1133,8 @@ private:
GUIList<const Company*> companies; GUIList<const Company*> companies;
uint ordinal_width; ///< The width of the ordinal number uint ordinal_width; ///< The width of the ordinal number
uint text_width; ///< The width of the actual text uint text_width; ///< The width of the actual text
uint icon_width; ///< The width of the company icon
int line_height; ///< Height of the text lines int line_height; ///< Height of the text lines
Dimension icon; ///< Dimenion of the company icon.
/** /**
* (Re)Build the company league list * (Re)Build the company league list
@ -1178,27 +1179,26 @@ public:
{ {
if (widget != WID_CL_BACKGROUND) return; if (widget != WID_CL_BACKGROUND) return;
int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - this->line_height) / 2; Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint y = r.top + WD_FRAMERECT_TOP - icon_y_offset; int icon_y_offset = (this->line_height - this->icon.height) / 2;
int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint ordinal_left = rtl ? r.right - WD_FRAMERECT_LEFT - this->ordinal_width : r.left + WD_FRAMERECT_LEFT; Rect ordinal = ir.WithWidth(this->ordinal_width, rtl);
uint ordinal_right = rtl ? r.right - WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->ordinal_width; uint icon_left = ir.Indent(rtl ? this->text_width : this->ordinal_width, rtl).left;
uint icon_left = r.left + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + (rtl ? this->text_width : this->ordinal_width); Rect text = ir.WithWidth(this->text_width, !rtl);
uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_LEFT - this->text_width;
uint text_right = rtl ? r.left + WD_FRAMERECT_LEFT + this->text_width : r.right - WD_FRAMERECT_LEFT;
for (uint i = 0; i != this->companies.size(); i++) { for (uint i = 0; i != this->companies.size(); i++) {
const Company *c = this->companies[i]; const Company *c = this->companies[i];
DrawString(ordinal_left, ordinal_right, y, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW); DrawString(ordinal.left, ordinal.right, ir.top + text_y_offset, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
DrawCompanyIcon(c->index, icon_left, y + icon_y_offset); DrawCompanyIcon(c->index, icon_left, ir.top + icon_y_offset);
SetDParam(0, c->index); SetDParam(0, c->index);
SetDParam(1, c->index); SetDParam(1, c->index);
SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history)); SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
DrawString(text_left, text_right, y, STR_COMPANY_LEAGUE_COMPANY_NAME); DrawString(text.left, text.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_NAME);
y += this->line_height; ir.top += this->line_height;
} }
} }
@ -1222,9 +1222,8 @@ public:
} }
} }
Dimension d = GetSpriteSize(SPR_COMPANY_ICON); this->icon = GetSpriteSize(SPR_COMPANY_ICON);
this->icon_width = d.width + 2; this->line_height = std::max<int>(this->icon.height + 2, FONT_HEIGHT_NORMAL);
this->line_height = std::max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
for (const Company *c : Company::Iterate()) { for (const Company *c : Company::Iterate()) {
SetDParam(0, c->index); SetDParam(0, c->index);
@ -1235,7 +1234,7 @@ public:
this->text_width = widest_width + 30; // Keep some extra spacing this->text_width = widest_width + 30; // Keep some extra spacing
size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon_width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT; size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon.width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM; size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM;
} }

View File

@ -563,25 +563,23 @@ public:
occupancy += v->trip_occupancy; occupancy += v->trip_occupancy;
} }
const int left = r.left + WD_FRAMERECT_LEFT + 8; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
const int right = r.right - WD_FRAMERECT_RIGHT - 8;
int y = r.top + WD_FRAMERECT_TOP; DrawString(tr, STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
DrawString(left, right, y, STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
SetDParam(0, this_year); SetDParam(0, this_year);
DrawString(left, right, y, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT); DrawString(tr, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
DrawString(left, right, y, STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK); DrawString(tr, STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
SetDParam(0, last_year); SetDParam(0, last_year);
DrawString(left, right, y, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT); DrawString(tr, STR_JUST_CURRENCY_LONG, TC_BLACK, SA_RIGHT);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
DrawString(left, right, y, STR_GROUP_OCCUPANCY, TC_BLACK); DrawString(tr, STR_GROUP_OCCUPANCY, TC_BLACK);
const size_t vehicle_count = this->vehicles.size(); const size_t vehicle_count = this->vehicles.size();
if (vehicle_count > 0) { if (vehicle_count > 0) {
SetDParam(0, occupancy / vehicle_count); SetDParam(0, occupancy / vehicle_count);
DrawString(left, right, y, STR_GROUP_OCCUPANCY_VALUE, TC_BLACK, SA_RIGHT); DrawString(tr, STR_GROUP_OCCUPANCY_VALUE, TC_BLACK, SA_RIGHT);
} }
break; break;
@ -612,14 +610,14 @@ public:
case WID_GL_LIST_VEHICLE: case WID_GL_LIST_VEHICLE:
if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) { if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) {
/* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */ /* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */
int y = r.top; Rect mr = r.WithHeight(this->resize.step_height);
uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size())); uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()));
for (uint i = this->vscroll->GetPosition(); i < max; ++i) { for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
const Vehicle *v = this->vehgroups[i].GetSingleVehicle(); const Vehicle *v = this->vehgroups[i].GetSingleVehicle();
if (v->group_id != this->vli.index) { if (v->group_id != this->vli.index) {
GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 2, _colour_gradient[COLOUR_GREY][3], FILLRECT_CHECKER); GfxFillRect(mr.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), _colour_gradient[COLOUR_GREY][3], FILLRECT_CHECKER);
} }
y += this->resize.step_height; mr = mr.Translate(0, this->resize.step_height);
} }
} }

View File

@ -513,52 +513,41 @@ public:
{ {
switch (widget) { switch (widget) {
case WID_DPI_MATRIX_WIDGET: { case WID_DPI_MATRIX_WIDGET: {
uint text_left, text_right, icon_left, icon_right; bool rtl = _current_text_dir == TD_RTL;
if (_current_text_dir == TD_RTL) { Rect text = r.WithHeight(this->resize.step_height).Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
icon_right = r.right - WD_MATRIX_RIGHT; Rect icon = text.WithWidth(this->legend.width, rtl);
icon_left = icon_right - this->legend.width; text = text.Indent(this->legend.width + ScaleFontTrad(7), rtl);
text_right = icon_left - ScaleFontTrad(7);
text_left = r.left + WD_MATRIX_LEFT;
} else {
icon_left = r.left + WD_MATRIX_LEFT;
icon_right = icon_left + this->legend.width;
text_left = icon_right + ScaleFontTrad(7);
text_right = r.right - WD_MATRIX_RIGHT;
}
/* Vertical offset for legend icon. */ /* Vertical offset for legend icon. */
int icon_top = (this->resize.step_height - this->legend.height + 1) / 2; icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
int icon_bottom = icon_top + this->legend.height; icon.bottom = icon.top + this->legend.height - 1;
int y = r.top; int y = r.top;
for (uint16 i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) { for (uint16 i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
bool selected = this->selected_index == i + this->vscroll->GetPosition(); bool selected = this->selected_index == i + this->vscroll->GetPosition();
if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) { if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
DrawString(text_left, text_right, y + WD_MATRIX_TOP, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE); DrawString(text, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
y += this->resize.step_height; } else {
continue; const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]);
/* Draw the name of the industry in white is selected, otherwise, in orange */
DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE);
GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
GfxFillRect(icon.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), indsp->map_colour);
} }
const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]);
/* Draw the name of the industry in white is selected, otherwise, in orange */ text = text.Translate(0, this->resize.step_height);
DrawString(text_left, text_right, y + WD_MATRIX_TOP, indsp->name, selected ? TC_WHITE : TC_ORANGE); icon = icon.Translate(0, this->resize.step_height);
GfxFillRect(icon_left, y + icon_top, icon_right, y + icon_bottom, selected ? PC_WHITE : PC_BLACK);
GfxFillRect(icon_left + 1, y + icon_top + 1, icon_right - 1, y + icon_bottom - 1, indsp->map_colour);
y += this->resize.step_height;
} }
break; break;
} }
case WID_DPI_INFOPANEL: { case WID_DPI_INFOPANEL: {
int y = r.top + WD_FRAMERECT_TOP; Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int bottom = r.bottom - WD_FRAMERECT_BOTTOM;
int left = r.left + WD_FRAMERECT_LEFT;
int right = r.right - WD_FRAMERECT_RIGHT;
if (this->selected_type == INVALID_INDUSTRYTYPE) { if (this->selected_type == INVALID_INDUSTRYTYPE) {
DrawStringMultiLine(left, right, y, bottom, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP); DrawStringMultiLine(ir, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
break; break;
} }
@ -566,8 +555,8 @@ public:
if (_game_mode != GM_EDITOR) { if (_game_mode != GM_EDITOR) {
SetDParam(0, indsp->GetConstructionCost()); SetDParam(0, indsp->GetConstructionCost());
DrawString(left, right, y, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST); DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
y += FONT_HEIGHT_NORMAL; ir.top += FONT_HEIGHT_NORMAL;
} }
CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)]; CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
@ -575,12 +564,12 @@ public:
/* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */ /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix); GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
y = DrawStringMultiLine(left, right, y, bottom, cargostring); ir.top = DrawStringMultiLine(ir, cargostring);
/* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */ /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix); GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
y = DrawStringMultiLine(left, right, y, bottom, cargostring); ir.top = DrawStringMultiLine(ir, cargostring);
/* Get the additional purchase info text, if it has not already been queried. */ /* Get the additional purchase info text, if it has not already been queried. */
if (HasBit(indsp->callback_mask, CBM_IND_FUND_MORE_TEXT)) { if (HasBit(indsp->callback_mask, CBM_IND_FUND_MORE_TEXT)) {
@ -592,7 +581,7 @@ public:
StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
if (str != STR_UNDEFINED) { if (str != STR_UNDEFINED) {
StartTextRefStackUsage(indsp->grf_prop.grffile, 6); StartTextRefStackUsage(indsp->grf_prop.grffile, 6);
DrawStringMultiLine(left, right, y, bottom, str, TC_YELLOW); DrawStringMultiLine(ir, str, TC_YELLOW);
StopTextRefStackUsage(); StopTextRefStackUsage();
} }
} }
@ -848,10 +837,10 @@ public:
if (this->IsShaded()) return; // Don't draw anything when the window is shaded. if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_IV_INFO); const Rect r = this->GetWidget<NWidgetBase>(WID_IV_INFO)->GetCurrentRect();
uint expected = this->DrawInfo(nwi->pos_x, nwi->pos_x + nwi->current_x - 1, nwi->pos_y) - nwi->pos_y; int expected = this->DrawInfo(r);
if (expected > nwi->current_y - 1) { if (expected > r.bottom) {
this->info_height = expected + 1; this->info_height = expected - r.top + 1;
this->ReInit(); this->ReInit();
return; return;
} }
@ -864,30 +853,29 @@ public:
* @param top Top edge of the panel. * @param top Top edge of the panel.
* @return Expected position of the bottom edge of the panel. * @return Expected position of the bottom edge of the panel.
*/ */
int DrawInfo(uint left, uint right, uint top) int DrawInfo(const Rect &r)
{ {
Industry *i = Industry::Get(this->window_number); Industry *i = Industry::Get(this->window_number);
const IndustrySpec *ind = GetIndustrySpec(i->type); const IndustrySpec *ind = GetIndustrySpec(i->type);
int y = top + WD_FRAMERECT_TOP; Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
bool first = true; bool first = true;
bool has_accept = false; bool has_accept = false;
if (i->prod_level == PRODLEVEL_CLOSURE) { if (i->prod_level == PRODLEVEL_CLOSURE) {
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE); DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
y += 2 * FONT_HEIGHT_NORMAL; ir.top += 2 * FONT_HEIGHT_NORMAL;
} }
CargoSuffix cargo_suffix[lengthof(i->accepts_cargo)]; CargoSuffix cargo_suffix[lengthof(i->accepts_cargo)];
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix); GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
bool stockpiling = HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS); bool stockpiling = HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS);
uint left_side = left + WD_FRAMERECT_LEFT * 4; // Indent accepted cargoes.
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) { for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (i->accepts_cargo[j] == CT_INVALID) continue; if (i->accepts_cargo[j] == CT_INVALID) continue;
has_accept = true; has_accept = true;
if (first) { if (first) {
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_REQUIRES); DrawString(ir, STR_INDUSTRY_VIEW_REQUIRES);
y += FONT_HEIGHT_NORMAL; ir.top += FONT_HEIGHT_NORMAL;
first = false; first = false;
} }
SetDParam(0, CargoSpec::Get(i->accepts_cargo[j])->name); SetDParam(0, CargoSpec::Get(i->accepts_cargo[j])->name);
@ -913,8 +901,8 @@ public:
default: default:
NOT_REACHED(); NOT_REACHED();
} }
DrawString(left_side, right - WD_FRAMERECT_RIGHT, y, str); DrawString(ir.Indent(10, _current_text_dir == TD_RTL), str);
y += FONT_HEIGHT_NORMAL; ir.top += FONT_HEIGHT_NORMAL;
} }
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, i->produced_cargo, cargo_suffix); GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, i->produced_cargo, cargo_suffix);
@ -922,10 +910,10 @@ public:
for (byte j = 0; j < lengthof(i->produced_cargo); j++) { for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->produced_cargo[j] == CT_INVALID) continue; if (i->produced_cargo[j] == CT_INVALID) continue;
if (first) { if (first) {
if (has_accept) y += WD_PAR_VSEP_WIDE; if (has_accept) ir.top += WD_PAR_VSEP_WIDE;
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE); DrawString(ir, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
y += FONT_HEIGHT_NORMAL; ir.top += FONT_HEIGHT_NORMAL;
if (this->editable == EA_RATE) this->production_offset_y = y; if (this->editable == EA_RATE) this->production_offset_y = ir.top;
first = false; first = false;
} }
@ -933,26 +921,24 @@ public:
SetDParam(1, i->last_month_production[j]); SetDParam(1, i->last_month_production[j]);
SetDParamStr(2, cargo_suffix[j].text); SetDParamStr(2, cargo_suffix[j].text);
SetDParam(3, ToPercent8(i->last_month_pct_transported[j])); SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
uint x = left + WD_FRAMETEXT_LEFT + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + 10 : 0); DrawString(ir.Indent(this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + 10 : 0, false), STR_INDUSTRY_VIEW_TRANSPORTED);
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
/* Let's put out those buttons.. */ /* Let's put out those buttons.. */
if (this->editable == EA_RATE) { if (this->editable == EA_RATE) {
DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0, DrawArrowButtons(ir.left, ir.top, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
i->production_rate[j] > 0, i->production_rate[j] < 255); i->production_rate[j] > 0, i->production_rate[j] < 255);
} }
y += FONT_HEIGHT_NORMAL; ir.top += FONT_HEIGHT_NORMAL;
} }
/* Display production multiplier if editable */ /* Display production multiplier if editable */
if (this->editable == EA_MULTIPLIER) { if (this->editable == EA_MULTIPLIER) {
y += WD_PAR_VSEP_WIDE; ir.top += WD_PAR_VSEP_WIDE;
this->production_offset_y = y; this->production_offset_y = ir.top;
SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT)); SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT));
uint x = left + WD_FRAMETEXT_LEFT + SETTING_BUTTON_WIDTH + 10; DrawString(ir.Indent(SETTING_BUTTON_WIDTH + 10, false), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LEVEL); DrawArrowButtons(ir.left, ir.top, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
i->prod_level > PRODLEVEL_MINIMUM, i->prod_level < PRODLEVEL_MAXIMUM); i->prod_level > PRODLEVEL_MINIMUM, i->prod_level < PRODLEVEL_MAXIMUM);
y += FONT_HEIGHT_NORMAL; ir.top += FONT_HEIGHT_NORMAL;
} }
/* Get the extra message for the GUI */ /* Get the extra message for the GUI */
@ -964,13 +950,13 @@ public:
} else { } else {
StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res); StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
if (message != STR_NULL && message != STR_UNDEFINED) { if (message != STR_NULL && message != STR_UNDEFINED) {
y += WD_PAR_VSEP_WIDE; ir.top += WD_PAR_VSEP_WIDE;
StartTextRefStackUsage(ind->grf_prop.grffile, 6); StartTextRefStackUsage(ind->grf_prop.grffile, 6);
/* Use all the available space left from where we stand up to the /* Use all the available space left from where we stand up to the
* end of the window. We ALSO enlarge the window if needed, so we * end of the window. We ALSO enlarge the window if needed, so we
* can 'go' wild with the bottom of the window. */ * can 'go' wild with the bottom of the window. */
y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, message, TC_BLACK); ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, message, TC_BLACK);
StopTextRefStackUsage(); StopTextRefStackUsage();
} }
} }
@ -979,11 +965,11 @@ public:
if (!i->text.empty()) { if (!i->text.empty()) {
SetDParamStr(0, i->text); SetDParamStr(0, i->text);
y += WD_PAR_VSEP_WIDE; ir.top += WD_PAR_VSEP_WIDE;
y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK); ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
} }
return y + WD_FRAMERECT_BOTTOM; return ir.top - 1 + WD_FRAMERECT_BOTTOM;
} }
void SetStringParameters(int widget) const override void SetStringParameters(int widget) const override
@ -1661,9 +1647,9 @@ public:
case WID_ID_INDUSTRY_LIST: { case WID_ID_INDUSTRY_LIST: {
int n = 0; int n = 0;
int y = r.top + WD_FRAMERECT_TOP; Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
if (this->industries.size() == 0) { if (this->industries.size() == 0) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_DIRECTORY_NONE); DrawString(ir, STR_INDUSTRY_DIRECTORY_NONE);
break; break;
} }
TextColour tc; TextColour tc;
@ -1676,9 +1662,9 @@ public:
tc = TC_GREY | TC_FORCED; tc = TC_GREY | TC_FORCED;
} }
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, this->GetIndustryString(this->industries[i]), tc); DrawString(ir, this->GetIndustryString(this->industries[i]), tc);
y += this->resize.step_height; ir.top += this->resize.step_height;
if (++n == this->vscroll->GetCapacity()) break; // max number of industries in 1 window if (++n == this->vscroll->GetCapacity()) break; // max number of industries in 1 window
} }
break; break;
@ -2920,14 +2906,13 @@ struct IndustryCargoesWindow : public Window {
{ {
if (widget != WID_IC_PANEL) return; if (widget != WID_IC_PANEL) return;
Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
DrawPixelInfo tmp_dpi, *old_dpi; DrawPixelInfo tmp_dpi, *old_dpi;
int width = r.Width(); if (!FillDrawPixelInfo(&tmp_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return;
int height = r.Height() - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM;
if (!FillDrawPixelInfo(&tmp_dpi, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, width, height)) return;
old_dpi = _cur_dpi; old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi; _cur_dpi = &tmp_dpi;
int left_pos = WD_FRAMERECT_LEFT; int left_pos = ir.left;
if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2; if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2;
int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2; int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;

View File

@ -610,15 +610,17 @@ void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, const
void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
{ {
Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
if (this->IsWidgetLowered(widget)) br = br.Translate(1, 1);
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) { if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return; if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST); CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON); Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height)); DrawCompanyIcon(cid, CenterBounds(br.left, br.right, sprite_size.width), CenterBounds(br.top, br.bottom, sprite_size.height));
} }
if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) { if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
uint8 colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST]; uint8 colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST];
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour); GfxFillRect(br, colour);
StringID str = STR_NULL; StringID str = STR_NULL;
if (widget == WID_LGL_SATURATION_FIRST) { if (widget == WID_LGL_SATURATION_FIRST) {
str = STR_LINKGRAPH_LEGEND_UNUSED; str = STR_LINKGRAPH_LEGEND_UNUSED;
@ -628,14 +630,14 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
str = STR_LINKGRAPH_LEGEND_SATURATED; str = STR_LINKGRAPH_LEGEND_SATURATED;
} }
if (str != STR_NULL) { if (str != STR_NULL) {
DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_SMALL), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER); DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, FONT_HEIGHT_SMALL), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER);
} }
} }
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) { if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return; if (this->IsWidgetDisabled(widget)) return;
CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST); CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, cargo->legend_colour); GfxFillRect(br, cargo->legend_colour);
DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_SMALL), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER); DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, FONT_HEIGHT_SMALL), cargo->abbrev, GetContrastColour(cargo->legend_colour, 73), SA_HOR_CENTER);
} }
} }

View File

@ -75,16 +75,15 @@ public:
{ {
if (widget != WID_LI_BACKGROUND) return; if (widget != WID_LI_BACKGROUND) return;
uint y = r.top + WD_TEXTPANEL_TOP; Rect ir = r.Shrink(WD_FRAMETEXT_LEFT, WD_TEXTPANEL_TOP, WD_FRAMETEXT_RIGHT, WD_TEXTPANEL_BOTTOM);
for (size_t i = 0; i < this->landinfo_data.size(); i++) { for (size_t i = 0; i < this->landinfo_data.size(); i++) {
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER); DrawString(ir, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; ir.top += FONT_HEIGHT_NORMAL + (i == 0 ? WD_PAR_VSEP_WIDE : WD_PAR_VSEP_NORMAL);
if (i == 0) y += 4;
} }
if (!this->cargo_acceptance.empty()) { if (!this->cargo_acceptance.empty()) {
SetDParamStr(0, this->cargo_acceptance); SetDParamStr(0, this->cargo_acceptance);
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_TEXTPANEL_BOTTOM, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER); DrawStringMultiLine(ir, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
} }
} }
@ -97,8 +96,7 @@ public:
uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT; uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
size->width = std::max(size->width, width); size->width = std::max(size->width, width);
size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; size->height += FONT_HEIGHT_NORMAL + (i == 0 ? WD_PAR_VSEP_WIDE : WD_PAR_VSEP_NORMAL);
if (i == 0) size->height += 4;
} }
if (!this->cargo_acceptance.empty()) { if (!this->cargo_acceptance.empty()) {
@ -730,13 +728,13 @@ struct TooltipsWindow : public Window
void DrawWidget(const Rect &r, int widget) const override void DrawWidget(const Rect &r, int widget) const override
{ {
/* There is only one widget. */ /* There is only one widget. */
GfxFillRect(r.left, r.top, r.right, r.bottom, PC_BLACK); GfxFillRect(r, PC_BLACK);
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_LIGHT_YELLOW); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_LIGHT_YELLOW);
for (uint arg = 0; arg < this->paramcount; arg++) { for (uint arg = 0; arg < this->paramcount; arg++) {
SetDParam(arg, this->params[arg]); SetDParam(arg, this->params[arg]);
} }
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, this->string_id, TC_FROMSTRING, SA_CENTER); DrawStringMultiLine(r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM), this->string_id, TC_FROMSTRING, SA_CENTER);
} }
void OnMouseLoop() override void OnMouseLoop() override
@ -1041,8 +1039,7 @@ struct QueryStringWindow : public Window
if (widget != WID_QS_WARNING) return; if (widget != WID_QS_WARNING) return;
if (this->flags & QSF_PASSWORD) { if (this->flags & QSF_PASSWORD) {
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT - WD_FRAMERECT_RIGHT, DrawStringMultiLine(r.Shrink(WD_FRAMERECT_LEFT + WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP + WD_FRAMETEXT_TOP, WD_FRAMERECT_RIGHT + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM + WD_FRAMETEXT_BOTTOM),
r.top + WD_FRAMERECT_TOP + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMERECT_BOTTOM - WD_FRAMETEXT_BOTTOM,
STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER);
} }
} }
@ -1194,7 +1191,7 @@ struct QueryWindow : public Window {
{ {
if (widget != WID_Q_TEXT) return; if (widget != WID_Q_TEXT) return;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, DrawStringMultiLine(r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM),
this->message, TC_FROMSTRING, SA_CENTER); this->message, TC_FROMSTRING, SA_CENTER);
} }

View File

@ -522,29 +522,29 @@ struct MusicTrackSelectionWindow : public Window {
{ {
switch (widget) { switch (widget) {
case WID_MTS_LIST_LEFT: { case WID_MTS_LIST_LEFT: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_BLACK);
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) { for (MusicSystem::Playlist::const_iterator song = _music.music_set.begin(); song != _music.music_set.end(); ++song) {
SetDParam(0, song->tracknr); SetDParam(0, song->tracknr);
SetDParam(1, 2); SetDParam(1, 2);
SetDParamStr(2, song->songname); SetDParamStr(2, song->songname);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_PLAYLIST_TRACK_NAME); DrawString(tr, STR_PLAYLIST_TRACK_NAME);
y += FONT_HEIGHT_SMALL; tr.top += FONT_HEIGHT_SMALL;
} }
break; break;
} }
case WID_MTS_LIST_RIGHT: { case WID_MTS_LIST_RIGHT: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_BLACK);
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
for (MusicSystem::Playlist::const_iterator song = _music.active_playlist.begin(); song != _music.active_playlist.end(); ++song) { for (MusicSystem::Playlist::const_iterator song = _music.active_playlist.begin(); song != _music.active_playlist.end(); ++song) {
SetDParam(0, song->tracknr); SetDParam(0, song->tracknr);
SetDParam(1, 2); SetDParam(1, 2);
SetDParamStr(2, song->songname); SetDParamStr(2, song->songname);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_PLAYLIST_TRACK_NAME); DrawString(tr, STR_PLAYLIST_TRACK_NAME);
y += FONT_HEIGHT_SMALL; tr.top += FONT_HEIGHT_SMALL;
} }
break; break;
} }
@ -712,7 +712,7 @@ struct MusicWindow : public Window {
{ {
switch (widget) { switch (widget) {
case WID_M_TRACK_NR: { case WID_M_TRACK_NR: {
GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, PC_BLACK); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, 0, WD_BEVEL_BOTTOM), PC_BLACK);
if (BaseMusic::GetUsedSet()->num_available == 0) { if (BaseMusic::GetUsedSet()->num_available == 0) {
break; break;
} }
@ -722,12 +722,12 @@ struct MusicWindow : public Window {
SetDParam(1, 2); SetDParam(1, 2);
str = STR_MUSIC_TRACK_DIGIT; str = STR_MUSIC_TRACK_DIGIT;
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str); DrawString(r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM), str);
break; break;
} }
case WID_M_TRACK_NAME: { case WID_M_TRACK_NAME: {
GfxFillRect(r.left, r.top + 1, r.right - 1, r.bottom, PC_BLACK); GfxFillRect(r.Shrink(0, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_BLACK);
StringID str = STR_MUSIC_TITLE_NONE; StringID str = STR_MUSIC_TITLE_NONE;
MusicSystem::PlaylistEntry entry(_music.GetCurrentSong()); MusicSystem::PlaylistEntry entry(_music.GetCurrentSong());
if (BaseMusic::GetUsedSet()->num_available == 0) { if (BaseMusic::GetUsedSet()->num_available == 0) {
@ -736,7 +736,7 @@ struct MusicWindow : public Window {
str = STR_MUSIC_TITLE_NAME; str = STR_MUSIC_TITLE_NAME;
SetDParamStr(0, entry.songname); SetDParamStr(0, entry.songname);
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_FROMSTRING, SA_HOR_CENTER); DrawString(r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM), str, TC_FROMSTRING, SA_HOR_CENTER);
break; break;
} }

View File

@ -616,17 +616,15 @@ public:
*/ */
void DrawMatrix(const Rect &r) const void DrawMatrix(const Rect &r) const
{ {
const NWidgetBase *nwi_checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX); Rect checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX)->GetCurrentRect();
const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(WID_NCL_NAME); Rect name = this->GetWidget<NWidgetBase>(WID_NCL_NAME)->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, 0, WD_FRAMERECT_RIGHT, 0);
const NWidgetBase *nwi_type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE); Rect type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE)->GetCurrentRect();
int line_height = std::max(this->checkbox_size.height, (uint)FONT_HEIGHT_NORMAL);
/* Fill the matrix with the information */ /* Fill the matrix with the information */
int sprite_y_offset = WD_MATRIX_TOP + (line_height - this->checkbox_size.height) / 2 - 1; int sprite_y_offset = (this->resize.step_height - this->checkbox_size.height) / 2;
int text_y_offset = WD_MATRIX_TOP + (line_height - FONT_HEIGHT_NORMAL) / 2; int text_y_offset = (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2;
uint y = r.top;
Rect mr = r.WithHeight(this->resize.step_height);
auto iter = this->content.begin() + this->vscroll->GetPosition(); auto iter = this->content.begin() + this->vscroll->GetPosition();
size_t last = this->vscroll->GetPosition() + this->vscroll->GetCapacity(); size_t last = this->vscroll->GetPosition() + this->vscroll->GetCapacity();
auto end = (last < this->content.size()) ? this->content.begin() + last : this->content.end(); auto end = (last < this->content.size()) ? this->content.begin() + last : this->content.end();
@ -634,7 +632,7 @@ public:
for (/**/; iter != end; iter++) { for (/**/; iter != end; iter++) {
const ContentInfo *ci = *iter; const ContentInfo *ci = *iter;
if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, PC_GREY); if (ci == this->selected) GfxFillRect(mr.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_GREY);
SpriteID sprite; SpriteID sprite;
SpriteID pal = PAL_NONE; SpriteID pal = PAL_NONE;
@ -646,13 +644,13 @@ public:
case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break; case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
DrawSprite(sprite, pal, nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), y + sprite_y_offset + (pal == PAL_NONE ? 1 : 0)); DrawSprite(sprite, pal, checkbox.left + (sprite == SPR_BLOT ? 3 : 2), mr.top + sprite_y_offset + (sprite == SPR_BLOT ? 0 : 1));
StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS; StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS;
DrawString(nwi_type->pos_x, nwi_type->pos_x + nwi_type->current_x - 1, y + text_y_offset, str, TC_BLACK, SA_HOR_CENTER); DrawString(type.left, type.right, mr.top + text_y_offset, str, TC_BLACK, SA_HOR_CENTER);
DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + text_y_offset, ci->name, TC_BLACK); DrawString(name.left, name.right, mr.top + text_y_offset, ci->name, TC_BLACK);
y += this->resize.step_height; mr = mr.Translate(0, this->resize.step_height);
} }
} }
@ -662,60 +660,59 @@ public:
*/ */
void DrawDetails(const Rect &r) const void DrawDetails(const Rect &r) const
{ {
static const int DETAIL_LEFT = 5; ///< Number of pixels at the left
static const int DETAIL_RIGHT = 5; ///< Number of pixels at the right
static const int DETAIL_TOP = 5; ///< Number of pixels at the top
/* Height for the title banner */ /* Height for the title banner */
int DETAIL_TITLE_HEIGHT = 5 * FONT_HEIGHT_NORMAL; int HEADER_HEIGHT = 3 * FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
Rect tr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
tr.top += HEADER_HEIGHT;
/* Create the nice grayish rectangle at the details top */ /* Create the nice grayish rectangle at the details top */
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + DETAIL_TITLE_HEIGHT, PC_DARK_BLUE); GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, 0), PC_DARK_BLUE);
DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + FONT_HEIGHT_NORMAL + WD_INSET_TOP, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER); DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
/* Draw the total download size */ /* Draw the total download size */
SetDParam(0, this->filesize_sum); SetDParam(0, this->filesize_sum);
DrawString(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_NORMAL, STR_CONTENT_TOTAL_DOWNLOAD_SIZE); DrawString(tr.left, tr.right, tr.bottom - FONT_HEIGHT_NORMAL + 1, STR_CONTENT_TOTAL_DOWNLOAD_SIZE);
if (this->selected == nullptr) return; if (this->selected == nullptr) return;
/* And fill the rest of the details when there's information to place there */ /* And fill the rest of the details when there's information to place there */
DrawStringMultiLine(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + DETAIL_TITLE_HEIGHT / 2, r.top + DETAIL_TITLE_HEIGHT, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER); DrawStringMultiLine(hr.left, hr.right, hr.top + FONT_HEIGHT_NORMAL, hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
/* Also show the total download size, so keep some space from the bottom */ /* Also show the total download size, so keep some space from the bottom */
const uint max_y = r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_WIDE; tr.bottom -= FONT_HEIGHT_NORMAL + WD_PAR_VSEP_WIDE;
int y = r.top + DETAIL_TITLE_HEIGHT + DETAIL_TOP;
if (this->selected->upgrade) { if (this->selected->upgrade) {
SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS); SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_UPDATE); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_UPDATE);
y += WD_PAR_VSEP_WIDE; tr.top += WD_PAR_VSEP_WIDE;
} }
SetDParamStr(0, this->selected->name); SetDParamStr(0, this->selected->name);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_NAME); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_NAME);
if (!this->selected->version.empty()) { if (!this->selected->version.empty()) {
SetDParamStr(0, this->selected->version); SetDParamStr(0, this->selected->version);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_VERSION); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_VERSION);
} }
if (!this->selected->description.empty()) { if (!this->selected->description.empty()) {
SetDParamStr(0, this->selected->description); SetDParamStr(0, this->selected->description);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DESCRIPTION); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DESCRIPTION);
} }
if (!this->selected->url.empty()) { if (!this->selected->url.empty()) {
SetDParamStr(0, this->selected->url); SetDParamStr(0, this->selected->url);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_URL); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_URL);
} }
SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS); SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TYPE); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TYPE);
y += WD_PAR_VSEP_WIDE; tr.top += WD_PAR_VSEP_WIDE;
SetDParam(0, this->selected->filesize); SetDParam(0, this->selected->filesize);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_FILESIZE); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_FILESIZE);
if (!this->selected->dependencies.empty()) { if (!this->selected->dependencies.empty()) {
/* List dependencies */ /* List dependencies */
@ -733,7 +730,7 @@ public:
} }
} }
SetDParamStr(0, buf); SetDParamStr(0, buf);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DEPENDENCIES); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DEPENDENCIES);
} }
if (!this->selected->tags.empty()) { if (!this->selected->tags.empty()) {
@ -744,7 +741,7 @@ public:
p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", tag.c_str()); p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", tag.c_str());
} }
SetDParamStr(0, buf); SetDParamStr(0, buf);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TAGS); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TAGS);
} }
if (this->selected->IsSelected()) { if (this->selected->IsSelected()) {
@ -761,7 +758,7 @@ public:
} }
if (p != buf) { if (p != buf) {
SetDParamStr(0, buf); SetDParamStr(0, buf);
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF); tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
} }
} }
} }

View File

@ -633,15 +633,19 @@ public:
{ {
NetworkGameList *sel = this->server; NetworkGameList *sel = this->server;
const int detail_height = 6 + 8 + 6 + 3 * FONT_HEIGHT_NORMAL; /* Height for the title banner */
int HEADER_HEIGHT = 3 * FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
Rect tr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
tr.top += HEADER_HEIGHT;
/* Draw the right menu */ /* Draw the right menu */
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, PC_DARK_BLUE); /* Create the nice grayish rectangle at the details top */
GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, 0), PC_DARK_BLUE);
if (sel == nullptr) { if (sel == nullptr) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER); DrawString(hr.left, hr.right, hr.top, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
} else if (sel->status != NGLS_ONLINE) { } else if (sel->status != NGLS_ONLINE) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
StringID message = INVALID_STRING_ID; StringID message = INVALID_STRING_ID;
switch (sel->status) { switch (sel->status) {
case NGLS_OFFLINE: message = STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; break; case NGLS_OFFLINE: message = STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; break;
@ -652,63 +656,63 @@ public:
/* Handled by the if-case above. */ /* Handled by the if-case above. */
case NGLS_ONLINE: NOT_REACHED(); case NGLS_ONLINE: NOT_REACHED();
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + detail_height + 4, message, TC_FROMSTRING, SA_HOR_CENTER); // server offline
DrawString(hr.left, hr.right, hr.top, message, TC_FROMSTRING, SA_HOR_CENTER); // server offline
DrawStringMultiLine(hr.left, hr.right, hr.top + FONT_HEIGHT_NORMAL, hr.bottom, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
DrawString(tr.left, tr.right, tr.top, message, TC_FROMSTRING, SA_HOR_CENTER); // server offline
} else { // show game info } else { // show game info
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER); DrawString(hr.left, hr.right, hr.top, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name DrawStringMultiLine(hr.left, hr.right, hr.top + FONT_HEIGHT_NORMAL, hr.bottom, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
uint16 y = r.top + detail_height + 4;
SetDParam(0, sel->info.clients_on); SetDParam(0, sel->info.clients_on);
SetDParam(1, sel->info.clients_max); SetDParam(1, sel->info.clients_max);
SetDParam(2, sel->info.companies_on); SetDParam(2, sel->info.companies_on);
SetDParam(3, sel->info.companies_max); SetDParam(3, sel->info.companies_max);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CLIENTS); DrawString(tr, STR_NETWORK_SERVER_LIST_CLIENTS);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + sel->info.landscape); SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + sel->info.landscape);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_LANDSCAPE); // landscape DrawString(tr, STR_NETWORK_SERVER_LIST_LANDSCAPE); // landscape
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, sel->info.map_width); SetDParam(0, sel->info.map_width);
SetDParam(1, sel->info.map_height); SetDParam(1, sel->info.map_height);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_MAP_SIZE); // map size DrawString(tr, STR_NETWORK_SERVER_LIST_MAP_SIZE); // map size
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
SetDParamStr(0, sel->info.server_revision); SetDParamStr(0, sel->info.server_revision);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_SERVER_VERSION); // server version DrawString(tr, STR_NETWORK_SERVER_LIST_SERVER_VERSION); // server version
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
SetDParamStr(0, sel->connection_string); SetDParamStr(0, sel->connection_string);
StringID invite_or_address = StrStartsWith(sel->connection_string, "+") ? STR_NETWORK_SERVER_LIST_INVITE_CODE : STR_NETWORK_SERVER_LIST_SERVER_ADDRESS; StringID invite_or_address = StrStartsWith(sel->connection_string, "+") ? STR_NETWORK_SERVER_LIST_INVITE_CODE : STR_NETWORK_SERVER_LIST_SERVER_ADDRESS;
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, invite_or_address); // server address / invite code DrawString(tr, invite_or_address); // server address / invite code
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, sel->info.start_date); SetDParam(0, sel->info.start_date);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_START_DATE); // start date DrawString(tr, STR_NETWORK_SERVER_LIST_START_DATE); // start date
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, sel->info.game_date); SetDParam(0, sel->info.game_date);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE); // current date DrawString(tr, STR_NETWORK_SERVER_LIST_CURRENT_DATE); // current date
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
if (sel->info.gamescript_version != -1) { if (sel->info.gamescript_version != -1) {
SetDParamStr(0, sel->info.gamescript_name); SetDParamStr(0, sel->info.gamescript_name);
SetDParam(1, sel->info.gamescript_version); SetDParam(1, sel->info.gamescript_version);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_GAMESCRIPT); // gamescript name and version tr.top = DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_GAMESCRIPT); // gamescript name and version
y += FONT_HEIGHT_NORMAL;
} }
y += WD_PAR_VSEP_NORMAL; tr.top += WD_PAR_VSEP_WIDE;
if (!sel->info.compatible) { if (!sel->info.compatible) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TC_FROMSTRING, SA_HOR_CENTER); // server mismatch DrawString(tr, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TC_FROMSTRING, SA_HOR_CENTER); // server mismatch
} else if (sel->info.clients_on == sel->info.clients_max) { } else if (sel->info.clients_on == sel->info.clients_max) {
/* Show: server full, when clients_on == max_clients */ /* Show: server full, when clients_on == max_clients */
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_SERVER_FULL, TC_FROMSTRING, SA_HOR_CENTER); // server full DrawString(tr, STR_NETWORK_SERVER_LIST_SERVER_FULL, TC_FROMSTRING, SA_HOR_CENTER); // server full
} else if (sel->info.use_password) { } else if (sel->info.use_password) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_PASSWORD, TC_FROMSTRING, SA_HOR_CENTER); // password warning DrawString(tr, STR_NETWORK_SERVER_LIST_PASSWORD, TC_FROMSTRING, SA_HOR_CENTER); // password warning
} }
} }
} }
@ -2088,8 +2092,8 @@ public:
uint line = 0; uint line = 0;
if (this->hover_index >= 0) { if (this->hover_index >= 0) {
uint offset = this->hover_index * this->line_height; Rect br = r.WithHeight(this->line_height).Translate(0, this->hover_index * this->line_height);
GfxFillRect(r.left + 2, r.top + offset, r.right - 1, r.top + offset + this->line_height - 2, GREY_SCALE(9)); GfxFillRect(br.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), GREY_SCALE(9));
} }
NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id); NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
@ -2314,8 +2318,7 @@ struct NetworkCompanyPasswordWindow : public Window {
{ {
if (widget != WID_NCP_WARNING) return; if (widget != WID_NCP_WARNING) return;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, DrawStringMultiLine(r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM),
r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER);
} }
@ -2415,7 +2418,7 @@ struct NetworkAskRelayWindow : public Window {
void DrawWidget(const Rect &r, int widget) const override void DrawWidget(const Rect &r, int widget) const override
{ {
if (widget == WID_NAR_TEXT) { if (widget == WID_NAR_TEXT) {
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMETEXT_BOTTOM, STR_NETWORK_ASK_RELAY_TEXT, TC_FROMSTRING, SA_CENTER); DrawStringMultiLine(r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM), STR_NETWORK_ASK_RELAY_TEXT, TC_FROMSTRING, SA_CENTER);
} }
} }

View File

@ -428,7 +428,8 @@ struct NewGRFInspectWindow : Window {
if (u == v) sel_end = total_width; if (u == v) sel_end = total_width;
} }
int width = r.Width() - WD_BEVEL_LEFT - WD_BEVEL_RIGHT; Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
int width = br.Width();
int skip = 0; int skip = 0;
if (total_width > width) { if (total_width > width) {
int sel_center = (sel_start + sel_end) / 2; int sel_center = (sel_start + sel_end) / 2;
@ -437,8 +438,8 @@ struct NewGRFInspectWindow : Window {
GrfSpecFeature f = GetFeatureNum(this->window_number); GrfSpecFeature f = GetFeatureNum(this->window_number);
int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height; int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height;
int y = CenterBounds(r.top, r.bottom, h); int y = CenterBounds(br.top, br.bottom, h);
DrawVehicleImage(v->First(), r.left + WD_BEVEL_LEFT, r.right - WD_BEVEL_RIGHT, y + 1, INVALID_VEHICLE, EIT_IN_DETAILS, skip); DrawVehicleImage(v->First(), br.left, br.right, y + 1, INVALID_VEHICLE, EIT_IN_DETAILS, skip);
/* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */ /* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */
if (_current_text_dir == TD_RTL) { if (_current_text_dir == TD_RTL) {
@ -878,13 +879,12 @@ struct SpriteAlignerWindow : Window {
case WID_SA_SPRITE: { case WID_SA_SPRITE: {
/* Center the sprite ourselves */ /* Center the sprite ourselves */
const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL); const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL);
int width = r.Width() - WD_BEVEL_LEFT - WD_BEVEL_RIGHT; Rect ir = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
int height = r.Height() - WD_BEVEL_TOP - WD_BEVEL_BOTTOM; int x = -UnScaleGUI(spr->x_offs) + (ir.Width() - UnScaleGUI(spr->width) ) / 2;
int x = -UnScaleGUI(spr->x_offs) + (width - UnScaleGUI(spr->width) ) / 2; int y = -UnScaleGUI(spr->y_offs) + (ir.Height() - UnScaleGUI(spr->height)) / 2;
int y = -UnScaleGUI(spr->y_offs) + (height - UnScaleGUI(spr->height)) / 2;
DrawPixelInfo new_dpi; DrawPixelInfo new_dpi;
if (!FillDrawPixelInfo(&new_dpi, r.left + WD_BEVEL_LEFT, r.top + WD_BEVEL_TOP, width, height)) break; if (!FillDrawPixelInfo(&new_dpi, ir.left, ir.top, ir.Width(), ir.Height())) break;
DrawPixelInfo *old_dpi = _cur_dpi; DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &new_dpi; _cur_dpi = &new_dpi;
@ -902,11 +902,11 @@ struct SpriteAlignerWindow : Window {
std::vector<SpriteID> &list = _newgrf_debug_sprite_picker.sprites; std::vector<SpriteID> &list = _newgrf_debug_sprite_picker.sprites;
int max = std::min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)list.size()); int max = std::min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)list.size());
int y = r.top + WD_FRAMERECT_TOP; Rect ir = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
for (int i = this->vscroll->GetPosition(); i < max; i++) { for (int i = this->vscroll->GetPosition(); i < max; i++) {
SetDParam(0, list[i]); SetDParam(0, list[i]);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE); DrawString(ir, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
y += step_size; ir.top += step_size;
} }
break; break;
} }

View File

@ -66,8 +66,9 @@ void ShowNewGRFError()
} }
} }
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint bottom, bool show_params) static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
{ {
Rect tr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
if (c->error != nullptr) { if (c->error != nullptr) {
char message[512]; char message[512];
SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
@ -79,34 +80,34 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
GetString(message, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message)); GetString(message, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
SetDParamStr(0, message); SetDParamStr(0, message);
y = DrawStringMultiLine(x, right, y, bottom, c->error->severity); tr.top = DrawStringMultiLine(tr, c->error->severity);
} }
/* Draw filename or not if it is not known (GRF sent over internet) */ /* Draw filename or not if it is not known (GRF sent over internet) */
if (c->filename != nullptr) { if (c->filename != nullptr) {
SetDParamStr(0, c->filename); SetDParamStr(0, c->filename);
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_FILENAME);
} }
/* Prepare and draw GRF ID */ /* Prepare and draw GRF ID */
char buff[256]; char buff[256];
seprintf(buff, lastof(buff), "%08X", BSWAP32(c->ident.grfid)); seprintf(buff, lastof(buff), "%08X", BSWAP32(c->ident.grfid));
SetDParamStr(0, buff); SetDParamStr(0, buff);
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_GRF_ID);
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) { if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
SetDParam(0, c->version); SetDParam(0, c->version);
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_VERSION); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_VERSION);
} }
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->min_loadable_version != 0) { if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->min_loadable_version != 0) {
SetDParam(0, c->min_loadable_version); SetDParam(0, c->min_loadable_version);
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MIN_VERSION); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MIN_VERSION);
} }
/* Prepare and draw MD5 sum */ /* Prepare and draw MD5 sum */
md5sumToString(buff, lastof(buff), c->ident.md5sum); md5sumToString(buff, lastof(buff), c->ident.md5sum);
SetDParamStr(0, buff); SetDParamStr(0, buff);
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MD5SUM);
/* Show GRF parameter list */ /* Show GRF parameter list */
if (show_params) { if (show_params) {
@ -117,7 +118,7 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
} else { } else {
SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE); SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
} }
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PARAMETER); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_PARAMETER);
/* Draw the palette of the NewGRF */ /* Draw the palette of the NewGRF */
if (c->palette & GRFP_BLT_32BPP) { if (c->palette & GRFP_BLT_32BPP) {
@ -125,21 +126,21 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
} else { } else {
SetDParam(0, (c->palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT); SetDParam(0, (c->palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT);
} }
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PALETTE); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_PALETTE);
} }
/* Show flags */ /* Show flags */
if (c->status == GCS_NOT_FOUND) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NOT_FOUND); if (c->status == GCS_NOT_FOUND) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NOT_FOUND);
if (c->status == GCS_DISABLED) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_DISABLED); if (c->status == GCS_DISABLED) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_DISABLED);
if (HasBit(c->flags, GCF_INVALID)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_INCOMPATIBLE); if (HasBit(c->flags, GCF_INVALID)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
if (HasBit(c->flags, GCF_COMPATIBLE)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_COMPATIBLE_LOADED); if (HasBit(c->flags, GCF_COMPATIBLE)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
/* Draw GRF info if it exists */ /* Draw GRF info if it exists */
if (!StrEmpty(c->GetDescription())) { if (!StrEmpty(c->GetDescription())) {
SetDParamStr(0, c->GetDescription()); SetDParamStr(0, c->GetDescription());
y = DrawStringMultiLine(x, right, y, bottom, STR_BLACK_RAW_STRING); tr.top = DrawStringMultiLine(tr, STR_BLACK_RAW_STRING);
} else { } else {
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NO_INFO); tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NO_INFO);
} }
} }
@ -252,18 +253,17 @@ struct NewGRFParametersWindow : public Window {
if (par_info == nullptr) return; if (par_info == nullptr) return;
const char *desc = GetGRFStringFromGRFText(par_info->desc); const char *desc = GetGRFStringFromGRFText(par_info->desc);
if (desc == nullptr) return; if (desc == nullptr) return;
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_TEXTPANEL_TOP, r.bottom - WD_TEXTPANEL_BOTTOM, desc, TC_BLACK); DrawStringMultiLine(r.Shrink(WD_FRAMERECT_LEFT, WD_TEXTPANEL_TOP, WD_FRAMERECT_RIGHT, WD_TEXTPANEL_BOTTOM), desc, TC_BLACK);
return; return;
} else if (widget != WID_NP_BACKGROUND) { } else if (widget != WID_NP_BACKGROUND) {
return; return;
} }
Rect ir = r.Shrink(WD_FRAMERECT_LEFT, 0, WD_FRAMERECT_RIGHT, 0);
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4; uint buttons_left = rtl ? ir.right - SETTING_BUTTON_WIDTH - 3 : ir.left + 4;
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8); Rect tr = r.Indent(SETTING_BUTTON_WIDTH + 8, rtl);
uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
int y = r.top;
int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2; int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2; int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) { for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
@ -273,13 +273,13 @@ struct NewGRFParametersWindow : public Window {
bool selected = (i == this->clicked_row); bool selected = (i == this->clicked_row);
if (par_info->type == PTYPE_BOOL) { if (par_info->type == PTYPE_BOOL) {
DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, this->editable); DrawBoolButton(buttons_left, ir.top + button_y_offset, current_value != 0, this->editable);
SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON); SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
} else if (par_info->type == PTYPE_UINT_ENUM) { } else if (par_info->type == PTYPE_UINT_ENUM) {
if (par_info->complete_labels) { if (par_info->complete_labels) {
DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable); DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
} else { } else {
DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, this->editable && current_value > par_info->min_value, this->editable && current_value < par_info->max_value); DrawArrowButtons(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, this->editable && current_value > par_info->min_value, this->editable && current_value < par_info->max_value);
} }
SetDParam(2, STR_JUST_INT); SetDParam(2, STR_JUST_INT);
SetDParam(3, current_value); SetDParam(3, current_value);
@ -301,8 +301,8 @@ struct NewGRFParametersWindow : public Window {
SetDParam(1, i + 1); SetDParam(1, i + 1);
} }
DrawString(text_left, text_right, y + text_y_offset, STR_NEWGRF_PARAMETERS_SETTING, selected ? TC_WHITE : TC_LIGHT_BLUE); DrawString(tr.left, tr.right, ir.top + text_y_offset, STR_NEWGRF_PARAMETERS_SETTING, selected ? TC_WHITE : TC_LIGHT_BLUE);
y += this->line_height; ir.top += this->line_height;
} }
} }
@ -833,10 +833,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
{ {
switch (widget) { switch (widget) {
case WID_NS_FILE_LIST: { case WID_NS_FILE_LIST: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK); const Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
GfxFillRect(br, PC_BLACK);
Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint step_height = this->GetWidget<NWidgetBase>(WID_NS_FILE_LIST)->resize_y; uint step_height = this->GetWidget<NWidgetBase>(WID_NS_FILE_LIST)->resize_y;
uint y = r.top + WD_FRAMERECT_TOP;
Dimension square = GetSpriteSize(SPR_SQUARE); Dimension square = GetSpriteSize(SPR_SQUARE);
Dimension warning = GetSpriteSize(SPR_WARNING_SIGN); Dimension warning = GetSpriteSize(SPR_WARNING_SIGN);
int square_offset_y = (step_height - square.height) / 2; int square_offset_y = (step_height - square.height) / 2;
@ -844,10 +845,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2; int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + square.width + 15; uint text_left = rtl ? tr.left : tr.left + square.width + 13;
uint text_right = rtl ? r.right - square.width - 15 : r.right - WD_FRAMERECT_RIGHT; uint text_right = rtl ? tr.right - square.width - 13 : tr.right;
uint square_left = rtl ? r.right - square.width - 5 : r.left + 5; uint square_left = rtl ? tr.right - square.width - 3 : tr.left + 3;
uint warning_left = rtl ? r.right - square.width - warning.width - 10 : r.left + square.width + 10; uint warning_left = rtl ? tr.right - square.width - warning.width - 8 : tr.left + square.width + 8;
int i = 0; int i = 0;
for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) { for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) {
@ -857,35 +858,36 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
PaletteID pal = this->GetPalette(c); PaletteID pal = this->GetPalette(c);
if (h) { if (h) {
GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, PC_DARK_BLUE); GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
} else if (i == this->active_over) { } else if (i == this->active_over) {
/* Get index of current selection. */ /* Get index of current selection. */
int active_sel_pos = 0; int active_sel_pos = 0;
for (GRFConfig *c = this->actives; c != nullptr && c != this->active_sel; c = c->next, active_sel_pos++) {} for (GRFConfig *c = this->actives; c != nullptr && c != this->active_sel; c = c->next, active_sel_pos++) {}
if (active_sel_pos != this->active_over) { if (active_sel_pos != this->active_over) {
uint top = this->active_over < active_sel_pos ? y + 1 : y + step_height - 2; uint top = this->active_over < active_sel_pos ? tr.top + 1 : tr.top + step_height - 2;
GfxFillRect(r.left + WD_FRAMERECT_LEFT, top - 1, r.right - WD_FRAMERECT_RIGHT, top + 1, PC_GREY); GfxFillRect(tr.left, top - 1, tr.right, top + 1, PC_GREY);
} }
} }
DrawSprite(SPR_SQUARE, pal, square_left, y + square_offset_y); DrawSprite(SPR_SQUARE, pal, square_left, tr.top + square_offset_y);
if (c->error != nullptr) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + warning_offset_y); if (c->error != nullptr) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, tr.top + warning_offset_y);
uint txtoffset = c->error == nullptr ? 0 : warning.width; uint txtoffset = c->error == nullptr ? 0 : warning.width;
DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), y + offset_y, text, h ? TC_WHITE : TC_ORANGE); DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, text, h ? TC_WHITE : TC_ORANGE);
y += step_height; tr.top += step_height;
} }
} }
if (i == this->active_over && this->vscroll->IsVisible(i)) { // Highlight is after the last GRF entry. if (i == this->active_over && this->vscroll->IsVisible(i)) { // Highlight is after the last GRF entry.
GfxFillRect(r.left + WD_FRAMERECT_LEFT, y, r.right - WD_FRAMERECT_RIGHT, y + 2, PC_GREY); GfxFillRect(tr.left, tr.top, tr.right, tr.top + 2, PC_GREY);
} }
break; break;
} }
case WID_NS_AVAIL_LIST: { case WID_NS_AVAIL_LIST: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, this->active_over == -2 ? PC_DARK_GREY : PC_BLACK); const Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
GfxFillRect(br, this->active_over == -2 ? PC_DARK_GREY : PC_BLACK);
Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint step_height = this->GetWidget<NWidgetBase>(WID_NS_AVAIL_LIST)->resize_y; uint step_height = this->GetWidget<NWidgetBase>(WID_NS_AVAIL_LIST)->resize_y;
int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2; int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
uint y = r.top + WD_FRAMERECT_TOP;
uint min_index = this->vscroll2->GetPosition(); uint min_index = this->vscroll2->GetPosition();
uint max_index = std::min(min_index + this->vscroll2->GetCapacity(), (uint)this->avails.size()); uint max_index = std::min(min_index + this->vscroll2->GetCapacity(), (uint)this->avails.size());
@ -894,16 +896,16 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
bool h = (c == this->avail_sel); bool h = (c == this->avail_sel);
const char *text = c->GetName(); const char *text = c->GetName();
if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, PC_DARK_BLUE); if (h) GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + offset_y, text, h ? TC_WHITE : TC_SILVER); DrawString(tr.left, tr.right, tr.top + offset_y, text, h ? TC_WHITE : TC_SILVER);
y += step_height; tr.top += step_height;
} }
break; break;
} }
case WID_NS_NEWGRF_INFO_TITLE: case WID_NS_NEWGRF_INFO_TITLE:
/* Create the nice grayish rectangle at the details top. */ /* Create the nice grayish rectangle at the details top. */
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_DARK_BLUE); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_DARK_BLUE);
DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER); DrawString(r.left, r.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
break; break;
@ -911,7 +913,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
const GRFConfig *selected = this->active_sel; const GRFConfig *selected = this->active_sel;
if (selected == nullptr) selected = this->avail_sel; if (selected == nullptr) selected = this->avail_sel;
if (selected != nullptr) { if (selected != nullptr) {
ShowNewGRFInfo(selected, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, r.right - WD_FRAMERECT_RIGHT, r.bottom - WD_FRAMERECT_BOTTOM, this->show_params); ShowNewGRFInfo(selected, r, this->show_params);
} }
break; break;
} }
@ -2091,20 +2093,21 @@ struct SavePresetWindow : public Window {
{ {
switch (widget) { switch (widget) {
case WID_SVP_PRESET_LIST: { case WID_SVP_PRESET_LIST: {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK); const Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
GfxFillRect(br, PC_BLACK);
uint step_height = this->GetWidget<NWidgetBase>(WID_SVP_PRESET_LIST)->resize_y; uint step_height = this->GetWidget<NWidgetBase>(WID_SVP_PRESET_LIST)->resize_y;
int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2; int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
uint y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint min_index = this->vscroll->GetPosition(); uint min_index = this->vscroll->GetPosition();
uint max_index = std::min(min_index + this->vscroll->GetCapacity(), (uint)this->presets.size()); uint max_index = std::min(min_index + this->vscroll->GetCapacity(), (uint)this->presets.size());
for (uint i = min_index; i < max_index; i++) { for (uint i = min_index; i < max_index; i++) {
if ((int)i == this->selected) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 2, PC_DARK_BLUE); if ((int)i == this->selected) GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
const char *text = this->presets[i].c_str(); const char *text = this->presets[i].c_str();
DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y + offset_y, text, ((int)i == this->selected) ? TC_WHITE : TC_SILVER); DrawString(tr.left, tr.right, tr.top + offset_y, text, ((int)i == this->selected) ? TC_WHITE : TC_SILVER);
y += step_height; tr.top += step_height;
} }
break; break;
} }

View File

@ -1135,9 +1135,6 @@ static void DrawNewsString(uint left, uint right, int y, TextColour colour, cons
} }
struct MessageHistoryWindow : Window { struct MessageHistoryWindow : Window {
static const int top_spacing; ///< Additional spacing at the top of the #WID_MH_BACKGROUND widget.
static const int bottom_spacing; ///< Additional spacing at the bottom of the #WID_MH_BACKGROUND widget.
int line_height; /// < Height of a single line in the news history window including spacing. int line_height; /// < Height of a single line in the news history window including spacing.
int date_width; /// < Width needed for the date part. int date_width; /// < Width needed for the date part.
@ -1154,7 +1151,7 @@ struct MessageHistoryWindow : Window {
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{ {
if (widget == WID_MH_BACKGROUND) { if (widget == WID_MH_BACKGROUND) {
this->line_height = FONT_HEIGHT_NORMAL + 2; this->line_height = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
resize->height = this->line_height; resize->height = this->line_height;
/* Months are off-by-one, so it's actually 8. Not using /* Months are off-by-one, so it's actually 8. Not using
@ -1162,7 +1159,7 @@ struct MessageHistoryWindow : Window {
SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30)); SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30));
this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width; this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width;
size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible. size->height = 4 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; // At least 4 lines are visible.
size->width = std::max(200u, size->width); // At least 200 pixels wide. size->width = std::max(200u, size->width); // At least 200 pixels wide.
} }
} }
@ -1185,17 +1182,15 @@ struct MessageHistoryWindow : Window {
} }
/* Fill the widget with news items. */ /* Fill the widget with news items. */
int y = r.top + this->top_spacing;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint date_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT; Rect news = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM).Indent(this->date_width + ScaleFontTrad(5), rtl);
uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width; Rect date = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM).WithWidth(this->date_width, rtl);
uint news_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->date_width + WD_FRAMERECT_RIGHT + ScaleFontTrad(5); int y = news.top;
uint news_right = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width - WD_FRAMERECT_RIGHT - ScaleFontTrad(5) : r.right - WD_FRAMERECT_RIGHT;
for (int n = this->vscroll->GetCapacity(); n > 0; n--) { for (int n = this->vscroll->GetCapacity(); n > 0; n--) {
SetDParam(0, ni->date); SetDParam(0, ni->date);
DrawString(date_left, date_right, y, STR_SHORT_DATE); DrawString(date.left, date.right, y, STR_SHORT_DATE);
DrawNewsString(news_left, news_right, y, TC_WHITE, ni); DrawNewsString(news.left, news.right, y, TC_WHITE, ni);
y += this->line_height; y += this->line_height;
ni = ni->prev; ni = ni->prev;
@ -1235,9 +1230,6 @@ struct MessageHistoryWindow : Window {
} }
}; };
const int MessageHistoryWindow::top_spacing = WD_FRAMERECT_TOP + 4;
const int MessageHistoryWindow::bottom_spacing = WD_FRAMERECT_BOTTOM;
static const NWidgetPart _nested_message_history[] = { static const NWidgetPart _nested_message_history[] = {
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN), NWidget(WWT_CLOSEBOX, COLOUR_BROWN),

View File

@ -313,8 +313,8 @@ public:
break; break;
case WID_BO_SELECT_IMAGE: case WID_BO_SELECT_IMAGE:
size->width = ScaleGUITrad(64) + 2; size->width = ScaleGUITrad(64) + WD_BEVEL_LEFT + WD_BEVEL_RIGHT;
size->height = ScaleGUITrad(58) + 2; size->height = ScaleGUITrad(58) + WD_BEVEL_TOP + WD_BEVEL_BOTTOM;
break; break;
default: break; default: break;
@ -325,15 +325,15 @@ public:
{ {
switch (GB(widget, 0, 16)) { switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: { case WID_BO_CLASS_LIST: {
int y = r.top; Rect mr = r.Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
uint pos = 0; uint pos = 0;
for (auto object_class_id : this->object_classes) { for (auto object_class_id : this->object_classes) {
ObjectClass *objclass = ObjectClass::Get(object_class_id); ObjectClass *objclass = ObjectClass::Get(object_class_id);
if (objclass->GetUISpecCount() == 0) continue; if (objclass->GetUISpecCount() == 0) continue;
if (!this->vscroll->IsVisible(pos++)) continue; if (!this->vscroll->IsVisible(pos++)) continue;
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, objclass->name, DrawString(mr, objclass->name,
(object_class_id == _selected_object_class) ? TC_WHITE : TC_BLACK); (object_class_id == _selected_object_class) ? TC_WHITE : TC_BLACK);
y += this->line_height; mr.top += this->line_height;
} }
break; break;
} }
@ -360,9 +360,9 @@ public:
if (spec->grf_prop.grffile == nullptr) { if (spec->grf_prop.grffile == nullptr) {
extern const DrawTileSprites _objects[]; extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id]; const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE); DrawOrigTileSeqInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
} else { } else {
DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec, GB(widget, 16, 16)); DrawNewObjectTileInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec, GB(widget, 16, 16));
} }
_cur_dpi = old_dpi; _cur_dpi = old_dpi;
} }
@ -377,19 +377,19 @@ public:
if (spec == nullptr) break; if (spec == nullptr) break;
if (!spec->IsAvailable()) { if (!spec->IsAvailable()) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_BLACK, FILLRECT_CHECKER);
} }
DrawPixelInfo tmp_dpi; DrawPixelInfo tmp_dpi;
/* Set up a clipping area for the preview. */ /* Set up a clipping area for the preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.Height())) { if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi; DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi; _cur_dpi = &tmp_dpi;
if (spec->grf_prop.grffile == nullptr) { if (spec->grf_prop.grffile == nullptr) {
extern const DrawTileSprites _objects[]; extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id]; const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE); DrawOrigTileSeqInGUI(r.Width() / 2 - 1, r.Height() - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
} else { } else {
DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec, DrawNewObjectTileInGUI(r.Width() / 2 - 1, r.Height() - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec,
std::min<int>(_selected_object_view, spec->views - 1)); std::min<int>(_selected_object_view, spec->views - 1));
} }
_cur_dpi = old_dpi; _cur_dpi = old_dpi;

View File

@ -1074,12 +1074,13 @@ public:
{ {
if (widget != WID_O_ORDER_LIST) return; if (widget != WID_O_ORDER_LIST) return;
Rect ir = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMERECT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMERECT_BOTTOM);
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2); SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3; int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width; int middle = rtl ? ir.right - index_column_width : ir.left + index_column_width;
int y = r.top + WD_FRAMERECT_TOP; int y = ir.top;
int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y; int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
int i = this->vscroll->GetPosition(); int i = this->vscroll->GetPosition();
@ -1093,9 +1094,9 @@ public:
if (i != this->selected_order && i == this->order_over) { if (i != this->selected_order && i == this->order_over) {
/* Highlight dragged order destination. */ /* Highlight dragged order destination. */
int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP; int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
int bottom = std::min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM); int bottom = std::min(top + 2, ir.bottom);
top = std::max(top - 3, r.top + WD_FRAMERECT_TOP); top = std::max(top - 3, ir.top);
GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]); GfxFillRect(ir.left, top, ir.right, bottom, _colour_gradient[COLOUR_GREY][7]);
break; break;
} }
y += line_height; y += line_height;
@ -1105,7 +1106,7 @@ public:
} }
/* Reset counters for drawing the orders. */ /* Reset counters for drawing the orders. */
y = r.top + WD_FRAMERECT_TOP; y = ir.top;
i = this->vscroll->GetPosition(); i = this->vscroll->GetPosition();
order = this->vehicle->GetOrder(i); order = this->vehicle->GetOrder(i);
} }
@ -1115,7 +1116,7 @@ public:
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
if (!this->vscroll->IsVisible(i)) break; if (!this->vscroll->IsVisible(i)) break;
DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT); DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, ir.left, middle, ir.right);
y += line_height; y += line_height;
i++; i++;
@ -1124,7 +1125,7 @@ public:
if (this->vscroll->IsVisible(i)) { if (this->vscroll->IsVisible(i)) {
StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS; StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
DrawString(rtl ? r.left + WD_FRAMETEXT_LEFT : middle, rtl ? middle : r.right - WD_FRAMETEXT_RIGHT, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK); DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
} }
} }

View File

@ -1281,14 +1281,14 @@ public:
break; break;
case WID_BRAS_NEWST_LIST: { case WID_BRAS_NEWST_LIST: {
Rect ir = r.Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_BOTTOM);
uint statclass = 0; uint statclass = 0;
uint row = 0;
for (auto station_class : this->station_classes) { for (auto station_class : this->station_classes) {
if (this->vscroll->IsVisible(statclass)) { if (this->vscroll->IsVisible(statclass)) {
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, row * this->line_height + r.top + WD_MATRIX_TOP, DrawString(ir,
StationClass::Get(station_class)->name, StationClass::Get(station_class)->name,
station_class == _railstation.station_class ? TC_WHITE : TC_BLACK); station_class == _railstation.station_class ? TC_WHITE : TC_BLACK);
row++; ir.top += this->line_height;
} }
statclass++; statclass++;
} }
@ -1301,7 +1301,7 @@ public:
/* Check station availability callback */ /* Check station availability callback */
const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type); const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
if (!IsStationAvailable(statspec)) { if (!IsStationAvailable(statspec)) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_BLACK, FILLRECT_CHECKER);
} }
/* Set up a clipping area for the station preview. */ /* Set up a clipping area for the station preview. */
@ -2043,7 +2043,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
DrawWaypointSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), type, _cur_railtype); DrawWaypointSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), type, _cur_railtype);
if (!IsStationAvailable(statspec)) { if (!IsStationAvailable(statspec)) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER); GfxFillRect(r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM), PC_BLACK, FILLRECT_CHECKER);
} }
} }
} }

View File

@ -194,30 +194,29 @@ struct SignListWindow : Window, SignList {
{ {
switch (widget) { switch (widget) {
case WID_SIL_LIST: { case WID_SIL_LIST: {
uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget. Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint text_offset_y = (this->resize.step_height - FONT_HEIGHT_NORMAL + 1) / 2; uint text_offset_y = (this->resize.step_height - FONT_HEIGHT_NORMAL + 1) / 2;
/* No signs? */ /* No signs? */
if (this->vscroll->GetCount() == 0) { if (this->vscroll->GetCount() == 0) {
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y + text_offset_y, STR_STATION_LIST_NONE); DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_STATION_LIST_NONE);
return; return;
} }
Dimension d = GetSpriteSize(SPR_COMPANY_ICON); Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int sprite_offset_y = (this->resize.step_height - d.height + 1) / 2; int sprite_offset_y = (this->resize.step_height - d.height + 1) / 2;
uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left); uint icon_left = rtl ? tr.right - this->text_offset : tr.left;
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset); tr = tr.Indent(this->text_offset, rtl);
uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
/* At least one sign available. */ /* At least one sign available. */
for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) { for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
const Sign *si = this->signs[i]; const Sign *si = this->signs[i];
if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y); if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, tr.top + sprite_offset_y);
SetDParam(0, si->index); SetDParam(0, si->index);
DrawString(text_left, text_right, y + text_offset_y, STR_SIGN_NAME, TC_YELLOW); DrawString(tr.left, tr.right, tr.top + text_offset_y, STR_SIGN_NAME, TC_YELLOW);
y += this->resize.step_height; tr.top += this->resize.step_height;
} }
break; break;
} }

View File

@ -1214,8 +1214,9 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
{ {
switch (widget) { switch (widget) {
case WID_SM_MAP: { case WID_SM_MAP: {
Rect ir = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
DrawPixelInfo new_dpi; 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); this->DrawSmallMap(&new_dpi);
break; break;
} }
@ -1224,17 +1225,13 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
uint columns = this->GetNumberColumnsLegend(r.Width()); uint columns = this->GetNumberColumnsLegend(r.Width());
uint number_of_rows = this->GetNumberRowsLegend(columns); uint number_of_rows = this->GetNumberRowsLegend(columns);
bool rtl = _current_text_dir == TD_RTL; 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 i = 0; // Row counter for industry legend.
uint row_height = FONT_HEIGHT_SMALL; uint row_height = FONT_HEIGHT_SMALL;
int padding = ScaleFontTrad(1); int padding = ScaleFontTrad(1);
uint text_left = rtl ? 0 : this->legend_width + WD_FRAMERECT_LEFT; Rect origin = r.WithWidth(this->column_width, rtl).Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM).WithHeight(row_height);
uint text_right = this->column_width - padding - (rtl ? this->legend_width + WD_FRAMERECT_RIGHT : 0); Rect text = origin.Indent(this->legend_width + padding, rtl);
uint blob_left = rtl ? this->column_width - padding - this->legend_width : 0; Rect icon = origin.WithWidth(this->legend_width, rtl).Shrink(0, padding, 0, 0);
uint blob_right = rtl ? this->column_width - padding : this->legend_width;
StringID string = STR_NULL; StringID string = STR_NULL;
switch (this->map_type) { 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)) { 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 /* Column break needed, continue at top, COLUMN_WIDTH pixels
* (one "row") to the right. */ * (one "row") to the right. */
x += rtl ? -(int)this->column_width : this->column_width; int x = rtl ? -(int)this->column_width : this->column_width;
y = y_org; int y = origin.top - text.top;
text = text.Translate(x, y);
icon = icon.Translate(x, y);
i = 1; i = 1;
} }
@ -1283,10 +1282,10 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
if (!tbl->show_on_map) { if (!tbl->show_on_map) {
/* Simply draw the string, not the black border of the legend colour. /* Simply draw the string, not the black border of the legend colour.
* This will enforce the idea of the disabled item */ * 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 { } else {
DrawString(x + text_left, x + text_right, y, string, TC_BLACK); DrawString(text, string, TC_BLACK);
GfxFillRect(x + blob_left, y + padding, x + blob_right, y + row_height - 1, PC_BLACK); // Outer border of the legend colour GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour
} }
break; break;
} }
@ -1295,13 +1294,14 @@ void SmallMapWindow::RebuildColourIndexIfNecessary()
default: default:
if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP); 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 */ /* 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); GfxFillRect(icon, PC_BLACK);
DrawString(x + text_left, x + text_right, y, tbl->legend); DrawString(text, tbl->legend);
break; 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);
} }
} }
} }

View File

@ -433,7 +433,7 @@ public:
case WID_STL_LIST: { case WID_STL_LIST: {
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size()); int max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size());
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y; uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
/* Spacing between station name and first rating graph. */ /* Spacing between station name and first rating graph. */
int text_spacing = ScaleFontTrad(5); int text_spacing = ScaleFontTrad(5);
@ -450,7 +450,7 @@ public:
SetDParam(0, st->index); SetDParam(0, st->index);
SetDParam(1, st->facilities); SetDParam(1, st->facilities);
int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + (line_height - FONT_HEIGHT_NORMAL) / 2, STR_STATION_LIST_STATION); int x = DrawString(tr.left, tr.right, tr.top + (line_height - FONT_HEIGHT_NORMAL) / 2, STR_STATION_LIST_STATION);
x += rtl ? -text_spacing : text_spacing; x += rtl ? -text_spacing : text_spacing;
/* show cargo waiting and station ratings */ /* show cargo waiting and station ratings */
@ -463,20 +463,20 @@ public:
* the space. */ * the space. */
if (rtl) { if (rtl) {
x -= rating_width + rating_spacing; x -= rating_width + rating_spacing;
if (x < r.left + WD_FRAMERECT_LEFT) break; if (x < tr.left) break;
} }
StationsWndShowStationRating(x, x + rating_width, y, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating); StationsWndShowStationRating(x, x + rating_width, tr.top, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
if (!rtl) { if (!rtl) {
x += rating_width + rating_spacing; x += rating_width + rating_spacing;
if (x > r.right - WD_FRAMERECT_RIGHT) break; if (x > tr.right) break;
} }
} }
} }
y += line_height; tr.top += line_height;
} }
if (this->vscroll->GetCount() == 0) { // company has no stations if (this->vscroll->GetCount() == 0) { // company has no stations
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_NONE); DrawString(tr.left, tr.right, tr.top + (line_height - FONT_HEIGHT_NORMAL) / 2, STR_STATION_LIST_NONE);
return; return;
} }
break; break;
@ -484,11 +484,13 @@ public:
default: default:
if (widget >= WID_STL_CARGOSTART) { if (widget >= WID_STL_CARGOSTART) {
Rect br = r.Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART]; const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 1 : 0; 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); br = br.Translate(cg_ofst, cg_ofst);
GfxFillRect(br, cs->rating_colour);
TextColour tc = GetContrastColour(cs->rating_colour); TextColour tc = GetContrastColour(cs->rating_colour);
DrawString(r.left + cg_ofst, r.right + cg_ofst, CenterBounds(r.top, r.bottom, FONT_HEIGHT_SMALL) + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER); DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, FONT_HEIGHT_SMALL), cs->abbrev, tc, SA_HOR_CENTER);
} }
break; break;
} }
@ -1367,7 +1369,7 @@ struct StationViewWindow : public Window {
case WID_SV_WAITING: case WID_SV_WAITING:
resize->height = FONT_HEIGHT_NORMAL; resize->height = FONT_HEIGHT_NORMAL;
size->height = WD_FRAMERECT_TOP + 4 * resize->height + WD_FRAMERECT_BOTTOM; size->height = WD_FRAMERECT_TOP + 4 * resize->height + WD_FRAMERECT_BOTTOM;
this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width);
break; break;
case WID_SV_ACCEPT_RATING_LIST: case WID_SV_ACCEPT_RATING_LIST:
@ -1439,7 +1441,7 @@ struct StationViewWindow : public Window {
/* Draw waiting cargo. */ /* Draw waiting cargo. */
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SV_WAITING); NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SV_WAITING);
Rect waiting_rect = nwi->GetCurrentRect(); Rect waiting_rect = nwi->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0); this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0);
scroll_to_row = INT_MAX; scroll_to_row = INT_MAX;
} }
@ -1711,7 +1713,7 @@ struct StationViewWindow : public Window {
* @param cargo Current cargo being drawn (if cargo column has been passed). * @param cargo Current cargo being drawn (if cargo column has been passed).
* @return row (in "pos" counting) after the one we have last drawn to. * @return row (in "pos" counting) after the one we have last drawn to.
*/ */
int DrawEntries(CargoDataEntry *entry, Rect &r, int pos, int maxrows, int column, CargoID cargo = CT_INVALID) int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo = CT_INVALID)
{ {
if (this->sortings[column] == ST_AS_GROUPING) { if (this->sortings[column] == ST_AS_GROUPING) {
if (this->groupings[column] != GR_CARGO) { if (this->groupings[column] != GR_CARGO) {
@ -1729,13 +1731,13 @@ struct StationViewWindow : public Window {
if (pos > -maxrows && pos <= 0) { if (pos > -maxrows && pos <= 0) {
StringID str = STR_EMPTY; StringID str = STR_EMPTY;
int y = r.top + WD_FRAMERECT_TOP - pos * FONT_HEIGHT_NORMAL; int y = r.top - pos * FONT_HEIGHT_NORMAL;
SetDParam(0, cargo); SetDParam(0, cargo);
SetDParam(1, cd->GetCount()); SetDParam(1, cd->GetCount());
if (this->groupings[column] == GR_CARGO) { if (this->groupings[column] == GR_CARGO) {
str = STR_STATION_VIEW_WAITING_CARGO; str = STR_STATION_VIEW_WAITING_CARGO;
DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + WD_FRAMERECT_LEFT + this->expand_shrink_width, r.right - WD_FRAMERECT_RIGHT - this->expand_shrink_width, y); DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + this->expand_shrink_width, r.right - this->expand_shrink_width, y);
} else { } else {
if (!auto_distributed) grouping = GR_SOURCE; if (!auto_distributed) grouping = GR_SOURCE;
StationID station = cd->GetStation(); StationID station = cd->GetStation();
@ -1760,12 +1762,10 @@ struct StationViewWindow : public Window {
} }
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int text_left = rtl ? r.left + this->expand_shrink_width : r.left + WD_FRAMERECT_LEFT + column * this->expand_shrink_width; Rect text = r.Indent(column * this->expand_shrink_width, rtl).Indent(this->expand_shrink_width, !rtl);
int text_right = rtl ? r.right - WD_FRAMERECT_LEFT - column * this->expand_shrink_width : r.right - this->expand_shrink_width; Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl);
int shrink_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - this->expand_shrink_width + WD_FRAMERECT_LEFT;
int shrink_right = rtl ? r.left + this->expand_shrink_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
DrawString(text_left, text_right, y, str); DrawString(text.left, text.right, y, str);
if (column < NUM_COLUMNS - 1) { if (column < NUM_COLUMNS - 1) {
const char *sym = nullptr; const char *sym = nullptr;
@ -1780,7 +1780,7 @@ struct StationViewWindow : public Window {
sym = "+"; sym = "+";
} }
} }
if (sym) DrawString(shrink_left, shrink_right, y, sym, TC_YELLOW); if (sym != nullptr) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW);
} }
this->SetDisplayedRow(cd); this->SetDisplayedRow(cd);
} }
@ -1800,13 +1800,14 @@ struct StationViewWindow : public Window {
int DrawAcceptedCargo(const Rect &r) const int DrawAcceptedCargo(const Rect &r) const
{ {
const Station *st = Station::Get(this->window_number); const Station *st = Station::Get(this->window_number);
Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
CargoTypes cargo_mask = 0; CargoTypes cargo_mask = 0;
for (CargoID i = 0; i < NUM_CARGO; i++) { for (CargoID i = 0; i < NUM_CARGO; i++) {
if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(cargo_mask, i); if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(cargo_mask, i);
} }
SetDParam(0, cargo_mask); SetDParam(0, cargo_mask);
int bottom = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO); int bottom = DrawStringMultiLine(tr.left, tr.right, tr.top, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO);
return CeilDiv(bottom - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL); return CeilDiv(bottom - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
} }
@ -1818,16 +1819,17 @@ struct StationViewWindow : public Window {
int DrawCargoRatings(const Rect &r) const int DrawCargoRatings(const Rect &r) const
{ {
const Station *st = Station::Get(this->window_number); const Station *st = Station::Get(this->window_number);
int y = r.top + WD_FRAMERECT_TOP; bool rtl = _current_text_dir == TD_RTL;
Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
if (st->town->exclusive_counter > 0) { if (st->town->exclusive_counter > 0) {
SetDParam(0, st->town->exclusivity); SetDParam(0, st->town->exclusivity);
y = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY); tr.top = DrawStringMultiLine(tr, st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY);
y += WD_PAR_VSEP_WIDE; tr.top += WD_PAR_VSEP_WIDE;
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_VIEW_SUPPLY_RATINGS_TITLE); DrawString(tr, STR_STATION_VIEW_SUPPLY_RATINGS_TITLE);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
for (const CargoSpec *cs : _sorted_standard_cargo_specs) { for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
const GoodsEntry *ge = &st->goods[cs->Index()]; const GoodsEntry *ge = &st->goods[cs->Index()];
@ -1838,10 +1840,10 @@ struct StationViewWindow : public Window {
SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].Supply()) : 0); SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].Supply()) : 0);
SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5)); SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
SetDParam(3, ToPercent8(ge->rating)); SetDParam(3, ToPercent8(ge->rating));
DrawString(r.left + WD_FRAMERECT_LEFT + 6, r.right - WD_FRAMERECT_RIGHT - 6, y, STR_STATION_VIEW_CARGO_SUPPLY_RATING); DrawString(tr.Indent(6, rtl), STR_STATION_VIEW_CARGO_SUPPLY_RATING);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
} }
return CeilDiv(y - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL); return CeilDiv(tr.top - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
} }
/** /**
@ -2287,20 +2289,20 @@ struct SelectStationWindow : Window {
{ {
if (widget != WID_JS_PANEL) return; if (widget != WID_JS_PANEL) return;
uint y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
if (this->vscroll->GetPosition() == 0) { if (this->vscroll->GetPosition() == 0) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION); DrawString(tr, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
y += this->resize.step_height; tr.top += this->resize.step_height;
} }
for (uint i = std::max<uint>(1, this->vscroll->GetPosition()); i <= _stations_nearby_list.size(); ++i, y += this->resize.step_height) { for (uint i = std::max<uint>(1, this->vscroll->GetPosition()); i <= _stations_nearby_list.size(); ++i, tr.top += this->resize.step_height) {
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
if (i - this->vscroll->GetPosition() >= this->vscroll->GetCapacity()) break; if (i - this->vscroll->GetPosition() >= this->vscroll->GetCapacity()) break;
const T *st = T::Get(_stations_nearby_list[i - 1]); const T *st = T::Get(_stations_nearby_list[i - 1]);
SetDParam(0, st->index); SetDParam(0, st->index);
SetDParam(1, st->facilities); SetDParam(1, st->facilities);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION); DrawString(tr, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION);
} }
} }

View File

@ -137,24 +137,24 @@ struct StatusBarWindow : Window {
void DrawWidget(const Rect &r, int widget) const override void DrawWidget(const Rect &r, int widget) const override
{ {
int text_offset = std::max(0, (r.Height() - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered Rect tr = r.Shrink(WD_FRAMERECT_LEFT, 0, WD_FRAMERECT_RIGHT, 0);
int text_top = r.top + text_offset; tr.top = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL);
switch (widget) { switch (widget) {
case WID_S_LEFT: case WID_S_LEFT:
/* Draw the date */ /* Draw the date */
SetDParam(0, _date); SetDParam(0, _date);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
break; break;
case WID_S_RIGHT: { case WID_S_RIGHT: {
if (_local_company == COMPANY_SPECTATOR) { if (_local_company == COMPANY_SPECTATOR) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_STATUSBAR_SPECTATOR, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, STR_STATUSBAR_SPECTATOR, TC_FROMSTRING, SA_HOR_CENTER);
} else { } else {
/* Draw company money, if any */ /* Draw company money, if any */
const Company *c = Company::GetIfValid(_local_company); const Company *c = Company::GetIfValid(_local_company);
if (c != nullptr) { if (c != nullptr) {
SetDParam(0, c->money); SetDParam(0, c->money);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_COMPANY_MONEY, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, STR_COMPANY_MONEY, TC_FROMSTRING, SA_HOR_CENTER);
} }
} }
break; break;
@ -163,12 +163,12 @@ struct StatusBarWindow : Window {
case WID_S_MIDDLE: case WID_S_MIDDLE:
/* Draw status bar */ /* Draw status bar */
if (this->saving) { // true when saving is active if (this->saving) { // true when saving is active
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_HOR_CENTER | SA_VERT_CENTER); DrawString(tr, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_HOR_CENTER | SA_VERT_CENTER);
} else if (_do_autosave) { } else if (_do_autosave) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_HOR_CENTER);
} else if (_pause_mode != PM_UNPAUSED) { } else if (_pause_mode != PM_UNPAUSED) {
StringID msg = (_pause_mode & PM_PAUSED_LINK_GRAPH) ? STR_STATUSBAR_PAUSED_LINK_GRAPH : STR_STATUSBAR_PAUSED; StringID msg = (_pause_mode & PM_PAUSED_LINK_GRAPH) ? STR_STATUSBAR_PAUSED_LINK_GRAPH : STR_STATUSBAR_PAUSED;
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, msg, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, msg, TC_FROMSTRING, SA_HOR_CENTER);
} else if (this->ticker_scroll < TICKER_STOP && _statusbar_news_item != nullptr && _statusbar_news_item->string_id != 0) { } else if (this->ticker_scroll < TICKER_STOP && _statusbar_news_item != nullptr && _statusbar_news_item->string_id != 0) {
/* Draw the scrolling news text */ /* Draw the scrolling news text */
if (!DrawScrollingStatusText(_statusbar_news_item, ScaleGUITrad(this->ticker_scroll), r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) { if (!DrawScrollingStatusText(_statusbar_news_item, ScaleGUITrad(this->ticker_scroll), r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) {
@ -176,20 +176,20 @@ struct StatusBarWindow : Window {
if (Company::IsValidID(_local_company)) { if (Company::IsValidID(_local_company)) {
/* This is the default text */ /* This is the default text */
SetDParam(0, _local_company); SetDParam(0, _local_company);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_HOR_CENTER);
} }
} }
} else { } else {
if (Company::IsValidID(_local_company)) { if (Company::IsValidID(_local_company)) {
/* This is the default text */ /* This is the default text */
SetDParam(0, _local_company); SetDParam(0, _local_company);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, text_top, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_HOR_CENTER); DrawString(tr, STR_STATUSBAR_COMPANY_NAME, TC_FROMSTRING, SA_HOR_CENTER);
} }
} }
if (!this->reminder_timeout.HasElapsed()) { if (!this->reminder_timeout.HasElapsed()) {
Dimension icon_size = GetSpriteSize(SPR_UNREAD_NEWS); Dimension icon_size = GetSpriteSize(SPR_UNREAD_NEWS);
DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, r.right - WD_FRAMERECT_RIGHT - icon_size.width, CenterBounds(r.top, r.bottom, icon_size.height)); DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, tr.right - icon_size.width, CenterBounds(r.top, r.bottom, icon_size.height));
} }
break; break;
} }

View File

@ -692,19 +692,17 @@ public:
StoryPage *page = this->GetSelPage(); StoryPage *page = this->GetSelPage();
if (page == nullptr) return; if (page == nullptr) return;
const int x = r.left + WD_FRAMETEXT_LEFT; Rect fr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
const int y = r.top + WD_FRAMETEXT_TOP;
const int right = r.right - WD_FRAMETEXT_RIGHT;
const int bottom = r.bottom - WD_FRAMETEXT_BOTTOM;
/* Set up a clipping region for the panel. */ /* Set up a clipping region for the panel. */
DrawPixelInfo tmp_dpi; DrawPixelInfo tmp_dpi;
if (!FillDrawPixelInfo(&tmp_dpi, x, y, right - x + 1, bottom - y + 1)) return; if (!FillDrawPixelInfo(&tmp_dpi, fr.left, fr.top, fr.Width(), fr.Height())) return;
DrawPixelInfo *old_dpi = _cur_dpi; DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi; _cur_dpi = &tmp_dpi;
/* Draw content (now coordinates given to Draw** are local to the new clipping region). */ /* Draw content (now coordinates given to Draw** are local to the new clipping region). */
fr = fr.Translate(-fr.left, -fr.top);
int line_height = FONT_HEIGHT_NORMAL; int line_height = FONT_HEIGHT_NORMAL;
const int scrollpos = this->vscroll->GetPosition(); const int scrollpos = this->vscroll->GetPosition();
int y_offset = -scrollpos; int y_offset = -scrollpos;
@ -712,13 +710,13 @@ public:
/* Date */ /* Date */
if (page->date != INVALID_DATE) { if (page->date != INVALID_DATE) {
SetDParam(0, page->date); SetDParam(0, page->date);
DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK); DrawString(0, fr.right, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
} }
y_offset += line_height; y_offset += line_height;
/* Title */ /* Title */
SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title); SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER); y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
/* Page elements */ /* Page elements */
this->EnsureStoryPageElementLayout(); this->EnsureStoryPageElementLayout();

View File

@ -145,15 +145,13 @@ struct SubsidyListWindow : Window {
YearMonthDay ymd; YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd); ConvertDateToYMD(_date, &ymd);
int right = r.right - WD_FRAMERECT_RIGHT; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int y = r.top + WD_FRAMERECT_TOP;
int x = r.left + WD_FRAMERECT_LEFT;
int pos = -this->vscroll->GetPosition(); int pos = -this->vscroll->GetPosition();
const int cap = this->vscroll->GetCapacity(); const int cap = this->vscroll->GetCapacity();
/* Section for drawing the offered subsidies */ /* Section for drawing the offered subsidies */
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_TITLE); if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_TITLE);
pos++; pos++;
uint num = 0; uint num = 0;
@ -163,7 +161,7 @@ struct SubsidyListWindow : Window {
/* Displays the two offered towns */ /* Displays the two offered towns */
SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::Gui); SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::Gui);
SetDParam(7, _date - ymd.day + s->remaining * 32); SetDParam(7, _date - ymd.day + s->remaining * 32);
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_FROM_TO); DrawString(tr.left, tr.right, tr.top + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_FROM_TO);
} }
pos++; pos++;
num++; num++;
@ -171,13 +169,13 @@ struct SubsidyListWindow : Window {
} }
if (num == 0) { if (num == 0) {
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE); if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE);
pos++; pos++;
} }
/* Section for drawing the already granted subsidies */ /* Section for drawing the already granted subsidies */
pos++; pos++;
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_TITLE); if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_TITLE);
pos++; pos++;
num = 0; num = 0;
@ -189,7 +187,7 @@ struct SubsidyListWindow : Window {
SetDParam(8, _date - ymd.day + s->remaining * 32); SetDParam(8, _date - ymd.day + s->remaining * 32);
/* Displays the two connected stations */ /* Displays the two connected stations */
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_FROM_TO); DrawString(tr.left, tr.right, tr.top + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_FROM_TO);
} }
pos++; pos++;
num++; num++;
@ -197,7 +195,7 @@ struct SubsidyListWindow : Window {
} }
if (num == 0) { if (num == 0) {
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE); if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE);
pos++; pos++;
} }
} }

View File

@ -148,17 +148,15 @@ void TextfileWindow::SetupScrollbars(bool force_reflow)
{ {
if (widget != WID_TF_BACKGROUND) return; if (widget != WID_TF_BACKGROUND) return;
const int x = r.left + WD_FRAMETEXT_LEFT; Rect fr = r.Shrink(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM);
const int y = r.top + WD_FRAMETEXT_TOP;
const int right = r.right - WD_FRAMETEXT_RIGHT;
const int bottom = r.bottom - WD_FRAMETEXT_BOTTOM;
DrawPixelInfo new_dpi; DrawPixelInfo new_dpi;
if (!FillDrawPixelInfo(&new_dpi, x, y, right - x + 1, bottom - y + 1)) return; if (!FillDrawPixelInfo(&new_dpi, fr.left, fr.top, fr.Width(), fr.Height())) return;
DrawPixelInfo *old_dpi = _cur_dpi; DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &new_dpi; _cur_dpi = &new_dpi;
/* Draw content (now coordinates given to DrawString* are local to the new clipping region). */ /* Draw content (now coordinates given to DrawString* are local to the new clipping region). */
fr = fr.Translate(-fr.left, -fr.top);
int line_height = FONT_HEIGHT_MONO; int line_height = FONT_HEIGHT_MONO;
int pos = this->vscroll->GetPosition(); int pos = this->vscroll->GetPosition();
int cap = this->vscroll->GetCapacity(); int cap = this->vscroll->GetCapacity();
@ -169,9 +167,9 @@ void TextfileWindow::SetupScrollbars(bool force_reflow)
int y_offset = (line.top - pos) * line_height; int y_offset = (line.top - pos) * line_height;
if (IsWidgetLowered(WID_TF_WRAPTEXT)) { if (IsWidgetLowered(WID_TF_WRAPTEXT)) {
DrawStringMultiLine(0, right - x, y_offset, bottom - y, line.text, TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO); DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, line.text, TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO);
} else { } else {
DrawString(-this->hscroll->GetPosition(), right - x, y_offset, line.text, TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO); DrawString(-this->hscroll->GetPosition(), fr.right, y_offset, line.text, TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO);
} }
} }

View File

@ -356,7 +356,7 @@ struct TimetableWindow : Window {
switch (widget) { switch (widget) {
case WID_VT_TIMETABLE_PANEL: { case WID_VT_TIMETABLE_PANEL: {
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
int i = this->vscroll->GetPosition(); int i = this->vscroll->GetPosition();
VehicleOrderID order_id = (i + 1) / 2; VehicleOrderID order_id = (i + 1) / 2;
bool final_order = false; bool final_order = false;
@ -364,7 +364,7 @@ struct TimetableWindow : Window {
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
SetDParamMaxValue(0, v->GetNumOrders(), 2); SetDParamMaxValue(0, v->GetNumOrders(), 2);
int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3; int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
int middle = rtl ? r.right - WD_FRAMERECT_RIGHT - index_column_width : r.left + WD_FRAMERECT_LEFT + index_column_width; int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
const Order *order = v->GetOrder(order_id); const Order *order = v->GetOrder(order_id);
while (order != nullptr) { while (order != nullptr) {
@ -372,7 +372,7 @@ struct TimetableWindow : Window {
if (!this->vscroll->IsVisible(i)) break; if (!this->vscroll->IsVisible(i)) break;
if (i % 2 == 0) { if (i % 2 == 0) {
DrawOrderString(v, order, order_id, y, i == selected, true, r.left + WD_FRAMERECT_LEFT, middle, r.right - WD_FRAMERECT_RIGHT); DrawOrderString(v, order, order_id, tr.top, i == selected, true, tr.left, middle, tr.right);
order_id++; order_id++;
@ -408,13 +408,13 @@ struct TimetableWindow : Window {
} }
SetDParam(2, order->GetMaxSpeed()); SetDParam(2, order->GetMaxSpeed());
DrawString(rtl ? r.left + WD_FRAMERECT_LEFT : middle, rtl ? middle : r.right - WD_FRAMERECT_LEFT, y, string, colour); DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top, string, colour);
if (final_order) break; if (final_order) break;
} }
i++; i++;
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
} }
break; break;
} }
@ -432,16 +432,13 @@ struct TimetableWindow : Window {
VehicleOrderID earlyID = BuildArrivalDepartureList(v, arr_dep) ? cur_order : (VehicleOrderID)INVALID_VEH_ORDER_ID; VehicleOrderID earlyID = BuildArrivalDepartureList(v, arr_dep) ? cur_order : (VehicleOrderID)INVALID_VEH_ORDER_ID;
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
bool show_late = this->show_expected && v->lateness_counter > DAY_TICKS; bool show_late = this->show_expected && v->lateness_counter > DAY_TICKS;
Ticks offset = show_late ? 0 : -v->lateness_counter; Ticks offset = show_late ? 0 : -v->lateness_counter;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int abbr_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->deparr_abbr_width : r.left + WD_FRAMERECT_LEFT; Rect abbr = tr.WithWidth(this->deparr_abbr_width, rtl);
int abbr_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->deparr_abbr_width; Rect time = tr.WithWidth(this->deparr_time_width, !rtl);
int time_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_RIGHT - this->deparr_time_width;
int time_right = rtl ? r.left + WD_FRAMERECT_LEFT + this->deparr_time_width : r.right - WD_FRAMERECT_RIGHT;
for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop for (int i = this->vscroll->GetPosition(); i / 2 < v->GetNumOrders(); ++i) { // note: i is also incremented in the loop
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
@ -449,54 +446,54 @@ struct TimetableWindow : Window {
if (i % 2 == 0) { if (i % 2 == 0) {
if (arr_dep[i / 2].arrival != INVALID_TICKS) { if (arr_dep[i / 2].arrival != INVALID_TICKS) {
DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK); DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
if (this->show_expected && i / 2 == earlyID) { if (this->show_expected && i / 2 == earlyID) {
SetDParam(0, _date + arr_dep[i / 2].arrival / DAY_TICKS); SetDParam(0, _date + arr_dep[i / 2].arrival / DAY_TICKS);
DrawString(time_left, time_right, y, STR_JUST_DATE_TINY, TC_GREEN); DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY, TC_GREEN);
} else { } else {
SetDParam(0, _date + (arr_dep[i / 2].arrival + offset) / DAY_TICKS); SetDParam(0, _date + (arr_dep[i / 2].arrival + offset) / DAY_TICKS);
DrawString(time_left, time_right, y, STR_JUST_DATE_TINY, DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY,
show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK); show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
} }
} }
} else { } else {
if (arr_dep[i / 2].departure != INVALID_TICKS) { if (arr_dep[i / 2].departure != INVALID_TICKS) {
DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK); DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
SetDParam(0, _date + (arr_dep[i/2].departure + offset) / DAY_TICKS); SetDParam(0, _date + (arr_dep[i/2].departure + offset) / DAY_TICKS);
DrawString(time_left, time_right, y, STR_JUST_DATE_TINY, DrawString(time.left, time.right, tr.top, STR_JUST_DATE_TINY,
show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK); show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
} }
} }
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
} }
break; break;
} }
case WID_VT_SUMMARY_PANEL: { case WID_VT_SUMMARY_PANEL: {
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0; Ticks total_time = v->orders != nullptr ? v->orders->GetTimetableDurationIncomplete() : 0;
if (total_time != 0) { if (total_time != 0) {
SetTimetableParams(0, 1, total_time); SetTimetableParams(0, 1, total_time);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, v->orders->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE); DrawString(tr, v->orders->IsCompleteTimetable() ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE);
} }
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
if (v->timetable_start != 0) { if (v->timetable_start != 0) {
/* We are running towards the first station so we can start the /* We are running towards the first station so we can start the
* timetable at the given time. */ * timetable at the given time. */
SetDParam(0, STR_JUST_DATE_TINY); SetDParam(0, STR_JUST_DATE_TINY);
SetDParam(1, v->timetable_start); SetDParam(1, v->timetable_start);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TIMETABLE_STATUS_START_AT); DrawString(tr, STR_TIMETABLE_STATUS_START_AT);
} else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) { } else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
/* We aren't running on a timetable yet, so how can we be "on time" /* We aren't running on a timetable yet, so how can we be "on time"
* when we aren't even "on service"/"on duty"? */ * when we aren't even "on service"/"on duty"? */
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TIMETABLE_STATUS_NOT_STARTED); DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
} else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DAY_TICKS == 0)) { } else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DAY_TICKS == 0)) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TIMETABLE_STATUS_ON_TIME); DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME);
} else { } else {
SetTimetableParams(0, 1, abs(v->lateness_counter)); SetTimetableParams(0, 1, abs(v->lateness_counter));
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, v->lateness_counter < 0 ? STR_TIMETABLE_STATUS_EARLY : STR_TIMETABLE_STATUS_LATE); DrawString(tr, v->lateness_counter < 0 ? STR_TIMETABLE_STATUS_EARLY : STR_TIMETABLE_STATUS_LATE);
} }
break; break;
} }

View File

@ -106,10 +106,11 @@ public:
void Draw(const Rect &r, bool sel, Colours bg_colour) const override void Draw(const Rect &r, bool sel, Colours bg_colour) const override
{ {
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
Rect tr = r.Shrink(WD_DROPDOWNTEXT_LEFT, 0, WD_DROPDOWNTEXT_RIGHT, 0);
if (this->checked) { if (this->checked) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK); DrawString(tr, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
} }
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : this->checkmark_width), r.right - WD_FRAMERECT_RIGHT - (rtl ? this->checkmark_width : 0), r.top, this->String(), sel ? TC_WHITE : TC_BLACK); DrawString(tr.Indent(this->checkmark_width, rtl), this->String(), sel ? TC_WHITE : TC_BLACK);
} }
}; };
@ -138,12 +139,12 @@ public:
CompanyID company = (CompanyID)this->result; CompanyID company = (CompanyID)this->result;
SetDParam(0, company); SetDParam(0, company);
SetDParam(1, company); SetDParam(1, company);
return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6; return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT + 6;
} }
uint Height(uint width) const override uint Height(uint width) const override
{ {
return std::max(std::max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL); return std::max(std::max(this->icon_size.height, this->lock_size.height) + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM, (uint)FONT_HEIGHT_NORMAL);
} }
void Draw(const Rect &r, bool sel, Colours bg_colour) const override void Draw(const Rect &r, bool sel, Colours bg_colour) const override
@ -154,13 +155,14 @@ public:
/* It's possible the company is deleted while the dropdown is open */ /* It's possible the company is deleted while the dropdown is open */
if (!Company::IsValidID(company)) return; if (!Company::IsValidID(company)) return;
Rect tr = r.Shrink(WD_DROPDOWNTEXT_LEFT, 0, WD_DROPDOWNTEXT_RIGHT, 0);
int icon_y = CenterBounds(r.top, r.bottom, icon_size.height); int icon_y = CenterBounds(r.top, r.bottom, icon_size.height);
int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL); int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL);
int lock_y = CenterBounds(r.top, r.bottom, lock_size.height); int lock_y = CenterBounds(r.top, r.bottom, lock_size.height);
DrawCompanyIcon(company, rtl ? r.right - this->icon_size.width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT, icon_y); DrawCompanyIcon(company, tr.WithWidth(this->icon_size.width, rtl).left, icon_y);
if (NetworkCompanyIsPassworded(company)) { if (NetworkCompanyIsPassworded(company)) {
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? r.left + WD_FRAMERECT_LEFT : r.right - this->lock_size.width - WD_FRAMERECT_RIGHT, lock_y); DrawSprite(SPR_LOCK, PAL_NONE, tr.WithWidth(this->lock_size.width, !rtl).left, lock_y);
} }
SetDParam(0, company); SetDParam(0, company);
@ -171,7 +173,8 @@ public:
} else { } else {
col = sel ? TC_WHITE : TC_BLACK; col = sel ? TC_WHITE : TC_BLACK;
} }
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 3 + this->lock_size.width : 3 + this->icon_size.width), r.right - WD_FRAMERECT_RIGHT - (rtl ? 3 + this->icon_size.width : 3 + this->lock_size.width), text_y, STR_COMPANY_NAME_COMPANY_NUM, col); tr = tr.Indent(this->icon_size.width + 3, rtl).Indent(this->lock_size.width + 3, !rtl);
DrawString(tr.left, tr.right, text_y, STR_COMPANY_NAME_COMPANY_NUM, col);
} }
}; };
@ -2355,10 +2358,10 @@ struct ScenarioEditorToolbarWindow : Window {
{ {
switch (widget) { switch (widget) {
case WID_TE_SPACER: { case WID_TE_SPACER: {
int height = r.bottom - r.top; int height = r.Height();
if (height > 2 * FONT_HEIGHT_NORMAL) { if (height > 2 * FONT_HEIGHT_NORMAL) {
DrawString(r.left, r.right, (height + 1) / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER); DrawString(r.left, r.right, height / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, (height + 1) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER); DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
} else { } else {
DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER); DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
} }

View File

@ -137,14 +137,10 @@ public:
/** Draw the contents of the ratings panel. May request a resize of the window if the contents does not fit. */ /** Draw the contents of the ratings panel. May request a resize of the window if the contents does not fit. */
void DrawRatings() void DrawRatings()
{ {
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO); Rect r = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO)->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint left = nwid->pos_x + WD_FRAMERECT_LEFT;
uint right = nwid->pos_x + nwid->current_x - 1 - WD_FRAMERECT_RIGHT;
uint y = nwid->pos_y + WD_FRAMERECT_TOP; DrawString(r, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
r.top += FONT_HEIGHT_NORMAL;
DrawString(left, right, y, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
y += FONT_HEIGHT_NORMAL;
Dimension icon_size = GetSpriteSize(SPR_COMPANY_ICON); Dimension icon_size = GetSpriteSize(SPR_COMPANY_ICON);
int icon_width = icon_size.width; int icon_width = icon_size.width;
@ -155,56 +151,52 @@ public:
int exclusive_y_offset = (FONT_HEIGHT_NORMAL - exclusive_size.height) / 2; int exclusive_y_offset = (FONT_HEIGHT_NORMAL - exclusive_size.height) / 2;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint text_left = left + (rtl ? 0 : icon_width + exclusive_width + 4); Rect text = r.Indent(icon_width + exclusive_width + 4, rtl);
uint text_right = right - (rtl ? icon_width + exclusive_width + 4 : 0); uint icon_left = r.WithWidth(icon_width, rtl).left;
uint icon_left = rtl ? right - icon_width : left; uint exclusive_left = r.Indent(icon_width + 2, rtl).WithWidth(exclusive_width, rtl).left;
uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
/* Draw list of companies */ /* Draw list of companies */
for (const Company *c : Company::Iterate()) { for (const Company *c : Company::Iterate()) {
if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) { if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
DrawCompanyIcon(c->index, icon_left, y + icon_y_offset); DrawCompanyIcon(c->index, icon_left, text.top + icon_y_offset);
SetDParam(0, c->index); SetDParam(0, c->index);
SetDParam(1, c->index); SetDParam(1, c->index);
int r = this->town->ratings[c->index]; int rating = this->town->ratings[c->index];
StringID str = STR_CARGO_RATING_APPALLING; StringID str = STR_CARGO_RATING_APPALLING;
if (r > RATING_APPALLING) str++; if (rating > RATING_APPALLING) str++;
if (r > RATING_VERYPOOR) str++; if (rating > RATING_VERYPOOR) str++;
if (r > RATING_POOR) str++; if (rating > RATING_POOR) str++;
if (r > RATING_MEDIOCRE) str++; if (rating > RATING_MEDIOCRE) str++;
if (r > RATING_GOOD) str++; if (rating > RATING_GOOD) str++;
if (r > RATING_VERYGOOD) str++; if (rating > RATING_VERYGOOD) str++;
if (r > RATING_EXCELLENT) str++; if (rating > RATING_EXCELLENT) str++;
SetDParam(2, str); SetDParam(2, str);
if (this->town->exclusivity == c->index) { if (this->town->exclusivity == c->index) {
DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive_left, y + exclusive_y_offset); DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive_left, r.top + exclusive_y_offset);
} }
DrawString(text_left, text_right, y, STR_LOCAL_AUTHORITY_COMPANY_RATING); DrawString(text, STR_LOCAL_AUTHORITY_COMPANY_RATING);
y += FONT_HEIGHT_NORMAL; text.top += FONT_HEIGHT_NORMAL;
} }
} }
y = y + WD_FRAMERECT_BOTTOM - nwid->pos_y; // Compute needed size of the widget. text.bottom = text.top - 1;
if (y > nwid->current_y) { if (text.bottom > r.bottom) {
/* If the company list is too big to fit, mark ourself dirty and draw again. */ /* If the company list is too big to fit, mark ourself dirty and draw again. */
ResizeWindow(this, 0, y - nwid->current_y, false); ResizeWindow(this, 0, text.bottom - r.bottom, false);
} }
} }
/** Draws the contents of the actions panel. May re-initialise window to resize panel, if the list does not fit. */ /** Draws the contents of the actions panel. May re-initialise window to resize panel, if the list does not fit. */
void DrawActions() void DrawActions()
{ {
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST); Rect r = this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST)->GetCurrentRect().Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
uint left = nwid->pos_x + WD_FRAMERECT_LEFT;
uint right = nwid->pos_x + nwid->current_x - 1 - WD_FRAMERECT_RIGHT;
uint y = nwid->pos_y + WD_FRAMERECT_TOP;
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTIONS_TITLE); DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
y += FONT_HEIGHT_NORMAL; r.top += FONT_HEIGHT_NORMAL;
/* Draw list of actions */ /* Draw list of actions */
for (int i = 0; i < TACT_COUNT; i++) { for (int i = 0; i < TACT_COUNT; i++) {
@ -216,8 +208,8 @@ public:
if (HasBit(this->available_actions, i)) action_colour = TC_ORANGE; if (HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
if (this->sel_index == i) action_colour = TC_WHITE; if (this->sel_index == i) action_colour = TC_WHITE;
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour); DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
y += FONT_HEIGHT_NORMAL; r.top += FONT_HEIGHT_NORMAL;
} }
} }
@ -235,7 +227,7 @@ public:
bool affordable = action_cost < Company::GetIfValid(_local_company)->money; bool affordable = action_cost < Company::GetIfValid(_local_company)->money;
SetDParam(0, action_cost); SetDParam(0, action_cost);
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, DrawStringMultiLine(r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM),
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index, STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index,
affordable ? TC_YELLOW : TC_RED); affordable ? TC_YELLOW : TC_RED);
} }
@ -389,21 +381,24 @@ public:
{ {
if (widget != WID_TV_INFO) return; if (widget != WID_TV_INFO) return;
uint y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
SetDParam(0, this->town->cache.population); SetDParam(0, this->town->cache.population);
SetDParam(1, this->town->cache.num_houses); SetDParam(1, this->town->cache.num_houses);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y, STR_TOWN_VIEW_POPULATION_HOUSES); DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, 1 << CT_PASSENGERS); SetDParam(0, 1 << CT_PASSENGERS);
SetDParam(1, this->town->supplied[CT_PASSENGERS].old_act); SetDParam(1, this->town->supplied[CT_PASSENGERS].old_act);
SetDParam(2, this->town->supplied[CT_PASSENGERS].old_max); SetDParam(2, this->town->supplied[CT_PASSENGERS].old_max);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX); DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, 1 << CT_MAIL); SetDParam(0, 1 << CT_MAIL);
SetDParam(1, this->town->supplied[CT_MAIL].old_act); SetDParam(1, this->town->supplied[CT_MAIL].old_act);
SetDParam(2, this->town->supplied[CT_MAIL].old_max); SetDParam(2, this->town->supplied[CT_MAIL].old_max);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX); DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
tr.top += FONT_HEIGHT_NORMAL;
bool first = true; bool first = true;
for (int i = TE_BEGIN; i < TE_END; i++) { for (int i = TE_BEGIN; i < TE_END; i++) {
@ -412,13 +407,12 @@ public:
if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue; if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
if (first) { if (first) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH); DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
tr.top += FONT_HEIGHT_NORMAL;
first = false; first = false;
} }
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
uint cargo_text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : 20);
uint cargo_text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? 20 : 0);
const CargoSpec *cargo = FindFirstCargoWithTownEffect((TownEffect)i); const CargoSpec *cargo = FindFirstCargoWithTownEffect((TownEffect)i);
assert(cargo != nullptr); assert(cargo != nullptr);
@ -448,26 +442,30 @@ public:
SetDParam(2, cargo->Index()); SetDParam(2, cargo->Index());
SetDParam(3, this->town->goal[i]); SetDParam(3, this->town->goal[i]);
} }
DrawString(cargo_text_left, cargo_text_right, y += FONT_HEIGHT_NORMAL, string); DrawString(tr.Indent(20, rtl), string);
tr.top += FONT_HEIGHT_NORMAL;
} }
if (HasBit(this->town->flags, TOWN_IS_GROWING)) { if (HasBit(this->town->flags, TOWN_IS_GROWING)) {
SetDParam(0, RoundDivSU(this->town->growth_rate + 1, DAY_TICKS)); SetDParam(0, RoundDivSU(this->town->growth_rate + 1, DAY_TICKS));
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED); DrawString(tr, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED);
tr.top += FONT_HEIGHT_NORMAL;
} else { } else {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_TOWN_GROW_STOPPED); DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
tr.top += FONT_HEIGHT_NORMAL;
} }
/* only show the town noise, if the noise option is activated. */ /* only show the town noise, if the noise option is activated. */
if (_settings_game.economy.station_noise_level) { if (_settings_game.economy.station_noise_level) {
SetDParam(0, this->town->noise_reached); SetDParam(0, this->town->noise_reached);
SetDParam(1, this->town->MaxTownNoise()); SetDParam(1, this->town->MaxTownNoise());
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_NOISE_IN_TOWN); DrawString(tr, STR_TOWN_VIEW_NOISE_IN_TOWN);
tr.top += FONT_HEIGHT_NORMAL;
} }
if (!this->town->text.empty()) { if (!this->town->text.empty()) {
SetDParamStr(0, this->town->text); SetDParamStr(0, this->town->text);
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y += FONT_HEIGHT_NORMAL, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK); tr.top = DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_BLACK);
} }
} }
@ -821,18 +819,17 @@ public:
case WID_TD_LIST: { case WID_TD_LIST: {
int n = 0; int n = 0;
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
if (this->towns.size() == 0) { // No towns available. if (this->towns.size() == 0) { // No towns available.
DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y, STR_TOWN_DIRECTORY_NONE); DrawString(tr, STR_TOWN_DIRECTORY_NONE);
break; break;
} }
/* At least one town available. */ /* At least one town available. */
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD); Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
int text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : icon_size.width + 2); int icon_x = tr.WithWidth(icon_size.width, rtl).left;
int text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? icon_size.width + 2 : 0); tr = tr.Indent(icon_size.width + 2, rtl);
int icon_x = rtl ? r.right - WD_FRAMERECT_RIGHT - icon_size.width : r.left + WD_FRAMERECT_LEFT;
for (uint i = this->vscroll->GetPosition(); i < this->towns.size(); i++) { for (uint i = this->vscroll->GetPosition(); i < this->towns.size(); i++) {
const Town *t = this->towns[i]; const Town *t = this->towns[i];
@ -840,19 +837,19 @@ public:
/* Draw rating icon. */ /* Draw rating icon. */
if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) { if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) {
DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2); DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
} else { } else {
SpriteID icon = SPR_TOWN_RATING_APALLING; SpriteID icon = SPR_TOWN_RATING_APALLING;
if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE; if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE;
if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD; if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD;
DrawSprite(icon, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2); DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
} }
SetDParam(0, t->index); SetDParam(0, t->index);
SetDParam(1, t->cache.population); SetDParam(1, t->cache.population);
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, GetTownString(t)); DrawString(tr.left, tr.right, tr.top + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, GetTownString(t));
y += this->resize.step_height; tr.top += this->resize.step_height;
if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window
} }
break; break;

View File

@ -52,18 +52,20 @@ public:
case WID_TT_CATENARY: case WID_TT_CATENARY:
case WID_TT_LOADING: { case WID_TT_LOADING: {
uint i = widget - WID_TT_BEGIN; uint i = widget - WID_TT_BEGIN;
if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + 1, r.top + 1); if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + WD_BEVEL_LEFT, r.top + WD_BEVEL_TOP);
break; break;
} }
case WID_TT_BUTTONS: case WID_TT_BUTTONS: {
const Rect fr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) { for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) {
if (i == WID_TT_LOADING) continue; // Do not draw button for invisible loading indicators. if (i == WID_TT_LOADING) continue; // Do not draw button for invisible loading indicators.
const NWidgetBase *wi = this->GetWidget<NWidgetBase>(i); const Rect wr = this->GetWidget<NWidgetBase>(i)->GetCurrentRect().Shrink(WD_BEVEL_LEFT, WD_BEVEL_TOP, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM);
DrawFrameRect(wi->pos_x + 1, r.top + 2, wi->pos_x + wi->current_x - 2, r.bottom - 2, COLOUR_PALE_GREEN, DrawFrameRect(wr.left, fr.top, wr.right, fr.bottom, COLOUR_PALE_GREEN,
HasBit(_invisibility_opt, i - WID_TT_BEGIN) ? FR_LOWERED : FR_NONE); HasBit(_invisibility_opt, i - WID_TT_BEGIN) ? FR_LOWERED : FR_NONE);
} }
break; break;
}
} }
} }

View File

@ -169,7 +169,7 @@ public:
if (widget >= WID_BT_TYPE_BUTTON_FIRST) { if (widget >= WID_BT_TYPE_BUTTON_FIRST) {
const int index = widget - WID_BT_TYPE_BUTTON_FIRST; const int index = widget - WID_BT_TYPE_BUTTON_FIRST;
/* Trees "grow" in the centre on the bottom line of the buttons */ /* Trees "grow" in the centre on the bottom line of the buttons */
DrawSprite(tree_sprites[index].sprite, tree_sprites[index].pal, CenterBounds(r.left, r.right, 0) + WD_FRAMERECT_LEFT, r.bottom - ScaleGUITrad(BUTTON_BOTTOM_OFFSET)); DrawSprite(tree_sprites[index].sprite, tree_sprites[index].pal, CenterBounds(r.left, r.right, 0), r.bottom - ScaleGUITrad(BUTTON_BOTTOM_OFFSET));
} }
} }

View File

@ -539,7 +539,7 @@ typedef std::vector<RefitOption> SubtypeList; ///< List of refit subtypes associ
*/ */
static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int sel[2], uint pos, uint rows, uint delta, const Rect &r) static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int sel[2], uint pos, uint rows, uint delta, const Rect &r)
{ {
uint y = r.top + WD_MATRIX_TOP; Rect ir = r.Shrink(WD_MATRIX_LEFT, WD_MATRIX_TOP, WD_MATRIX_RIGHT, WD_MATRIX_LEFT);
uint current = 0; uint current = 0;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
@ -547,12 +547,11 @@ static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int
uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height; uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height;
int linecolour = _colour_gradient[COLOUR_ORANGE][4]; int linecolour = _colour_gradient[COLOUR_ORANGE][4];
int iconleft = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth : r.left + WD_MATRIX_LEFT; int iconleft = rtl ? ir.right - iconwidth : ir.left;
int iconcenter = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth / 2 : r.left + WD_MATRIX_LEFT + iconwidth / 2; int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2;
int iconinner = rtl ? r.right - WD_MATRIX_RIGHT - iconwidth : r.left + WD_MATRIX_LEFT + iconwidth; int iconinner = rtl ? ir.right - iconwidth : ir.left + iconwidth;
int textleft = r.left + WD_MATRIX_LEFT + (rtl ? 0 : iconwidth + 4); Rect tr = ir.Indent(iconwidth + 4, rtl);
int textright = r.right - WD_MATRIX_RIGHT - (rtl ? iconwidth + 4 : 0);
/* Draw the list of subtypes for each cargo, and find the selected refit option (by its position). */ /* Draw the list of subtypes for each cargo, and find the selected refit option (by its position). */
for (uint i = 0; current < pos + rows && i < NUM_CARGO; i++) { for (uint i = 0; current < pos + rows && i < NUM_CARGO; i++) {
@ -571,12 +570,12 @@ static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int
if (list[i].size() > 1) { if (list[i].size() > 1) {
if (refit.subtype != 0xFF) { if (refit.subtype != 0xFF) {
/* Draw tree lines */ /* Draw tree lines */
int ycenter = y + FONT_HEIGHT_NORMAL / 2; int ycenter = tr.top + FONT_HEIGHT_NORMAL / 2;
GfxDrawLine(iconcenter, y - WD_MATRIX_TOP, iconcenter, j == list[i].size() - 1 ? ycenter : y - WD_MATRIX_TOP + delta - 1, linecolour); GfxDrawLine(iconcenter, tr.top - WD_MATRIX_TOP, iconcenter, j == list[i].size() - 1 ? ycenter : tr.top - WD_MATRIX_TOP + delta - 1, linecolour);
GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour); GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour);
} else { } else {
/* Draw expand/collapse icon */ /* Draw expand/collapse icon */
DrawSprite(sel[0] == (int)i ? SPR_CIRCLE_UNFOLDED : SPR_CIRCLE_FOLDED, PAL_NONE, iconleft, y + (FONT_HEIGHT_NORMAL - iconheight) / 2); DrawSprite(sel[0] == (int)i ? SPR_CIRCLE_UNFOLDED : SPR_CIRCLE_FOLDED, PAL_NONE, iconleft, tr.top + (FONT_HEIGHT_NORMAL - iconheight) / 2);
} }
} }
@ -584,9 +583,9 @@ static void DrawVehicleRefitWindow(const SubtypeList list[NUM_CARGO], const int
/* Get the cargo name. */ /* Get the cargo name. */
SetDParam(0, CargoSpec::Get(refit.cargo)->name); SetDParam(0, CargoSpec::Get(refit.cargo)->name);
SetDParam(1, refit.string); SetDParam(1, refit.string);
DrawString(textleft, textright, y, STR_JUST_STRING_STRING, colour); DrawString(tr, STR_JUST_STRING_STRING, colour);
y += delta; tr.top += delta;
current++; current++;
} }
} }
@ -999,8 +998,7 @@ struct RefitWindow : public Window {
if (this->cargo != nullptr) { if (this->cargo != nullptr) {
StringID string = this->GetCapacityString(this->cargo); StringID string = this->GetCapacityString(this->cargo);
if (string != INVALID_STRING_ID) { if (string != INVALID_STRING_ID) {
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, DrawStringMultiLine(r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM), string);
r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, string);
} }
} }
break; break;
@ -1637,25 +1635,22 @@ uint GetVehicleListHeight(VehicleType type, uint divisor)
*/ */
void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
{ {
int left = r.left + WD_MATRIX_LEFT; Rect ir = r.WithHeight(line_height).Shrink(WD_MATRIX_LEFT, 0, WD_MATRIX_RIGHT, 0);
int right = r.right - WD_MATRIX_RIGHT;
int width = right - left;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
int text_offset = std::max<int>(GetSpriteSize(SPR_PROFIT_LOT).width, GetDigitWidth() * this->unitnumber_digits) + WD_FRAMERECT_RIGHT; Dimension profit = GetSpriteSize(SPR_PROFIT_LOT);
int text_left = left + (rtl ? 0 : text_offset); int text_offset = std::max<int>(profit.width, GetDigitWidth() * this->unitnumber_digits) + WD_FRAMERECT_RIGHT;
int text_right = right - (rtl ? text_offset : 0); Rect tr = ir.Indent(text_offset, rtl);
bool show_orderlist = this->vli.vtype >= VEH_SHIP; bool show_orderlist = this->vli.vtype >= VEH_SHIP;
int orderlist_left = left + (rtl ? 0 : std::max(ScaleGUITrad(100) + text_offset, width / 2)); Rect olr = ir.Indent(std::max(ScaleGUITrad(100) + text_offset, ir.Width() / 2), rtl);
int orderlist_right = right - (rtl ? std::max(ScaleGUITrad(100) + text_offset, width / 2) : 0);
int image_left = (rtl && show_orderlist) ? orderlist_right : text_left; int image_left = (rtl && show_orderlist) ? olr.right : tr.left;
int image_right = (!rtl && show_orderlist) ? orderlist_left : text_right; int image_right = (!rtl && show_orderlist) ? olr.left : tr.right;
int image_height = ScaleGUITrad(GetVehicleHeight(this->vli.vtype));
int vehicle_button_x = rtl ? right - GetSpriteSize(SPR_PROFIT_LOT).width : left; int vehicle_button_x = rtl ? ir.right - profit.width : ir.left;
int y = r.top;
uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size())); uint max = static_cast<uint>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()));
for (uint i = this->vscroll->GetPosition(); i < max; ++i) { for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
@ -1663,31 +1658,31 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
SetDParam(0, vehgroup.GetDisplayProfitThisYear()); SetDParam(0, vehgroup.GetDisplayProfitThisYear());
SetDParam(1, vehgroup.GetDisplayProfitLastYear()); SetDParam(1, vehgroup.GetDisplayProfitLastYear());
DrawString(text_left, text_right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR); DrawString(tr.left, tr.right, ir.bottom - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
DrawVehicleProfitButton(vehgroup.GetOldestVehicleAge(), vehgroup.GetDisplayProfitLastYear(), vehgroup.NumVehicles(), vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3); DrawVehicleProfitButton(vehgroup.GetOldestVehicleAge(), vehgroup.GetDisplayProfitLastYear(), vehgroup.NumVehicles(), vehicle_button_x, ir.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL);
switch (this->grouping) { switch (this->grouping) {
case GB_NONE: { case GB_NONE: {
const Vehicle *v = vehgroup.GetSingleVehicle(); const Vehicle *v = vehgroup.GetSingleVehicle();
if (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) { if (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) {
DrawSprite(SPR_WARNING_SIGN, PAL_NONE, vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3 + GetSpriteSize(SPR_PROFIT_LOT).height); DrawSprite(SPR_WARNING_SIGN, PAL_NONE, vehicle_button_x, ir.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL + profit.height);
} }
DrawVehicleImage(v, image_left, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0); DrawVehicleImage(v, image_left, image_right, CenterBounds(ir.top, ir.bottom, image_height), selected_vehicle, EIT_IN_LIST, 0);
if (!v->name.empty()) { if (!v->name.empty()) {
/* The vehicle got a name so we will print it */ /* The vehicle got a name so we will print it */
SetDParam(0, v->index); SetDParam(0, v->index);
DrawString(text_left, text_right, y, STR_TINY_BLACK_VEHICLE); DrawString(tr.left, tr.right, ir.top, STR_TINY_BLACK_VEHICLE);
} else if (v->group_id != DEFAULT_GROUP) { } else if (v->group_id != DEFAULT_GROUP) {
/* The vehicle has no name, but is member of a group, so print group name */ /* The vehicle has no name, but is member of a group, so print group name */
SetDParam(0, v->group_id); SetDParam(0, v->group_id);
DrawString(text_left, text_right, y, STR_TINY_GROUP, TC_BLACK); DrawString(tr.left, tr.right, ir.top, STR_TINY_GROUP, TC_BLACK);
} }
if (show_orderlist) DrawSmallOrderList(v, orderlist_left, orderlist_right, y, this->order_arrow_width, v->cur_real_order_index); if (show_orderlist) DrawSmallOrderList(v, olr.left, olr.right, ir.top, this->order_arrow_width, v->cur_real_order_index);
StringID str; StringID str;
if (v->IsChainInDepot()) { if (v->IsChainInDepot()) {
@ -1697,7 +1692,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
} }
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
DrawString(left, right, y + 2, str); DrawString(ir.left, ir.right, ir.top + WD_FRAMERECT_TOP, str);
break; break;
} }
@ -1706,20 +1701,20 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
for (int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) { for (int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
if (image_left + 8 * i >= image_right) break; // Break if there is no more space to draw any more vehicles anyway. if (image_left + 8 * i >= image_right) break; // Break if there is no more space to draw any more vehicles anyway.
DrawVehicleImage(vehgroup.vehicles_begin[i], image_left + 8 * i, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0); DrawVehicleImage(vehgroup.vehicles_begin[i], image_left + 8 * i, image_right, CenterBounds(ir.top, ir.bottom, image_height), selected_vehicle, EIT_IN_LIST, 0);
} }
if (show_orderlist) DrawSmallOrderList((vehgroup.vehicles_begin[0])->GetFirstOrder(), orderlist_left, orderlist_right, y, this->order_arrow_width); if (show_orderlist) DrawSmallOrderList((vehgroup.vehicles_begin[0])->GetFirstOrder(), olr.left, olr.right, ir.top, this->order_arrow_width);
SetDParam(0, vehgroup.NumVehicles()); SetDParam(0, vehgroup.NumVehicles());
DrawString(left, right, y + 2, STR_BLACK_COMMA); DrawString(ir.left, ir.right, ir.top + WD_FRAMERECT_TOP, STR_BLACK_COMMA);
break; break;
default: default:
NOT_REACHED(); NOT_REACHED();
} }
y += line_height; ir = ir.Translate(0, line_height);
} }
} }
@ -2434,15 +2429,15 @@ struct VehicleDetailsWindow : Window {
switch (widget) { switch (widget) {
case WID_VD_TOP_DETAILS: { case WID_VD_TOP_DETAILS: {
int y = r.top + WD_FRAMERECT_TOP; Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM);
/* Draw running cost */ /* Draw running cost */
SetDParam(1, v->age / DAYS_IN_LEAP_YEAR); SetDParam(1, v->age / DAYS_IN_LEAP_YEAR);
SetDParam(0, (v->age + DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED); SetDParam(0, (v->age + DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED);
SetDParam(2, v->max_age / DAYS_IN_LEAP_YEAR); SetDParam(2, v->max_age / DAYS_IN_LEAP_YEAR);
SetDParam(3, v->GetDisplayRunningCost()); SetDParam(3, v->GetDisplayRunningCost());
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_AGE_RUNNING_COST_YR); DrawString(tr, STR_VEHICLE_INFO_AGE_RUNNING_COST_YR);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
/* Draw max speed */ /* Draw max speed */
StringID string; StringID string;
@ -2473,24 +2468,24 @@ struct VehicleDetailsWindow : Window {
string = STR_VEHICLE_INFO_MAX_SPEED; string = STR_VEHICLE_INFO_MAX_SPEED;
} }
} }
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, string); DrawString(tr, string);
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
/* Draw profit */ /* Draw profit */
SetDParam(0, v->GetDisplayProfitThisYear()); SetDParam(0, v->GetDisplayProfitThisYear());
SetDParam(1, v->GetDisplayProfitLastYear()); SetDParam(1, v->GetDisplayProfitLastYear());
if (v->IsGroundVehicle()) { if (v->IsGroundVehicle()) {
SetDParam(2, v->GetDisplayMinPowerToWeight()); SetDParam(2, v->GetDisplayMinPowerToWeight());
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_MIN_PERFORMANCE); DrawString(tr, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_MIN_PERFORMANCE);
} else { } else {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); DrawString(tr, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
} }
y += FONT_HEIGHT_NORMAL; tr.top += FONT_HEIGHT_NORMAL;
/* Draw breakdown & reliability */ /* Draw breakdown & reliability */
SetDParam(0, ToPercent16(v->reliability)); SetDParam(0, ToPercent16(v->reliability));
SetDParam(1, v->breakdowns_since_last_service); SetDParam(1, v->breakdowns_since_last_service);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS); DrawString(tr, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
break; break;
} }
@ -3032,16 +3027,13 @@ public:
/* Draw the flag plus orders. */ /* Draw the flag plus orders. */
bool rtl = (_current_text_dir == TD_RTL); bool rtl = (_current_text_dir == TD_RTL);
uint text_offset = std::max({GetSpriteSize(SPR_WARNING_SIGN).width, GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width}) + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT; uint icon_width = std::max({GetSpriteSize(SPR_WARNING_SIGN).width, GetSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetSpriteSize(SPR_FLAG_VEH_RUNNING).width});
int text_left = r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : text_offset); int lowered = this->IsWidgetLowered(widget) ? 1 : 0;
int text_right = r.right - (rtl ? text_offset : (uint)WD_FRAMERECT_RIGHT); Rect tr = r.Shrink(WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM).Translate(lowered, lowered);
int text_top = CenterBounds(r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, FONT_HEIGHT_NORMAL); SpriteID image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING; DrawSprite(image, PAL_NONE, tr.WithWidth(icon_width, rtl).left, CenterBounds(tr.top, tr.bottom, GetSpriteSize(image).height));
int image_left = (rtl ? text_right + 1 : r.left) + WD_IMGBTN_LEFT; tr = tr.Indent(icon_width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT, rtl);
int image_top = CenterBounds(r.top + WD_IMGBTN_TOP, r.bottom - WD_IMGBTN_BOTTOM, GetSpriteSize(image).height); DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, FONT_HEIGHT_NORMAL), str, text_colour, SA_HOR_CENTER);
int lowered = this->IsWidgetLowered(WID_VV_START_STOP) ? 1 : 0;
DrawSprite(image, PAL_NONE, image_left + lowered, image_top + lowered);
DrawString(text_left + lowered, text_right + lowered, text_top + lowered, str, text_colour, SA_HOR_CENTER);
} }
void OnClick(Point pt, int widget, int click_count) override void OnClick(Point pt, int widget, int click_count) override

View File

@ -88,8 +88,10 @@ uint DropDownListIconItem::Width() const
void DropDownListIconItem::Draw(const Rect &r, bool sel, Colours bg_colour) const void DropDownListIconItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{ {
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
DrawSprite(this->sprite, this->pal, rtl ? r.right - this->dim.width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT, CenterBounds(r.top, r.bottom, this->sprite_y)); Rect ir = r.Shrink(WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_TOP, WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_LEFT);
DrawString(r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), r.right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK); Rect tr = ir.Indent(this->dim.width + WD_FRAMERECT_LEFT, rtl);
DrawSprite(this->sprite, this->pal, ir.WithWidth(this->dim.width, rtl).left, CenterBounds(r.top, r.bottom, this->sprite_y));
DrawString(tr.left, tr.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK);
} }
void DropDownListIconItem::SetDimension(Dimension d) void DropDownListIconItem::SetDimension(Dimension d)