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[lwjglx]: make the mouse implementation better suited for resolution changes #6

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:

- name: Upload modules release output
if: ${{matrix.arch == 'arm64'}} # Only upload this once
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: lwjgl3-android-modules
path: bin/RELEASE

- name: Upload native build output
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: lwjgl3-android-natives-${{matrix.arch}}
path: bin/out
4 changes: 2 additions & 2 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
bash ci_build_ios.bash

- name: Upload modules release output
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: lwjgl3-ios-modules
path: bin/RELEASE

- name: Upload native build output
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: lwjgl3-ios-natives
path: bin/out
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ public class GLFWInputImplementation implements InputImplementation {
private final ByteBuffer keyboardEvent = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
public final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
public final byte[] mouse_buffer = new byte[3];
public int mouseX = 0;
public int mouseY = 0;
public int mouseLastEventX = 0;
public int mouseLastEventY = 0;
public int mouseX = 0, lastPhysicalX = 0;
public int mouseY = 0, lastPhysicalY = 0;
public int mouseLastX = 0;
public int mouseLastY = 0;
public int mouseComparatorX;
public int mouseComparatorY;
public boolean grab;
private long last_event_nanos = System.nanoTime();
@Override
Expand Down Expand Up @@ -140,23 +136,27 @@ public boolean isInsideWindow() {
return true;
}

public void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
int acoord1=0;
int acoord2=0;
if(coord1 == -1 && coord2 == -1) {
acoord1 = mouseX;
acoord2 = mouseY;
}else{
acoord1 = coord1;
acoord2= coord2;
public void putMouseEventWithCoords(byte button, byte state, int px, int py, int dz, long nanos) {
if(px == -1 && py == -1) {
px = lastPhysicalX;
py = lastPhysicalY;
}
event_buffer.clear();
event_buffer.put(button).put(state);
//always put deltas when grabbed
if (grab) {
event_buffer.putInt(acoord1-mouseX).putInt(acoord2-mouseY);
int dx = px - lastPhysicalX;
// The coordinate from GLFW is inverted relative to LWJGL2's input, so
// invert the delta here for more consitency between resolution changes
int dy = (py - lastPhysicalY) * -1;
mouseX += dx;
mouseY += dy;
event_buffer.putInt(dx).putInt(dy);
}else{
event_buffer.putInt(acoord1).putInt(acoord2);
mouseX = px;
// If not grabbing, invert absolute coordinate in the window's coordinate space
mouseY = (int)((py - Display.getHeight())*-1);
event_buffer.putInt(mouseX).putInt(mouseY);
}
if(button != -1) {
mouse_buffer[button]=state;
Expand All @@ -165,8 +165,8 @@ public void putMouseEventWithCoords(byte button, byte state, int coord1, int coo
event_buffer.flip();
event_queue.putEvent(event_buffer);
last_event_nanos = nanos;
mouseX = acoord1;
mouseY = acoord2;
lastPhysicalX = px;
lastPhysicalY = py;
}

public void setMouseButtonInGrabMode(byte button, byte state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void invoke(long window, boolean entered) {
Window.cursorPosCallback = new GLFWCursorPosCallback() {
@Override
public void invoke(long window, double xpos, double ypos) {
GLFWInputImplementation.singleton.putMouseEventWithCoords((byte)-1, (byte)0,(int)xpos,(int)((ypos - Display.getHeight())*-1),0,Sys.getNanoTime());
GLFWInputImplementation.singleton.putMouseEventWithCoords((byte)-1, (byte)0,(int)xpos,(int)ypos,0,Sys.getNanoTime());
}
};

Expand Down
Loading