train-journey-visuals/display.py

44 lines
1.3 KiB
Python
Raw Normal View History

2024-04-17 15:35:07 +00:00
from typing import Optional
import pygame
class Display:
APP_NAME = "Train Journey"
def __init__(self, surf: pygame.Surface):
self.surf: pygame.Surface = surf
self.font: pygame.font.Font = pygame.font.SysFont("ubuntu", 20)
self._tooltip_surf: Optional[pygame.Surface] = None
def mainloop(self) -> None:
running = True
self.init_interactive()
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
elif event.key == pygame.K_s and event.mod & pygame.KMOD_CTRL:
path = "/tmp/image.jpg"
pygame.image.save(self.surf, path)
print(f"Saved as {path}")
pygame.display.set_caption(f"{self.APP_NAME} - {clock.get_fps():.2f}fps")
self.render()
pygame.display.flip()
clock.tick(30)
def init_interactive(self) -> None:
self._tooltip_surf = pygame.Surface(self.surf.get_size(), pygame.SRCALPHA)
def render(self) -> None:
pass