From 43abc7b51df476ee087e4498f447718838f930c4 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 31 Oct 2009 13:29:53 +0000 Subject: (svn r17918) -Codechange: Move tooltip size calculation into the tooltip window class. --- src/misc_gui.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 5732950e5..10adba37b 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -791,9 +791,8 @@ struct TooltipsWindow : public Window byte paramcount; ///< Number of string parameters in #string_id. uint64 params[5]; ///< The string parameters. bool use_left_mouse_button; ///< Wait for left mouse button to close window (else, wait for right button). - Dimension window_size; ///< Size of the window. - TooltipsWindow(const Dimension &window_size, StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) : Window() + TooltipsWindow(StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) : Window() { this->string_id = str; assert_compile(sizeof(this->params[0]) == sizeof(params[0])); @@ -802,8 +801,6 @@ struct TooltipsWindow : public Window this->paramcount = paramcount; this->use_left_mouse_button = use_left_mouse_button; - this->window_size = window_size; - this->InitNested(&_tool_tips_desc); this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip @@ -826,7 +823,14 @@ struct TooltipsWindow : public Window virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize) { /* There is only one widget. */ - *size = this->window_size; + for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]); + + size->width = min(GetStringBoundingBox(this->string_id).width, 194); + size->height = GetStringHeight(this->string_id, size->width); + + /* Increase slightly to have some space around the box. */ + size->width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; + size->height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; } virtual void DrawWidget(const Rect &r, int widget) const @@ -867,17 +871,7 @@ void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], bool if (str == STR_NULL) return; - for (uint i = 0; i != paramcount; i++) SetDParam(i, params[i]); - - Dimension br; - br.width = min(GetStringBoundingBox(str).width, 194); - br.height = GetStringHeight(str, br.width); - - /* increase slightly to have some space around the box */ - br.width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; - br.height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; - - new TooltipsWindow(br, str, paramcount, params, use_left_mouse_button); + new TooltipsWindow(str, paramcount, params, use_left_mouse_button); } -- cgit v1.2.3-54-g00ecf