Add min sizing.

This commit is contained in:
Juanjo
2013-06-29 15:12:06 +02:00
committed by pelya
parent 034e8677ad
commit 0442649289
32 changed files with 252 additions and 201 deletions

View File

@@ -107,7 +107,7 @@ struct AIListWindow : public Window {
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget == WID_AIL_LIST) {
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
resize->width = 1;
resize->height = this->line_height;
@@ -345,7 +345,7 @@ struct AISettingsWindow : public Window {
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget == WID_AIS_BACKGROUND) {
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
resize->width = 1;
resize->height = this->line_height;
@@ -761,7 +761,7 @@ struct AIConfigWindow : public Window {
break;
case WID_AIC_LIST:
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
size->height = 8 * this->line_height;
break;
}
@@ -1072,7 +1072,7 @@ struct AIDebugWindow : public Window {
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget == WID_AID_LOG_PANEL) {
resize->height = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL);
size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
}
}

View File

@@ -272,6 +272,7 @@ public:
d.width += padding.width;
d.height += padding.height;
*size = maxdim(*size, d);
size->height = GetMinSizing(NWST_STEP, size->height);
break;
}
@@ -283,7 +284,7 @@ public:
size->width = max(size->width, GetStringBoundingBox(as->name).width);
}
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
this->line_height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
size->height = 5 * this->line_height;
break;
}
@@ -524,7 +525,7 @@ static const NWidgetPart _nested_build_airport_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 0), SetPIP(2, 0, 2),
NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL, STR_NULL), SetFill(1, 0),
NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetSizingType(NWST_STEP), SetDataTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL, STR_NULL), SetFill(1, 0),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_AP_CLASS_DROPDOWN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_STATION_BUILD_AIRPORT_TOOLTIP),
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_AIRPORT_SPRITE), SetFill(1, 0),
NWidget(NWID_HORIZONTAL),
@@ -532,9 +533,9 @@ static const NWidgetPart _nested_build_airport_widgets[] = {
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AP_SCROLLBAR),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_DECREASE), SetMinimalSize(12, 0), SetDataTip(AWV_DECREASE, STR_NULL),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_DECREASE), SetSizingType(NWST_STEP), SetMinimalSize(12, 0), SetDataTip(AWV_DECREASE, STR_NULL),
NWidget(WWT_LABEL, COLOUR_GREY, WID_AP_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_INCREASE), SetMinimalSize(12, 0), SetDataTip(AWV_INCREASE, STR_NULL),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_INCREASE), SetSizingType(NWST_STEP), SetMinimalSize(12, 0), SetDataTip(AWV_INCREASE, STR_NULL),
EndContainer(),
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_EXTRA_TEXT), SetFill(1, 0), SetMinimalSize(150, 0),
EndContainer(),

View File

@@ -44,7 +44,8 @@
*/
uint GetEngineListHeight(VehicleType type)
{
return max<uint>(FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM, GetVehicleImageCellSize(type, EIT_PURCHASE).height);
uint size = max<uint>(FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM, GetVehicleImageCellSize(type, EIT_PURCHASE).height);
return GetMinSizing(NWST_STEP, size);
}
static const NWidgetPart _nested_build_vehicle_widgets[] = {
@@ -58,12 +59,12 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASSENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASSENDING_DESCENDING), SetSizingType(NWST_STEP), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetSizingType(NWST_STEP), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetSizingType(NWST_STEP), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
EndContainer(),
EndContainer(),
EndContainer(),
@@ -1323,6 +1324,7 @@ struct BuildVehicleWindow : Window {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
d.height = GetMinSizing(NWST_STEP, d.height);
*size = maxdim(*size, d);
break;
}

View File

@@ -886,7 +886,6 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
int sprite_width = sprite_left + sprite_right;
int sprite_x = rtl ? r - sprite_right - 1 : l + sprite_left + 1;
int sprite_y_offset = sprite_y_offsets[type] + step_size / 2;
Dimension replace_icon = {0, 0};
int count_width = 0;
@@ -902,22 +901,18 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
int count_left = l;
int count_right = rtl ? text_left : r - WD_FRAMERECT_RIGHT - replace_icon.width - 8;
int normal_text_y_offset = (step_size - FONT_HEIGHT_NORMAL) / 2;
int small_text_y_offset = step_size - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1;
int replace_icon_y_offset = (step_size - replace_icon.height) / 2 - 1;
for (; min < max; min++, y += step_size) {
const EngineID engine = (*eng_list)[min];
/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
SetDParam(0, engine);
DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE);
DrawString(text_left, text_right, Center(y, step_size), STR_ENGINE_NAME, text_colour);
DrawVehicleEngine(l, r, sprite_x, Center(y, step_size, sprite_y_offsets[type]), engine, palette_crash ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE);
if (show_count) {
SetDParam(0, num_engines);
DrawString(count_left, count_right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, y + replace_icon_y_offset);
DrawString(count_left, count_right, Center(y, step_size, FONT_HEIGHT_SMALL), STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, Center(y, step_size, replace_icon.height));
}
}
}

View File

@@ -35,6 +35,7 @@
#include "road_func.h"
#include "water.h"
#include "station_func.h"
#include "widget_type.h"
#include "widgets/company_widget.h"
@@ -526,7 +527,7 @@ public:
uint Height(uint width) const
{
return max(FONT_HEIGHT_NORMAL, 14);
return GetMinSizing(NWST_STEP, max(FONT_HEIGHT_NORMAL, 14));
}
bool Selectable() const

View File

@@ -473,7 +473,7 @@ public:
break;
case WID_SL_DRIVES_DIRECTORIES_LIST:
resize->height = FONT_HEIGHT_NORMAL;
resize->height = GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL);
size->height = resize->height * 10 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
break;
case WID_SL_SORT_BYNAME:

View File

@@ -451,6 +451,7 @@ struct GenerateLandscapeWindow : public Window {
case WID_GL_MAPSIZE_Y_PULLDOWN:
SetDParamMaxValue(0, MAX_MAP_SIZE);
*size = GetStringBoundingBox(STR_JUST_INT);
size->width = size->width + GetMinSizing(NWST_BUTTON);
break;
case WID_GL_SNOW_LEVEL_TEXT:
@@ -508,7 +509,7 @@ struct GenerateLandscapeWindow : public Window {
}
}
size->width += padding.width;
size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
size->height = GetMinSizing(NWST_BUTTON, FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM);
}
virtual void DrawWidget(const Rect &r, int widget) const

View File

@@ -114,6 +114,7 @@ static NWidgetBase *MakeNWidgetCompanyLines(int *biggest_index)
for (int widnum = WID_GL_FIRST_COMPANY; widnum <= WID_GL_LAST_COMPANY; widnum++) {
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
panel->sizing_type = NWST_STEP;
panel->SetMinimalSize(246, line_height);
panel->SetFill(1, 0);
panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);

View File

@@ -66,7 +66,7 @@ static const NWidgetPart _nested_group_widgets[] = {
/* right part */
NWidget(NWID_VERTICAL),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_SORT_BY_ORDER), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_SORT_BY_ORDER), SetSizingType(NWST_STEP), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GL_SORT_BY_DROPDOWN), SetMinimalSize(167, 12), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetResize(1, 0), EndContainer(),
EndContainer(),
@@ -74,7 +74,7 @@ static const NWidgetPart _nested_group_widgets[] = {
NWidget(WWT_MATRIX, COLOUR_GREY, WID_GL_LIST_VEHICLE), SetMinimalSize(248, 0), SetMatrixDataTip(1, 0, STR_NULL), SetResize(1, 1), SetFill(1, 0), SetScrollbar(WID_GL_LIST_VEHICLE_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_GL_LIST_VEHICLE_SCROLLBAR),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(1, 0), SetFill(1, 1), SetResize(1, 0), EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_AVAILABLE_VEHICLES), SetMinimalSize(106, 12), SetFill(0, 1),
SetDataTip(STR_BLACK_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
@@ -167,7 +167,7 @@ private:
this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
/* We consider the max average length of characters to be the one of "a" */
this->column_size[VGC_NAME].width = max(GetCharacterWidth(FS_NORMAL, 97) * (MAX_LENGTH_GROUP_NAME_CHARS - 4), this->column_size[VGC_NAME].width);
this->tiny_step_height = this->column_size[VGC_NAME].height;
this->tiny_step_height = max(11U, this->column_size[VGC_NAME].height);
this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
@@ -189,6 +189,7 @@ private:
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
this->tiny_step_height += WD_MATRIX_TOP;
this->tiny_step_height = GetMinSizing(NWST_STEP, this->tiny_step_height);
return WD_FRAMERECT_LEFT + 8 +
this->column_size[VGC_NAME].width + 2 +
@@ -343,14 +344,8 @@ public:
/* Minimum height is the height of the list widget minus all and default vehicles... */
size->height = 4 * GetVehicleListHeight(this->vli.vtype, this->tiny_step_height) - 2 * this->tiny_step_height;
/* ... minus the buttons at the bottom ... */
uint max_icon_height = GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->widget_data).height;
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->widget_data).height);
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data).height);
max_icon_height = max(max_icon_height, GetSpriteSize(this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data).height);
/* Get a multiple of tiny_step_height of that amount */
size->height = Ceil(size->height - max_icon_height, tiny_step_height);
size->height = Ceil(size->height, tiny_step_height);
break;
}

View File

@@ -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;

View File

@@ -1260,7 +1260,7 @@ public:
case WID_ID_INDUSTRY_LIST: {
int n = 0;
int y = r.top + WD_FRAMERECT_TOP;
int y = Center(r.top, this->resize.step_height);
if (this->industries.Length() == 0) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_DIRECTORY_NONE);
break;

View File

@@ -344,6 +344,7 @@ NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index)
row = new NWidgetHorizontal(NC_EQUALSIZE);
}
NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST);
wid->sizing_type = NWST_STEP;
wid->SetMinimalSize(25, FONT_HEIGHT_SMALL);
wid->SetFill(1, 1);
wid->SetResize(0, 0);

View File

@@ -524,7 +524,7 @@ public:
}
case WID_NCL_MATRIX:
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);
size->height = 10 * resize->height;
break;
}

View File

@@ -499,12 +499,12 @@ public:
break;
case WID_NG_MATRIX:
resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
resize->height = GetMinSizing(NWST_STEP, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
size->height = 10 * resize->height;
break;
case WID_NG_LASTJOINED:
size->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
size->height = GetMinSizing(NWST_STEP, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
break;
case WID_NG_LASTJOINED_SPACER:
@@ -931,7 +931,7 @@ static const NWidgetPart _nested_network_game_widgets[] = {
/* LEFT SIDE */
NWidget(NWID_VERTICAL), SetPIP(0, 7, 0),
NWidget(NWID_HORIZONTAL), SetPIP(0, 7, 0),
NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NG_CONNECTION), SetDataTip(STR_NETWORK_SERVER_LIST_ADVERTISED, STR_NULL),
NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NG_CONNECTION), SetSizingType(NWST_STEP), SetDataTip(STR_NETWORK_SERVER_LIST_ADVERTISED, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_NG_CONN_BTN),
SetDataTip(STR_BLACK_STRING, STR_NETWORK_SERVER_LIST_ADVERTISED_TOOLTIP),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
@@ -1080,8 +1080,8 @@ struct NetworkStartServerWindow : public Window {
switch (widget) {
case WID_NSS_CONNTYPE_BTN:
*size = maxdim(GetStringBoundingBox(_connection_types_dropdown[0]), GetStringBoundingBox(_connection_types_dropdown[1]));
size->width += padding.width;
size->height += padding.height;
size->width = GetMinSizing(NWST_BUTTON, size->width + padding.width);
size->height = GetMinSizing(NWST_BUTTON, size->height + padding.height);
break;
}
}
@@ -1264,15 +1264,15 @@ static const NWidgetPart _nested_network_start_server_window_widgets[] = {
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 6, 10),
NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NSS_CONNTYPE_LABEL), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_ADVERTISED, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_NSS_CONNTYPE_BTN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NETWORK_SERVER_LIST_ADVERTISED_TOOLTIP),
NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_NSS_CONNTYPE_BTN), SetSizingType(NWST_BUTTON), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NETWORK_SERVER_LIST_ADVERTISED_TOOLTIP),
EndContainer(),
NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NSS_LANGUAGE_LABEL), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_LANGUAGE_SPOKEN, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_NSS_LANGUAGE_BTN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NETWORK_START_SERVER_LANGUAGE_TOOLTIP),
NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_NSS_LANGUAGE_BTN), SetSizingType(NWST_BUTTON), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NETWORK_START_SERVER_LANGUAGE_TOOLTIP),
EndContainer(),
NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
NWidget(NWID_SPACER), SetFill(1, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_SETPWD), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_SET_PASSWORD, STR_NETWORK_START_SERVER_PASSWORD_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_SETPWD), SetSizingType(NWST_BUTTON), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_SET_PASSWORD, STR_NETWORK_START_SERVER_PASSWORD_TOOLTIP),
EndContainer(),
EndContainer(),
@@ -1375,7 +1375,7 @@ struct NetworkLobbyWindow : public Window {
break;
case WID_NL_MATRIX:
resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
resize->height = GetMinSizing(NWST_STEP, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
size->height = 10 * resize->height;
break;

View File

@@ -681,14 +681,14 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_FILE_LIST:
{
Dimension d = maxdim(GetSpriteSize(SPR_SQUARE), GetSpriteSize(SPR_WARNING_SIGN));
resize->height = max(d.height + 2U, FONT_HEIGHT_NORMAL + 2U);
size->height = max(size->height, WD_FRAMERECT_TOP + 6 * resize->height + WD_FRAMERECT_BOTTOM);
resize->height = GetMinSizing(NWST_STEP, max(d.height + 2U, FONT_HEIGHT_NORMAL + 2U));
size->height = max(size->height, WD_FRAMERECT_TOP + 4 * resize->height + WD_FRAMERECT_BOTTOM);
break;
}
case WID_NS_AVAIL_LIST:
resize->height = max(12, FONT_HEIGHT_NORMAL + 2);
size->height = max(size->height, WD_FRAMERECT_TOP + 8 * resize->height + WD_FRAMERECT_BOTTOM);
resize->height = GetMinSizing(NWST_STEP, max(12, FONT_HEIGHT_NORMAL + 2));
size->height = max(size->height, WD_FRAMERECT_TOP + 4 * resize->height + WD_FRAMERECT_BOTTOM);
break;
case WID_NS_NEWGRF_INFO_TITLE: {
@@ -711,6 +711,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
}
d.width += padding.width;
d.height = GetMinSizing(NWST_BUTTON, d.height);
*size = maxdim(d, *size);
break;
}
@@ -721,6 +722,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
*size = maxdim(d, GetStringBoundingBox(STR_INTRO_ONLINE_CONTENT));
size->width += padding.width;
size->height += padding.height;
size->height = GetMinSizing(NWST_BUTTON, size->height);
break;
}
}

View File

@@ -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;

View File

@@ -1151,7 +1151,7 @@ uint SettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int bas
case SEF_SUBTREE_KIND:
if (cur_row >= first_row) {
DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, Center(y, SETTING_HEIGHT), this->d.sub.title);
}
cur_row++;
if (!this->d.sub.folded) {
@@ -1243,7 +1243,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
}
this->SetValueDParams(1, value);
DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
DrawString(text_left, text_right, Center(y, SETTING_HEIGHT), sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
}

View File

@@ -77,6 +77,8 @@ struct GUISettings {
bool lost_vehicle_warn; ///< if a vehicle can't find its destination, show a warning
uint8 order_review_system; ///< perform order reviews on vehicles
bool vehicle_income_warn; ///< if a vehicle isn't generating income, show a warning
uint min_button; ///< min size of most button widgets
uint min_step; ///< min size of scrollbar/dropdown elements
bool show_finances; ///< show finances at end of year
bool sg_new_nonstop; ///< ttdpatch compatible nonstop handling read from pre v93 savegames
bool new_nonstop; ///< ttdpatch compatible nonstop handling

View File

@@ -267,6 +267,7 @@ struct SignListWindow : Window, SignList {
Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
resize->height = max<uint>(FONT_HEIGHT_NORMAL, spr_dim.height);
resize->height = GetMinSizing(NWST_STEP, resize->height);
Dimension d = {this->text_offset + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
*size = maxdim(*size, d);
break;

View File

@@ -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;

View File

@@ -2303,7 +2303,7 @@ struct SelectStationWindow : Window {
{
if (widget != WID_JS_PANEL) return;
uint y = r.top + WD_FRAMERECT_TOP;
uint y = Center(r.top, this->resize.step_height);
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);
y += this->resize.step_height;

View File

@@ -219,6 +219,25 @@ name = ""mono_aa""
var = _freetype.mono.aa
def = false
[SDTG_VAR]
name = ""min_button_size""
type = SLE_UINT
var = _settings_client.gui.min_button
def = 0
min = 0
max = 100
cat = SC_EXPERT
[SDTG_VAR]
name = ""min_step_size""
type = SLE_UINT
var = _settings_client.gui.min_step
def = 0
min = 0
max = 100
cat = SC_EXPERT
[SDTG_VAR]
name = ""sprite_cache_size_px""
type = SLE_UINT

View File

@@ -133,7 +133,7 @@ public:
uint Height(uint width) const
{
return max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
return GetMinSizing(NWST_STEP, max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL));
}
void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const

View File

@@ -133,7 +133,7 @@ public:
uint Height(uint width) const
{
return GetMinSizing(NWST_STEP, max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL));
return max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
}
void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
@@ -958,7 +958,7 @@ static CallBackFunction MenuClickBuildAir(int index)
static CallBackFunction ToolbarForestClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 1);
PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 3);
return CBF_NONE;
}
@@ -972,6 +972,8 @@ static CallBackFunction MenuClickForest(int index)
{
switch (index) {
case 0: ShowTerraformToolbar(); break;
case 1: ShowBuildTreesToolbar(); break;
case 2: return SelectSignTool();
}
return CBF_NONE;
}

View File

@@ -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<NWidgetBase>(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<NWidgetBase>(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;

View File

@@ -197,7 +197,7 @@ public:
case WID_TA_COMMAND_LIST: {
int numact;
uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
int y = r.top + WD_FRAMERECT_TOP;
int y = Center(r.top, this->resize.step_height);
int pos = this->vscroll->GetPosition();
if (--pos < 0) {

View File

@@ -648,7 +648,7 @@ struct RefitWindow : public Window {
{
switch (widget) {
case WID_VR_MATRIX:
resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
resize->height = GetMinSizing(NWST_STEP, WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM);
size->height = resize->height * 8;
break;
@@ -1329,7 +1329,7 @@ void DrawVehicleImage(const Vehicle *v, int left, int right, int y, int height,
uint GetVehicleListHeight(VehicleType type, uint divisor)
{
/* Name + vehicle + profit */
uint base = GetVehicleHeight(type) + 2 * FONT_HEIGHT_SMALL;
uint base = GetMinSizing(NWST_STEP, GetVehicleHeight(type) + 2 * FONT_HEIGHT_SMALL);
/* Drawing of the 4 small orders + profit*/
if (type >= VEH_SHIP) base = max(base, 5U * FONT_HEIGHT_SMALL);

View File

@@ -318,7 +318,7 @@ typedef SmallVector<RefitOption, 32> SubtypeList; ///< List of refit subtypes as
*/
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;
uint y = Center(r.top, delta);
uint current = 0;
bool rtl = _current_text_dir == TD_RTL;
@@ -713,7 +713,7 @@ struct RefitWindow : public Window {
case WID_VR_VEHICLE_PANEL_DISPLAY: {
Vehicle *v = Vehicle::Get(this->window_number);
DrawVehicleImage(v, this->sprite_left + WD_FRAMERECT_LEFT, this->sprite_right - WD_FRAMERECT_RIGHT,
r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != NULL ? this->hscroll->GetPosition() : 0);
r.top, r.bottom - r.top, INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != NULL ? this->hscroll->GetPosition() : 0);
/* Highlight selected vehicles. */
if (this->order != INVALID_VEH_ORDER_ID) break;
@@ -1308,8 +1308,9 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, Veh
* @param selection Selected vehicle to draw a frame around
* @param skip Number of pixels to skip at the front (for scrolling)
*/
void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
void DrawVehicleImage(const Vehicle *v, int left, int right, int y, int height, VehicleID selection, EngineImageType image_type, int skip)
{
y = Center(y, height, GetVehicleHeight(v->type));
switch (v->type) {
case VEH_TRAIN: DrawTrainImage(Train::From(v), left, right, y, selection, image_type, skip); break;
case VEH_ROAD: DrawRoadVehImage(v, left, right, y, selection, image_type, skip); break;
@@ -1374,7 +1375,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
SetDParam(0, v->GetDisplayProfitThisYear());
SetDParam(1, v->GetDisplayProfitLastYear());
DrawVehicleImage(v, image_left, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0);
DrawVehicleImage(v, image_left, image_right, y, line_height, selected_vehicle, EIT_IN_LIST, 0);
DrawString(text_left, text_right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
if (v->name != NULL) {
@@ -2085,12 +2086,12 @@ struct VehicleDetailsWindow : Window {
/* Articulated road vehicles use a complete line. */
if (v->type == VEH_ROAD && v->HasArticulatedPart()) {
DrawVehicleImage(v, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, 0);
DrawVehicleImage(v, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top, r.bottom - r.top, INVALID_VEHICLE, EIT_IN_DETAILS, 0);
} else {
uint sprite_left = rtl ? text_right : r.left;
uint sprite_right = rtl ? r.right : text_left;
DrawVehicleImage(v, sprite_left + WD_FRAMERECT_LEFT, sprite_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, EIT_IN_DETAILS, 0);
DrawVehicleImage(v, sprite_left + WD_FRAMERECT_LEFT, sprite_right - WD_FRAMERECT_RIGHT, r.top, r.bottom - r.top, INVALID_VEHICLE, EIT_IN_DETAILS, 0);
}
DrawVehicleDetails(v, text_left + WD_FRAMERECT_LEFT, text_right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, 0, 0, this->tab);
break;
@@ -2632,7 +2633,7 @@ public:
int image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING;
int lowered = this->IsWidgetLowered(WID_VV_START_STOP) ? 1 : 0;
DrawSprite(image, PAL_NONE, image_left + lowered, r.top + WD_IMGBTN_TOP + lowered);
DrawString(text_left + lowered, text_right + lowered, r.top + WD_FRAMERECT_TOP + lowered, str, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(text_left + lowered, text_right + lowered, Center(r.top + lowered, r.bottom - r.top), str, TC_FROMSTRING, SA_HOR_CENTER);
}
virtual void OnClick(Point pt, int widget, int click_count)

View File

@@ -523,7 +523,7 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
{
int text_offset = max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
int dd_width = NWidgetLeaf::dropdown_dimension.width;
int dd_width = GetMinSizing(NWST_STEP, NWidgetLeaf::dropdown_dimension.width);
if (_current_text_dir == TD_LTR) {
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
@@ -746,6 +746,7 @@ NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
*/
NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) : NWidgetBase(tp)
{
this->sizing_type = NWST_NONE;
this->fill_x = fill_x;
this->fill_y = fill_y;
}
@@ -757,8 +758,23 @@ NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) :
*/
void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
{
this->min_x = min_x;
this->min_y = min_y;
uint min_size = 0;
switch (this->sizing_type) {
case NWST_NONE:
case NWST_OVERRIDE:
min_size = 0;
break;
case NWST_BUTTON:
min_size = _settings_client.gui.min_button;
break;
case NWST_STEP:
min_size = _settings_client.gui.min_step;
break;
default: NOT_REACHED();
}
this->min_x = max(min_x, min_size);
this->min_y = max(min_y, min_size);
}
/**
@@ -810,6 +826,7 @@ void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, ui
*/
NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
{
this->sizing_type = NWST_NONE;
this->colour = colour;
this->index = -1;
this->widget_data = widget_data;
@@ -1930,6 +1947,7 @@ void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
{
assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
this->sizing_type = NWST_STEP;
this->SetIndex(index);
switch (this->type) {
@@ -2001,7 +2019,9 @@ void NWidgetScrollbar::Draw(const Window *w)
if (vertical_dimension.width == 0) {
vertical_dimension = maxdim(GetSpriteSize(SPR_ARROW_UP), GetSpriteSize(SPR_ARROW_DOWN));
vertical_dimension.width += extra.width;
vertical_dimension.width = GetMinSizing(NWST_STEP, vertical_dimension.width);
vertical_dimension.height += extra.height;
vertical_dimension.height = GetMinSizing(NWST_STEP, vertical_dimension.height);
}
return vertical_dimension;
}
@@ -2012,7 +2032,9 @@ void NWidgetScrollbar::Draw(const Window *w)
if (horizontal_dimension.width == 0) {
horizontal_dimension = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
horizontal_dimension.width += extra.width;
horizontal_dimension.width = GetMinSizing(NWST_STEP, horizontal_dimension.width);
horizontal_dimension.height += extra.height;
horizontal_dimension.height = GetMinSizing(NWST_STEP, horizontal_dimension.height);
}
return horizontal_dimension;
}
@@ -2050,8 +2072,40 @@ Dimension NWidgetLeaf::dropdown_dimension = {0, 0};
*/
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
{
assert(this->sizing_type < NWST_END);
assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEFSIZEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
if (index >= 0) this->SetIndex(index);
if (this->sizing_type == NWST_NONE) {
switch (tp) {
case WWT_PUSHBTN:
case WWT_IMGBTN:
case WWT_PUSHIMGBTN:
case WWT_IMGBTN_2:
case WWT_TEXTBTN:
case WWT_PUSHTXTBTN:
case WWT_TEXTBTN_2:
case WWT_PUSHARROWBTN:
case WWT_EDITBOX:
case WWT_CAPTION:
case WWT_STICKYBOX:
case WWT_SHADEBOX:
case WWT_DEBUGBOX:
case WWT_DEFSIZEBOX:
case WWT_RESIZEBOX:
case WWT_CLOSEBOX:
this->sizing_type = NWST_BUTTON;
break;
case NWID_PUSHBUTTON_DROPDOWN:
case NWID_BUTTON_DROPDOWN:
case WWT_DROPDOWN:
this->sizing_type = NWST_STEP;
break;
default:
this->sizing_type = NWST_OVERRIDE;
}
}
this->SetMinimalSize(0, 0);
this->SetResize(0, 0);
@@ -2463,11 +2517,12 @@ void NWidgetLeaf::Draw(const Window *w)
*/
bool NWidgetLeaf::ButtonHit(const Point &pt)
{
uint button_size = GetMinSizing(NWST_STEP, 12);
if (_current_text_dir == TD_LTR) {
int button_width = this->pos_x + this->current_x - 12;
int button_width = this->pos_x + this->current_x - button_size;
return pt.x < button_width;
} else {
int button_left = this->pos_x + 12;
int button_left = this->pos_x + button_size;
return pt.x >= button_left;
}
}
@@ -2560,6 +2615,16 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
break;
}
case WPT_SIZINGTYPE: {
NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
if (nwrb != NULL) {
assert(parts->u.sizing_type < NWST_END);
nwrb->sizing_type = parts->u.sizing_type;
nwrb->SetMinimalSize(0, 0);
}
break;
}
case WPT_MINSIZE: {
NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
if (nwrb != NULL) {
@@ -2816,6 +2881,7 @@ NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int wid
}
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
panel->sizing_type = NWST_STEP;
panel->SetMinimalSize(sprite_size.width, sprite_size.height);
panel->SetFill(1, 1);
panel->SetResize(1, 0);
@@ -2836,3 +2902,28 @@ NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int wid
if (hor != NULL) vert->Add(hor);
return vert;
}
/**
* Return the minimal automatic size for a widget.
* @param type The automatic sizing type to use.
* @param min_1 Minimal passed value.
* @return At least the passed value, or the minimal size for the associated sizing type.
*/
uint GetMinSizing(NWidSizingType type, uint min_1)
{
uint min_sizing;
switch (type) {
case NWST_NONE:
case NWST_OVERRIDE:
return min_1;
case NWST_BUTTON:
min_sizing = _settings_client.gui.min_button;
break;
case NWST_STEP:
min_sizing = _settings_client.gui.min_step;
break;
default: NOT_REACHED();
}
return max(min_sizing, min_1);
}

View File

@@ -523,7 +523,7 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
{
int text_offset = max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
int dd_width = GetMinSizing(NWST_STEP, NWidgetLeaf::dropdown_dimension.width);
int dd_width = NWidgetLeaf::dropdown_dimension.width;
if (_current_text_dir == TD_LTR) {
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
@@ -746,7 +746,6 @@ NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
*/
NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) : NWidgetBase(tp)
{
this->sizing_type = NWST_NONE;
this->fill_x = fill_x;
this->fill_y = fill_y;
}
@@ -758,26 +757,8 @@ NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) :
*/
void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
{
uint min_size = 0;
switch (this->sizing_type) {
case NWST_NONE:
case NWST_OVERRIDE:
min_size = 0;
break;
case NWST_BUTTON:
min_size = _settings_client.gui.min_button;
break;
case NWST_STEP:
min_size = _settings_client.gui.min_step;
break;
case NWST_VIEWPORT:
min_size = 3 * _settings_client.gui.min_button;
break;
default: NOT_REACHED();
}
this->min_x = max(min_x, min_size);
this->min_y = max(min_y, min_size);
this->min_x = min_x;
this->min_y = min_y;
}
/**
@@ -829,7 +810,6 @@ void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, ui
*/
NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
{
this->sizing_type = NWST_NONE;
this->colour = colour;
this->index = -1;
this->widget_data = widget_data;
@@ -1950,7 +1930,6 @@ void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
{
assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
this->sizing_type = NWST_STEP;
this->SetIndex(index);
switch (this->type) {
@@ -2022,9 +2001,7 @@ void NWidgetScrollbar::Draw(const Window *w)
if (vertical_dimension.width == 0) {
vertical_dimension = maxdim(GetSpriteSize(SPR_ARROW_UP), GetSpriteSize(SPR_ARROW_DOWN));
vertical_dimension.width += extra.width;
vertical_dimension.width = GetMinSizing(NWST_STEP, vertical_dimension.width);
vertical_dimension.height += extra.height;
vertical_dimension.height = GetMinSizing(NWST_STEP, vertical_dimension.height);
}
return vertical_dimension;
}
@@ -2035,9 +2012,7 @@ void NWidgetScrollbar::Draw(const Window *w)
if (horizontal_dimension.width == 0) {
horizontal_dimension = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
horizontal_dimension.width += extra.width;
horizontal_dimension.width = GetMinSizing(NWST_STEP, horizontal_dimension.width);
horizontal_dimension.height += extra.height;
horizontal_dimension.height = GetMinSizing(NWST_STEP, horizontal_dimension.height);
}
return horizontal_dimension;
}
@@ -2075,40 +2050,8 @@ Dimension NWidgetLeaf::dropdown_dimension = {0, 0};
*/
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
{
assert(this->sizing_type < NWST_END);
assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEFSIZEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
if (index >= 0) this->SetIndex(index);
if (this->sizing_type == NWST_NONE) {
switch (tp) {
case WWT_PUSHBTN:
case WWT_IMGBTN:
case WWT_PUSHIMGBTN:
case WWT_IMGBTN_2:
case WWT_TEXTBTN:
case WWT_PUSHTXTBTN:
case WWT_TEXTBTN_2:
case WWT_PUSHARROWBTN:
case WWT_EDITBOX:
case WWT_CAPTION:
case WWT_STICKYBOX:
case WWT_SHADEBOX:
case WWT_DEBUGBOX:
case WWT_DEFSIZEBOX:
case WWT_RESIZEBOX:
case WWT_CLOSEBOX:
this->sizing_type = NWST_BUTTON;
break;
case NWID_PUSHBUTTON_DROPDOWN:
case NWID_BUTTON_DROPDOWN:
case WWT_DROPDOWN:
this->sizing_type = NWST_STEP;
break;
default:
this->sizing_type = NWST_OVERRIDE;
}
}
this->SetMinimalSize(0, 0);
this->SetResize(0, 0);
@@ -2135,7 +2078,7 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data,
case WWT_EDITBOX: {
Dimension sprite_size = GetSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
this->SetMinimalSize(30 + GetMinSizing(NWST_BUTTON, sprite_size.width), sprite_size.height);
this->SetMinimalSize(30 + sprite_size.width, sprite_size.height);
this->SetFill(0, 0);
break;
}
@@ -2520,12 +2463,11 @@ void NWidgetLeaf::Draw(const Window *w)
*/
bool NWidgetLeaf::ButtonHit(const Point &pt)
{
uint button_size = GetMinSizing(NWST_STEP, 12);
if (_current_text_dir == TD_LTR) {
int button_width = this->pos_x + this->current_x - button_size;
int button_width = this->pos_x + this->current_x - 12;
return pt.x < button_width;
} else {
int button_left = this->pos_x + button_size;
int button_left = this->pos_x + 12;
return pt.x >= button_left;
}
}
@@ -2618,16 +2560,6 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
break;
}
case WPT_SIZINGTYPE: {
NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
if (nwrb != NULL) {
assert(parts->u.sizing_type < NWST_END);
nwrb->sizing_type = parts->u.sizing_type;
nwrb->SetMinimalSize(0, 0);
}
break;
}
case WPT_MINSIZE: {
NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
if (nwrb != NULL) {
@@ -2884,7 +2816,6 @@ NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int wid
}
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
panel->sizing_type = NWST_STEP;
panel->SetMinimalSize(sprite_size.width, sprite_size.height);
panel->SetFill(1, 1);
panel->SetResize(1, 0);
@@ -2905,34 +2836,3 @@ NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int wid
if (hor != NULL) vert->Add(hor);
return vert;
}
/**
* Return the minimal automatic size for a widget.
* @param type The automatic sizing type to use.
* @param min_1 Minimal passed value.
* @return At least the passed value, or the minimal size for the associated sizing type.
*/
uint GetMinSizing(NWidSizingType type, uint min_1)
{
uint min_sizing;
switch (type) {
case NWST_NONE:
case NWST_OVERRIDE:
return min_1;
case NWST_BUTTON:
min_sizing = _settings_client.gui.min_button;
break;
case NWST_STEP:
min_sizing = _settings_client.gui.min_step;
break;
case NWST_KEYBOARD:
min_sizing = 2 * _settings_client.gui.min_button;
break;
case NWST_WINDOW_LENGTH:
min_sizing = 8 * _settings_client.gui.min_button;
break;
default: NOT_REACHED();
}
return max(min_sizing, min_1);
}

View File

@@ -40,6 +40,17 @@ enum ArrowWidgetValues {
AWV_RIGHT, ///< Force the arrow to the right
};
/** Values for different minimal sizing of widgets. */
enum NWidSizingType {
NWST_NONE, ///< No sizing type is yet defined.
///< Most buttons and scrollbars are initialized with this value.
///< Later, they are automatically set to NWST_BUTTON or NWST_STEP.
NWST_BUTTON, ///< Size will be set at least _settings_client.gui.min_button.
NWST_STEP, ///< Size will be set at least _settings_client.gui.min_step (scrollbars and dropdowns).
NWST_OVERRIDE, ///< Avoid widgets to use automatic minimal sizing.
NWST_END
};
/**
* Window widget types, nested widget types, and nested widget part types.
*/
@@ -85,6 +96,7 @@ enum WidgetType {
/* Nested widget part types. */
WPT_RESIZE, ///< Widget part for specifying resizing.
WPT_SIZINGTYPE, ///< Widget part for specifying sizing mode.
WPT_MINSIZE, ///< Widget part for specifying minimal size.
WPT_MINTEXTLINES, ///< Widget part for specifying minimal number of lines of text.
WPT_FILL, ///< Widget part for specifying fill.
@@ -160,11 +172,12 @@ public:
virtual void Draw(const Window *w) = 0;
virtual void SetDirty(const Window *w) const;
WidgetType type; ///< Type of the widget / nested widget.
uint fill_x; ///< Horizontal fill stepsize (from initial size, \c 0 means not resizable).
uint fill_y; ///< Vertical fill stepsize (from initial size, \c 0 means not resizable).
uint resize_x; ///< Horizontal resize step (\c 0 means not resizable).
uint resize_y; ///< Vertical resize step (\c 0 means not resizable).
WidgetType type; ///< Type of the widget / nested widget.
NWidSizingType sizing_type; ///< Type for deciding minimal sizes of the widget.
uint fill_x; ///< Horizontal fill stepsize (from initial size, \c 0 means not resizable).
uint fill_y; ///< Vertical fill stepsize (from initial size, \c 0 means not resizable).
uint resize_x; ///< Horizontal resize step (\c 0 means not resizable).
uint resize_y; ///< Vertical resize step (\c 0 means not resizable).
/* Size of the widget in the smallest window possible.
* Computed by #SetupSmallestSize() followed by #AssignSizePosition().
*/
@@ -918,6 +931,7 @@ struct NWidgetPart {
NWidgetPartTextLines text_lines; ///< Part with text line data.
NWidgetFunctionType *func_ptr; ///< Part with a function call.
NWidContainerFlags cont_flags; ///< Part with container flags.
NWidSizingType sizing_type; ///< Part with sizing type.
} u;
};
@@ -938,6 +952,23 @@ static inline NWidgetPart SetResize(int16 dx, int16 dy)
return part;
}
/**
* Widget part function for setting the automatic minimal size.
* @param type How to decide the minimal size of the widget.
* @ingroup NestedWidgetParts
*/
static inline NWidgetPart SetSizingType(NWidSizingType type)
{
NWidgetPart part;
part.type = WPT_SIZINGTYPE;
part.u.sizing_type = type;
return part;
}
uint GetMinSizing(NWidSizingType type, uint min_1 = 0);
/**
* Widget part function for setting the minimal size.
* @param x Horizontal minimal size.

View File

@@ -13,6 +13,7 @@
#define WIDGETS_DROPDOWN_TYPE_H
#include "../window_type.h"
#include "../widget_type.h"
#include "../gfx_func.h"
#include "../core/smallvec_type.hpp"
#include "table/strings.h"
@@ -30,7 +31,7 @@ public:
virtual ~DropDownListItem() {}
virtual bool Selectable() const { return false; }
virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
virtual uint Height(uint width) const { return GetMinSizing(NWST_STEP, FONT_HEIGHT_NORMAL); }
virtual uint Width() const { return 0; }
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
};