Tooltips
by Jacob · in Torque Game Engine Advanced · 08/01/2007 (11:12 am) · 14 replies
It seems to me that they are not working in TGEA 1.01. The code is there but if the tooltip text is provided for a gui element, nothing happens.
While debugging, I found that GuiControl::renderTooltip in guiControl.cpp is never called so I put a call to it in GuiControl::onMouseEnter to make it look like this:
This still didn't call renderTooltip so I tried putting the call in GuiControl::onRightMouseUp like so:
Now renderTooltip gets called on right mouse up but all I see is a flash on the screen but no tooltip.
The code runs throught the entire length of renderTooltip and looks as if it should be working but...
Any ideas?
While debugging, I found that GuiControl::renderTooltip in guiControl.cpp is never called so I put a call to it in GuiControl::onMouseEnter to make it look like this:
void GuiControl::onMouseEnter(const GuiEvent &event)
{
renderTooltip(event.mousePoint);
}This still didn't call renderTooltip so I tried putting the call in GuiControl::onRightMouseUp like so:
void GuiControl::onRightMouseUp(const GuiEvent &event)
{
renderTooltip(event.mousePoint);
}Now renderTooltip gets called on right mouse up but all I see is a flash on the screen but no tooltip.
The code runs throught the entire length of renderTooltip and looks as if it should be working but...
Any ideas?
About the author
#2
I would still like to find out if anyone knows if tooltips are supposed to work out of the box in TGEA. Otherwise, what needs to be done to make them work, since some code reffering to them is in the engine code already.
08/04/2007 (9:54 am)
A workaround was created since there were no replies here....I would still like to find out if anyone knows if tooltips are supposed to work out of the box in TGEA. Otherwise, what needs to be done to make them work, since some code reffering to them is in the engine code already.
#3
08/05/2007 (2:18 pm)
Tooltips are probably something that not a lot of people need in their projects. It is useful for RPGs or certain other types of games, but that is probably why no response. A lot of people probably hadn't even noticed that they were not working.
#4
08/05/2007 (2:27 pm)
I think you're right J.C. I just thought that a GG employee might chime in and explain if they should be working out of the box since some code is in the engine...so if it's not too much too ask of GG, I would still like to know - Thank You!
#5
08/05/2007 (10:04 pm)
@Jacob: I think your problem is that you put the rendering code inside a method which is called only when the event occurs. So your code is called only when the event is fired. You should a memory of this event (for example a boolean) which keep track that the mouse is inside the control.
#6
08/06/2007 (7:25 am)
Thanks Frank, that makes sense and explains the quick flash on the screen :) I will try to figure out how to make it stay on the screen as long as the mouse is inside the control - if I need help I will post here again.
#7
08/06/2007 (6:31 pm)
I made quick changes in the control to do it. I will post it soon if you like as I want also to add the 'temporary' display of the tooltip, not always active when the mouse is inside the control.
#8
First, add the following member inside GuiControl.h just after mCanSave:
Then edit the method GuiControl::onMouseEnter, onMouseLeave and onMouseMove
Then add the following lines just before renderChild inside GuiControl::onRender
and add the following lines also inside GuiControl::renderTooltip just before the awake test
Now, the tooltip will work for all control who do not forget to execute GuiControl::xxx methods..... and this is not the case for the button control for example.
So, you need to add the following code inside guiButtonBaseCtrl.cpp:
and
and the last one inside GuiButtonCtrl::onRender, add just before the renderChild:
Then, it should work if you set the correct information inside your object in the script and you should have something like that:

Enjoy it.
08/07/2007 (7:49 am)
Ok here is my contribution for your tooltip.First, add the following member inside GuiControl.h just after mCanSave:
U32 mTooltipTimer; Point2I mMousePos;
Then edit the method GuiControl::onMouseEnter, onMouseLeave and onMouseMove
void GuiControl::onMouseEnter(const GuiEvent &)
{
mTooltipTimer = Sim::getCurrentTime();
}
void GuiControl::onMouseLeave(const GuiEvent &)
{
mTooltipTimer = 0;
}
void GuiControl::onMouseMove(const GuiEvent &event)
{
mMousePos = event.mousePoint;
[...rest of code is same...]Then add the following lines just before renderChild inside GuiControl::onRender
// Render tooltip
if(mTooltipTimer) renderTooltip(mMousePos);and add the following lines also inside GuiControl::renderTooltip just before the awake test
if(mTooltipTimer && (mTooltipTimer+mTipHoverTime) < Sim::getCurrentTime()) {
mTooltipTimer = 0;
return false;
}Now, the tooltip will work for all control who do not forget to execute GuiControl::xxx methods..... and this is not the case for the button control for example.
So, you need to add the following code inside guiButtonBaseCtrl.cpp:
void GuiButtonBaseCtrl::onMouseLeave(const GuiEvent &event)
{
GuiControl::onMouseLeave(event);
[...rest of code is same...]and
void GuiButtonBaseCtrl::onMouseEnter(const GuiEvent &event)
{
GuiControl::onMouseEnter(event);
[...rest of code is same...]and the last one inside GuiButtonCtrl::onRender, add just before the renderChild:
if(mTooltipTimer) GuiControl::renderTooltip(mMousePos);
Then, it should work if you set the correct information inside your object in the script and you should have something like that:

Enjoy it.
#9
This seems really simple - I suggest that it be included in the next update by GG.
08/07/2007 (8:12 am)
Hey, you didn't even give me a chance to try and figure it out myself - just kidding :) Thank You, I shall try it out soon!This seems really simple - I suggest that it be included in the next update by GG.
#10
I found that any gui control type that wants to be able to display tooltips needs to have
added to the end of it's onRender method (or just before renderChildControls).
Also, I added a tooltip offset field so that each case can have a custom offset if needed (I found that keeping the same rendering location of the tooltip for all of my controls did not look the best)
Very simple addition:
In guiControl.h add just after S32 mTipHoverTime:
In GuiControl::GuiControl() add somewhere:
In GuiControl::initPersistFields() add into the "ToolTip" group:
And finally in GuiControl::renderTooltip change this line:
to look like this:
Now you can change the offset for your tooltip on a case by case basis if needed.
08/08/2007 (9:46 am)
Works good, Thanks again for your time Frank.I found that any gui control type that wants to be able to display tooltips needs to have
if(mTooltipTimer) GuiControl::renderTooltip(mMousePos);
added to the end of it's onRender method (or just before renderChildControls).
Also, I added a tooltip offset field so that each case can have a custom offset if needed (I found that keeping the same rendering location of the tooltip for all of my controls did not look the best)
Very simple addition:
In guiControl.h add just after S32 mTipHoverTime:
Point2I mTooltipOffset;
In GuiControl::GuiControl() add somewhere:
mTooltipOffset.set(0, 0); // set this to whatever is most commonly best in your case
In GuiControl::initPersistFields() add into the "ToolTip" group:
addField("offset", TypePoint2I, Offset(mTooltipOffset, GuiControl));And finally in GuiControl::renderTooltip change this line:
Point2I offset = cursorPos;
to look like this:
Point2I offset = cursorPos + mTooltipOffset;
Now you can change the offset for your tooltip on a case by case basis if needed.
#11
08/08/2007 (10:19 pm)
@Jacob: maybe will be a good idea to make a ressource, so it can be shared among many GG fellows. I personnaly will not have time to do so, so if you have time I will be glad if you can do it.
#12
08/09/2007 (4:58 am)
I was thinking about that as well. I can wrap it up in a resource and maybe put it on TDN. I'll give you credit for the core of it :)
#14
08/10/2007 (7:01 am)
Nicely done Jacob. And thanks for the credit.
Torque 3D Owner Jacob