Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release CursorButtonEvent not sent when a different button is clicked outside of the spatial #102

Open
jcfandino opened this issue Jul 8, 2021 · 0 comments

Comments

@jcfandino
Copy link

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:

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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant