Jump to content
  • Advertisement
Sign in to follow this  
fcoutel

How to make a tooltip?

This topic is 5099 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, In my OGL scene I have some objects and I know their name. What I would like to do is some kind of Tooltip i.e draw a rectangle with the object's name when I hover on it with the mouse. Would someone have some example source code for doing this? Many thanks!

Share this post


Link to post
Share on other sites
Advertisement
No source code, but how about this (pseudocode):



DrawToolTip(text, xpos, ypos)
{
boxwidth, boxheight = CalculateTextWidth&Height(text)

if xpos + boxwidth > screen resolution
MoveBoxToFitOnScreen() // (or maybe just xpos = screenres - boxwidth)

// same for boxheight

DrawRectangle(boxwidth, boxheight, xpos, ypos)

DrawText(xpos, ypos)

}




Or something similar. That example won't look very impressive but it's a start in the right direction.

Whenever you know that the mouse is over an object (via some other part of your code), just call DrawToolTip(objectname, mousex, mousey) or something.

Share this post


Link to post
Share on other sites
You might also want to look at lesson 32 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=32) if you want to know how to tell what object the cursor is over. If you only do a selection check every second or so then the performance hit will be pretty much nothing.

If your only putting tooltips on 2d stuff though, your better of doing your own checking as it will be a lot faster, especially if there are a lot of objects.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!