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

Fix for #2327 Mouse pointer moves to centre of canvas on click in OpenGL3 with Swing #2328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be changed to

if (!canRotate) {
    return;
} else 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to } else { (one line)

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