Skip to content

Commit 84d37e2

Browse files
committed
Add missing MouseButtonEvent.integer_position property
1 parent a954fa3 commit 84d37e2

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
### Added
10+
11+
- `MouseButtonEvent.integer_position` property.
12+
13+
## Fixed
14+
15+
- `integer_position` was missing from mouse button events.
16+
917
## [21.0.0] - 2026-03-13
1018

1119
### Added

tcod/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ def convert_event(self, event: _Event) -> _Event:
255255
Now returns a new event with the coordinates converted into tiles.
256256
"""
257257
event_copy = copy.copy(event)
258-
if isinstance(event, (tcod.event.MouseState, tcod.event.MouseMotion)):
259-
assert isinstance(event_copy, (tcod.event.MouseState, tcod.event.MouseMotion))
258+
if isinstance(event, (tcod.event.MouseState, tcod.event.MouseMotion, tcod.event.MouseButtonEvent)):
259+
assert isinstance(event_copy, (tcod.event.MouseState, tcod.event.MouseMotion, tcod.event.MouseButtonEvent))
260260
event_copy.position = tcod.event.Point(*self.pixel_to_tile(event.position[0], event.position[1]))
261261
event._tile = tcod.event.Point(floor(event_copy.position[0]), floor(event_copy.position[1]))
262262
if isinstance(event, tcod.event.MouseMotion):

tcod/event.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,15 @@ class MouseButtonEvent(Event):
652652
.. versionadded:: 21.0
653653
"""
654654

655+
@property
656+
def integer_position(self) -> Point[int]:
657+
"""Integer coordinates of this event.
658+
659+
.. versionadded:: Unreleased
660+
"""
661+
x, y = self.position
662+
return Point(floor(x), floor(y))
663+
655664
@classmethod
656665
def _from_sdl_event(cls, sdl_event: _C_SDL_Event) -> Self:
657666
button = sdl_event.button

0 commit comments

Comments
 (0)