An odd new issue. The coordinates I’m getting from action.x and action.y are offset by half a pixel. +0.5 X and -0.5 Y.
Defold 1.2.183, Linux Mint 20.1 Ulyssa.
Reported on github: action.x and action.y are offset by half a pixel. · Issue #5925 · defold/defold · GitHub
Can someone else test this project to see if they get the same results? (without resizing the window of course.)
mouse-pos-test.zip (2.7 KB)
“gui pos” is action.x, action.y, “screen pos” is action.screen_x, action.screen_y.
Not only that, but also this:
opened 04:07PM - 03 Jul 21 UTC
bug
input
macos
Run attached project and see.
I expect y coords in range [0, 179], just like x … in range - [0, 319].
Instead, y is in range [1, 180].

[mouse_test.zip](https://github.com/defold/defold/files/6758686/mouse_test.zip)
This is macOS 10.15.7, Defold 1.2.184
And these are not new issues, this has been the case from the very beginning.
1 Like
MacOS Big Sur, Defold 1.2.184 on a retina Macbook Pro. How strange!
1 Like
Thank you for reporting and reminding us of these. The upside now is that the source code is available and accepting pull requests!
3 Likes
totebo:
on a retina Macbook Pro.
Thanks! I guess with a high-dpi screen the coordinates are halved, right?
If you double that gui pos, you get: 409.5, 638.5
Which is exactly the +0.5 X and -0.5 Y from screen pos that I have.
It’s really mind-boggling that I haven’t noticed this before. I thought I’d done the conversion between them dozens of times. I guess I usually only use screen coordinates outside of GUI because they don’t get stretched.
So, I tried looking at the source code to figure this out and this is what I found:
The 0.5 offset seems very intentional. I would like to see the reason of that explained, though I assume it’s to make a pixel coordinate centered.
The y coordinates being in [1, window_height] and not in [0, window_height - 1] as expected is likely due to off-by-one error in this line:
So, the simplest fix is
input_action.m_ScreenY = window_height - 1 - action->m_Y;
Keep in mind though, that this is my first time looking at Defold source code, so I may be completely wrong I also don’t have the knowledge to build and test the engine, so I can’t confirm the proposed fix actually works.
britzl
August 22, 2023, 7:00am
7
Correct. According to the very old commit it was due to picking:
committed 01:41PM - 27 Aug 11 UTC
You’re right. That’s probably it.