further tweaks to canvas tooltip mechanism

This commit is contained in:
Paul Davis 2014-09-26 12:24:47 -04:00
parent bb68d83e43
commit df5a188825
2 changed files with 35 additions and 9 deletions

View file

@ -39,6 +39,8 @@
using namespace std; using namespace std;
using namespace ArdourCanvas; using namespace ArdourCanvas;
uint32_t Canvas::tooltip_timeout_msecs = 750;
/** Construct a new Canvas */ /** Construct a new Canvas */
Canvas::Canvas () Canvas::Canvas ()
: _root (this) : _root (this)
@ -332,6 +334,12 @@ Canvas::queue_draw_item_area (Item* item, Rect area)
request_redraw (item->item_to_window (area)); request_redraw (item->item_to_window (area));
} }
void
Canvas::set_tooltip_timeout (uint32_t msecs)
{
tooltip_timeout_msecs = msecs;
}
void void
GtkCanvas::re_enter () GtkCanvas::re_enter ()
{ {
@ -607,12 +615,11 @@ GtkCanvas::deliver_enter_leave (Duple const & point, int state)
if (_new_current_item && !_new_current_item->ignore_events()) { if (_new_current_item && !_new_current_item->ignore_events()) {
enter_event.detail = enter_detail; enter_event.detail = enter_detail;
DEBUG_TRACE (PBD::DEBUG::CanvasEnterLeave, string_compose ("ENTER %1/%2\n", _new_current_item->whatami(), _new_current_item->name)); DEBUG_TRACE (PBD::DEBUG::CanvasEnterLeave, string_compose ("ENTER %1/%2\n", _new_current_item->whatami(), _new_current_item->name));
start_tooltip_timeout (_new_current_item);
_new_current_item->Event ((GdkEvent*)&enter_event); _new_current_item->Event ((GdkEvent*)&enter_event);
} }
start_tooltip_timeout (_new_current_item);
_current_item = _new_current_item; _current_item = _new_current_item;
} }
@ -1012,7 +1019,7 @@ GtkCanvas::really_start_tooltip_timeout ()
*/ */
if (current_tooltip_item) { if (current_tooltip_item) {
_current_timeout_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &GtkCanvas::show_tooltip), 1000); tooltip_timeout_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &GtkCanvas::show_tooltip), tooltip_timeout_msecs);
} }
return false; /* this is called from an idle callback, don't call it again */ return false; /* this is called from an idle callback, don't call it again */
@ -1022,7 +1029,7 @@ void
GtkCanvas::stop_tooltip_timeout () GtkCanvas::stop_tooltip_timeout ()
{ {
current_tooltip_item = 0; current_tooltip_item = 0;
_current_timeout_connection.disconnect (); tooltip_timeout_connection.disconnect ();
} }
bool bool
@ -1054,18 +1061,29 @@ GtkCanvas::show_tooltip ()
(void) toplevel->get_window()->get_pointer (pointer_x, pointer_y, mask); (void) toplevel->get_window()->get_pointer (pointer_x, pointer_y, mask);
Duple tooltip_item_center (pointer_x, pointer_y); Duple tooltip_window_origin (pointer_x, pointer_y);
/* convert to root window coordinates */ /* convert to root window coordinates */
int win_x, win_y; int win_x, win_y;
dynamic_cast<Gtk::Window*>(toplevel)->get_position (win_x, win_y); dynamic_cast<Gtk::Window*>(toplevel)->get_position (win_x, win_y);
tooltip_item_center = tooltip_item_center.translate (Duple (win_x, win_y)); tooltip_window_origin = tooltip_window_origin.translate (Duple (win_x, win_y));
/* we don't want the pointer to be inside the window when it is
* displayed, because then we generate a leave/enter event pair when
* the window is displayed then hidden - the enter event will
* trigger a new tooltip timeout.
*
* So move the window right of the pointer position by just a enough
* to get it away from the pointer.
*/
tooltip_window_origin.x += 20;
/* move the tooltip window into position */ /* move the tooltip window into position */
tooltip_window->move (tooltip_item_center.x, tooltip_item_center.y); tooltip_window->move (tooltip_window_origin.x, tooltip_window_origin.y);
/* ready to show */ /* ready to show */
@ -1079,6 +1097,8 @@ GtkCanvas::show_tooltip ()
void void
GtkCanvas::hide_tooltip () GtkCanvas::hide_tooltip ()
{ {
/* hide it if its there */
if (tooltip_window) { if (tooltip_window) {
tooltip_window->hide (); tooltip_window->hide ();
} }

View file

@ -149,12 +149,18 @@ public:
virtual void start_tooltip_timeout (Item*) {} virtual void start_tooltip_timeout (Item*) {}
virtual void stop_tooltip_timeout () {} virtual void stop_tooltip_timeout () {}
/** Set the timeout used to display tooltips, in milliseconds
*/
static void set_tooltip_timeout (uint32_t msecs);
protected: protected:
void queue_draw_item_area (Item *, Rect); void queue_draw_item_area (Item *, Rect);
/** our root item */ /** our root item */
Root _root; Root _root;
static uint32_t tooltip_timeout_msecs;
virtual void pick_current_item (int state) = 0; virtual void pick_current_item (int state) = 0;
virtual void pick_current_item (Duple const &, int state) = 0; virtual void pick_current_item (Duple const &, int state) = 0;
@ -217,7 +223,7 @@ private:
/** the item that currently has key focus or 0 */ /** the item that currently has key focus or 0 */
Item * _focused_item; Item * _focused_item;
sigc::connection _current_timeout_connection; sigc::connection tooltip_timeout_connection;
Item* current_tooltip_item; Item* current_tooltip_item;
Gtk::Window* tooltip_window; Gtk::Window* tooltip_window;
Gtk::Label* tooltip_label; Gtk::Label* tooltip_label;