How to make a tooltip?
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!
No source code, but how about this (pseudocode):
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.
DrawToolTip(text, xpos, ypos){boxwidth, boxheight = CalculateTextWidth&Height(text)if xpos + boxwidth > screen resolutionMoveBoxToFitOnScreen() // (or maybe just xpos = screenres - boxwidth)// same for boxheightDrawRectangle(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.
"I must not fear. Fear is the mindkiller. Fear is the little death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past me I will turn to see fear's path. Where the fear has gone there will be nothing. Only I will remain." ~Frank Herbert, DuneMy slice of the web
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement