From 3999ff518d08778d25cb0d00329943ee5c2ef222 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 18 Jul 2020 21:13:09 +0200 Subject: Draw tooltips below the mouse cursor instead of below parent widget. --- src/ui/ui.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/ui/ui.cc') diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 7fb25dd..c1558b1 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -283,12 +283,19 @@ void UI::frame() ui_mouse_focus = f; // show tooltip if the timeout has expired - if (ui_mouse_focus && ui_mouse_focus->tooltip() && ui_mouse_focus->tooltip()->hidden()) + if (ui_mouse_focus && ui_mouse_focus->tooltip() && ui_mouse_focus->tooltip()->text().size() && ui_mouse_focus->tooltip()->hidden()) { assert(ui_tooltiptimeout != nullptr); unsigned long timeout = (unsigned long) ui_tooltiptimeout->value(); if (ui_tooltip_timestamp + timeout < core::application()->timestamp()) { + // move the tooltip below the mouse cursor + math::Vector2f p( + ui_mouse_focus->tooltip()->parent() ? + ui_mouse_focus->tooltip()->parent()->to_local_coords(mouse_cursor) : + mouse_cursor); + + ui_mouse_focus->tooltip()->set_location(p.x() - ui_mouse_focus->tooltip()->width() * 0.5f, p.y() + pointer_size * 0.5f); ui_mouse_focus->tooltip()->show(); } } @@ -299,12 +306,13 @@ void UI::frame() // draw the widget stack event_draw(); - // draw tooltip - Tooltip::event_draw_global(); - - // draw the mouse pointer - if (visible()) + if (visible()) { + // draw tooltip + Tooltip::event_draw_global(); + + // draw the mouse pointer draw_pointer(); + } } /* -- global event handlers ---------------------------------------- */ -- cgit v1.2.3