From a53c92464f2d87bcb9e8b31a1f68d5e26e29aded Mon Sep 17 00:00:00 2001 From: Darkvater Date: Tue, 5 Sep 2006 23:11:41 +0000 Subject: [PATCH] (svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering cursor size and cursor offset (hotspot). The maximum and minimum y-values for the tooltip are just below the mainbar and statusbar. Also, if the tooltip would be too low, flip it above the cursor. --- misc_gui.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/misc_gui.c b/misc_gui.c index 4deead8994..77c8630c07 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -666,27 +666,25 @@ void GuiShowTooltips(StringID string_id) GetString(buffer, string_id); - right = GetStringWidth(buffer) + 4; + right = GetStringWidth(buffer) + 6; + /* Cut tooltip length to 200 pixels max, wrap to new line if longer */ bottom = 14; if (right > 200) { bottom += ((right - 4) / 176) * 10; right = 200; } - y = _cursor.pos.y + 30; - if (y < 22) y = 22; - - if (y > (_screen.height - 44) && (y-=52) > (_screen.height - 44)) - y = (_screen.height - 44); - - x = _cursor.pos.x - (right >> 1); - if (x < 0) x = 0; - if (x > (_screen.width - right)) x = _screen.width - right; + /* Correctly position the tooltip position, watch out for window and cursor size + * Clamp value to below main toolbar and above statusbar. If tooltip would + * go below window, flip it so it is shown above the cursor */ + y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12); + if (y + bottom > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - bottom - 5; + x = clamp(_cursor.pos.x - (right >> 1), 0, _screen.width - right); w = AllocateWindow(x, y, right, bottom, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets); WP(w,tooltips_d).string_id = string_id; - w->flags4 &= ~WF_WHITE_BORDER_MASK; + w->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip w->widget[0].right = right; w->widget[0].bottom = bottom; }