summaryrefslogtreecommitdiff
path: root/src/sliceitoff/display/scaling.py
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-16 12:35:07 +0200
committerViljami Ilola <+@hix.fi>2024-03-16 12:35:07 +0200
commita23b6647b0ca2cd9f2ccbbe12360c3fa0f96a554 (patch)
treebab154622f9767fd340278ab275babb76fc569d5 /src/sliceitoff/display/scaling.py
parent1ad8357f0039292b929e66cf703b4314660aded2 (diff)
scaling as class
Diffstat (limited to 'src/sliceitoff/display/scaling.py')
-rw-r--r--src/sliceitoff/display/scaling.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/sliceitoff/display/scaling.py b/src/sliceitoff/display/scaling.py
new file mode 100644
index 0000000..6be00da
--- /dev/null
+++ b/src/sliceitoff/display/scaling.py
@@ -0,0 +1,36 @@
+import pygame
+
+from .static import INTERNAL_WIDTH, INTERNAL_HEIGHT
+
+class Scaling():
+ factor = 0.02
+ left = 0
+ top = 0
+
+ @staticmethod
+ def area_to_rect(area: tuple) -> pygame.Rect:
+ """ converts area coordinates to pygame.Rect"""
+ return pygame.Rect(
+ area[0] * __class__.factor + __class__.left,
+ area[1] * __class__.factor + __class__.top,
+ area[2] * __class__.factor,
+ area[3] * __class__.factor)
+
+ @staticmethod
+ def scale_coordinates(coords: tuple ) -> tuple:
+ return (
+ coords[0] * __class__.factor + __class__.left,
+ coords[1] * __class__.factor + __class__.top)
+
+ @staticmethod
+ def update_scaling(size: tuple) -> None:
+ if size[0] / size[1] <= INTERNAL_WIDTH / INTERNAL_HEIGHT:
+ __class__.factor = size[0] / INTERNAL_WIDTH
+ __class__.left = 0
+ __class__.top = (size[1] - INTERNAL_HEIGHT * __class__.factor) // 2
+ else:
+ __class__.factor = size[1] / INTERNAL_HEIGHT
+ __class__.left = (size[0] - INTERNAL_WIDTH * __class__.factor) // 2
+ __class__.top = 0
+
+ \ No newline at end of file