diff options
-rw-r--r-- | src/sliceitoff/display/__init__.py | 4 | ||||
-rw-r--r-- | src/sliceitoff/display/colors.py | 21 | ||||
-rw-r--r-- | src/sliceitoff/display/display.py | 11 | ||||
-rw-r--r-- | src/sliceitoff/display/scaling.py | 7 | ||||
-rw-r--r-- | src/sliceitoff/display/static.py | 21 | ||||
-rw-r--r-- | src/sliceitoff/text/__init__.py | 1 | ||||
-rw-r--r-- | src/sliceitoff/text/text.py | 21 |
7 files changed, 55 insertions, 31 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) +] diff --git a/src/sliceitoff/text/__init__.py b/src/sliceitoff/text/__init__.py index 6392649..082179e 100644 --- a/src/sliceitoff/text/__init__.py +++ b/src/sliceitoff/text/__init__.py @@ -1,2 +1,3 @@ +""" text - fonts, letters, texts and related """ from .text import TextPage, LetterSprite from .fonts import Font, Fonts diff --git a/src/sliceitoff/text/text.py b/src/sliceitoff/text/text.py index 198ff4f..85958e0 100644 --- a/src/sliceitoff/text/text.py +++ b/src/sliceitoff/text/text.py @@ -1,3 +1,4 @@ +""" text.text - letters, texts and scaling and coloring of fonts """ import pygame from random import randrange @@ -7,6 +8,13 @@ from display import Scaling, CGA_COLORS scaled_fonts = {} class LetterSprite(pygame.sprite.Sprite): + """ Single letter at given properties hopefully from cache + + args: + font_key: (font name, width to scale, color) + ch: 0-255 character on cp473 + color: 0-15 as in CGA palette + """ def __init__(self, font_key, ch, pos): super().__init__() self.dead = True @@ -25,7 +33,7 @@ class LetterSprite(pygame.sprite.Sprite): self.direction = ( Scaling.factor * (1_000 - randrange(2_000)), Scaling.factor * (1_000 - randrange(2_000))) - + def update(self, dt = 0, explode = 0, **kwargs): if explode and dt: self.rect = pygame.Rect( @@ -36,9 +44,18 @@ class LetterSprite(pygame.sprite.Sprite): self.direction = ( self.direction[0] * 0.95, self.direction[1] * 0.95 + 0.3) - class TextPage(pygame.sprite.Group): + """ Creates sprite group out of given text and parameters + + args: + + text Just text. \xe0 - \xef to cahnge color on cga palette + pos Position of right top corner in internal cooordinates + size Single character size (w,h) + grid Space for a character (w,h) + font Font loaded in Fonts.fonts dict + """ def __init__( self, text, |