diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-16 15:11:12 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-16 15:11:12 +0200 |
commit | 3d1e8a068f98a32e0146d8e9ab58dea49fbb4c74 (patch) | |
tree | 013814df21967af7dc9dfb390fd6de9770799616 /src/sliceitoff/display | |
parent | 77d104cced553b8dfc9896cb456bd039807ed6c6 (diff) |
controls and gamelogic draft
Diffstat (limited to 'src/sliceitoff/display')
-rw-r--r-- | src/sliceitoff/display/scaling.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/sliceitoff/display/scaling.py b/src/sliceitoff/display/scaling.py index 6be00da..aad6c18 100644 --- a/src/sliceitoff/display/scaling.py +++ b/src/sliceitoff/display/scaling.py @@ -17,12 +17,24 @@ class Scaling(): area[3] * __class__.factor) @staticmethod - def scale_coordinates(coords: tuple ) -> tuple: + def scale_to_display(coords: tuple ) -> tuple: + """ Converts internal coordinates to display coodinates """ return ( coords[0] * __class__.factor + __class__.left, coords[1] * __class__.factor + __class__.top) @staticmethod + def scale_to_internal(coords: tuple ) -> tuple: + """ Converts display coordinates to internal coodinates """ + x = coords[0] - __class__.left + x = max(x, 0) / __class__.factor + x = min(x, INTERNAL_WIDTH - 1) + y = coords[1] - __class__.top + y = max(y, 0) / __class__.factor + y = min(y, INTERNAL_HEIGHT - 1) + return (x, y) + + @staticmethod def update_scaling(size: tuple) -> None: if size[0] / size[1] <= INTERNAL_WIDTH / INTERNAL_HEIGHT: __class__.factor = size[0] / INTERNAL_WIDTH @@ -32,5 +44,4 @@ class Scaling(): __class__.factor = size[1] / INTERNAL_HEIGHT __class__.left = (size[0] - INTERNAL_WIDTH * __class__.factor) // 2 __class__.top = 0 -
\ No newline at end of file |