on hover events

magiconexxx

17-04-2009 04:02:32

kungfoomaster:

I tried creating an event handler for a button that used the WIDGET_EVENT_ON_HOVER eventype, but this doesn't seem to work. I set my hover timer to 2 seconds:
QuickGUI::ButtonDesc* bd = QuickGUI::DescManager::getSingleton().getDefaultButtonDesc();
bd->resetToDefault();
bd->widget_name = name;
bd->widget_hoverTime = 2;
bd->widget_dimensions = QuickGUI::Rect(0,0,64,32);
QuickGUI::Button *pButton = mpPanel->createButton(bd);
pButton->setSkinType(name);
pButton->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_BUTTON_DOWN, &StructurePanel::StructureSelectedCallback, this);
pButton->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_ON_HOVER, &StructurePanel::StructureHoverCallback,this);
pButton->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_LEAVE, &StructurePanel::StructureHoverGoneCallback,this);


My HoverCallback function never got called, though.

I looked through some of the QuickGUI code, and it seems like the only function that actually fires this widget event is the void GUIManager::hoverTimerCallback() function, which never gets referenced anywhere else in the QuickGUI code. I looked at the GUI manager, and I see it creates a timer at the constructor, then starts a timer at every mouse movement event, and it looks like an ogre framelistener runs through all of the timers and updates them. I set a breakpoint to the Timer::update section, and mCallback->execute(); never seems to get called. A little more digging, and it looks like mCallback needs to instantiated by Timer::setCallback, but I don't actually see this get called anywhere, either. I'm guessing there is missing glue to hook Timer::setCallback to GUIManager::hoverTimerCallback?

Am I on the right track, or am I missing something in my code?

kungfoomasta

17-04-2009 19:35:10

Oops! :oops: It looks like the callback wasn't set, as you suggested. Thanks for looking into this, you are definately on the right track.

I implemented the hover functionality a ways back, but I never tested it out, and I don't think anybody ever got around to using it. I'm happy that somebody wants to make use of it. :)

I believe the fix is simply setting the hover timer's callback method, in the GUIManager's constructor:

mHoverTimer->setCallback(&GUIManager::hoverTimerCallback,this);

If I can ask, how are you using the hover callback? I was wondering how I should go about extending the hover functionality, to allow the pop up text that is popularly done. I'm also wondering if people would want more than text to pop up, for example graphics, or even widgets, like buttons, etc. Not sure how to organize this to allow such flexibility and ease of implementing, from a user's standpoint.

[edit] I've committed the fix to SVN [\edit]

magiconexxx

17-04-2009 20:03:30

If you look at my two eventhandlers:

pButton->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_ON_HOVER, &StructurePanel::StructureHoverCallback,this);
pButton->addWidgetEventHandler(QuickGUI::WIDGET_EVENT_MOUSE_LEAVE, &StructurePanel::StructureHoverGoneCallback,this);


In my Structure class init function, I pre-created a textarea and set it to invisible.

In the 'StructureHoverCallback' function, I set the hover textarea's text by referring to the button that was hovered over, grab that button's name, which maps back to the "structure" (building) that it associates to, and grab that structure's description.

The 'StructureHoverGoneCallback' just sets the textarea to invisible.

The method I have seems to work pretty well. I suppose you could shortcut this by having it automatically create a textarea, or a few other widgets by request. Since it appears I'm the only one using it right now, I wouldn't waste too much time on it.

I'll post some screenshots up soon (probably in another topic) of what I have so far.

kungfoomasta

17-04-2009 21:39:20

Awesome, I love screenshots. :)

I think the TextArea trick would be a good idea, but if you have a complex layout, it might get hidden behind other widgets. Although you could probably use a Window with a TextArea, that would do the trick. Now that I think about it, people would probably want to implement this themselves, just as you have, so they can customize the information/content that is displayed, as well as the way its displayed, etc.

magiconexxx

18-04-2009 03:42:56

thanks, that fixed it!

I agree, the hover could be used for multiple things besides just textareas, such as running scripts, animations, moving characters... who knows?