From 398eebe7829622c6983cb28528f2208b4d596f32 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Wed, 20 Mar 2024 16:59:13 +0200 Subject: text to srites. cache scaled font sprites... --- src/sliceitoff/display/display.py | 12 +++++++++++- src/sliceitoff/display/scaling.py | 32 +++++++++++++++++++++++++++++++- src/sliceitoff/display/static.py | 4 ++-- 3 files changed, 44 insertions(+), 4 deletions(-) (limited to 'src/sliceitoff/display') diff --git a/src/sliceitoff/display/display.py b/src/sliceitoff/display/display.py index 54b1586..2d6605f 100644 --- a/src/sliceitoff/display/display.py +++ b/src/sliceitoff/display/display.py @@ -1,9 +1,12 @@ +import os import pygame from stats import Stats from .scaling import Scaling +DEBUG = os.getenv("DEBUG") + class Display(): def __init__(self): @@ -14,10 +17,17 @@ class Display(): pygame.FULLSCREEN | pygame.SCALED, vsync = 1 ) Scaling.update_scaling(self.screen.get_size()) + self.screen.fill(Stats.bordercolor) + if DEBUG: + print( + "DISPLAY: \n" + f" {Scaling.active = }\n" + f" {Scaling.border = }\n" + f" {Scaling.factor = }\n") def update(self, groups = None): """ Updates the screen: clear, blit gropus and flip """ - self.screen.fill(Stats.bgcolor) + self.screen.fill(Stats.bgcolor, rect=Scaling.active) for group in groups: group.draw(self.screen) pygame.display.flip() diff --git a/src/sliceitoff/display/scaling.py b/src/sliceitoff/display/scaling.py index af307d1..f40d33c 100644 --- a/src/sliceitoff/display/scaling.py +++ b/src/sliceitoff/display/scaling.py @@ -6,6 +6,8 @@ class Scaling(): factor = 0.02 left = 0 top = 0 + borders = (pygame.Rect(0,0,0,0), pygame.Rect(0,0,0,0)) + active = pygame.Rect(0,0,0,0) @staticmethod def area_to_rect(area: tuple) -> pygame.Rect: @@ -40,8 +42,36 @@ class Scaling(): __class__.factor = size[0] / INTERNAL_WIDTH __class__.left = 0 __class__.top = (size[1] - INTERNAL_HEIGHT * __class__.factor) // 2 + __class__.border = ( + pygame.Rect( + 0, + 0, + size[0], + __class__.top), + pygame.Rect( + 0, + size[1] - __class__.top, + size[0], + __class__.top), + ) 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 + __class__.border = ( + pygame.Rect( + 0, + 0, + __class__.left, + size[1]), + pygame.Rect( + size[0] - __class__.left, + 0, + __class__.left, + size[1]), + ) + __class__.active = pygame.Rect( + __class__.left, + __class__.top, + INTERNAL_WIDTH * __class__.factor, + INTERNAL_HEIGHT * __class__.factor) diff --git a/src/sliceitoff/display/static.py b/src/sliceitoff/display/static.py index af1cc67..a9f487a 100644 --- a/src/sliceitoff/display/static.py +++ b/src/sliceitoff/display/static.py @@ -1,2 +1,2 @@ -INTERNAL_WIDTH = 400_000 -INTERNAL_HEIGHT = 300_000 +INTERNAL_WIDTH = 320_000 +INTERNAL_HEIGHT = 240_000 -- cgit v1.2.3