Usually after adding a CursorListener to a Spatial the click-release event is triggered even when the cursor is moved outside of the area in the screen where the spatial is seen.
However if another mouse button is clicked before releasing the first one and the cursor is not picking the spatial anymore then the click-release event for the first button is not sent because the target is lost.
The capture variable is being set to null when the second button is clicked.
Follow this example to reproduce the bug:
public class LemurMouseEventsDemo extends SimpleApplication {
public static void main(String[] args) {
new LemurMouseEventsDemo().start();
}
@Override
public void simpleInitApp() {
GuiGlobals.initialize(this);
flyCam.setEnabled(false);
var material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", Gray);
var geo = new Geometry("box", new Box(1, 1, 1));
geo.setMaterial(material);
rootNode.attachChild(geo);
CursorEventControl.addListenersToSpatial(geo, new DefaultCursorListener() {
@Override
public void cursorButtonEvent(CursorButtonEvent event, Spatial target, Spatial capture) {
System.out.println("Click: " + event.getButtonIndex() + "-" + event.isPressed());
if (event.isPressed()) { // set color when button down
material.setColor("Color", event.getButtonIndex() == 0 ? Yellow : Blue);
} else { // clear color when button up
material.setColor("Color", Gray);
}
}
});
}
}
Steps to reproduce:
Left click on box (becomes yellow)
Move pointer outside of the box
Right click
Release both buttons in any order
Result: The box stays yellow instead of turning gray.
When skipping step 2 (right click and releasing buttons inside the box) it will change colors as expected.
When skipping step 3 (release left click outside the box) it will turn gray as expected.
Usually after adding a CursorListener to a Spatial the click-release event is triggered even when the cursor is moved outside of the area in the screen where the spatial is seen. However if another mouse button is clicked before releasing the first one and the cursor is not picking the spatial anymore then the click-release event for the first button is not sent because the target is lost.
This code is involved: https://github.com/jMonkeyEngine-Contributions/Lemur/blob/7ca8f1ee22fedec4979b6548038d3b98efa8b122/src/main/java/com/simsilica/lemur/event/PickEventSession.java#L654
The
capture
variable is being set tonull
when the second button is clicked.Follow this example to reproduce the bug:
Steps to reproduce:
Result: The box stays yellow instead of turning gray. When skipping step 2 (right click and releasing buttons inside the box) it will change colors as expected. When skipping step 3 (release left click outside the box) it will turn gray as expected.