changeset 13821:bce8f2b7d284 draft

(svn r18347) -Codechange: Compute width of labels in news settings window once.
author alberth <alberth@openttd.org>
date Sun, 29 Nov 2009 21:17:37 +0000
parents 0e36ac197b16
children b599335e5e9e
files src/news_gui.cpp
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -1071,7 +1071,8 @@
 
 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 @@
 		}
 	}
 
+	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 @@
 
 			/* 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 @@
 			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.
 			}