g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.74k stars 292 forks source link

MacOS with Retina: UI clickable area is calculated incorrectly #281

Open dant3 opened 2 years ago

dant3 commented 2 years ago

Most likely bug is caused by incorrect calculation of UI element position due to Retina. See video for a reproduction. I used an example code from the readme.md

https://user-images.githubusercontent.com/820057/183709276-7f04556c-5cc8-4ad5-b405-e5fde9a16b60.mov

danaugrs commented 2 years ago

Hi and thanks for the video! Unfortunately I don't have a MacOS device and can't reproduce/debug/fix. The relevant code is probably in gui/panel.go in the SetModelMatrix function if you (or anyone else with a MacOS device) would like to have a stab at fixing it. You might also want to add the window hint mentioned in https://github.com/g3n/engine/pull/161#issuecomment-1159476963 and it might be helpful to look through that PR and the ones linked there.

berkeleynerd commented 2 years ago

I am able to reproduce this issue on a MacBook Pro M1.

TheRealDigitalMaster commented 2 years ago

How to put this in html?

danaugrs commented 2 years ago

@TheRealDigitalMaster please see https://github.com/g3n/engine/issues/282#issuecomment-1235806125.

tomekc commented 1 year ago

Hi, I come late to the party and took a moment to apply #161 tu current master, and it brings some improvement: the button is now clickable, but apparently incorrectly scaled (2x) with regards to size and position I guess.

I also am experiencing a strange glitch where initially the 3D scene takes only lower left quadrant of the window. It gets right after simply moving a window (!).

Screenshot 2023-04-07 at 02 25 37

And after moving a window button is clickable:

Screenshot 2023-04-07 at 02 25 55

EDIT

Glitch resolved by fixing onResize handler:

        scaleX, scaleY := a.GetScale()
        width, height := a.GetSize()
        a.Gls().Viewport(0, 0, int32(float32(width)*scaleX), int32(float32(height)*scaleY))

Now the UI is rendered properly, but mouse coordinates read improperly (need to move to coordinates 2x position of the button to click). Probably resolved by simple fix of the mouse coordinate reading?

Screenshot 2023-04-07 at 02 40 49
zyxkad commented 9 months ago

Hi @tomekc , your solution works for me. The cursor position does not have the 2x error but have 2 pixels offset on my computer. Also, the actual code fixed for me is:

r.Gls().Viewport(0, 0, (int32)((float64)(w)*scaleX), (int32)((float64)(h)*scaleY))

which scaleX/Y is float64