diff options
author | alberth <alberth@openttd.org> | 2009-07-25 11:54:53 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-07-25 11:54:53 +0000 |
commit | e3033ee895d8d621ffe2bb115b2293206db0e52f (patch) | |
tree | 8bf38b6bf210fb0fa73272deefb61347b14aba89 /src | |
parent | e5bfc5660d35e408de764cde63bf376fbade37c5 (diff) | |
download | openttd-e3033ee895d8d621ffe2bb115b2293206db0e52f.tar.xz |
(svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
Diffstat (limited to 'src')
-rw-r--r-- | src/intro_gui.cpp | 9 | ||||
-rw-r--r-- | src/rail_gui.cpp | 12 | ||||
-rw-r--r-- | src/town_gui.cpp | 12 | ||||
-rw-r--r-- | src/widget.cpp | 16 | ||||
-rw-r--r-- | src/window_gui.h | 8 |
5 files changed, 38 insertions, 19 deletions
diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index 9b2c8511b..36989926a 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -75,12 +75,9 @@ struct SelectGameWindow : public Window { this->DrawWidgets(); } - virtual void DrawWidget(const Rect &r, int widget) const + virtual void SetStringParameters(int widget) const { - if (widget == SGI_DIFFICULTIES) { - SetDParam(0, STR_DIFFICULTY_LEVEL_EASY + _settings_newgame.difficulty.diff_level); - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_INTRO_DIFFICULTY, TC_FROMSTRING, SA_CENTER); - } + if (widget == SGI_DIFFICULTIES) SetDParam(0, STR_DIFFICULTY_LEVEL_EASY + _settings_newgame.difficulty.diff_level); } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize) @@ -211,7 +208,7 @@ static const NWidgetPart _nested_select_game_widgets[] = { NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, SGI_OPTIONS), SetMinimalSize(158, 12), SetDataTip(STR_INTRO_GAME_OPTIONS, STR_INTRO_TOOLTIP_GAME_OPTIONS), SetPadding(0, 0, 0, 10), SetFill(1, 0), NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, SGI_DIFFICULTIES), SetMinimalSize(158, 12), - SetDataTip(STR_NULL, STR_INTRO_TOOLTIP_DIFFICULTY_OPTIONS), SetPadding(0, 10, 0, 0), SetFill(1, 0), + SetDataTip(STR_INTRO_DIFFICULTY, STR_INTRO_TOOLTIP_DIFFICULTY_OPTIONS), SetPadding(0, 10, 0, 0), SetFill(1, 0), EndContainer(), NWidget(NWID_SPACER), SetMinimalSize(0, 6), diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index f6c7d667a..fb0c96b66 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1128,14 +1128,14 @@ public: } break; } - - case BRSW_NEWST_DROPDOWN: - SetDParam(0, GetStationClassName(_railstation.station_class)); - DrawString(r.left + WD_DROPDOWNTEXT_LEFT, r.right - WD_DROPDOWNTEXT_RIGHT, r.top + WD_DROPDOWNTEXT_TOP, STR_BLACK_STRING, TC_BLACK); - break; } } + virtual void SetStringParameters(int widget) const + { + if (widget == BRSW_NEWST_DROPDOWN) SetDParam(0, GetStationClassName(_railstation.station_class)); + } + virtual void OnClick(Point pt, int widget) { switch (widget) { @@ -1377,7 +1377,7 @@ static const NWidgetPart _nested_newstation_builder_widgets[] = { NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BRSW_BACKGROUND), /* begin newstations gui additions. */ NWidget(NWID_SPACER), SetMinimalSize(0, 3), - NWidget(WWT_DROPDOWN, COLOUR_GREY, BRSW_NEWST_DROPDOWN), SetMinimalSize(134, 12), SetPadding(0, 7, 0, 7), SetDataTip(STR_EMPTY, STR_SELECT_STATION_CLASS_TIP), + NWidget(WWT_DROPDOWN, COLOUR_GREY, BRSW_NEWST_DROPDOWN), SetMinimalSize(134, 12), SetPadding(0, 7, 0, 7), SetDataTip(STR_BLACK_STRING, STR_SELECT_STATION_CLASS_TIP), NWidget(NWID_SPACER), SetMinimalSize(0, 3), NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7), NWidget(WWT_MATRIX, COLOUR_GREY, BRSW_NEWST_LIST), SetMinimalSize(122, 71), SetFill(1, 0), SetDataTip(0x501, STR_SELECT_STATION_TYPE_TIP), diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 924d47b6d..b589f24d7 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -517,7 +517,7 @@ static const NWidgetPart _nested_town_directory_widgets[] = { NWidget(WWT_PANEL, COLOUR_BROWN, TDW_CENTERTOWN), SetMinimalSize(196, 164), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP), SetFill(1, 0), SetResize(0, 10), EndContainer(), NWidget(WWT_PANEL, COLOUR_BROWN, TDW_BOTTOM_PANEL), - NWidget(WWT_TEXT, COLOUR_BROWN, TDW_BOTTOM_TEXT), SetPadding(2, 0, 0, 2), SetMinimalSize(196, 12), SetFill(1, 0), SetDataTip(STR_EMPTY, STR_NULL), + NWidget(WWT_TEXT, COLOUR_BROWN, TDW_BOTTOM_TEXT), SetPadding(2, 0, 0, 2), SetMinimalSize(196, 12), SetFill(1, 0), SetDataTip(STR_TOWN_POPULATION, STR_NULL), EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), @@ -611,6 +611,11 @@ public: this->DrawWidgets(); } + virtual void SetStringParameters(int widget) const + { + if (widget == TDW_BOTTOM_TEXT) SetDParam(0, GetWorldPopulation()); + } + virtual void DrawWidget(const Rect &r, int widget) const { switch(widget) { @@ -638,11 +643,6 @@ public: if (++n == this->vscroll.cap) break; // max number of towns in 1 window } } break; - - case TDW_BOTTOM_TEXT: - SetDParam(0, GetWorldPopulation()); - DrawString(r.left, r.right, r.top, STR_TOWN_POPULATION); - break; } } diff --git a/src/widget.cpp b/src/widget.cpp index 700d59ee9..7a3371c2b 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1694,7 +1694,10 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array) Dimension d = {this->min_x, this->min_y}; Dimension resize = {this->resize_x, this->resize_y}; if (w != NULL) { // A non-NULL window pointer acts as switch to turn dynamic widget size on. - if (this->type == WWT_FRAME || this->type == WWT_INSET) d = maxdim(d, GetStringBoundingBox(this->widget_data)); + if (this->type == WWT_FRAME || this->type == WWT_INSET) { + if (this->index >= 0) w->SetStringParameters(this->index); + d = maxdim(d, GetStringBoundingBox(this->widget_data)); + } if (this->index >= 0) { static const Dimension padding = {0, 0}; w->UpdateWidgetSize(this->index, &d, padding, &resize); @@ -1745,10 +1748,12 @@ void NWidgetBackground::Draw(const Window *w) break; case WWT_FRAME: + if (this->index >= 0) w->SetStringParameters(this->index); DrawFrame(r, this->colour, this->widget_data); break; case WWT_INSET: + if (this->index >= 0) w->SetStringParameters(this->index); DrawInset(r, this->colour, this->widget_data); break; @@ -1983,6 +1988,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array) case WWT_TEXTBTN_2: { static const Dimension extra = {WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM}; padding = &extra; + if (this->index >= 0) w->SetStringParameters(this->index); Dimension d2 = GetStringBoundingBox(this->widget_data); d2.width += extra.width; d2.height += extra.height; @@ -1993,12 +1999,14 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array) case WWT_TEXT: { static const Dimension extra = {0, 0}; padding = &extra; + if (this->index >= 0) w->SetStringParameters(this->index); size = maxdim(size, GetStringBoundingBox(this->widget_data)); break; } case WWT_CAPTION: { static const Dimension extra = {WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT, WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM}; padding = &extra; + if (this->index >= 0) w->SetStringParameters(this->index); Dimension d2 = GetStringBoundingBox(this->widget_data); d2.width += extra.width; d2.height += extra.height; @@ -2008,6 +2016,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array) case WWT_DROPDOWN: { static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM}; padding = &extra; + if (this->index >= 0) w->SetStringParameters(this->index); Dimension d2 = GetStringBoundingBox(this->widget_data); d2.width += extra.width; d2.height += extra.height; @@ -2059,15 +2068,18 @@ void NWidgetLeaf::Draw(const Window *w) case WWT_TEXTBTN: case WWT_PUSHTXTBTN: case WWT_TEXTBTN_2: + if (this->index >= 0) w->SetStringParameters(this->index); DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE); DrawLabel(r, this->type, clicked, this->widget_data); break; case WWT_LABEL: + if (this->index >= 0) w->SetStringParameters(this->index); DrawLabel(r, this->type, clicked, this->widget_data); break; case WWT_TEXT: + if (this->index >= 0) w->SetStringParameters(this->index); DrawText(r, (TextColour)this->colour, this->widget_data); break; @@ -2094,6 +2106,7 @@ void NWidgetLeaf::Draw(const Window *w) break; case WWT_CAPTION: + if (this->index >= 0) w->SetStringParameters(this->index); DrawCaption(r, this->colour, w->owner, this->widget_data); break; @@ -2119,6 +2132,7 @@ void NWidgetLeaf::Draw(const Window *w) break; case WWT_DROPDOWN: + if (this->index >= 0) w->SetStringParameters(this->index); DrawDropdown(r, this->colour, clicked, this->widget_data); break; diff --git a/src/window_gui.h b/src/window_gui.h index 3cb1fa9f6..f44efbcc2 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -534,6 +534,14 @@ public: virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize) {} /** + * Initialize string parameters for a widget. + * Calls to this function are made during initialization to measure the size (that is as part of #InitNested()), during drawing, + * and while re-initializing the window. Only for widgets that render text initializing is requested. + * @param widget Widget number. + */ + virtual void SetStringParameters(int widget) const {} + + /** * Called when window gains focus */ virtual void OnFocus() {} |