Removed auto-centering of mouse cursor

define_list_fix
saloisio 9 years ago
parent 65164e2075
commit 76cbd45784
  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 Point location;
private Point centerLocation;
private Point centerLocationOnScreen;
private Point lastKnownLocation;
private Point lockPosition;
private boolean isRecentering;
private boolean cursorMoved;
private int eventsSinceRecenter;
private volatile int mousePressedX;
private volatile int mousePressedY;
public NewtMouseInput() {
location = new Point();
centerLocation = new Point();
centerLocationOnScreen = new Point();
lastKnownLocation = new Point();
lockPosition = new Point();
}
public void setInputSource(GLWindow comp) {
@ -102,8 +104,8 @@ public class NewtMouseInput implements MouseInput, MouseListener {
lastEventWheel = 0;
location = new Point();
centerLocation = new Point();
centerLocationOnScreen = new Point();
lastKnownLocation = new Point();
lockPosition = new Point();
}
component = comp;
@ -151,17 +153,14 @@ public class NewtMouseInput implements MouseInput, MouseListener {
@Override
public void setCursorVisible(boolean visible) {
lastKnownLocation.setX(0);
lastKnownLocation.setY(0);
this.visible = visible;
component.setPointerVisible(visible);
component.confinePointer(!visible);
lockPosition.set(lastKnownLocation.getX(), lastKnownLocation.getY());
hack_confinePointer();
}
private void hack_confinePointer() {
if (component.hasFocus() && component.isPointerConfined() && !component.isPointerVisible()) {
if (component.hasFocus() && !component.isPointerVisible()) {
recenterMouse(component);
}
}
@ -215,7 +214,9 @@ public class NewtMouseInput implements MouseInput, MouseListener {
@Override
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());
synchronized (eventQueue) {
eventQueue.add(evt);
@ -261,7 +262,7 @@ public class NewtMouseInput implements MouseInput, MouseListener {
// 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
// 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.setY(awtEvt.getY());
isRecentering = false;
@ -285,12 +286,7 @@ public class NewtMouseInput implements MouseInput, MouseListener {
private void recenterMouse(final GLWindow component) {
eventsSinceRecenter = 0;
isRecentering = true;
centerLocation.setX(component.getSurfaceWidth() / 2);
centerLocation.setY(component.getSurfaceHeight() / 2);
centerLocationOnScreen.setX(centerLocation.getX());
centerLocationOnScreen.setY(centerLocation.getY());
component.warpPointer(centerLocationOnScreen.getX(), centerLocationOnScreen.getY());
component.warpPointer(lockPosition.getX(), lockPosition.getY());
}
private int getJMEButtonIndex(MouseEvent awtEvt) {

Loading…
Cancel
Save