From 3d1e8a068f98a32e0146d8e9ab58dea49fbb4c74 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sat, 16 Mar 2024 15:11:12 +0200 Subject: controls and gamelogic draft --- src/sliceitoff/display/scaling.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/sliceitoff/display') 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,11 +17,23 @@ 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: @@ -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 -- cgit v1.2.3