summaryrefslogtreecommitdiff
path: root/src/sliceitoff/text
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-29 13:52:24 +0200
committerViljami Ilola <+@hix.fi>2024-03-29 13:52:24 +0200
commit063628a3c493df902af9cef4f56f726a9d4ee906 (patch)
tree3a9b95f1060cc5d4302b6ff86d2ddf9901dd361e /src/sliceitoff/text
parent4e88912ff032f1df77480ba37c82fb7049d1ff1b (diff)
refactor lettersrite and textpage; field explodes to letters
Diffstat (limited to 'src/sliceitoff/text')
-rw-r--r--src/sliceitoff/text/__init__.py2
-rw-r--r--src/sliceitoff/text/text.py31
2 files changed, 17 insertions, 16 deletions
diff --git a/src/sliceitoff/text/__init__.py b/src/sliceitoff/text/__init__.py
index e37e2e0..6392649 100644
--- a/src/sliceitoff/text/__init__.py
+++ b/src/sliceitoff/text/__init__.py
@@ -1,2 +1,2 @@
-from .text import TextPage
+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 dd9b719..198ff4f 100644
--- a/src/sliceitoff/text/text.py
+++ b/src/sliceitoff/text/text.py
@@ -7,9 +7,20 @@ from display import Scaling, CGA_COLORS
scaled_fonts = {}
class LetterSprite(pygame.sprite.Sprite):
- def __init__(self, image, pos):
+ def __init__(self, font_key, ch, pos):
super().__init__()
- self.image = image
+ self.dead = True
+ if font_key not in scaled_fonts:
+ scaled_fonts[font_key]=[None for _ in range(256)]
+ if scaled_fonts[font_key][ch] == None:
+ font, w, color = font_key
+ scaled_fonts[font_key][ch] = pygame.transform.scale_by(
+ Fonts.fonts[font].get(ch),
+ w/8 * Scaling.factor)
+ scaled_fonts[font_key][ch].fill(
+ CGA_COLORS[color],
+ special_flags = pygame.BLEND_RGBA_MULT)
+ self.image = scaled_fonts[font_key][ch]
self.rect = self.image.get_rect().move(pos)
self.direction = (
Scaling.factor * (1_000 - randrange(2_000)),
@@ -54,18 +65,8 @@ class TextPage(pygame.sprite.Group):
if ch in range(0xe0,0xf0):
color = ch - 0xe0
continue
- font_key = (font, w, color)
- if font_key not in scaled_fonts:
- scaled_fonts[font_key]=[None for _ in range(256)]
- if scaled_fonts[font_key][ch] == None:
- scaled_fonts[font_key][ch] = pygame.transform.scale_by(
- Fonts.fonts[font].get(ch),
- size[0]/8 * Scaling.factor)
- scaled_fonts[font_key][ch].fill(
- CGA_COLORS[color],
- special_flags = pygame.BLEND_RGBA_MULT)
- image = scaled_fonts[font_key][ch]
- image_pos = Scaling.scale_to_display( (x+col*w, y+row*h) )
- self.add(LetterSprite(image, image_pos))
+ font_key = (font, size[0], color)
+ sprite_pos = Scaling.scale_to_display( (x+col*w, y+row*h) )
+ self.add(LetterSprite(font_key, ch, sprite_pos))
col += 1
\ No newline at end of file