_
This commit is contained in:
25
UI/Objects/Scene.py
Normal file
25
UI/Objects/Scene.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pygame.transform
|
||||
from Objects.Screen import Screen
|
||||
from numpy import array as a
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Scene(Screen):
|
||||
def __init__(self, width: float, height: float, font_size: int, screen_size: a, bg=(60, 60, 60)):
|
||||
super().__init__(width, height, font_size, screen_size)
|
||||
|
||||
self.bg = bg
|
||||
self.r_objects = [] # resizable Objects
|
||||
self.nr_objects = [] # non-resizable Objects
|
||||
|
||||
def redraw(self):
|
||||
self.s_.fill(self.bg)
|
||||
|
||||
for object_ in self.r_objects:
|
||||
object_.blit()
|
||||
|
||||
rs = pygame.transform.scale(self.s_, self.screen_size)
|
||||
self.s.blit(rs, [0, 0])
|
||||
|
||||
pygame.display.update()
|
||||
|
24
UI/Objects/Screen.py
Normal file
24
UI/Objects/Screen.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from numpy import array as a
|
||||
import numpy as np
|
||||
import pygame
|
||||
|
||||
|
||||
class Screen:
|
||||
def __init__(self, width: float, height: float, font_size: int, screen_size: a):
|
||||
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]
|
||||
])
|
||||
|
||||
self.s_ = pygame.Surface([width, height])
|
||||
self.s = pygame.display.set_mode(screen_size)
|
||||
|
||||
self.font_size = font_size
|
||||
|
||||
self.center = a([width, height]) / 2
|
15
UI/Objects/r_objects/Rect.py
Normal file
15
UI/Objects/r_objects/Rect.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pygame.draw
|
||||
from numpy import array as a
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Rect:
|
||||
def __init__(self, pos, size, color, scene):
|
||||
self.pos = pos
|
||||
self.size = size
|
||||
self.color = color
|
||||
self.rect = pygame.Rect(self.pos, self.size)
|
||||
self.scene = scene
|
||||
|
||||
def blit(self):
|
||||
pygame.draw.rect(self.scene.s_, self.color, self.rect)
|
Reference in New Issue
Block a user