-
-
Notifications
You must be signed in to change notification settings - Fork 193
Add Renderer.logical_to_window and Renderer.window_to_logical from SDL2 #3519
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
base: main
Are you sure you want to change the base?
Conversation
See https://wiki.libsdl.org/SDL2/SDL_RenderLogicalToWindow and https://wiki.libsdl.org/SDL2/SDL_RenderWindowToLogical When setting renderer.logical_size, these two functions offer translation between window space and logical space.
I've seen the failing stub stuff, have no experience with it, but just had a look at the github action. Fix coming... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the SDL3 porting guide I found this note
SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been renamed SDL_RenderCoordinatesFromWindow() and SDL_RenderCoordinatesToWindow() and take floating point coordinates in both directions.
I think we should consider whether we should stick to SDL2 terminology or use SDL3's. In either case, I think it makes more sense to keep input consistent for both methods (a single Point
argument, like rest of the functions in this module) and a tuple[float, float]
return type.
I've not yet been in this situation, so this is unfounded gut feeling, but if I was using the How about aliasing them to provide both names? Like Vector2's "lengh" and "magnitude" methods?
Sure, I'll change that. Give me an hour or so... |
Looking at the other functions, e.g. draw_line, draw_point, they also all accept kwargs, which brings us to naming conventions. Leave any thoughts here, I'll go with |
Both functions now expect a tuple, following the pygame conventions. For SDL3, the ported functions have been renamed and changed. > SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been > renamed SDL_RenderCoordinatesFromWindow() and > SDL_RenderCoordinatesToWindow() and take floating point coordinates in > both directions. I settled on the following decisions * Regardless of the difference in the windows coordinates being ints in the old, and floats in the new version, I just aliased the new names to the old functions on the python side. * Even on SDL3, the window coordinates will be truncated to int to guarantee future compatibility with old code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR! 🎉
But before we merge it, we should also consider whether the same functionality must be implemented in pygame._sdl2.video
which is the original implementation. I haven't been keeping up with pygame._render
so I don't know what the plan is, requesting @Starbuck5 and/or @MightyJosip to review this aspect.
can't assure my info is correct, but _render is a C implementation of sdl2_video. so from what I know _render (future render) is the "official", future-to-be public implementation of sdl2_video. it's like pygame.window and sdl2_video.Window, the latter (second one, I always confuse former and latter) stopped receiving updates, and in my opinion it makes sense to keep updates to _render. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me and makes sense. not merging right away to allow more contributors to check it since it would be new api (tho not immediately public)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But we need to consider what to do with the docs. Because by the way you currently did it, this functionality would be available in pygame._sdl2.video.Renderer
as well, however, it exists only in pygame._render
. After the testing phase, it should probably be moved to another module docs, like it currently works for Window https://pyga.me/docs/ref/sdl2_video.html#pygame._sdl2.video.Window
I followed the existing doc strings in So I see three options:
|
See https://wiki.libsdl.org/SDL2/SDL_RenderLogicalToWindow and https://wiki.libsdl.org/SDL2/SDL_RenderWindowToLogical
When setting renderer.logical_size, these two functions offer translation between window space and logical space when the renderer is scaled different from the window.
This is e.g. useful to translate mouse coordinates that are in window space, to logical_size coordinates of the renderer (or back).