Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2014-01-21 01:22:16 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2014-01-21 01:22:16 (GMT)
commit3e7f035b9526b0daaba740ee915c5f02332c867c (patch)
tree8507af7a73667fa6c1fae3d5e2b3425e69fef2e4 /src/api
parentb0b1d81a5de43653ba22e1ddc934f0b20c0a55f7 (diff)
simplify label and multilabel init
Diffstat (limited to 'src/api')
-rw-r--r--src/api/Label.py20
-rw-r--r--src/api/MultiLabel.py10
2 files changed, 16 insertions, 14 deletions
diff --git a/src/api/Label.py b/src/api/Label.py
index b5f3f70..86148c7 100644
--- a/src/api/Label.py
+++ b/src/api/Label.py
@@ -2,6 +2,8 @@
import pygame
font_path = 'assets/fonts/'
+default_font = 'assets/fonts/DejaVuSans.ttf'
+
class CLabel(pygame.sprite.Sprite):
""" a basic label
@@ -14,22 +16,25 @@ class CLabel(pygame.sprite.Sprite):
size: (width, height) of label
"""
- def __init__(self, fontName = "DejaVuSans.ttf", transparent=False):
+ def __init__(self):
pygame.sprite.Sprite.__init__(self)
- self.font = pygame.font.Font(font_path + fontName, 20)
+ self.font = pygame.font.Font(default_font, 20)
+ self.transparent = False
self.text = ""
self.fgColor = (0x00, 0x00, 0x00)
self.bgColor = (0xFF, 0xFF, 0xFF)
- self.transparent = transparent
self.center = (0, 0)
self.size = (0, 0)
+ self.image = pygame.surface.Surface((0, 0), 0)
+ self.rect = self.image.get_rect()
- def set_font(self, fontName = "DejaVuSans.ttf", fontSize= 20):
+ def set_font(self, fontName, fontSize = 20):
self.font = pygame.font.Font(font_path + fontName, fontSize)
self._update_image()
def set_center(self, aCenter):
self.center = aCenter
+ self.rect.center = self.center
def set_size(self, aSize):
self.size = aSize
@@ -57,15 +62,12 @@ class CLabel(pygame.sprite.Sprite):
fontSurface = self.font.render(self.text, True, self.fgColor)
else:
fontSurface = self.font.render(self.text, True, self.fgColor, self.bgColor)
- #center the text
xPos = (self.image.get_width() - fontSurface.get_width())/2
self.image.blit(fontSurface, (xPos, 0))
- self.update()
-
- def update(self):
self.rect = self.image.get_rect()
self.rect.center = self.center
-
+
def destroy(self):
self.font = None
self.image = None
+
diff --git a/src/api/MultiLabel.py b/src/api/MultiLabel.py
index 3dee9de..3180e89 100644
--- a/src/api/MultiLabel.py
+++ b/src/api/MultiLabel.py
@@ -3,8 +3,6 @@
import pygame
from api.Label import CLabel
-font_path = 'assets/fonts/'
-
class CMultiLabel(CLabel):
""" accepts a string separate with \n, creates a multi-line
label to display text
@@ -15,8 +13,8 @@ class CMultiLabel(CLabel):
least 30 pixels per line (with the default font)
"""
- def __init__(self, fontName = "DejaVuSans.ttf", transparent=False):
- CLabel.__init__(self, fontName, transparent)
+ def __init__(self):
+ CLabel.__init__(self)
self.vSize = 35
def set_vertical(self, aVer=35):
@@ -42,4 +40,6 @@ class CMultiLabel(CLabel):
xPos = (self.image.get_width() - fontSurface.get_width())/2
yPos = lineNum * self.vSize + fix
self.image.blit(fontSurface, (xPos, yPos))
- self.update()
+ self.rect = self.image.get_rect()
+ self.rect.center = self.center
+