diff options
author | alberth <alberth@openttd.org> | 2009-10-31 13:29:53 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-10-31 13:29:53 +0000 |
commit | 43abc7b51df476ee087e4498f447718838f930c4 (patch) | |
tree | 20c63b8d52859d5cfc9ffa984e800e964197c663 /src | |
parent | 4374647cbeb76653fc1629ce109186c50440d272 (diff) | |
download | openttd-43abc7b51df476ee087e4498f447718838f930c4.tar.xz |
(svn r17918) -Codechange: Move tooltip size calculation into the tooltip window class.
Diffstat (limited to 'src')
-rw-r--r-- | src/misc_gui.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
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); } |