LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: intrigus on August 29, 2015, 23:03:07

Title: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: intrigus on August 29, 2015, 23:03:07
Is it somehow possible to set a cursor to a platform specific cursor like http://docs.oracle.com/javase/7/docs/api/java/awt/Cursor.html (http://docs.oracle.com/javase/7/docs/api/java/awt/Cursor.html)?
So that I can set the cursor to Cursor.WAIT_CURSOR and all platforms show a WAIT_CURSOR (but a platform specific).


Edit:
We use GLFW 3.0 so no support for glfwSetCursor(window, cursor); I confused myself...
Title: Re: Set Cursor to platform specific Cursor LWJGL 2
Post by: Evan407 on August 29, 2015, 23:33:27
This is related but it's my understanding this tutorial is for LWJGL 3 and GLFW.
https://github.com/SilverTiger/lwjgl3-tutorial/wiki/Input#cursor-objects
(the "Cursor objects" section)
Title: Re: Set Cursor to platform specific Cursor LWJGL 2
Post by: quew8 on August 30, 2015, 10:42:42
So are you using GLFW or LWJGL2? Your post states the former but your title the latter.
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: intrigus on August 30, 2015, 13:46:40
Sorry for the confusion. (Don't write posts if your are almost sleeping ^^)
I use libgdx. It's lwjgl backend uses lwjgl 2.9.2.
I know that you can use Mouse.setCursor() to set a cursor, but you can only set the cursor to a cursor that you created.
As far as I know, it's not possible to set the Cursor to a predefined cursor like a wait cursor, resize cursor and so on.
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: Cornix on August 30, 2015, 14:36:22
If you dont have a problem with initializing AWT you might always use AWT to get the native cursor image, extract the image data and create an OpenGL texture from it. (or a bytebuffer or whatever LWJGL2 uses for cursors)
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: quew8 on August 30, 2015, 14:42:11
Don't worry, think we've all been there.

The answer is, not that I know of. I don't think you can retrieve the raw image from an awt Cursor. You might be able to in JavaFX however. You can get system cursors via the static in fields in the javafx.scene.Cursor class then if you can cast them to javafx.scene.ImageCursor (I have no idea whether or not they would be ImageCursors or not) you can retrieve a JavaFX image which can be used. I am sceptical about whether or not this would work however AND it would require loading the whole of JavaFX.

Easier to support a few OSs by having built in images for them, or knowing where to look for the defaults on the various OSs.

EDIT: If @Cornix says otherwise about extracting images from awt Cursors, I'm probably wrong.
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: Cornix on August 30, 2015, 14:48:02
I dont know if you can, I am only assuming, because why not? AWT certainly has the image data so why not allow us to get it?
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: quew8 on August 30, 2015, 15:21:41
Well I don't know but there's nothing in the docs http://docs.oracle.com/javase/7/docs/api/java/awt/Cursor.html (http://docs.oracle.com/javase/7/docs/api/java/awt/Cursor.html)
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: Cornix on August 30, 2015, 15:49:56
Yeah, I looked at the source code, does not seem like there is any way to get the images. Maybe one could dig deeper but I would guess its all platform dependent code.
Title: Re: Set Cursor to platform specific Cursor LWJGL 2.9.2
Post by: Kai on August 31, 2015, 09:11:55
Quote from: intrigus on August 29, 2015, 23:03:07
So that I can set the cursor to Cursor.WAIT_CURSOR and all platforms show a WAIT_CURSOR (but a platform specific).
I proposed a pull request (https://github.com/glfw/glfw/pull/592) on the GLFW repository to support a platform-specific "wait" cursor with a Windows implementation using ICL_WAIT, and an X11 implementation using XC_watch.
People would have to contribute a Cocoa implementation to support this on OS X, too.