summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-09-05 23:11:41 +0000
committerDarkvater <Darkvater@openttd.org>2006-09-05 23:11:41 +0000
commita53c92464f2d87bcb9e8b31a1f68d5e26e29aded (patch)
tree93a518eea686fcab8e01f919ea88961a179c9710
parent4721a3fcce1ef7e6f7c37c8d49ecac972933ecfd (diff)
downloadopenttd-a53c92464f2d87bcb9e8b31a1f68d5e26e29aded.tar.xz
(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.
-rw-r--r--misc_gui.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/misc_gui.c b/misc_gui.c
index 4deead899..77c8630c0 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;
}