mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-07 05:57:14 +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:
parent
0a286d4ddc
commit
f0aa04a7ee
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue