mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-05-24 13:54:57 +00:00
fix: compute logical mouse position using window scale factor
Fixes mouse support in menus on systems with scaling factors other than 1.0x
This commit is contained in:
@@ -54,7 +54,7 @@ void Screen::mouseClicked(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == 0)
|
||||
{
|
||||
AUTO_VAR(itEnd, buttons.end());
|
||||
AUTO_VAR(itEnd, buttons.end());
|
||||
for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++)
|
||||
{
|
||||
Button *button = *it; //buttons[i];
|
||||
@@ -116,11 +116,15 @@ void Screen::updateEvents()
|
||||
GLFWwindow* window = glfwGetCurrentContext();
|
||||
if (!window) return;
|
||||
|
||||
float windowScaleX = 1;
|
||||
float windowScaleY = 1;
|
||||
glfwGetWindowContentScale(window, &windowScaleX, &windowScaleY);
|
||||
|
||||
double xpos, ypos;
|
||||
glfwGetCursorPos(window, &xpos, &ypos);
|
||||
|
||||
int xMouse = (int)xpos * screenWidth / fbw;
|
||||
int yMouse = (int)ypos * screenHeight / fbh - 1;
|
||||
int xMouse = (int)(xpos * windowScaleX) * screenWidth / fbw;
|
||||
int yMouse = (int)(ypos * windowScaleY) * screenHeight / fbh - 1;
|
||||
|
||||
static bool prevLeftState = false;
|
||||
static bool prevRightState = false;
|
||||
|
||||
Reference in New Issue
Block a user