Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return scaled center coordinates for widgets #258

Merged
merged 2 commits into from
Dec 27, 2023

Conversation

DigiEggz
Copy link
Contributor

@DigiEggz DigiEggz commented Nov 7, 2023

The button width / height always return the center values of the native button. At larger scale modes, the disparity grows enough that other buttons can sometimes be pressed when overlapping each other because it doesn't return the actual center coordinates.

The button width / height return the center values of the native button. At larger scale modes, the disparity grows enough that other buttons can sometimes be pressed when overlapping each other because it doesn't return the actual center coordinates.
@DigiEggz DigiEggz changed the title Return proper center coordinates for widgets Return scaled center coordinates for widgets Nov 7, 2023
@Geokureli
Copy link
Member

Can I get a simple test case that quickly highlights the benefit of this change?

@DigiEggz
Copy link
Contributor Author

DigiEggz commented Nov 30, 2023

The widget function _getWidgetPoint(), which is used when clicking buttons, does not return the correct center point when the screen is scaled. When the scale factor changes, the buttons width and height need to use the camera's totalScaleX and totalScaleY values, respectively. This causes misclicks at higher resolutions, especially when buttons are close together.

I made red X marks render where the widget reports its center is at a scale of 3x. The green X marks render at a scaled resolution of 10x. The marks should always overlap, no matter the scale mode.

For clarity, here is what the buttons bounding boxes look like:

bb

Reported centers before the change:

b1
(2560 × 1440, totalScale: 3)

b2
(2560 × 1440, totalScale: 10)

Reported centers after the change:

a1
(2560 × 1440, totalScale: 3)

a2
(2560 × 1440, totalScale: 10)

In the "before the change" section, you can see the button centers report different values (from the misaligned X marks) when the game is at a different scale factors. The red X locations are also very high up on the button and not actually centered, either.

@DigiEggz
Copy link
Contributor Author

DigiEggz commented Dec 18, 2023

To summarize, create a list of widgets for a FlxUICursor to traverse. Then enter fullscreen at different screen resolutions. The cursor always reports the original coordinates instead of the new scaled coordinates. This causes issues clicking buttons, especially so with larger scale factors.

@Geokureli
Copy link
Member

Geokureli commented Dec 18, 2023

sorry for the holdup, been really busy, can you merge the dev branch into this to fix CI, I'll try to get to this soon

Edit: Thanks!

@Geokureli
Copy link
Member

Geokureli commented Dec 22, 2023

I'm finally looking into this, and I don't quite understand the issue, you mark invalid centers on your images, but when I run the Cursor Demo with a scale of 4 I get no issues with clicking or the cursor's position. (note that the demo currently has a scale of 2)

How are you achieving a totalScale of 3, or 10. And what actual code is failing that depends on these centers?

Screen.Recording.2023-12-22.at.12.38.06.PM.mov

@DigiEggz
Copy link
Contributor Author

DigiEggz commented Dec 22, 2023

FlxUICursor uses Camera.totalScaleX and Camera.totalScaleY to determine coordinates for the widget point. When the game is scaled, the totalScale values increase. I got the scale value to increase by entering fullscreen, which happens to increase the scale for my monitor to 10. The author forgot to adjust the center widget coordinates by this scale factor, despite correctly doing so a few lines above.

You will not experience any issues at smaller resolutions because the disparity is not large enough to cause errant clicks, depending on your button size. As the scale size increases, the difference of the "center" becomes to large that it starts to overlap other buttons. You can see that the center is wrong by tracing out the center coordinate of any widget. The value should change with the scale size.

The X's were placed programmatically. You can see that the "center" location is too high in the first section and it only gets worse as the scale size grows.

@Geokureli
Copy link
Member

Geokureli commented Dec 22, 2023

@DigiEggz I'm still not seeing it even with very large scales, does this happen to you with the Cursor demo? I need a solid way to reproduce this issue

Here's at least 5x scale
https://imgur.com/BHQh7zR

@DigiEggz
Copy link
Contributor Author

I'll work on something to show you soon. Happy holidays!

@DigiEggz
Copy link
Contributor Author

DigiEggz commented Dec 23, 2023

I've attached a sample project. Please excuse the absurd verbosity—I tried to make this as fast as I could because I have an event and need to head out.

Demo.zip

Use the arrow keys to traverse the list and then press the X key or Enter to select a button. Press the S key to view the current scale.

At lower scale factors, the button presses normally. Next, either drag the window or go fullscreen with F. At any scale factor of roughly 6.5 or greater, multiple buttons are pressed when you press X or Enter. It also traces out multiple keypresses at once.

@Geokureli
Copy link
Member

Geokureli commented Dec 23, 2023

I tried the demo, I cannot see a difference in behavior with or without this change. fullscreen seems to have no effect on my behavior, either. No matter what, FlxUICursor presses multiple buttons when I press X, with this change, without it, fullscreen or not. I also see no change in the behavior of mouseover

I'm on mac, my fullscreen scale is 12, I don't know if you're on windows or linux or something but I can try those. is your scale an integer, like mine? maybe the issue is more noticeable at, say, 6.5, than 7.0?

Also there's no urgency on this, feel free to come back to this after the holidays, I know this time can be hectic for some

Edit: also the fact that I can ever press more than 1 button is an indicator that FlxUICursor is set up weird, I don't think this is an issue of "widgetPoint" being off, but perhaps that FlxUICursor is using it's position to determine whether it's pointing at multiple widgets

@DigiEggz
Copy link
Contributor Author

DigiEggz commented Dec 23, 2023

That's very strange. I've also been testing on macOS, so the difference may lie elsewhere. Once my scale grows greater that a certain value (in this case ~6.x), the drift is large enough that it starts to overlap other buttons. I'll try and make a video when I get the chance.

If you spawn a graphic where the widget center point is, does the center point stay in the same location each time you create a new one at different scales? I noticed that the center point was always reporting the native size values of the widget.

Edit: I set up HaxeFlixel on a Windows laptop, installed latest versions of all libraries and was able to reproduce the issue.

@DigiEggz
Copy link
Contributor Author

DigiEggz commented Dec 24, 2023

Demo2.zip

I modified the code so that when you press the D key, it will draw an "X" mark graphic at the reported Y-center of the FlxUICursor's current widget. The mark should always render at the same location, regardless of scale. When I test it with the old code, the mark location changes depending on the scale.

@Geokureli Geokureli merged commit 47dc1d6 into HaxeFlixel:dev Dec 27, 2023
15 checks passed
@Geokureli
Copy link
Member

Sorry for the hold-up just needed to make sure I could reproduce the actual symptoms

@Geokureli Geokureli added this to the 2.6.0 milestone Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants