Simple Mouse Cursor

A simple question:

When I position a DirectLabel based on the mouse position I need todo this:

if base.mouseWatcherNode.hasMouse():
    x=base.mouseWatcherNode.getMouseX()
    y=base.mouseWatcherNode.getMouseY()
    self.cursor.setPos(1.33*x, 0, y)

What is the easiest way to get the aspect ratio for the window? Are there a couple of nice funcitons that give me the current window height and width?

If you look in direct/showbase/ShowBase.py you will find a function called getAspectRatio() I forget what you need to pass in :frowning:

Also, there is a function called enableSoftwareMouse or something which shows you how to setup a software mouse pointer.

Sorry I cant be more specific at the moment, but hopefully this will put you on the right tracks.

That was me. Forgot I was not logged in.

Right, Im home I can construct a real reply now :slight_smile:

To get the aspect ratio for the main window use…


base.getAspectRatio()

Or, if this is for a different window then use…


base.getAspectRatio(yourWin)

Now the fun bit. Try this out…


base.enableSoftwareMousePointer()

The code for this is handy to know ( taken from ShowBase.py )…

        """enableSoftwareMousePointer(self)

        Creates some geometry and parents it to render2d to show
        the currently-known mouse position.  Useful if the mouse
        pointer is invisible for some reason.
        """
        mouseViz = self.render2d.attachNewNode('mouseViz')
        lilsmiley = loader.loadModel('lilsmiley')
        lilsmiley.reparentTo(mouseViz)

        aspectRatio = self.getAspectRatio()
        # Scale the smiley face to 32x32 pixels.
        lilsmiley.setScale(
            32.0 / self.win.getHeight() / aspectRatio,
            1.0, 32.0 / self.win.getHeight())

If you will use a similar scale, then remember to change the self.win to base.win

Hope this helps!

Thanks Sandman, thats exactly what I needed.

Cheers!