summaryrefslogtreecommitdiff
path: root/src/sliceitoff/display
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-16 11:11:56 +0200
committerViljami Ilola <+@hix.fi>2024-03-16 11:11:56 +0200
commit85adc89f53763b4390f7e51161a05ab394143152 (patch)
treeb63de708a75d7ea3fd961f8d63ca2af381cb66c5 /src/sliceitoff/display
parent5d921239e0577988e2b7814025149d9160ecbdda (diff)
drafting game components
Diffstat (limited to 'src/sliceitoff/display')
-rw-r--r--src/sliceitoff/display/__init__.py7
-rw-r--r--src/sliceitoff/display/display.py24
-rw-r--r--src/sliceitoff/display/static.py11
3 files changed, 40 insertions, 2 deletions
diff --git a/src/sliceitoff/display/__init__.py b/src/sliceitoff/display/__init__.py
index 6332319..296f519 100644
--- a/src/sliceitoff/display/__init__.py
+++ b/src/sliceitoff/display/__init__.py
@@ -1 +1,8 @@
from .display import Display
+from .static import (
+ Scaling,
+ INTERNAL_WIDTH,
+ INTERNAL_HEIGHT,
+ INTERNAL_ASPECT)
+
+
diff --git a/src/sliceitoff/display/display.py b/src/sliceitoff/display/display.py
index 151bb11..af61d49 100644
--- a/src/sliceitoff/display/display.py
+++ b/src/sliceitoff/display/display.py
@@ -1,16 +1,36 @@
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.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()
+ self.screen.fill("magenta")
+ for group in groups:
+ group.draw(self.screen)
pygame.display.flip()
def __del__(self):
diff --git a/src/sliceitoff/display/static.py b/src/sliceitoff/display/static.py
new file mode 100644
index 0000000..43dc385
--- /dev/null
+++ b/src/sliceitoff/display/static.py
@@ -0,0 +1,11 @@
+from dataclasses import dataclass
+
+INTERNAL_WIDTH = 40000
+INTERNAL_HEIGHT = 30000
+INTERNAL_ASPECT = INTERNAL_WIDTH / INTERNAL_HEIGHT
+
+@dataclass
+class Scaling():
+ scale: float
+ left: int
+ top: int