glob2-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [glob2-devel] Tooltip System


From: Sébastien
Subject: Re: [glob2-devel] Tooltip System
Date: Fri, 21 Apr 2006 13:05:23 +0200
User-agent: KMail/1.9.1

Le Vendredi 21 Avril 2006 09:48, Stéphane Magnenat a écrit :
> On Friday 21 April 2006 08:51, Sébastien wrote:
> > After talking with Bradley, I added the tooltip functionnality to the
> > Widget class. As far as I know, it's working (I juste have to add
> > appropriate constructors to all subclasses, it's done for Button,
> > Highlightable & Rectangular for now)... In order to be sure that the
> > tooltip is always drawn on the top of other elements, I had to use a
> > template method (Screen now call draw on the Widgets, draw is declared in
> > Widget : it call paint and then displays the tooltip if necessary. I used
> > a similar way for ontimer and onSDLEvent (since Widget now has to handle
> > mouse mouvment and an inactivity timer).
> > Should I send a patch to this mailing list ?
>
> Yes. I do not understand why you need a template. Why not adding a
> paintOverlay to the Widget class which is called after all paint have been
> called ?
>
> Steph
>
>
> _______________________________________________
> glob2-devel mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/glob2-devel
I said a template method, not a template, this is the name of a design 
pattern ;)
For know here is an extract of what I did (I'll send a patch once we're are ok 
on the way to use and once i've added all constructors)...
In widget : 
---
void Widget::draw()
        {
                paint();
                // We have a tooltip and the mouse is idle on our widget for 
some ticks (1 
SDL tick = 1ms)
                if(tooltip.length() && (currentTick - lastIdleTick) > 1000 && 
isOnWidget(mx, 
my))
                {
                        DrawableSurface *gfx = parent->getSurface();
                        assert(gfx);
                        
                        int width = 
tooltipFontPtr->getStringWidth(tooltip.c_str());
                        int height = 
tooltipFontPtr->getStringHeight(tooltip.c_str());
                        gfx->drawFilledRect(mx - width - 9, my - height - 9, 
width + 1, height + 2, 
22, 0, 0, 128);
                        gfx->drawRect(mx - width - 10, my - height - 10, width 
+ 2, height + 3, 
255, 255, 255);
                        gfx->drawString(mx - width - 9, my - height - 10, 
tooltipFontPtr, tooltip);

                }
        }
---
and in screen :
---
void Screen::dispatchPaint(void)
        {
                assert(gfx);
                gfx->setClipRect();
                paint();
                for (std::set<Widget *>::iterator it=widgets.begin(); 
it!=widgets.end(); 
++it)
                {
                        if ((*it)->visible)
                                (*it)->draw();
                }
                gfx->nextFrame();
                
                if (animationFrame < SCREEN_ANIMATION_FRAME_COUNT)
                        animationFrame++;
        }
---
I don't know if adding a paintOverlay is a good thing, since if it's a virtual 
method, any subclass can overload it and kill the tooltip system... Here 
Widget::draw is non virtual so we're sure that tooltip is always drawn if 
necessary...
Objectively, I don't know if there's one way better than the other, it depends 
on if we want to ensure that tooltip is always avalaible or not





reply via email to

[Prev in Thread] Current Thread [Next in Thread]