Custom tooltips in games

It’s pretty nifty that JComponents all have a tooltip. However, what about creating tooltips with your own look and feel that don’t have the java background and the same restrictions? How about a completely custom tooltip class that we draw all pretty with openGL?

The problem I can’t seem to get my head around is if there’s a non-brute force method for determining if it’s time to display a particular tooltip over something we have our mouse over. I know that swing probably does it internally for JComponents with mouseEntered, would be required to implement some sort of thing on our entities? I mean at some level deep in java, there must be some kind of calculation that straight up checks whether your mouse is inside the component or not, we just think of it as magic because swing has so much abstraction.

Having the entities (Items on the ground, for example) checking to see if the mouse is over them every update just seems bad. The alternative seems to be implementing some kind of interface and using event firing somehow. I just don’t feel like I want to redesign an entire feature of JComponent. Has anyone implemented something similar?

I use a JWindow for my custom transparent tooltips, as for checking when to draw, every time the mouse is moved I check if it has entered a component then set a variable (an integer) to the component’s id.

I can reference that ‘id’ to see what component my mouse is currently over.

If that helps at all.

Or maybe start a timer that counts the number of milliseconds you want from mouseEntered to the time a tool tip pops up:

This is just pseudocode:


Timer popupTimer;

public void mouseEntered(MouseEvent me) {
    popupTimer = new Timer(timeForPopup,new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            //show popup
            popupTimer.stop();
        }
    }
    popupTimer.start();
}

public void mouseExited(MouseEvent me) {
    popupTimer.stop();
}

You will have to check the mouse on every update, but I wouldn’t do it in the entity.

Let the Entity have a getTooltip() method providing the text, or a texture/texcoords object if you use prerendered tooltips, and write something like a tooltip renderer that iterates over the entities (best would be if the list is already culled). Implement the mouse checking there. Easiest would be, if your Entities allready have a getBounds() method and you have a utility to convert the Bounds to window space rectangles.

The TooltipRenderer shoud have tooltipDelay, currentEntity and enteredTime members. Use the gameTime from your game loop for the latter, don’t use a separate Timer (imho). On every update you have to check, if the currentEntity is still under the mouse - if not update currentEntity and enteredTime. When the tooltipDelay has passed since enteredTime, show the Tooltip at the current mouse position (+cursor size).

You could just use TWL for your UI - it has full support for tooltips - even including XHTML + CSS rendering including tables and floating elements.

Unfortunately we are using JOGL and not LWJGL.

Take a look, if http://www.fenggui.org/doku.php suits your needs.

Pretty sweet, I’d have to play with it to see what kind of results I could get

You can easily write a JOGL backend - it’s all interface based. I even have a minimalistic Java2D backend :stuck_out_tongue:

Yeah, it looks good for building our level editor aswell.

Would it be difficult to write a JOGL backend for TWL?

Edit.: I see there is a libgdx backend, fine :slight_smile: Maybe this backend might be used with JOGL 2.

I was considering using TWL for the window system in my game but after I noticed that the jar was like 800kb I reconsidered :(, the whole game is currently 500kb and seeing as it’s an applet it can’t take forever to download on slow connections…

Mike

Sucks :frowning:

Thankfully we are writing a desktop app that will be big enough where it won’t really matter.

Ever heard of pack200 & lzma ? Even with only gzip the file size is below 200KB - with lzma it should be below 150KB 172KB. And LWJGL’s AppletLoader directly support pack200 + lzma or gzip.

Edit: fixed size (based on real value of nightly build server) - not sure if I stripped debug symbols or not.

To my experience it took longer to unpack the files than the extra overhead in downloading more kb’s :stuck_out_tongue: If it shrinks to 150kb I’ll definately look at it though as that’s even more than the lwjgl files.