From 3f81edb6640e7e23143151ecff5b2b7e2e0f1bc6 Mon Sep 17 00:00:00 2001 From: Juanjo Date: Sat, 27 Jul 2013 22:03:06 +0000 Subject: [PATCH] More sizing and centering. --- src/ai/ai_gui.cpp | 27 ++++++++++++++------------- src/cheat_gui.cpp | 16 +++++++++++----- src/industry_gui.cpp | 39 +++++++++++++++++++++------------------ src/industry_gui.cpp.orig | 4 ++-- src/intro_gui.cpp | 2 +- src/newgrf_debug_gui.cpp | 6 +++--- src/newgrf_gui.cpp | 1 + src/news_gui.cpp | 12 ++++++------ src/osk_gui.cpp | 5 +++-- src/osk_gui.cpp.orig | 5 ++--- src/settings_gui.cpp | 10 ++++++---- src/settings_gui.cpp.orig | 2 +- src/signs_gui.cpp | 2 +- src/station_gui.cpp | 2 +- src/station_gui.cpp.orig | 15 ++++++++------- src/town_gui.cpp | 2 +- src/town_gui.cpp.orig | 21 ++++++++++++--------- src/transparency_gui.cpp | 2 +- 18 files changed, 95 insertions(+), 78 deletions(-) diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 62fed7debf..1fec5ff746 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -120,16 +120,16 @@ struct AIListWindow : public Window { switch (widget) { case WID_AIL_LIST: { /* Draw a list of all available AIs. */ - int y = this->GetWidget(WID_AIL_LIST)->pos_y; + int y = Center(r.top, this->line_height); /* First AI in the list is hardcoded to random */ 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(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_LEFT, y, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE); y += this->line_height; } ScriptInfoList::const_iterator it = this->info_list->begin(); for (int i = 1; it != this->info_list->end(); i++, it++) { if (this->vscroll->IsVisible(i)) { - DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, (*it).second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE); + DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y, (*it).second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE); y += this->line_height; } } @@ -367,7 +367,6 @@ struct AISettingsWindow : public Window { uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8); 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; for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) { @@ -411,7 +410,7 @@ struct AISettingsWindow : public Window { } } - DrawString(text_left, text_right, y + WD_MATRIX_TOP, str, colour); + DrawString(text_left, text_right, Center(y, this->line_height), str, colour); y += this->line_height; } } @@ -679,7 +678,7 @@ static const NWidgetPart _nested_ai_config_widgets[] = { EndContainer(), NWidget(NWID_SPACER), SetMinimalSize(0, 9), NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT, STR_NULL), SetPadding(0, 5, 4, 5), - NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_GAMELIST), SetMinimalSize(288, 14), SetFill(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP), + NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_GAMELIST), SetSizingType(NWST_STEP), SetMinimalSize(288, 14), SetFill(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7), NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CHANGE, STR_AI_CONFIG_CHANGE_TOOLTIP), @@ -756,8 +755,8 @@ struct AIConfigWindow : public Window { { switch (widget) { case WID_AIC_GAMELIST: - this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; - size->height = 1 * this->line_height; + this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM); + size->height = this->line_height; break; case WID_AIC_LIST: @@ -799,14 +798,14 @@ struct AIConfigWindow : public Window { text = STR_JUST_RAW_STRING; } - DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text, + DrawString(r.left + 10, r.right - 10, Center(r.top, this->line_height), text, (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER)); break; } case WID_AIC_LIST: { - int y = r.top; + int y = Center(r.top, this->line_height); for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) { StringID text; @@ -818,7 +817,7 @@ struct AIConfigWindow : public Window { } else { text = STR_AI_CONFIG_RANDOM_AI; } - DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text, + DrawString(r.left + 10, r.right - 10, y, text, (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER)); y += this->line_height; } @@ -1088,6 +1087,8 @@ struct AIDebugWindow : public Window { bool dirty = false; + Dimension d = GetSpriteSize(SPR_COMPANY_ICON); + uint offset_y = Center(0, GetMinSizing(NWST_STEP, d.height + WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1), d.height); /* Paint the company icons */ for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { NWidgetCore *button = this->GetWidget(i + WID_AID_COMPANY_BUTTON_START); @@ -1108,7 +1109,7 @@ struct AIDebugWindow : public Window { if (!valid) continue; byte offset = (i == ai_debug_company) ? 1 : 0; - DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset); + DrawCompanyIcon(i, Center(button->pos_x + offset, button->current_x, d.width), button->pos_y + offset + offset_y); } /* Set button colour for Game Script. */ @@ -1187,7 +1188,7 @@ struct AIDebugWindow : public Window { ScriptLog::LogData *log = this->GetLogPointer(); if (log == NULL) return; - int y = this->top_offset; + int y = Center(this->top_offset, this->resize.step_height); for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) { int pos = (i + log->pos + 1 - log->used + log->count) % log->count; if (log->lines[pos] == NULL) break; diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 9eb405d2ab..01ea1a488e 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -172,9 +172,11 @@ static const NWidgetPart _nested_cheat_widgets[] = { struct CheatWindow : Window { int clicked; int header_height; + int line_height; CheatWindow(WindowDesc *desc) : Window(desc) { + this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL); this->InitNested(); } @@ -190,11 +192,12 @@ struct CheatWindow : Window { uint button_left = rtl ? r.right - 20 - SETTING_BUTTON_WIDTH : r.left + 20; uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 30 + SETTING_BUTTON_WIDTH); uint text_right = r.right - (rtl ? 30 + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT); + uint box_height = GetSpriteSize(SPR_BOX_EMPTY).height; for (int i = 0; i != lengthof(_cheats_ui); i++) { const CheatEntry *ce = &_cheats_ui[i]; - DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + 2); + DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, Center(y, SETTING_BUTTON_HEIGHT, box_height)); switch (ce->type) { case SLE_BOOL: { @@ -233,7 +236,7 @@ struct CheatWindow : Window { DrawString(text_left, text_right, y + 1, ce->str); - y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; + y += this->line_height; } } @@ -275,15 +278,18 @@ struct CheatWindow : Window { } } - size->width = width + 50 /* stuff on the left */ + 10 /* extra spacing on right */; + size->width = width + 30 + SETTING_BUTTON_WIDTH /* stuff on the left */ + 10 /* extra spacing on right */; this->header_height = GetStringHeight(STR_CHEATS_WARNING, size->width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT) + WD_PAR_VSEP_WIDE; - size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL) * lengthof(_cheats_ui); + size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + this->line_height * lengthof(_cheats_ui); } virtual void OnClick(Point pt, int widget, int click_count) { const NWidgetBase *wid = this->GetWidget(WID_C_PANEL); - uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL); + + if ((pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) % this->line_height > SETTING_BUTTON_HEIGHT) return; + + uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / this->line_height; uint x = pt.x - wid->pos_x; bool rtl = _current_text_dir == TD_RTL; if (rtl) x = wid->current_x - x; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index ca39e8f1cb..c14265c087 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -206,9 +206,6 @@ class BuildIndustryWindow : public Window { bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever) Scrollbar *vscroll; - /** The offset for the text in the matrix. */ - static const int MATRIX_TEXT_OFFSET = 17; - void SetupArrays() { this->count = 0; @@ -297,7 +294,7 @@ public: d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name)); } resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM); - d.width += MATRIX_TEXT_OFFSET + padding.width; + d.width += FONT_HEIGHT_NORMAL * 5 / 4 + padding.width; d.height = 5 * resize->height; *size = maxdim(*size, d); break; @@ -381,20 +378,22 @@ public: switch (widget) { case WID_DPI_MATRIX_WIDGET: { uint text_left, text_right, icon_left, icon_right; + uint square_size = FONT_HEIGHT_NORMAL - 2; + uint text_offset = FONT_HEIGHT_NORMAL * 5 / 4; if (_current_text_dir == TD_RTL) { icon_right = r.right - WD_MATRIX_RIGHT; - icon_left = icon_right - 10; - text_right = icon_right - BuildIndustryWindow::MATRIX_TEXT_OFFSET; + icon_left = icon_right - square_size; + text_right = icon_right - text_offset; text_left = r.left + WD_MATRIX_LEFT; } else { icon_left = r.left + WD_MATRIX_LEFT; - icon_right = icon_left + 10; - text_left = icon_left + BuildIndustryWindow::MATRIX_TEXT_OFFSET; + icon_right = icon_left + square_size; + text_left = icon_left + text_offset; text_right = r.right - WD_MATRIX_RIGHT; } - for (byte i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) { - int y = r.top + WD_MATRIX_TOP + i * this->resize.step_height; + int y = Center(r.top, this->resize.step_height); + for (byte i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++, y += this->resize.step_height) { bool selected = this->selected_index == i + this->vscroll->GetPosition(); if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) { @@ -405,8 +404,8 @@ public: /* Draw the name of the industry in white is selected, otherwise, in orange */ DrawString(text_left, text_right, y, indsp->name, selected ? TC_WHITE : TC_ORANGE); - GfxFillRect(icon_left, y + 1, icon_right, y + 7, selected ? PC_WHITE : PC_BLACK); - GfxFillRect(icon_left + 1, y + 2, icon_right - 1, y + 6, indsp->map_colour); + GfxFillRect(icon_left, y + 1, icon_right, y + square_size, selected ? PC_WHITE : PC_BLACK); + GfxFillRect(icon_left + 1, y + 2, icon_right - 1, y + square_size - 1, indsp->map_colour); } break; } @@ -758,7 +757,7 @@ public: if (first) { if (has_accept) y += WD_PAR_VSEP_WIDE; DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE); - y += FONT_HEIGHT_NORMAL; + y += this->editable == EA_RATE ? GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL) : FONT_HEIGHT_NORMAL; if (this->editable == EA_RATE) this->production_offset_y = y; first = false; } @@ -773,8 +772,10 @@ public: if (this->editable == EA_RATE) { DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0, i->production_rate[j] > 0, i->production_rate[j] < 255); + y += GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); + } else { + y += FONT_HEIGHT_NORMAL; } - y += FONT_HEIGHT_NORMAL; } /* Display production multiplier if editable */ @@ -786,7 +787,7 @@ public: DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LEVEL); 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); - y += FONT_HEIGHT_NORMAL; + y += GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); } /* Get the extra message for the GUI */ @@ -834,12 +835,14 @@ public: case EA_NONE: break; case EA_MULTIPLIER: - if (IsInsideBS(pt.y, this->production_offset_y, FONT_HEIGHT_NORMAL)) line = IL_MULTIPLIER; + if (IsInsideBS(pt.y, this->production_offset_y, SETTING_BUTTON_HEIGHT)) line = IL_MULTIPLIER; break; case EA_RATE: if (pt.y >= this->production_offset_y) { - int row = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL; + if ((pt.y - this->production_offset_y) % GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL) > SETTING_BUTTON_HEIGHT) break;; + + int row = (pt.y - this->production_offset_y) / GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); for (uint j = 0; j < lengthof(i->produced_cargo); j++) { if (i->produced_cargo[j] == CT_INVALID) continue; row--; @@ -1055,7 +1058,7 @@ static const NWidgetPart _nested_industry_directory_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetSizingType(NWST_STEP), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(), EndContainer(), diff --git a/src/industry_gui.cpp.orig b/src/industry_gui.cpp.orig index 1dabde2646..ca39e8f1cb 100644 --- a/src/industry_gui.cpp.orig +++ b/src/industry_gui.cpp.orig @@ -296,7 +296,7 @@ public: if (this->index[i] == INVALID_INDUSTRYTYPE) continue; d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name)); } - resize->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; + resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM); d.width += MATRIX_TEXT_OFFSET + padding.width; d.height = 5 * resize->height; *size = maxdim(*size, d); @@ -1303,7 +1303,7 @@ public: for (uint i = 0; i < this->industries.Length(); i++) { d = maxdim(d, GetStringBoundingBox(this->GetIndustryString(this->industries[i]))); } - resize->height = d.height; + resize->height = d.height = GetMinSizing(NWST_STEP, d.height); d.height *= 5; d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index 5d13058944..3d07096d6b 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -145,7 +145,7 @@ struct SelectGameWindow : public Window { }; static const NWidgetPart _nested_select_game_widgets[] = { - NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_INTRO_CAPTION, STR_NULL), + NWidget(WWT_CAPTION, COLOUR_BROWN), SetSizingType(NWST_BUTTON), SetDataTip(STR_INTRO_CAPTION, STR_NULL), NWidget(WWT_PANEL, COLOUR_BROWN), NWidget(NWID_SPACER), SetMinimalSize(0, 8), diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index be4e992130..2f14e6c518 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -840,7 +840,7 @@ struct SpriteAlignerWindow : Window { { if (widget != WID_SA_LIST) return; - resize->height = max(11, FONT_HEIGHT_NORMAL + 1); + resize->height = GetMinSizing(NWST_STEP, max(11, FONT_HEIGHT_NORMAL + 1)); resize->width = 1; /* Resize to about 200 pixels (for the preview) */ @@ -877,10 +877,10 @@ struct SpriteAlignerWindow : Window { SmallVector &list = _newgrf_debug_sprite_picker.sprites; int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), list.Length()); - int y = r.top + WD_FRAMERECT_TOP; + int y = Center(r.top + WD_FRAMERECT_TOP, step_size, FONT_HEIGHT_NORMAL); for (int i = this->vscroll->GetPosition(); i < max; 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(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_BLACK_COMMA, TC_FROMSTRING, SA_CENTER | SA_FORCE); y += step_size; } break; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index aedb4fddd3..a46aa79b26 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1943,6 +1943,7 @@ void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFC /** Widgets for the progress window. */ static const NWidgetPart _nested_scan_progress_widgets[] = { NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NEWGRF_SCAN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), + SetSizingType(NWST_BUTTON), NWidget(WWT_PANEL, COLOUR_GREY), NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20), NWidget(NWID_VERTICAL), SetPIP(11, 8, 11), diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 5639001b71..97d4f795ea 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -78,7 +78,7 @@ static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32 ref) static const NWidgetPart _nested_normal_news_widgets[] = { NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL), NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1), - NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), + NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetSizingType(NWST_BUTTON), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), NWidget(NWID_SPACER), SetFill(1, 0), NWidget(NWID_VERTICAL), NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL), @@ -101,7 +101,7 @@ static const NWidgetPart _nested_vehicle_news_widgets[] = { NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL), NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1), NWidget(NWID_VERTICAL), - NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), + NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetSizingType(NWST_BUTTON), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), NWidget(NWID_SPACER), SetFill(0, 1), EndContainer(), NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_VEH_TITLE), SetFill(1, 1), SetMinimalSize(419, 55), SetDataTip(STR_EMPTY, STR_NULL), @@ -128,7 +128,7 @@ static const NWidgetPart _nested_company_news_widgets[] = { NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL), NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1), NWidget(NWID_VERTICAL), - NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), + NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetSizingType(NWST_BUTTON), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), NWidget(NWID_SPACER), SetFill(0, 1), EndContainer(), NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_TITLE), SetFill(1, 1), SetMinimalSize(410, 20), SetDataTip(STR_EMPTY, STR_NULL), @@ -158,7 +158,7 @@ static WindowDesc _company_news_desc( static const NWidgetPart _nested_thin_news_widgets[] = { NWidget(WWT_PANEL, COLOUR_WHITE, WID_N_PANEL), NWidget(NWID_HORIZONTAL), SetPadding(1, 1, 0, 1), - NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), + NWidget(WWT_TEXT, COLOUR_WHITE, WID_N_CLOSEBOX), SetSizingType(NWST_STEP), SetDataTip(STR_SILVER_CROSS, STR_NULL), SetPadding(0, 0, 0, 1), NWidget(NWID_SPACER), SetFill(1, 0), NWidget(NWID_VERTICAL), NWidget(WWT_LABEL, COLOUR_WHITE, WID_N_DATE), SetDataTip(STR_DATE_LONG_SMALL, STR_NULL), @@ -1007,7 +1007,7 @@ struct MessageHistoryWindow : Window { virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget == WID_MH_BACKGROUND) { - this->line_height = FONT_HEIGHT_NORMAL + 2; + this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + 2); resize->height = this->line_height; /* Months are off-by-one, so it's actually 8. Not using @@ -1038,7 +1038,7 @@ struct MessageHistoryWindow : Window { } /* Fill the widget with news items. */ - int y = r.top + this->top_spacing; + int y = Center(r.top + this->top_spacing, this->line_height, FONT_HEIGHT_NORMAL); bool rtl = _current_text_dir == TD_RTL; uint date_left = rtl ? r.right - WD_FRAMERECT_RIGHT - this->date_width : r.left + WD_FRAMERECT_LEFT; uint date_right = rtl ? r.right - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT + this->date_width; diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp index d8d70e70c8..9445595ec2 100644 --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -230,7 +230,8 @@ static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys. */ static void AddKey(NWidgetHorizontal *hor, int height, int num_half, WidgetType widtype, int widnum, uint16 widdata, int *biggest_index) { - int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1); + int min_half_key = max(GetMinSizing(NWST_BUTTON) / 2, HALF_KEY_WIDTH); + int key_width = min_half_key + (INTER_KEY_SPACE + min_half_key) * (num_half - 1); if (widtype == NWID_SPACER) { if (!hor->IsEmpty()) key_width += INTER_KEY_SPACE; @@ -330,7 +331,7 @@ static NWidgetBase *MakeSpacebarKeys(int *biggest_index) static const NWidgetPart _nested_osk_widgets[] = { - NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL), + NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetSizingType(NWST_BUTTON), SetDataTip(STR_WHITE_STRING, STR_NULL), NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2), EndContainer(), diff --git a/src/osk_gui.cpp.orig b/src/osk_gui.cpp.orig index 9445595ec2..d8d70e70c8 100644 --- a/src/osk_gui.cpp.orig +++ b/src/osk_gui.cpp.orig @@ -230,8 +230,7 @@ static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys. */ static void AddKey(NWidgetHorizontal *hor, int height, int num_half, WidgetType widtype, int widnum, uint16 widdata, int *biggest_index) { - int min_half_key = max(GetMinSizing(NWST_BUTTON) / 2, HALF_KEY_WIDTH); - int key_width = min_half_key + (INTER_KEY_SPACE + min_half_key) * (num_half - 1); + int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1); if (widtype == NWID_SPACER) { if (!hor->IsEmpty()) key_width += INTER_KEY_SPACE; @@ -331,7 +330,7 @@ static NWidgetBase *MakeSpacebarKeys(int *biggest_index) static const NWidgetPart _nested_osk_widgets[] = { - NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetSizingType(NWST_BUTTON), SetDataTip(STR_WHITE_STRING, STR_NULL), + NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL), NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2), EndContainer(), diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 80f26b5282..755b829ff9 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2368,11 +2368,13 @@ void ShowGameSettings() void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right) { int colour = _colour_gradient[button_colour][2]; + int half_button = SETTING_BUTTON_WIDTH / 2; - DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE); - DrawFrameRect(x + SETTING_BUTTON_WIDTH / 2, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE); - DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP); - DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP); + DrawFrameRect(x, y, x + half_button - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE); + DrawFrameRect(x + half_button, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE); + Dimension d = GetSpriteSize(SPR_ARROW_LEFT); + DrawSprite(SPR_ARROW_LEFT, PAL_NONE, Center(x, half_button, d.width), Center(y, SETTING_BUTTON_HEIGHT, d.height)); + DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, Center(x + half_button, half_button, d.width), Center(y, SETTING_BUTTON_HEIGHT, d.height)); /* Grey out the buttons that aren't clickable */ bool rtl = _current_text_dir == TD_RTL; diff --git a/src/settings_gui.cpp.orig b/src/settings_gui.cpp.orig index c01d8391b8..80f26b5282 100644 --- a/src/settings_gui.cpp.orig +++ b/src/settings_gui.cpp.orig @@ -1797,7 +1797,7 @@ struct GameSettingsWindow : Window { { switch (widget) { case WID_GS_OPTIONSPANEL: - resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1); + resize->height = SETTING_HEIGHT = GetMinSizing(NWST_STEP, max(11, FONT_HEIGHT_NORMAL + 1)); resize->width = 1; size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET; diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 2ec36775cf..e572f51a33 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -195,7 +195,7 @@ struct SignListWindow : Window, SignList { { switch (widget) { case WID_SIL_LIST: { - uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget. + uint y = Center(r.top + WD_FRAMERECT_TOP, this->resize.step_height); // Offset from top of widget. /* No signs? */ if (this->vscroll->GetCount() == 0) { DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_STATION_LIST_NONE); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 5df21155c1..e57be72c86 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -744,7 +744,7 @@ static const NWidgetPart _nested_company_stations_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY), SetDataTip(0x0, STR_NULL), SetResize(1, 0), SetFill(1, 1), EndContainer(), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_SORTBY), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_SORTBY), SetSizingType(NWST_STEP), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_STL_SORTDROPBTN), SetMinimalSize(163, 12), SetDataTip(STR_SORT_BY_NAME, STR_TOOLTIP_SORT_CRITERIA), // widget_data gets overwritten. NWidget(WWT_PANEL, COLOUR_GREY), SetDataTip(0x0, STR_NULL), SetResize(1, 0), SetFill(1, 1), EndContainer(), EndContainer(), diff --git a/src/station_gui.cpp.orig b/src/station_gui.cpp.orig index 48a82f8d45..5df21155c1 100644 --- a/src/station_gui.cpp.orig +++ b/src/station_gui.cpp.orig @@ -400,7 +400,7 @@ public: } case WID_STL_LIST: - resize->height = FONT_HEIGHT_NORMAL; + resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); size->height = WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM; break; @@ -451,7 +451,8 @@ public: case WID_STL_LIST: { int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.Length()); - int y = r.top + WD_FRAMERECT_TOP; + uint line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); + int y = Center(r.top + WD_FRAMERECT_TOP, line_height); for (int i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner const Station *st = this->stations[i]; assert(st->xy != INVALID_TILE); @@ -464,9 +465,9 @@ public: SetDParam(1, st->facilities); int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_STATION); - StationsWndShowStationRating(st, r.left, r.right, x, FONT_HEIGHT_NORMAL + 2, y); + StationsWndShowStationRating(st, r.left, r.right, x, line_height + 2, y); - y += FONT_HEIGHT_NORMAL; + y += line_height; } if (this->vscroll->GetCount() == 0) { // company has no stations @@ -518,7 +519,7 @@ public: { switch (widget) { case WID_STL_LIST: { - uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_STL_LIST, 0, FONT_HEIGHT_NORMAL); + uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_STL_LIST, 0, this->resize.step_height); if (id_v >= this->stations.Length()) return; // click out of list bound const Station *st = this->stations[id_v]; @@ -2292,8 +2293,8 @@ struct SelectStationWindow : Window { d = maxdim(d, GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION)); } - resize->height = d.height; - d.height *= 5; + resize->height = GetMinSizing(NWST_STEP, d.height); + d.height = 5 * resize->height; d.width += WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT; d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; *size = d; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 76ee227e29..e6ad46e33b 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -614,7 +614,7 @@ static const NWidgetPart _nested_town_directory_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TD_SORT_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TD_SORT_ORDER), SetSizingType(NWST_STEP), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_TD_SORT_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(), EndContainer(), diff --git a/src/town_gui.cpp.orig b/src/town_gui.cpp.orig index 052fe4119d..76ee227e29 100644 --- a/src/town_gui.cpp.orig +++ b/src/town_gui.cpp.orig @@ -47,12 +47,12 @@ static const NWidgetPart _nested_town_authority_widgets[] = { NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN), NWidget(WWT_STICKYBOX, COLOUR_BROWN), EndContainer(), - NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_RATING_INFO), SetMinimalSize(317, 92), SetResize(1, 1), EndContainer(), + NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_RATING_INFO), SetMinimalSize(317, 92), SetResize(1, 1), SetFill(1, 1), EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_COMMAND_LIST), SetMinimalSize(305, 52), SetResize(1, 0), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), SetScrollbar(WID_TA_SCROLLBAR), EndContainer(), NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_TA_SCROLLBAR), EndContainer(), - NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_ACTION_INFO), SetMinimalSize(317, 52), SetResize(1, 0), EndContainer(), + NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_ACTION_INFO), SetMinimalSize(317, 52), SetResize(1, 1), SetFill(1, 1), EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TA_EXECUTE), SetMinimalSize(317, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP), NWidget(WWT_RESIZEBOX, COLOUR_BROWN), @@ -65,6 +65,7 @@ private: Town *town; ///< Town being displayed. int sel_index; ///< Currently selected town action, \c 0 to \c TACT_COUNT-1, \c -1 means no action selected. Scrollbar *vscroll; + uint actions_step; uint displayed_actions_on_previous_painting; ///< Actions that were available on the previous call to OnPaint() /** @@ -94,7 +95,8 @@ public: this->town = Town::Get(window_number); this->InitNested(window_number); this->vscroll = this->GetScrollbar(WID_TA_SCROLLBAR); - this->vscroll->SetCapacity((this->GetWidget(WID_TA_COMMAND_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / FONT_HEIGHT_NORMAL); + this->actions_step = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); + this->vscroll->SetCapacity((this->GetWidget(WID_TA_COMMAND_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->actions_step); } virtual void OnPaint() @@ -197,12 +199,12 @@ public: case WID_TA_COMMAND_LIST: { int numact; uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town); - int y = Center(r.top, this->resize.step_height); + int y = Center(r.top, this->actions_step); int pos = this->vscroll->GetPosition(); if (--pos < 0) { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTIONS_TITLE); - y += this->resize.step_height; + y += this->actions_step; } for (int i = 0; buttons; i++, buttons >>= 1) { @@ -211,7 +213,7 @@ public: if ((buttons & 1) && --pos < 0) { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, this->sel_index == i ? TC_WHITE : TC_ORANGE); - y += this->resize.step_height; + y += this->actions_step; } } break; @@ -238,7 +240,8 @@ public: } case WID_TA_COMMAND_LIST: - size->height = WD_FRAMERECT_TOP + 5 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM; + resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); + size->height = WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM; size->width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width; for (uint i = 0; i < TACT_COUNT; i++ ) { size->width = max(size->width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width); @@ -257,7 +260,7 @@ public: { switch (widget) { case WID_TA_COMMAND_LIST: { - int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, FONT_HEIGHT_NORMAL); + int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, this->actions_step); if (!IsInsideMM(y, 0, 5)) return; y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_company, this->town), y + this->vscroll->GetPosition() - 1); @@ -823,7 +826,7 @@ public: } Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD); d.width += icon_size.width + 2; - d.height = max(d.height, icon_size.height); + d.height = GetMinSizing(NWST_STEP, max(d.height, icon_size.height)); resize->height = d.height; d.height *= 5; d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; diff --git a/src/transparency_gui.cpp b/src/transparency_gui.cpp index 9e00552b68..50778fcc10 100644 --- a/src/transparency_gui.cpp +++ b/src/transparency_gui.cpp @@ -142,7 +142,7 @@ static const NWidgetPart _nested_transparency_widgets[] = { NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(), EndContainer(), /* Panel with 'invisibility' buttons. */ - NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_TT_BUTTONS), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_TOOLTIP), + NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_TT_BUTTONS), SetSizingType(NWST_STEP), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_TOOLTIP), EndContainer(), };