Merge pull request #520 from saloisio/v3.1

NewtMouseInput no longer auto-centers mouse cursor
cleanup_build_scripts
Julien Gouesse 9 years ago committed by GitHub
commit 75c3d61f8f
  1. 28
      jme3-jogl/src/main/java/com/jme3/input/jogl/NewtMouseInput.java

@ -75,17 +75,19 @@ public class NewtMouseInput implements MouseInput, MouseListener {
private int wheelPos; private int wheelPos;
private Point location; private Point location;
private Point centerLocation; private Point centerLocation;
private Point centerLocationOnScreen;
private Point lastKnownLocation; private Point lastKnownLocation;
private Point lockPosition;
private boolean isRecentering; private boolean isRecentering;
private boolean cursorMoved; private boolean cursorMoved;
private int eventsSinceRecenter; private int eventsSinceRecenter;
private volatile int mousePressedX;
private volatile int mousePressedY;
public NewtMouseInput() { public NewtMouseInput() {
location = new Point(); location = new Point();
centerLocation = new Point(); centerLocation = new Point();
centerLocationOnScreen = new Point();
lastKnownLocation = new Point(); lastKnownLocation = new Point();
lockPosition = new Point();
} }
public void setInputSource(GLWindow comp) { public void setInputSource(GLWindow comp) {
@ -102,8 +104,8 @@ public class NewtMouseInput implements MouseInput, MouseListener {
lastEventWheel = 0; lastEventWheel = 0;
location = new Point(); location = new Point();
centerLocation = new Point(); centerLocation = new Point();
centerLocationOnScreen = new Point();
lastKnownLocation = new Point(); lastKnownLocation = new Point();
lockPosition = new Point();
} }
component = comp; component = comp;
@ -151,17 +153,14 @@ public class NewtMouseInput implements MouseInput, MouseListener {
@Override @Override
public void setCursorVisible(boolean visible) { public void setCursorVisible(boolean visible) {
lastKnownLocation.setX(0);
lastKnownLocation.setY(0);
this.visible = visible; this.visible = visible;
component.setPointerVisible(visible); component.setPointerVisible(visible);
component.confinePointer(!visible); lockPosition.set(lastKnownLocation.getX(), lastKnownLocation.getY());
hack_confinePointer(); hack_confinePointer();
} }
private void hack_confinePointer() { private void hack_confinePointer() {
if (component.hasFocus() && component.isPointerConfined() && !component.isPointerVisible()) { if (component.hasFocus() && !component.isPointerVisible()) {
recenterMouse(component); recenterMouse(component);
} }
} }
@ -215,7 +214,9 @@ public class NewtMouseInput implements MouseInput, MouseListener {
@Override @Override
public void mousePressed(MouseEvent newtEvt) { public void mousePressed(MouseEvent newtEvt) {
MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(newtEvt), true, newtEvt.getX(), component.getSurfaceHeight() - newtEvt.getY()); mousePressedX = newtEvt.getX();
mousePressedY = component.getSurfaceHeight() - newtEvt.getY();
MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(newtEvt), true, mousePressedX, mousePressedY);
evt.setTime(newtEvt.getWhen()); evt.setTime(newtEvt.getWhen());
synchronized (eventQueue) { synchronized (eventQueue) {
eventQueue.add(evt); eventQueue.add(evt);
@ -261,7 +262,7 @@ public class NewtMouseInput implements MouseInput, MouseListener {
// MHenze (cylab) Fix Issue 35: // MHenze (cylab) Fix Issue 35:
// As long as the MouseInput is in recentering mode, nothing is done until the mouse is entered in the component // As long as the MouseInput is in recentering mode, nothing is done until the mouse is entered in the component
// by the events generated by the robot. If this happens, the last known location is resetted. // by the events generated by the robot. If this happens, the last known location is resetted.
if ((centerLocation.getX() == awtEvt.getX() && centerLocation.getY() == awtEvt.getY()) || eventsSinceRecenter++ == 5) { if ((lockPosition.getX() == awtEvt.getX() && lockPosition.getY() == awtEvt.getY()) || eventsSinceRecenter++ == 5) {
lastKnownLocation.setX(awtEvt.getX()); lastKnownLocation.setX(awtEvt.getX());
lastKnownLocation.setY(awtEvt.getY()); lastKnownLocation.setY(awtEvt.getY());
isRecentering = false; isRecentering = false;
@ -285,12 +286,7 @@ public class NewtMouseInput implements MouseInput, MouseListener {
private void recenterMouse(final GLWindow component) { private void recenterMouse(final GLWindow component) {
eventsSinceRecenter = 0; eventsSinceRecenter = 0;
isRecentering = true; isRecentering = true;
centerLocation.setX(component.getSurfaceWidth() / 2); component.warpPointer(lockPosition.getX(), lockPosition.getY());
centerLocation.setY(component.getSurfaceHeight() / 2);
centerLocationOnScreen.setX(centerLocation.getX());
centerLocationOnScreen.setY(centerLocation.getY());
component.warpPointer(centerLocationOnScreen.getX(), centerLocationOnScreen.getY());
} }
private int getJMEButtonIndex(MouseEvent awtEvt) { private int getJMEButtonIndex(MouseEvent awtEvt) {

Loading…
Cancel
Save