Add _render.Texture.scale_mode#3740
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds texture scale-mode support: three new constants (SCALEMODE_LINEAR, SCALEMODE_NEAREST, SCALEMODE_PIXELART) and a Texture.scale_mode property implemented in C, exposed in type stubs, and covered by a unit test. Changes
Sequence Diagram(s)sequenceDiagram
participant Py as Python (Texture)
participant C as C Extension (render.c)
participant SDL as SDL Library
Py->>C: getattr(Texture.scale_mode)
C->>SDL: SDL_GetTextureScaleMode(texture)
SDL-->>C: scale_mode (int)
C-->>Py: return int
Py->>C: setattr(Texture.scale_mode = value)
C->>SDL: SDL_SetTextureScaleMode(texture, value)
SDL-->>C: success / error
C-->>Py: None or raise error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/render_test.py`:
- Around line 276-279: The test uses a no-op comparison instead of setting the
property: replace the comparison expression "self.texture.scale_mode ==
pygame.SCALEMODE_LINEAR" with an assignment to set the scale mode (i.e., assign
pygame.SCALEMODE_LINEAR to self.texture.scale_mode) so that the subsequent
assertion in test_scale_mode actually verifies the setter behavior for the
texture.scale_mode property.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7881fd59-7219-43f0-bfc0-8710ec05fe58
📒 Files selected for processing (7)
buildconfig/stubs/pygame/__init__.pyibuildconfig/stubs/pygame/_render.pyibuildconfig/stubs/pygame/constants.pyibuildconfig/stubs/pygame/locals.pyisrc_c/constants.csrc_c/render.ctest/render_test.py
Should be straight forward. It's one of the texture properties you can freely get or set with SDL (both 2 and 3). Keeping it a constructor only argument makes no sense. That constructor only argument is also not conformed to SDL3. If this gets in I will make a follow up pull request that removes that argument (no deprecation needed since the module isn't public).
Currently to change the scale mode of a texture made from a surface your only option is create the texture and then use
Texture.update, but when you do that the alpha of the surface isn't ported properly. One could say that's a bug of its own, but even if, doesn't make this property less useful.SDL2 scale mode: https://wiki.libsdl.org/SDL2/SDL_ScaleMode
SDL3 scale mode: https://wiki.libsdl.org/SDL3/SDL_ScaleMode
I added
SCALEMODE_PIXELARTeven if SDL2 doesn't have it, as it can just fall back toSCALEMODE_NEAREST, given the similarities between them.Since the module isn't public and doesn't have a dedicated docs page I'm forced to add the docs to the stubs, which is what would have happened anyways when the docs were added to it.
Also, the C code for the scale mode isn't SDL3 compatible yet (the error macros have to branch for sdl3), a future pull request will make the whole module SDL3 compatible.