Skip to content

Commit

Permalink
Fix for jMonkeyEngine#2327 Mouse pointer moves to centre of canvas on…
Browse files Browse the repository at this point in the history
… click in OpenGL3 with Swing

Modify FlyByCamera to only hide the mouse cursor when the user actually rotates the camera, rather than when the user first presses the left mouse button.
When the mouse is clicked, instead of immediately hiding the cursor, a flag (hideCursorOnNextRotate) is set. If and when a rotate is detected, the flag is checked and if true the cursor is hidden and the flag is cleared.
  • Loading branch information
andreas committed Nov 15, 2024
1 parent b174117 commit d4d644d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class FlyByCamera implements AnalogListener, ActionListener {
protected boolean dragToRotate = false;
protected boolean canRotate = false;
protected boolean invertY = false;
private boolean hideCursorOnNextRotate = false;
protected InputManager inputManager;

/**
Expand Down Expand Up @@ -200,6 +201,7 @@ public void setEnabled(boolean enable){
if (enabled && !enable){
if (inputManager!= null && (!dragToRotate || (dragToRotate && canRotate))){
inputManager.setCursorVisible(true);
hideCursorOnNextRotate = false;
}
}
enabled = enable;
Expand Down Expand Up @@ -353,6 +355,10 @@ public void unregisterInput() {
protected void rotateCamera(float value, Vector3f axis) {
if (dragToRotate) {
if (canRotate) {
if(hideCursorOnNextRotate) {
inputManager.setCursorVisible(false);
hideCursorOnNextRotate = false;
}
// value = -value;
} else {
return;
Expand Down Expand Up @@ -499,7 +505,14 @@ public void onAction(String name, boolean value, float tpf) {

if (name.equals(CameraInput.FLYCAM_ROTATEDRAG) && dragToRotate) {
canRotate = value;
inputManager.setCursorVisible(!value);

if(value) {
hideCursorOnNextRotate = true;
}
else {
inputManager.setCursorVisible(true);
hideCursorOnNextRotate = false;
}
} else if (name.equals(CameraInput.FLYCAM_INVERTY)) {
// Invert the "up" direction.
if (!value) {
Expand Down

0 comments on commit d4d644d

Please sign in to comment.