From 7673c1a10a5483f1983d8eba723a6c47e0585af7 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Sat, 14 Apr 2018 19:41:33 +0100 Subject: [PATCH] [Fix] Fixed issue with tooltips not disappearing. --- src/gui_container.cpp | 11 +++++++++++ src/gui_container.h | 2 ++ src/gui_fixed.cpp | 2 +- src/gui_widget.cpp | 2 ++ src/gui_widget.h | 3 +++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gui_container.cpp b/src/gui_container.cpp index 939c4a8..ad25ac1 100644 --- a/src/gui_container.cpp +++ b/src/gui_container.cpp @@ -3,6 +3,17 @@ namespace Gui { +Container::Container(void) { + onMouseLeave.connect(sigc::mem_fun(this, &Container::_OnMouseLeave)); +} + +void Container::_OnMouseLeave(void) { + for(std::list::iterator i = m_children.begin(); i != m_children.end(); ++i) { + if((*i).w->IsMouseOver() == true) + (*i).w->OnMouseLeave(); + } +} + bool Container::OnMouseMotion(MouseMotionEvent* e) { float x = e->x; float y = e->y; diff --git a/src/gui_container.h b/src/gui_container.h index 0bcacdc..f347a8d 100644 --- a/src/gui_container.h +++ b/src/gui_container.h @@ -7,6 +7,7 @@ namespace Gui { class Container : public Widget { public: + Container(void); bool OnMouseDown(MouseButtonEvent* e); bool OnMouseUp(MouseButtonEvent* e); bool OnMouseMotion(MouseMotionEvent* e); @@ -15,6 +16,7 @@ namespace Gui { virtual void ShowAll(void); virtual void HideAll(void); private: + void _OnMouseLeave(void); bool HandleMouseEvent(MouseButtonEvent* e); protected: void PrependChild(Widget* w, float x, float y); diff --git a/src/gui_fixed.cpp b/src/gui_fixed.cpp index f868329..f939e90 100644 --- a/src/gui_fixed.cpp +++ b/src/gui_fixed.cpp @@ -3,7 +3,7 @@ namespace Gui { -Fixed::Fixed(float w, float h) { +Fixed::Fixed(float w, float h): Container() { SetSize(w, h); memcpy(m_bgcol, Color::bg, 3*sizeof(float)); m_w = w; m_h = h; diff --git a/src/gui_widget.cpp b/src/gui_widget.cpp index 3022e88..67bf0aa 100644 --- a/src/gui_widget.cpp +++ b/src/gui_widget.cpp @@ -37,6 +37,7 @@ void Widget::GetAbsolutePosition(float pos[2]) { void Widget::OnMouseEnter(void) { m_mouseOver = true; Gui::AddTimer(1000, &m_tooltipTimerSignal); + onMouseEnter.emit(); } void Widget::OnMouseLeave(void) { @@ -46,6 +47,7 @@ void Widget::OnMouseLeave(void) { m_tooltipWidget = 0; } Gui::RemoveTimer(&m_tooltipTimerSignal); + onMouseLeave.emit(); } void Widget::UpdateOverriddenTooltip(void) { diff --git a/src/gui_widget.h b/src/gui_widget.h index c04187f..28e8f8a 100644 --- a/src/gui_widget.h +++ b/src/gui_widget.h @@ -44,6 +44,9 @@ namespace Gui { EVENT_ALL = 0xffffffff }; unsigned int GetEventMask(void) { return m_eventMask; } + + sigc::signal onMouseEnter; + sigc::signal onMouseLeave; protected: unsigned int m_eventMask; struct {