]> git.tdb.fi Git - libs/gltk.git/commitdiff
Allow custom tooltips at empty areas of a Root
authorMikko Rasa <tdb@tdb.fi>
Fri, 26 Feb 2010 10:50:57 +0000 (10:50 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Feb 2010 10:50:57 +0000 (10:50 +0000)
Fix some bugs

source/container.cpp
source/root.cpp
source/root.h

index a755644bab6283bf3b6f7eb575befba32a3003d6..a46492d4ea3a1b7bb5e464952d7db846db4633c8 100644 (file)
@@ -67,7 +67,9 @@ Widget *Container::get_descendant_at(int x, int y)
        if(Container *cont=dynamic_cast<Container *>(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;
 }
index 0cd7e0f35d20ddb40a713e3d87beee7253bf0433..9fc48e00aac234aecca5f3e6e1ac1e5b0b7c09db 100644 (file)
@@ -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<int>(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<int>(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;
                }
        }
index 7cbd82744bb0d0426e6ff07108dfdbaded67896d..50445fecea3fd8a0bcc206de73561a1c229e05ef 100644 (file)
@@ -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<std::string, int, int> signal_tooltip;
+
 private:
        Graphics::Window &window;
        Label *lbl_tooltip;