Skip to content

Commit 3b944f9

Browse files
committed
Port SDL3 texture scale mode
1 parent eeb06fb commit 3b944f9

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@
348348
"PERLIN",
349349
"PILCROW",
350350
"pilmode",
351+
"PIXELART",
351352
"PIXELFORMAT",
352353
"PLUSMINUS",
353354
"pointsize",
@@ -401,6 +402,7 @@
401402
"rtype",
402403
"RWIN",
403404
"RWOPS",
405+
"SCALEMODE",
404406
"scalex",
405407
"scaley",
406408
"Scancode",

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `tcod.sdl.render`: Added `ScaleMode` enum and `Texture.scale_mode` attribute.
12+
913
## [19.2.0] - 2025-07-20
1014

1115
### Added

tcod/sdl/render.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ class BlendMode(enum.IntEnum):
141141
""""""
142142

143143

144+
class ScaleMode(enum.IntEnum):
145+
"""Texture scaling modes.
146+
147+
.. versionadded:: unreleased
148+
"""
149+
150+
NEAREST = lib.SDL_SCALEMODE_NEAREST
151+
"""Nearing neighbor."""
152+
LINEAR = lib.SDL_SCALEMODE_LINEAR
153+
"""Linier filtering."""
154+
# PIXELART = lib.SDL_SCALEMODE_PIXELART # Needs SDL 3.4 # noqa: ERA001
155+
156+
144157
def compose_blend_mode( # noqa: PLR0913
145158
source_color_factor: BlendFactor,
146159
dest_color_factor: BlendFactor,
@@ -254,6 +267,20 @@ def color_mod(self) -> tuple[int, int, int]:
254267
def color_mod(self, rgb: tuple[int, int, int]) -> None:
255268
_check(lib.SDL_SetTextureColorMod(self.p, rgb[0], rgb[1], rgb[2]))
256269

270+
@property
271+
def scale_mode(self) -> ScaleMode:
272+
"""Get or set this textures :any:`ScaleMode`.
273+
274+
..versionadded:: unreleased
275+
"""
276+
mode = ffi.new("SDL_ScaleMode*")
277+
_check(lib.SDL_GetTextureScaleMode(self.p, mode))
278+
return ScaleMode(mode[0])
279+
280+
@scale_mode.setter
281+
def scale_mode(self, value: ScaleMode, /) -> None:
282+
_check(lib.SDL_SetTextureScaleMode(self.p, value))
283+
257284

258285
class _RestoreTargetContext:
259286
"""A context manager which tracks the current render target and restores it on exiting."""

tests/test_sdl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_sdl_render(uses_window: None) -> None:
7070
rgb.alpha_mod = rgb.alpha_mod
7171
rgb.blend_mode = rgb.blend_mode
7272
rgb.color_mod = rgb.color_mod
73+
rgb.scale_mode = rgb.scale_mode
7374
rgba = render.upload_texture(np.zeros((8, 8, 4), np.uint8), access=tcod.sdl.render.TextureAccess.TARGET)
7475
with render.set_render_target(rgba):
7576
render.copy(rgb)

0 commit comments

Comments
 (0)