Info_edupage/UI/Objects/Screen.py

57 lines
1.7 KiB
Python
Raw Normal View History

2021-09-01 11:26:29 +02:00
from numpy import array as a
2021-09-03 16:44:18 +02:00
import math
2021-09-01 11:26:29 +02:00
import pygame
class Screen:
2021-09-01 22:22:18 +02:00
def __init__(self, width: float, height: float, screen_size: a):
2021-09-01 11:26:29 +02:00
pygame.init()
self.width = width
self.height = height
self.size = a([float(width), float(height)])
self.screen_size = a(screen_size)
self.matrix = a([
[screen_size[0] / width, 0],
[0, screen_size[1] / height]
])
2021-09-02 22:25:45 +02:00
self.inverse_matrix = a([
[1 / self.matrix[0, 0], 0],
[0, 1 / self.matrix[1, 1]]
])
2021-09-01 17:32:53 +02:00
self.pd = abs(self.matrix[0, 0] * self.matrix[1, 1]) # positive determinant
self.pd_ = math.sqrt(self.pd)
2021-09-01 11:26:29 +02:00
self.s_ = pygame.Surface([width, height])
self.s = pygame.display.set_mode(screen_size)
self.center = a([width, height]) / 2
2021-09-01 17:32:53 +02:00
2021-09-02 19:56:28 +02:00
def resize_screen(self, new_screen_size, subscene=False):
self.screen_size = a(new_screen_size)
self.matrix = a([
[new_screen_size[0] / self.width, 0],
[0, new_screen_size[1] / self.height]
])
2021-09-02 22:25:45 +02:00
self.inverse_matrix = a([
[1 / self.matrix[0, 0], 0],
[0, 1 / self.matrix[1, 1]]
])
2021-09-02 19:56:28 +02:00
self.pd = abs(self.matrix[0, 0] * self.matrix[1, 1]) # positive determinant
self.pd_ = math.sqrt(self.pd)
if subscene is False:
self.s = pygame.display.set_mode(new_screen_size)
else:
self.s = pygame.Surface(new_screen_size)
2021-09-01 22:22:18 +02:00
def save(self, path, size=None):
if size is None:
pygame.image.save(self.s, path)
else:
surface = pygame.Surface(size)
surface.blit(self.s, [0, 0])
pygame.image.save(surface, path)