summaryrefslogtreecommitdiff
path: root/src/sliceitoff/display/display.py
blob: af61d497dbfc6ac89d7cf911df8ef7c76c7e89f9 (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
import pygame

from .static import (
    Scaling,
    INTERNAL_WIDTH,
    INTERNAL_HEIGHT,
    INTERNAL_ASPECT)

class Display():
    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 )

    def get_scaling(self):
        w, h = self.screen.get_size()
        if w/h <= INTERNAL_ASPECT:
            scale = w / INTERNAL_WIDTH
            left = 0
            top = int((h - INTERNAL_HEIGHT * scale) / 2)
        else :
            scale = h / INTERNAL_HEIGHT
            left = int((w - INTERNAL_WIDTH * scale) / 2)
            top = 0
        return Scaling(scale, left, top)

    def update(self, groups = None):
        """ Updates the screen: clear, blit gropus and flip """
        self.screen.fill("magenta")
        for group in groups:
            group.draw(self.screen)
        pygame.display.flip()

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