From c1ce0ecd3458e1939b4e6c9947684378078a724f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 18 Jul 2020 17:39:47 +0200 Subject: Always draw tooltips on top of the widget stack. --- src/ui/label.h | 2 +- src/ui/tooltip.cc | 20 ++++++++++++++++++++ src/ui/tooltip.h | 22 ++++++++++++++++++---- src/ui/ui.cc | 3 +++ src/ui/widget.h | 2 +- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/ui/label.h b/src/ui/label.h index a895691..f187744 100644 --- a/src/ui/label.h +++ b/src/ui/label.h @@ -19,7 +19,7 @@ class Label : public Widget { public: Label(Widget *parent, const char *text = 0); - ~Label(); + virtual ~Label(); /// set the text displayed by the label void set_text(const std::string &text); diff --git a/src/ui/tooltip.cc b/src/ui/tooltip.cc index b1e8c3c..6a692ff 100644 --- a/src/ui/tooltip.cc +++ b/src/ui/tooltip.cc @@ -67,5 +67,25 @@ void Tooltip::hide() Label::hide(); } +void Tooltip::event_draw() +{ +} + +void Tooltip::event_draw_global() +{ + if (tooltip_global && tooltip_global->visible()) + { + if (tooltip_global->background()) + tooltip_global->draw_background(); + + if (tooltip_global->border()) + tooltip_global->draw_border(); + + tooltip_global->draw(); + + if (debug()) + tooltip_global->draw_debug(); + } +} } diff --git a/src/ui/tooltip.h b/src/ui/tooltip.h index 0cfa12d..629863a 100644 --- a/src/ui/tooltip.h +++ b/src/ui/tooltip.h @@ -23,23 +23,37 @@ class Tooltip : public Label /** * @brief resize the tooltip - */ + * */ virtual void resize(); /** * @brief show the tooltip - */ + * */ virtual void show(); /** * @brief hide the tooltip - */ + * */ virtual void hide(); + /** + * @brief draw event distributor + * The default draw event distributor is overwritten to do nothing. + * Tooltips are drawn separately because the need to be on top of everything else. + * @see event_draw_global + * */ + virtual void event_draw(); + + /** + * @brief global draw event distributor + * This is called by the user interface to draw the tooltip after everything else. + * */ + static void event_draw_global(); + /** * @brief the tooltip that is currently visible, nullptr if no tooltip is currently shown * - **/ + * */ static inline Tooltip *global() { return tooltip_global; diff --git a/src/ui/ui.cc b/src/ui/ui.cc index fc52bbf..7fb25dd 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -298,6 +298,9 @@ void UI::frame() // draw the widget stack event_draw(); + + // draw tooltip + Tooltip::event_draw_global(); // draw the mouse pointer if (visible()) diff --git a/src/ui/widget.h b/src/ui/widget.h index e1f199d..c3d952c 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -275,7 +275,7 @@ public: * @brief calls the draw event handler and sends the event to all child widgets * @see draw **/ - void event_draw(); + virtual void event_draw(); /** * @brief calls the key event handlers and sends unhandled keys to the parent widget -- cgit v1.2.3