summaryrefslogtreecommitdiff
path: root/src/sliceitoff/display
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-29 16:46:50 +0200
committerViljami Ilola <+@hix.fi>2024-03-29 16:46:50 +0200
commit43a58a7be48208f8d87ee5256c84008a02425ecf (patch)
tree8fee5e83861b7b1a382b26da4a089dc6872aa5b2 /src/sliceitoff/display
parent505ca2dead48d80b15f64f316218502bdc54daea (diff)
docstring etc linting
Diffstat (limited to 'src/sliceitoff/display')
-rw-r--r--src/sliceitoff/display/__init__.py4
-rw-r--r--src/sliceitoff/display/colors.py21
-rw-r--r--src/sliceitoff/display/display.py11
-rw-r--r--src/sliceitoff/display/scaling.py7
-rw-r--r--src/sliceitoff/display/static.py21
5 files changed, 35 insertions, 29 deletions
diff --git a/src/sliceitoff/display/__init__.py b/src/sliceitoff/display/__init__.py
index 92f4d75..543636b 100644
--- a/src/sliceitoff/display/__init__.py
+++ b/src/sliceitoff/display/__init__.py
@@ -1,4 +1,4 @@
+""" display - All drawing to the display should happen here """
from .scaling import Scaling
from .display import Display
-from .static import INTERNAL_WIDTH, INTERNAL_HEIGHT
-from .colors import CGA_COLORS
+from .static import INTERNAL_WIDTH, INTERNAL_HEIGHT, CGA_COLORS
diff --git a/src/sliceitoff/display/colors.py b/src/sliceitoff/display/colors.py
deleted file mode 100644
index f8747c0..0000000
--- a/src/sliceitoff/display/colors.py
+++ /dev/null
@@ -1,21 +0,0 @@
-""" text.colors - colors are defined here """
-
-CGA_COLORS=[
- (0x00,0x00,0x00,0xFF),
- (0x00,0x00,0xAA,0xFF),
- (0x00,0xAA,0x00,0xFF),
- (0x00,0xAA,0xAA,0xFF),
- (0xAA,0x00,0x00,0xFF),
- (0xAA,0x00,0xAA,0xFF),
- (0xAA,0x55,0x00,0xFF),
- (0xAA,0xAA,0xAA,0xFF),
- (0x55,0x55,0x55,0xFF),
- (0x55,0x55,0xFF,0xFF),
- (0x55,0xFF,0x55,0xFF),
- (0x55,0xFF,0xFF,0xFF),
- (0xFF,0x55,0x55,0xFF),
- (0xFF,0x55,0xFF,0xFF),
- (0xFF,0xFF,0x55,0xFF),
- (0xFF,0xFF,0xFF,0xFF)
-]
-
diff --git a/src/sliceitoff/display/display.py b/src/sliceitoff/display/display.py
index bdb2514..65b4713 100644
--- a/src/sliceitoff/display/display.py
+++ b/src/sliceitoff/display/display.py
@@ -1,13 +1,15 @@
+""" display.display - Routines to init and display graphics on screen """
import os
import pygame
from .scaling import Scaling
-from .colors import CGA_COLORS
+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()
@@ -16,7 +18,6 @@ class Display():
pygame.FULLSCREEN | pygame.SCALED,
vsync = 1 )
Scaling.update_scaling(self.screen.get_size())
- #self.screen.fill(0)
if DEBUG:
print(
"DISPLAY: \n"
@@ -24,6 +25,9 @@ class Display():
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)
@@ -32,6 +36,3 @@ class Display():
self.screen.fill(0, rect=Scaling.borders[0])
self.screen.fill(0, rect=Scaling.borders[1])
pygame.display.flip()
-
- def __del__(self):
- pygame.display.quit()
diff --git a/src/sliceitoff/display/scaling.py b/src/sliceitoff/display/scaling.py
index ddc897f..b4292b4 100644
--- a/src/sliceitoff/display/scaling.py
+++ b/src/sliceitoff/display/scaling.py
@@ -1,8 +1,11 @@
+""" display.scaling - for converting internal resolution to actual screen """
+
import pygame
from .static import INTERNAL_WIDTH, INTERNAL_HEIGHT
class Scaling():
+ """ Holds data and methods needed for coordinate conversion """
factor = 0.02
left = 0
top = 0
@@ -10,7 +13,7 @@ class Scaling():
center = (0,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:
""" converts area coordinates to pygame.Rect"""
@@ -40,6 +43,8 @@ class Scaling():
@staticmethod
def update_scaling(size: tuple) -> None:
+ """ Calculates new scaling and positionin according given
+ actual resolution """
__class__.resolution = size
__class__.center = (size[0]/2,size[1]/2)
if size[0] / size[1] <= INTERNAL_WIDTH / INTERNAL_HEIGHT:
diff --git a/src/sliceitoff/display/static.py b/src/sliceitoff/display/static.py
index a9f487a..8791fb0 100644
--- a/src/sliceitoff/display/static.py
+++ b/src/sliceitoff/display/static.py
@@ -1,2 +1,23 @@
+""" display.static - static data like resolution and colors defined here """
+
INTERNAL_WIDTH = 320_000
INTERNAL_HEIGHT = 240_000
+
+CGA_COLORS=[
+ (0x00,0x00,0x00,0xFF),
+ (0x00,0x00,0xAA,0xFF),
+ (0x00,0xAA,0x00,0xFF),
+ (0x00,0xAA,0xAA,0xFF),
+ (0xAA,0x00,0x00,0xFF),
+ (0xAA,0x00,0xAA,0xFF),
+ (0xAA,0x55,0x00,0xFF),
+ (0xAA,0xAA,0xAA,0xFF),
+ (0x55,0x55,0x55,0xFF),
+ (0x55,0x55,0xFF,0xFF),
+ (0x55,0xFF,0x55,0xFF),
+ (0x55,0xFF,0xFF,0xFF),
+ (0xFF,0x55,0x55,0xFF),
+ (0xFF,0x55,0xFF,0xFF),
+ (0xFF,0xFF,0x55,0xFF),
+ (0xFF,0xFF,0xFF,0xFF)
+]