[SOLVED] mouse pointer icon

Is there a function to set a custom mouse pointer in Panda3d?

mpointer = loader.loadModel('pointer') #png texture
mpointer.reparentTo(render2d)
mpointer.setBin('fixed', 100)

def mousePointerTask(task):
	if base.mouseWatcherNode.hasMouse():
	    mousex=base.mouseWatcherNode.getMouseX()
	    mousey=base.mouseWatcherNode.getMouseY()
		
	    mpointer.setX(mousex)
	    mpointer.setZ(mousey)
		
	return task.cont

taskMgr.add(mousePointerTask, 'mousePointerTask')

Kinda slow and changes size with resolution.

mpointer.reparentTo(aspect2d) - will solve the aspect ratio but not the scale.

Me thinks pixalated solution in 3d are bad even on aspect 2d(me hate tiny icons with high resolutions).

But its not slow,it’s just one frame behind the original mouse cursor pos.(correct me if im wrong)

Try that and see what happens.

Just try it without hiding the actual mouse.

you should use the hardware mouse pointer - this piece of code show how to hide the default pointer and to set a nodepath in place of it

    props = WindowProperties()
    props.setCursorHidden(True)
    base.win.requestProperties(props)
    base.mouseWatcherNode.setGeometry(yournodepath.node())

Both of these approaches use Panda to render a piece of geometry onscreen, in the same place as the hardware mouse pointer.

This does constrain the “mouse” to be drawn only once per frame, which means it is indeed one frame behind the actual mouse position. If your frame rate is high, this is not a problem; but if your frame rate is low to medium, this can create a real sense of sluggishness.

You can also configure the actual hardware mouse pointer to use a particular shape. This avoids the sluggishness, because it actually uses the hardware mouse cursor. It’s kind of limited in Panda: it only works on Windows, and you can only set it at startup time. To do this, specify the following in your Config.prc (or before you import DirectStart):

cursor-filename mycursor.ico

where mycursor.ico is a file in Windows ico format that you provide. There are a number of shareware and freeware tools that will help you paint a mouse cursor ico file.

David

That seems to do exactly what my code does. It doesn’t scale the mouse pointer when you scale the resolution, and if you parent it to aspect2d, the pointer position gets messed up when getting close to the borders of the window

@drwr: Yes that is good and GIMP can export to .ico format, but only Windows is a bit of problem here

If this is your only objection to this approach, then you can handle this yourself: listen for “window-event”, which is sent whenever the window changes properties (including its size), and when you receive this event, set the scale on your mouse pointer to the appropriate value based on the new size of the window.

And don’t parent the mouse pointer to aspect2d. :slight_smile:

David

OK, but shouldn’t that panda method do the same?
I don’t think changing size for a mouse pointer when changing the resolution is a good idea?

It could do this, but it doesn’t. So you have to do it. Fortunately that’s not hard.

David

Of course, I just wondered if thats the ‘standard’ way of doing it in games then?