Skip to content

Commit

Permalink
Fix mouse handling (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
JL2210 authored Sep 2, 2024
1 parent 3cd03f3 commit b132d86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/lwjgl/input/Mouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static void addMoveEvent(double mouseX, double mouseY) {
ignoreNextMove--;
return;
}
/*float scale = Display.getPixelScaleFactor();
float scale = Display.getPixelScaleFactor();
mouseX *= scale;
mouseY *= scale;*/
mouseY *= scale;
dx += (int) mouseX - latestX;
dy += Display.getHeight() - (int) mouseY - latestY;
latestX = (int) mouseX;
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/lwjgl/opengl/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,20 @@ public static float getPixelScaleFactor() {
if (!isCreated()) {
return 1.0f;
}
float[] xScale = new float[1];
float[] yScale = new float[1];
glfwGetWindowContentScale(getWindow(), xScale, yScale);
return Math.max(xScale[0], yScale[0]);
int[] windowWidth = new int[1];
int[] windowHeight = new int[1];
int[] framebufferWidth = new int[1];
int[] framebufferHeight = new int[1];
float xScale, yScale;
// via technicality we actually have to divide the framebuffer
// size by the window size here, since glfwGetWindowContentScale
// returns a value not equal to 1 even on platforms where the
// framebuffer size and window size always map 1:1
glfwGetWindowSize(getWindow(), windowWidth, windowHeight);
glfwGetFramebufferSize(getWindow(), framebufferWidth, framebufferHeight);
xScale = (float)framebufferWidth[0]/windowWidth[0];
yScale = (float)framebufferHeight[0]/windowHeight[0];
return Math.max(xScale, yScale);
}

public static void setTitle(String title) {
Expand Down

0 comments on commit b132d86

Please sign in to comment.