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

Port key and mouse to SDL3 #3207

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Port key and mouse to SDL3 #3207

wants to merge 2 commits into from

Conversation

ankith26
Copy link
Member

@ankith26 ankith26 commented Nov 2, 2024

Just following the footsteps of #3206 but separated out in a different PR because these changes are not as trivial as those

@ankith26 ankith26 requested a review from a team as a code owner November 2, 2024 08:51
@Starbuck5 Starbuck5 added the sdl3 label Nov 2, 2024
/* SDL3 changed the mouse API to deal with float coordinates, for now we
* still truncate the result to int before returning to python side.
* This can be changed in a breaking release in the future if needed. */
float x, y;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it gets it as a float, how does it get converted to an int? Because it gets passed a function that takes ints.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that just happens implicitly, I didn't bother documenting it because I didn't think it should cause any confusion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you had written int ix = (int)x; I wouldn't have batted an eye. Even int ix = x; So I assume that passing to into a parameter of a type is the same as assignment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true. I can make the function call
return pg_tuple_couple_from_values_int((int)x, (int)y); if that helps. It becomes more explicit but verbose

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, I'm not a fan of downcasting without explicitly checking that the value is within range of the destination data type. That just seems like a recipe for hard-to-diagnose bugs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use casts to ints from floats in other places, I don't see how we could check range elegantly. For this I think the mouse coordinates reported will be reasonable numbers.

@Starbuck5 Starbuck5 added mouse pygame.mouse key pygame.key labels Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
key pygame.key mouse pygame.mouse sdl3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants