From: Mikko Rasa Date: Fri, 26 Feb 2010 10:50:57 +0000 (+0000) Subject: Allow custom tooltips at empty areas of a Root X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3f301f9b6f73e886bdbb61565edb2c02667039d0;p=libs%2Fgltk.git Allow custom tooltips at empty areas of a Root Fix some bugs --- diff --git a/source/container.cpp b/source/container.cpp index a755644..a46492d 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -67,7 +67,9 @@ Widget *Container::get_descendant_at(int x, int y) if(Container *cont=dynamic_cast(wdg)) { const Geometry &cgeom=wdg->get_geometry(); - return cont->get_descendant_at(x-cgeom.x, y-cgeom.y); + Widget *wdg2=cont->get_descendant_at(x-cgeom.x, y-cgeom.y); + if(wdg2) + return wdg2; } return wdg; } diff --git a/source/root.cpp b/source/root.cpp index 0cd7e0f..9fc48e0 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -37,37 +37,45 @@ void Root::tick() { if(tooltip_timeout && Time::now()>tooltip_timeout) { + std::string tip; if(Widget *wdg=get_descendant_at(pointer_x, pointer_y)) { - const std::string &tip=wdg->get_tooltip(); - if(!tip.empty()) + tip=wdg->get_tooltip(); + tooltip_target=wdg; + } + else + { + tip=signal_tooltip.emit(pointer_x, pointer_y); + tooltip_target=this; + } + + if(!tip.empty()) + { + if(!lbl_tooltip) { - if(!lbl_tooltip) - { - lbl_tooltip=new Label(res); - add(*lbl_tooltip); - lbl_tooltip->set_style("tooltip"); - } - - lbl_tooltip->set_text(tip); - lbl_tooltip->autosize(); - const Geometry &tip_geom=lbl_tooltip->get_geometry(); - unsigned x=pointer_x+10; - unsigned y=pointer_y-10-lbl_tooltip->get_geometry().h; - if(x+tip_geom.w>geom.w) - { - if(pointer_x>static_cast(tip_geom.w+2)) - x=pointer_x-2-tip_geom.w; - else - x=geom.w-tip_geom.w; - } - lbl_tooltip->set_position(x, y); - raise(*lbl_tooltip); - lbl_tooltip->set_visible(true); - tooltip_timeout=Time::TimeStamp(); - tooltip_target=wdg; + lbl_tooltip=new Label(res); + add(*lbl_tooltip); + lbl_tooltip->set_style("tooltip"); } + + lbl_tooltip->set_text(tip); + lbl_tooltip->autosize(); + const Geometry &tip_geom=lbl_tooltip->get_geometry(); + unsigned x=pointer_x+10; + unsigned y=pointer_y-10-lbl_tooltip->get_geometry().h; + if(x+tip_geom.w>geom.w) + { + if(pointer_x>static_cast(tip_geom.w+2)) + x=pointer_x-2-tip_geom.w; + else + x=geom.w-tip_geom.w; + } + lbl_tooltip->set_position(x, y); + raise(*lbl_tooltip); + lbl_tooltip->set_visible(true); } + + tooltip_timeout=Time::TimeStamp(); } } @@ -98,18 +106,14 @@ void Root::pointer_motion_event(int x, int y) if(!tooltip_target) { - if(pointer_focus) - { - pointer_x=x; - pointer_y=y; - tooltip_timeout=Time::now()+700*Time::msec; - } - else - tooltip_timeout=Time::TimeStamp(); + pointer_x=x; + pointer_y=y; + tooltip_timeout=Time::now()+700*Time::msec; } else if(get_descendant_at(x, y)!=tooltip_target) { - lbl_tooltip->set_visible(false); + if(lbl_tooltip) + lbl_tooltip->set_visible(false); tooltip_target=0; } } diff --git a/source/root.h b/source/root.h index 7cbd827..50445fe 100644 --- a/source/root.h +++ b/source/root.h @@ -26,6 +26,9 @@ rendered to fill the window in order to get coordinates mapped correctly. */ class Root: public Panel, public sigc::trackable { +public: + sigc::signal signal_tooltip; + private: Graphics::Window &window; Label *lbl_tooltip;