Skip to content

Commit c8d0b7b

Browse files
committed
Add Window.mouse_rect.
Fix docs of changed properties.
1 parent e3fc45f commit c8d0b7b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

tcod/sdl/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ def _linked_version() -> Tuple[int, int, int]:
5858
return int(sdl_version.major), int(sdl_version.minor), int(sdl_version.patch)
5959

6060

61+
def _version_at_least(required: Tuple[int, int, int]) -> None:
62+
"""Raise an error if the compiled version is less than required. Used to guard recentally defined SDL functions."""
63+
if required <= _compiled_version():
64+
return
65+
raise RuntimeError(
66+
f"This feature requires SDL version {required}, but tcod was compiled with version {_compiled_version()}"
67+
)
68+
69+
6170
def _required_version(required: Tuple[int, int, int]) -> Callable[[T], T]:
6271
if not lib: # Read the docs mock object.
6372
return lambda x: x

tcod/sdl/render.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def format(self) -> int:
180180
def access(self) -> TextureAccess:
181181
"""Texture access mode, read only.
182182
183-
.. versionadded:: unreleased
183+
.. versionchanged:: unreleased
184184
Property now returns a TextureAccess instance.
185185
"""
186186
buffer = ffi.new("int*")
@@ -216,7 +216,7 @@ def alpha_mod(self, value: int) -> None:
216216
def blend_mode(self) -> BlendMode:
217217
"""Texture blend mode, can be set.
218218
219-
.. versionadded:: unreleased
219+
.. versionchanged:: unreleased
220220
Property now returns a BlendMode instance.
221221
"""
222222
out = ffi.new("SDL_BlendMode*")

tcod/sdl/video.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from numpy.typing import ArrayLike, NDArray
1313

1414
from tcod.loader import ffi, lib
15-
from tcod.sdl import _check, _check_p, _required_version
15+
from tcod.sdl import _check, _check_p, _required_version, _version_at_least
1616

1717
__all__ = (
1818
"WindowFlags",
@@ -278,6 +278,23 @@ def grab(self) -> bool:
278278
def grab(self, value: bool) -> None:
279279
lib.SDL_SetWindowGrab(self.p, value)
280280

281+
@property
282+
def mouse_rect(self) -> Optional[Tuple[int, int, int, int]]:
283+
"""Get or set the mouse confinement area when the window has mouse focus.
284+
285+
Setting this will not automatically grab the cursor.
286+
287+
.. versionadded:: unreleased
288+
"""
289+
_version_at_least((2, 0, 18))
290+
rect = lib.SDL_GetWindowMouseRect(self.p)
291+
return (rect.x, rect.y, rect.w, rect.h) if rect else None
292+
293+
@mouse_rect.setter
294+
def mouse_rect(self, rect: Optional[Tuple[int, int, int, int]]) -> None:
295+
_version_at_least((2, 0, 18))
296+
_check(lib.SDL_SetWindowMouseRect(self.p, (rect,) if rect else ffi.NULL))
297+
281298
@_required_version((2, 0, 16))
282299
def flash(self, operation: FlashOperation = FlashOperation.UNTIL_FOCUSED) -> None:
283300
"""Get the users attention."""

0 commit comments

Comments
 (0)