Click release event lost with lemur spatial listener

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:

  1. Left click on box (becomes yellow)
  2. Move pointer outside of the box
  3. Right click
  4. 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?

1 Like

Could be a bug. Without having time to look at the Lemur code right this minute, it could be that the second click outside the control somehow clears the target-tracking that makes sure to deliver the first button’s events back again.

The test case will be tremendously useful to tracking that down. So thanks for that.

1 Like

Thanks Paul.
This is really not a pressing issue for me since so far I’m the only user of my level editor :stuck_out_tongue:

I did a quick debugging and tracked the target clearing down to this line:

I don’t really feel I know that code good enough to suggest any fixes.
Maybe capture should be a collection? doesn’t look like a trivial change.

Yeah, it’s not a simple fix. Somehow the target would have to relate back to the button pressed.

If you feel inclined/motivated, please consider reporting the issue on the github project so that we are sure it doesn’t get lost.

Sure, here it is: Release CursorButtonEvent not sent when a different button is clicked outside of the spatial · Issue #102 · jMonkeyEngine-Contributions/Lemur · GitHub

1 Like

Awesome. Thanks.