Hi, I have some dragging controls in my app and I wanted to use the right click to cancel the dragging action but I was getting some strange behavior missing the button-up events sometimes.
So I made this minimal example to verify:
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);
}
}
});
}
}
So when the left mouse button is down the box turns yellow and when the right click is down it turns blue, when no button is pressed becomes gray.
However, if I follow these steps:
- Left click on box (becomes yellow)
- Move pointer outside of the box
- Right click
- Release both buttons in any order
The box stays yellow instead of turning gray.
If I skip step 2 (right click and releasing buttons inside the box) it will change colors as expected.
If I skip step 3 (release left click outside the box) it will turn gray as expected.
In the failing scenario the listener stops being called when a second button is introduced and the pointer is not over the spatial.
I makes sense than the second button doesn’t trigger an even but it shouldn’t stop the release event for the original button.
Am I missing something?