Mouse Cursor is resetted on mouse movement

Started by Faust, January 20, 2010, 12:34:31

Previous topic - Next topic

Faust

Hi,

i am using LWJGL for an 3d applet. The mouse should not be grabbed, so that the user may easily switch between using webpage elements and the applet.

To change the appearance for the mouse cursor the java.awt.Component.setCursor(Cursor cursor) Method can be used. The method does work but the cursor is immediatly resetted to the default cursor when the mouse is moved.

To clarify this issue / bug the gears test applet can be easily altered:
Within gameLoop() replace the Mouse.isButtonDown(0) if-else-clause with this code brick:

if(Mouse.isButtonDown(0))
{
  if (!mouseButtonDown)
  {
    prevMouseX = Mouse.getX();
    prevMouseY= Mouse.getY();
    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    System.out.println("setting cursor");
  }
  mouseButtonDown = true;
}
else
{
  if(mouseButtonDown)
  {
    setCursor(Cursor.getDefaultCursor());
    System.out.println("resetting cursor");
  }
  mouseButtonDown = false;
}


Is there another way to use the default cursors of awt when using LWJGL?

Thanks in advance!

kappa

you should really use LWJGL's built in methods for changing the cursor (Mouse.setNativeCursor), any reason you must use AWT?

p.s. hey, you stole my username, i use that on the ardor and jme forums ;D

Faust

Okay, i tried to devide my main class into 2 classes: one for setting up LWJGL as applet and one for the an application.
I mentioned that the Mouse.isCreated() returns true after Display has been created. Seems wrong to me...

When using the setNativeCursor method of LWJGL, how can i access the native cursors since the method takes cursor objects of LWJGL cursor classes and i cannot find a method for getting a list of available cursor objects?

kappa

Quote from: Faust on January 21, 2010, 15:46:26
Okay, i tried to devide my main class into 2 classes: one for setting up LWJGL as applet and one for the an application.
I mentioned that the Mouse.isCreated() returns true after Display has been created. Seems wrong to me...

When using the setNativeCursor method of LWJGL, how can i access the native cursors since the method takes cursor objects of LWJGL cursor classes and i cannot find a method for getting a list of available cursor objects?


Display.create() will automatically call Mouse.create() and Keyboard.create() so you are not suppose to call those methods manually yourself.

just store your own Cursor objects, and set setNativeCusor(null) to restore it to the default OS mouse.

Faust

Is there any benefit to use the native cursor method for changing the cursor instead of setting a transarent cursor and rendering the cursor image within the own opengl gui rendering process?
Hiding the cursor and doing the cursor rending within gameloop allows blending between 2D and 3D cursors (in a strategy game for example) and gets rid of any size or transparency limitations...

Rene

One important problem with that is that mouse input is horrible on lower framerates. It's a choice you have to make, depending on your needs.
When I am king, they shall not have bread and shelter only, but also teachings out of books, for a full belly is little worth where the mind is starved - Mark Twain

kappa

Quote from: Rene on January 22, 2010, 13:43:15
One important problem with that is that mouse input is horrible on lower framerates. It's a choice you have to make, depending on your needs.

not with when using a native cursor with lwjgl, that only applies if you're using a non native cursor with lwjgl (i.e. using Mouse.getX() getY() to draw your own).

Rene

Quote from: javalwjgl on January 22, 2010, 21:03:43
Quote from: Rene on January 22, 2010, 13:43:15
One important problem with that is that mouse input is horrible on lower framerates. It's a choice you have to make, depending on your needs.

not with when using a native cursor with lwjgl, that only applies if you're using a non native cursor with lwjgl (i.e. using Mouse.getX() getY() to draw your own).

But that's what he was asking  ;)

Quote from: Faust on January 22, 2010, 13:24:47
Is there any benefit to use the native cursor method for changing the cursor instead of setting a transarent cursor and rendering the cursor image within the own opengl gui rendering process?
Hiding the cursor and doing the cursor rending within gameloop allows blending between 2D and 3D cursors (in a strategy game for example) and gets rid of any size or transparency limitations...
When I am king, they shall not have bread and shelter only, but also teachings out of books, for a full belly is little worth where the mind is starved - Mark Twain

Faust

To end this thread: I implemented a wrapper class that switches between native cursors, 2d cursors (rendering images at mouse pos and using a transparent native cursor in applet mode or grabbing and hiding the mouse in application mode) as well as 3d cursors on demand.

Thanks again.