Skip to content

Commit 7da2440

Browse files
committed
Port SDL3 texture scale mode
1 parent c19aacd commit 7da2440

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-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",

tcod/sdl/render.py

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

142142

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

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

253280
class _RestoreTargetContext:
254281
"""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)