Skip to content

Commit

Permalink
Update GLFWInputImplementation.java
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell authored Nov 20, 2024
1 parent 8b61469 commit 7fd9a19
Showing 1 changed file with 16 additions and 11 deletions.
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 @@ -142,16 +138,27 @@ public boolean isInsideWindow() {

public void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
int dx = 0, dy = 0;
if(coord1 != -1) dx = coord1 - mouseX;
if(coord2 != -1) dy = (coord2 - mouseY) * -1;
if(coord1 != -1 && coord2 != -1) {
if(grab) {
dx = coord1 - lastPhysicalX;
dy = (coord2 - lastPhysicalY) * -1;
mouseX += dx;
mouseY += dy;
} else {
mouseX = coord1;
mouseY = (int)((coord2 - Display.getHeight())*-1);
}
lastPhysicalX = coord1;
lastPhysicalY = coord2;
}

event_buffer.clear();
event_buffer.put(button).put(state);
//always put deltas when grabbed
if (grab) {
event_buffer.putInt(dx).putInt(dy);
}else{
event_buffer.putInt(dx + mouseX).putInt(dy + mouseY);
event_buffer.putInt(mouseX).putInt(mouseY);
}
if(button != -1) {
mouse_buffer[button]=state;
Expand All @@ -160,8 +167,6 @@ public void putMouseEventWithCoords(byte button, byte state, int coord1, int coo
event_buffer.flip();
event_queue.putEvent(event_buffer);
last_event_nanos = nanos;
mouseX += dx;
mouseY += dy;
}

public void setMouseButtonInGrabMode(byte button, byte state) {
Expand Down

0 comments on commit 7fd9a19

Please sign in to comment.