I have a feature that allows the user to split the screen horizontally and vertically using splitHorizontal() and splitVertical(). What I would like to add is that when a certain button on the menu is pressed:
1- change the mouse cursor to a different shape . Saw several posts on the forum that this is still not resolved (however this is not THAT important) 2- wait for the user to press the left click and then trigger one of these two methods. The reason being is that these methods rely on the mouse cursor position to do the splitting. I used to do that using hotkeys but now that itâs in a menu I need to do that.
3- change mouse cursor back to original shape.
The issue is if I have a code like the one below⌠how can I hold on till left click is pressed befolre moving to the verticalSplit() method.
[java] @NiftyEventSubscriber(id=âhorizontalâ)
public void onHorizontalSplit(final String id, final ButtonClickedEvent event)
{
switchMouseCursor(); // <<<<<< what should this method be in order to wait for a left click before continuing
verticalSplit();
}[/java]
Thanks @normen, youâre right, I dk why the idea scared me. I used appStates to do that and was as u said very basic implementation. I basically have the appState listen for a left click before calling these mehtods.
any idea on how to change the mouse cursor though? I spent 2 days looking around on the forums for a hint with no luck⌠I never did anything like that before.
you have to make the cursor invisble, then add your own geometry to the guiNode to represent the cursor. Then use the inputManager to add listeners that will update your custom cursorâs location based on mouse actions.
thanks @pspeed I didnât know about the raw input listener, and it works great except that the geomtry that I am draggging (or moving according to the mouse position) cannot keep up with the mouse position. so if you can see the cursor you actually willl see the cursor move all the way up to the right upper corder while the geometry is only slightly moved to that side . Any idea why?
This test class demonstrate how to change cursor in jME3.
NOTE: This will not work on Android as it does not support cursors.
Cursor test
@author MadJack
*/
public class TestCursor extends SimpleApplication {
private ArrayList<JmeCursor> cursors = new ArrayList<JmeCursor>();
private long sysTime;
private int count = 0;
public static void main(String[] args){
TestCursor app = new TestCursor();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
flyCam.setEnabled(false);
// We need the cursor to be visible. If it is not visible the cursor
// will still be âusedâ and loaded, you just wonât see it on the screen.
inputManager.setCursorVisible(true);
/*
* To make jME3 use a custom cursor it is as simple as putting the
* .cur/.ico/.ani file in an asset directory. Here we use
* "Textures/GUI/Cursors".
*
* For the purpose of this demonstration we load 3 different cursors and add them
* into an array list and switch cursor every 8 seconds.
*
* The first ico has been made by Sirea and the set can be found here:
* http://www.rw-designer.com/icon-set/nyan-cat
*
* The second cursor has been made by Virum64 and is Public Domain.
* http://www.rw-designer.com/cursor-set/memes-faces-v64
*
* The animated cursor has been made by Pointer Adic and can be found here:
* http://www.rw-designer.com/cursor-set/monkey
*/
cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/meme.cur"));
cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/nyancat.ico"));
cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/monkey.ani"));
sysTime = System.currentTimeMillis();
inputManager.setMouseCursor(cursors.get(count));
}
@Override
public void simpleUpdate(float tpf) {
long currentTime = System.currentTimeMillis();
if (currentTime - sysTime > 8000) {
count++;
if (count >= cursors.size()) {
count = 0;
}
sysTime = currentTime;
// 8 seconds have passed,
// tell jME3 to swith to a different cursor.
inputManager.setMouseCursor(cursors.get(count));
}
thanks @pspeed I didnât know about the raw input listener, and it works great except that the geomtry that I am draggging (or moving according to the mouse position) cannot keep up with the mouse position. so if you can see the cursor you actually willl see the cursor move all the way up to the right upper corder while the geometry is only slightly moved to that side . Any idea why?
Must be how you are converting mouse coordinates to scene coordinates or something. (shrug)
Note that I think when the cursor is invisible then the cursor gets routinely snapped back to center, I think.
I like @navid113 's solution, except that it worked on the latest nightly but not on my stable version (and I am intending to stay with the stable version)
I tried looking into the source code to avoid doing an update but ran into a wall:
ByteBuffer data = img.getData(0);
data.rewind();
IntBuffer image = BufferUtils.createIntBuffer(img.getHeight() * img.getWidth());
for (int y = 0; y < img.getHeight(); y++){
for (int x = 0; x < img.getWidth(); x++){
int rgba = data.getInt();
image.put(rgba);
}
}
image.rewind();
Cursor cur = null;
try {
cur = new Cursor(img.getWidth(), img.getHeight(), 1, img.getHeight() â 1, 1, image, null);
} catch (LWJGLException ex) {
Logger.getLogger(Disenthral.class.getName()).log(Level.SEVERE, null, ex);
}
Sorry for not answering before, I was on vacations.
Is this still relevant?
There are ways to make cursors from png already, Iâm not sure if the above is a rewrite of what I wrote or a simple copy/paste hoping it would work in your program, but my question is, why not use one of the factory method to create a cursor based on an image?
I havenât touched that class in a very, very long time and I barely remember anything in there, but it is working here. If it were broken I would know since I use it in Disenthral. Arguably itâs not as good/perfect as it could be, but distortion shouldnât happen.
Anyway, more information would be appreciated if the âissueâ is still there.