Skip to content

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

@jcfandino

Description

@jcfandino

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions