Skip to content

Commit

Permalink
Cleanup: Text widgets are capable of drawing text without assistance.
Browse files Browse the repository at this point in the history
Remove custom text drawing of some widgets in favour of standard text
widgets.
  • Loading branch information
PeterN authored and michicc committed Oct 16, 2022
1 parent 0e34008 commit dc1b84a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 58 deletions.
13 changes: 2 additions & 11 deletions src/genworld_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static const NWidgetPart _nested_heightmap_load_widgets[] = {
EndContainer(),
/* Widgets at the right of the labels. */
NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextColour(TC_ORANGE), SetDataTip(STR_JUST_RAW_STRING, STR_EMPTY), SetFill(1, 0),
NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
Expand Down Expand Up @@ -441,6 +441,7 @@ struct GenerateLandscapeWindow : public Window {
}
break;

case WID_GL_HEIGHTMAP_NAME_TEXT: SetDParamStr(0, this->name); break;
case WID_GL_RIVER_PULLDOWN: SetDParam(0, _rivers[_settings_newgame.game_creation.amount_of_rivers]); break;
case WID_GL_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
case WID_GL_VARIETY_PULLDOWN: SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
Expand Down Expand Up @@ -624,16 +625,6 @@ struct GenerateLandscapeWindow : public Window {
size->height = std::max(size->height, (uint)(FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM));
}

void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_GL_HEIGHTMAP_NAME_TEXT: {
DrawString(r.left, r.right, r.top, this->name, TC_ORANGE);
break;
}
}
}

void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
Expand Down
10 changes: 1 addition & 9 deletions src/network/network_content_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,6 @@ class NetworkContentListWindow : public Window, ContentCallback {
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_NCL_FILTER_CAPT:
*size = maxdim(*size, GetStringBoundingBox(STR_CONTENT_FILTER_TITLE));
break;

case WID_NCL_CHECKBOX:
size->width = this->checkbox_size.width + WD_MATRIX_RIGHT + WD_MATRIX_LEFT;
break;
Expand All @@ -587,10 +583,6 @@ class NetworkContentListWindow : public Window, ContentCallback {
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_NCL_FILTER_CAPT:
DrawString(r.left, r.right, r.top, STR_CONTENT_FILTER_TITLE, TC_FROMSTRING, SA_RIGHT);
break;

case WID_NCL_DETAILS:
this->DrawDetails(r);
break;
Expand Down Expand Up @@ -1029,7 +1021,7 @@ static const NWidgetPart _nested_network_content_list_widgets[] = {
NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
/* Top */
NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, WID_NCL_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NCL_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_CONTENT_FILTER_TITLE, STR_NULL), SetAlignment(SA_RIGHT),
NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NCL_FILTER), SetFill(1, 0), SetResize(1, 0),
SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
EndContainer(),
Expand Down
34 changes: 3 additions & 31 deletions src/station_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,6 @@ class CompanyStationsWindow : public Window
this->rating_width = this->rating_width * 16 / 10;
break;

case WID_STL_CARGOALL:
case WID_STL_FACILALL:
case WID_STL_NOCARGOWAITING: {
Dimension d = GetStringBoundingBox(widget == WID_STL_NOCARGOWAITING ? STR_ABBREV_NONE : STR_ABBREV_ALL);
d.width += padding.width + 2;
d.height += padding.height;
*size = maxdim(*size, d);
break;
}

default:
if (widget >= WID_STL_CARGOSTART) {
Dimension d = GetStringBoundingBox(_sorted_cargo_specs[widget - WID_STL_CARGOSTART]->abbrev);
Expand Down Expand Up @@ -492,24 +482,6 @@ class CompanyStationsWindow : public Window
break;
}

case WID_STL_NOCARGOWAITING: {
int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_NONE, TC_BLACK, SA_HOR_CENTER);
break;
}

case WID_STL_CARGOALL: {
int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
break;
}

case WID_STL_FACILALL: {
int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
break;
}

default:
if (widget >= WID_STL_CARGOSTART) {
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
Expand Down Expand Up @@ -749,11 +721,11 @@ static const NWidgetPart _nested_company_stations_widgets[] = {
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_BUS), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_SHIP), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_AIRPLANE), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetFill(0, 1),
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
NWidgetFunction(CargoWidgets),
NWidget(WWT_PANEL, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_NO_WAITING_CARGO), SetFill(0, 1), EndContainer(),
NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_TYPES), SetFill(0, 1),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_ABBREV_NONE, STR_STATION_LIST_NO_WAITING_CARGO), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_TYPES), SetFill(0, 1),
NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL),
Expand Down
17 changes: 10 additions & 7 deletions src/toolbar_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,14 +2336,18 @@ struct ScenarioEditorToolbarWindow : Window {
this->DrawWidgets();
}

void DrawWidget(const Rect &r, int widget) const override
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_TE_DATE:
SetDParam(0, ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
DrawString(r.left, r.right, (this->height - FONT_HEIGHT_NORMAL) / 2, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
break;
}
}

void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_TE_SPACER: {
int height = r.bottom - r.top;
if (height > 2 * FONT_HEIGHT_NORMAL) {
Expand All @@ -2367,7 +2371,6 @@ struct ScenarioEditorToolbarWindow : Window {
case WID_TE_DATE:
SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
*size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
size->height = std::max(size->height, GetSpriteSize(SPR_IMG_SAVE).height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
break;
}
}
Expand Down Expand Up @@ -2530,10 +2533,10 @@ static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
NWidget(NWID_SPACER),
NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
NWidget(NWID_HORIZONTAL), SetPIP(3, 2, 3),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_NULL, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
NWidget(NWID_HORIZONTAL), SetPIP(2, 2, 2), SetPadding(1),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
NWidget(WWT_TEXT, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_WHITE_DATE_LONG, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE), SetAlignment(SA_CENTER), SetFill(0, 1),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
EndContainer(),
EndContainer(),
NWidget(NWID_SPACER),
Expand Down

0 comments on commit dc1b84a

Please sign in to comment.