Skip to content

Commit

Permalink
Fix[lwjglx]: make the mouse implementation better suited for resoluti…
Browse files Browse the repository at this point in the history
…on changes (#6)
  • Loading branch information
artdeell authored Nov 20, 2024
1 parent df5a4f8 commit 02b47ed
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
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

0 comments on commit 02b47ed

Please sign in to comment.