blob: 6be00da982b2a4827465d509b2de5eef75ca9d0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
|