Difference between revisions of "Tooltips"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
m (Robot: Adding Category:Uncategorised)
Line 1: Line 1:
 +
{{VersionBadge|0.5}} {{VersionBadge|0.6}}
 +
 
I am not an expert but I would like to share what I have learned and gleaned about the ''Tooltip'' widget.
 
I am not an expert but I would like to share what I have learned and gleaned about the ''Tooltip'' widget.
  
Line 13: Line 15:
 
CEGUI will manage a single default, system wide ''Tooltip'' widget for you that will take care of displaying your tooltip text. You have to initialize it by calling '''CEGUI::System::setDefaultTooltip()'' one time, somehwere in your code. I would recommend calling this right after initializing the CEGUI system. Here's a sample call:
 
CEGUI will manage a single default, system wide ''Tooltip'' widget for you that will take care of displaying your tooltip text. You have to initialize it by calling '''CEGUI::System::setDefaultTooltip()'' one time, somehwere in your code. I would recommend calling this right after initializing the CEGUI system. Here's a sample call:
  
<pre>
+
<source lang="cpp">
 
   // Create default ToolTip item
 
   // Create default ToolTip item
 
   CEGUI::System::getSingleton().setDefaultTooltip( (CEGUI::utf8*)"TaharezLook/Tooltip" );
 
   CEGUI::System::getSingleton().setDefaultTooltip( (CEGUI::utf8*)"TaharezLook/Tooltip" );
</pre>
+
</source>
  
 
Yep, that's all there is too it.
 
Yep, that's all there is too it.
Line 28: Line 30:
  
 
You can hardcode toolip text in your code by using the ''WindowObject::setTooltipText()'' function like so:
 
You can hardcode toolip text in your code by using the ''WindowObject::setTooltipText()'' function like so:
<pre>
+
<source lang="cpp">
 
CEGUI::PushButton *mPushButton = (CEGUI::PushButton *)mWinMgr->createWindow(
 
CEGUI::PushButton *mPushButton = (CEGUI::PushButton *)mWinMgr->createWindow(
 
(CEGUI::utf8*)"TaharezLook/PushButton", (CEGUI::utf8*)"PushButton");
 
(CEGUI::utf8*)"TaharezLook/PushButton", (CEGUI::utf8*)"PushButton");
 
// Set other properties like size, position, etc.
 
// Set other properties like size, position, etc.
 
mPushButton->setTooltipText("This is a tooltip.");
 
mPushButton->setTooltipText("This is a tooltip.");
</pre>
+
</source>
  
 
'''Setting the ''Tooltip'' text in your layout (xml) file'''
 
'''Setting the ''Tooltip'' text in your layout (xml) file'''
  
 
The prefered method is to set the tooltip text in your layout file and you can do it like so:
 
The prefered method is to set the tooltip text in your layout file and you can do it like so:
<pre>
+
<source lang="xml">
 
<Window Type="TaharezLook/Editbox" Name="Login/EditBox/Password">
 
<Window Type="TaharezLook/Editbox" Name="Login/EditBox/Password">
 
<Property Name="AbsoluteRect" Value="l:128.000000 t:0.000000 r:486.000000 b:46.000000" />
 
<Property Name="AbsoluteRect" Value="l:128.000000 t:0.000000 r:486.000000 b:46.000000" />
Line 47: Line 49:
 
</Window>
 
</Window>
  
</pre>
+
</source>
  
 
'''Ensure that the Tooltip is registered in your .Scheme file'''
 
'''Ensure that the Tooltip is registered in your .Scheme file'''
<pre>
+
<source lang="xml">
 
<WindowSet Filename="CEGUITaharezLook">
 
<WindowSet Filename="CEGUITaharezLook">
 
....
 
....
Line 56: Line 58:
 
....
 
....
 
</WindowSet>
 
</WindowSet>
</pre>
+
</source>
 +
 
 
'''Ensure that imageset contains graphics for the Tooltip'''
 
'''Ensure that imageset contains graphics for the Tooltip'''
<pre>
+
<source lang="xml">
 
<Imageset Name="TaharezLook" Imagefile="TaharezLook.png" NativeHorzRes="800" NativeVertRes="600" AutoScaled="true">
 
<Imageset Name="TaharezLook" Imagefile="TaharezLook.png" NativeHorzRes="800" NativeVertRes="600" AutoScaled="true">
 
....
 
....
Line 72: Line 75:
 
...
 
...
 
</Imageset>
 
</Imageset>
</pre>
+
</source>
  
 
== How to display the ''Tooltip'' ==
 
== How to display the ''Tooltip'' ==
Line 84: Line 87:
 
'''Inject Time Pulse: via a MAIN Loop'''
 
'''Inject Time Pulse: via a MAIN Loop'''
  
<pre>
+
<source lang="cpp">
 
+
 
#include <time.h>
 
#include <time.h>
 
...
 
...
Line 104: Line 106:
 
} // while
 
} // while
 
...
 
...
 
+
</source>
</pre>
+
  
 
'''Inject Time Pulse: via an Ogre::FrameListenter'''
 
'''Inject Time Pulse: via an Ogre::FrameListenter'''
<pre>
+
<source lang="cpp">
  
 
bool clsMyFrameListener::frameStarted(const Ogre::FrameEvent& evt)
 
bool clsMyFrameListener::frameStarted(const Ogre::FrameEvent& evt)
Line 121: Line 122:
 
} //frameStarted
 
} //frameStarted
  
</pre>
+
</source>
  
  
Line 132: Line 133:
 
Some advanced notes. You can have more than one ''Tooltip'' widget. There maybe some scenerios where just one ''Tooltip'' widget won't work (like for a different look and feel from that of the default one, etc.). You can create another ''Tooltip'' widget using the standard CEGUI method for creating all the window widgets then use the ''CEGUI::Window::setToolTip()'' function to set the widget to use the desired ''Tooltip''.
 
Some advanced notes. You can have more than one ''Tooltip'' widget. There maybe some scenerios where just one ''Tooltip'' widget won't work (like for a different look and feel from that of the default one, etc.). You can create another ''Tooltip'' widget using the standard CEGUI method for creating all the window widgets then use the ''CEGUI::Window::setToolTip()'' function to set the widget to use the desired ''Tooltip''.
  
[[Category:Uncategorised]]
+
[[Category:Tutorials]]
 +
[[Category:Update requested]]

Revision as of 17:00, 3 March 2011

Written for CEGUI 0.5


Works with versions 0.5.x (obsolete)

Written for CEGUI 0.6


Works with versions 0.6.x (obsolete)

I am not an expert but I would like to share what I have learned and gleaned about the Tooltip widget.

API References: Tooltip System

As you would expect, the Tooltip works very similar to most tooltip systems. Basically the user hovers the mouse over a CEGUI widget and when a specified time has elapsed the tooltip is displayed for a specified amount of time. As with most of the CEGUI widgets the Tooltip widget is based upon the CEGUI Window class widget.

Please note that the following example source code was gleaned and edited from project specific code so there may be some syntax errors.

Creating the Default System Tootip widget

CEGUI will manage a single default, system wide Tooltip widget for you that will take care of displaying your tooltip text. You have to initialize it by calling 'CEGUI::System::setDefaultTooltip() one time, somehwere in your code. I would recommend calling this right after initializing the CEGUI system. Here's a sample call:

  // Create default ToolTip item
  CEGUI::System::getSingleton().setDefaultTooltip( (CEGUI::utf8*)"TaharezLook/Tooltip" );

Yep, that's all there is too it. In newer versions of CEGUI the method has been renamed to setDefaultTooltip for consistency.

Setting the Tootip text to display

There are two methods for setting your tooltip text: In your code or in your layout file.

Setting the Tooltip text in your code

You can hardcode toolip text in your code by using the WindowObject::setTooltipText() function like so:

CEGUI::PushButton *mPushButton = (CEGUI::PushButton *)mWinMgr->createWindow(
(CEGUI::utf8*)"TaharezLook/PushButton", (CEGUI::utf8*)"PushButton");
// Set other properties like size, position, etc.
mPushButton->setTooltipText("This is a tooltip.");

Setting the Tooltip text in your layout (xml) file

The prefered method is to set the tooltip text in your layout file and you can do it like so:

<Window Type="TaharezLook/Editbox" Name="Login/EditBox/Password">
	<Property Name="AbsoluteRect" Value="l:128.000000 t:0.000000 r:486.000000 b:46.000000" />
	<Property Name="AlwaysOnTop" Value="True" />
	<Property Name="RelativeRect" Value="l:0.250000 t:0.000000 r:0.950000 b:1.000000" />
	<Property Name="Text" Value="{Enter Password Here}" />
	<Property Name="Tooltip" Value="Enter your password here." />
</Window>

Ensure that the Tooltip is registered in your .Scheme file

<WindowSet Filename="CEGUITaharezLook">
....
<WindowFactory Name="TaharezLook/Tooltip" />
....
</WindowSet>

Ensure that imageset contains graphics for the Tooltip

<Imageset Name="TaharezLook" Imagefile="TaharezLook.png" NativeHorzRes="800" NativeVertRes="600" AutoScaled="true">
....
<Image Name="TooltipLeftEdge" XPos="217" YPos="225" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipRightEdge" XPos="246" YPos="225" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipTopEdge" XPos="224" YPos="218" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipBottomEdge" XPos="224" YPos="248" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipTopLeft" XPos="217" YPos="218" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipTopRight" XPos="246" YPos="218" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipBottomLeft" XPos="217" YPos="248" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipBottomRight" XPos="246" YPos="248" Width="7" Height="7" XOffset="0" YOffset="0"/>
<Image Name="TooltipMiddle" XPos="2" YPos="2" Width="64" Height="64" XOffset="0" YOffset="0"/>
...
</Imageset>

How to display the Tooltip

Inject Time Pulse

CEGUI::System::injectTimePulse(float timeElapsed)

This is a very important piece of information that is not well documented in the current CEGUI system: Time Pulse Injection. The CEGUI system, to my knowledge, does not keep track of time for you by itself - it needs help. You must inject into the CEGUI System elapsed time. If you don't do this, then your Tooltip and other time sensitive window events (like fades, etc) will not work or will not work properly. What is the value you inject? The value should be the amount of time that has elapsed since the previous injection call. Refer to the CEGUI::System::injectTimePulse(). The best place to inject a time pulse into the CEGUI system is in a main loop. Here are a couple of examples of how to implement this:

Inject Time Pulse: via a MAIN Loop

#include <time.h>
...
clock_t mLastTimeInjection=clock();
...
// Your main loop
while ( true )
{
  ...
  // Make sure the CEGUI System is initialized and running
  // and if it is, inject a time pulse
  if ( CEGUI::System::getSingletonPtr() )
  {
    CEGUI::System::getSingleton().injectTimePulse( ( clock() - mLastTimeInjection ) * 0.001f );
    mLastTimeInjection = clock();
  } // CEGUI Time pulse
  ...
} // while
...

Inject Time Pulse: via an Ogre::FrameListenter

bool clsMyFrameListener::frameStarted(const Ogre::FrameEvent& evt)
{ 
  ...
  // Make sure the CEGUI System is initialized and running
  // and if it is, inject a time pulse
  if ( CEGUI::System::getSingletonPtr() )
    CEGUI::System::getSingleton().injectTimePulse( evt.timeSinceLastFrame );
  ...
  return true;
} //frameStarted


The finer the resolution of the injection, the better your fades will look. Injecting time every one second or greater will make your fades just popup instead of fading in.

Conclusion

That's really all there is to it. My biggest gotcha was the not knowing about the CEGUI::System::injectTimePulse() and how important it was. Once I stumbled upon that everything else fell into place.

Some advanced notes. You can have more than one Tooltip widget. There maybe some scenerios where just one Tooltip widget won't work (like for a different look and feel from that of the default one, etc.). You can create another Tooltip widget using the standard CEGUI method for creating all the window widgets then use the CEGUI::Window::setToolTip() function to set the widget to use the desired Tooltip.