summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-11-29 21:17:37 +0000
committeralberth <alberth@openttd.org>2009-11-29 21:17:37 +0000
commitf2f9ef7a9f72efb5bc1f0011f9e3f08011a0989e (patch)
tree51ffa493a0dde3217f61316d612d261814626cd3 /src/news_gui.cpp
parentbb19a2e7578e41c555cda914c3bc6046c2094556 (diff)
downloadopenttd-f2f9ef7a9f72efb5bc1f0011f9e3f08011a0989e.tar.xz
(svn r18347) -Codechange: Compute width of labels in news settings window once.
Diffstat (limited to 'src/news_gui.cpp')
-rw-r--r--src/news_gui.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index c36fe29ec..314f268cf 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -1071,7 +1071,8 @@ enum MessageOptionWidgets {
struct MessageOptionsWindow : Window {
static const StringID message_opt[]; ///< Message report options, 'off', 'summary', or 'full'.
- int state; ///< Option value for setting all categories at once.
+ int state; ///< Option value for setting all categories at once.
+ Dimension dim_message_opt; ///< Amount of space needed for a label such that all labels will fit.
MessageOptionsWindow(const WindowDesc *desc) : Window()
{
@@ -1118,6 +1119,12 @@ struct MessageOptionsWindow : Window {
}
}
+ virtual void OnInit()
+ {
+ this->dim_message_opt = {0, 0};
+ for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) this->dim_message_opt = maxdim(this->dim_message_opt, GetStringBoundingBox(*str));
+ }
+
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget >= WIDGET_NEWSOPT_START_OPTION && widget < WIDGET_NEWSOPT_END_OPTION) {
@@ -1126,9 +1133,7 @@ struct MessageOptionsWindow : Window {
/* Compute width for the label widget only. */
if ((widget - WIDGET_NEWSOPT_START_OPTION) % MOS_WIDG_PER_SETTING == 1) {
- Dimension d = {0, 0};
- for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) d = maxdim(d, GetStringBoundingBox(*str));
- size->width = d.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
+ size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
}
return;
}
@@ -1139,9 +1144,7 @@ struct MessageOptionsWindow : Window {
size->height = FONT_HEIGHT_NORMAL + max(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM);
if (widget == WIDGET_NEWSOPT_DROP_SUMMARY) {
- Dimension d = {0, 0};
- for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) d = maxdim(d, GetStringBoundingBox(*str));
- size->width = d.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
+ size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks.
} else if (widget == WIDGET_NEWSOPT_SOUNDTICKER) {
size->width += MOS_BUTTON_SPACE; // A bit extra for better looks.
}