summaryrefslogtreecommitdiff
path: root/src/sliceitoff/display/display.py
blob: 65b4713f9f6bc3828b4a2e7b11dc5c47e457daeb (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
37
38
""" display.display - Routines to init and display graphics on screen """
import os
import pygame

from .scaling import Scaling
from .static import CGA_COLORS

DEBUG = os.getenv("DEBUG")


class Display():
    """display.Display - Handles graphics. Init, clear, draw, borders... """
    def __init__(self):
        pygame.display.init()
        mode_info = pygame.display.Info()
        self.screen = pygame.display.set_mode(
                (mode_info.current_w, mode_info.current_h),
                pygame.FULLSCREEN | pygame.SCALED,
                vsync = 1 )
        Scaling.update_scaling(self.screen.get_size())
        if DEBUG:
            print(
                    "DISPLAY: \n"
                    f"  {Scaling.active = }\n"
                    f"  {Scaling.borders = }\n"
                    f"  {Scaling.factor = }\n")

    def __del__(self):
        pygame.display.quit()

    def update(self, groups = None):
        """ Updates the screen: clear, blit gropus and flip """
        self.screen.fill(CGA_COLORS[4], rect=Scaling.active)
        for group in groups:
            group.draw(self.screen)
        self.screen.fill(0, rect=Scaling.borders[0])
        self.screen.fill(0, rect=Scaling.borders[1])
        pygame.display.flip()