Reputation: 21
I am currently writing a java program with slick2D, and want to change the mouse cursor, but I don't want to use a downloaded image. Is there a way to change the mouse cursor to one of the system cursors?
Upvotes: 1
Views: 1444
Reputation: 2903
Since the System mouse Cursors are usually stored at C:\Windows\Cursors you should be able to Access These Folders and use the files in it. (in case you have Windows, you'd Need to Chat that for your OS)
If you now have a look at the Slick2D Documentation you will see that there is already a functionality for your Problem.
http://slick.ninjacave.com/javadoc/org/newdawn/slick/AppGameContainer.html
void setMouseCursor(org.lwjgl.input.Cursor cursor, int hotSpotX, int hotSpotY)
void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY)
void setMouseCursor(Image image, int hotSpotX, int hotSpotY)
void setMouseCursor(java.lang.String ref, int hotSpotX, int hotSpotY)
So you should be able to use one of These methods from your appcontainer and to set the Cursor.
I'm not sure whether you can directly create a new Image from a .cur file located at the Windows Folder though, you Need to check that. That means:
app.SetMouseCursor(new Image("C\Windows\Cursors\aero_link.cur"))
will probably not work.
The first one which requieres an org.lwjgl.input.Cursor Cursor should definitly work tho. See here for clarification which Parameters are requiered for constructing an org.lwjgl.input.Cursor Cusor object (http://legacy.lwjgl.org/javadoc/org/lwjgl/input/Cursor.html)
Worst case would be that you Need to convert the .cur file to a jpg or a png file before loading it, or maybe Windows has stored .cur files as usable Images files somewhere.
In case I missunderstood your question you could simply do as followed:
AppGameContainer apgcc = new AppGameContainer()
apgcc.setCursor(new Cursor(Cursor.MOVE_CURSOR)); //e.g. or AppGameContainer in case you are not programming an Applet.
I'd not consider These really as System Cursors though.
Upvotes: 0
Reputation: 94
You could try to get an instance of your Display and change it's cursor by:
Display.setCursor(Cursor.WAIT_CURSOR);
You could also attach your LWJGL
display to a JFrame
and then change the cursor.
Upvotes: 1