Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-08-14 22:28:44 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-08-14 22:28:44 (GMT)
commit615089bacff53fa5d83702de380bb180d3be943f (patch)
tree39f75ffba32f599a43ad1abdc6209ac3b80288c2
parentb306f2a87009083d3fca0e95e9e6a20c685bba08 (diff)
allow transparent multilabel
-rwxr-xr-xsrc/api/MultiLabel.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/api/MultiLabel.py b/src/api/MultiLabel.py
index fdaaa3e..956adf3 100755
--- a/src/api/MultiLabel.py
+++ b/src/api/MultiLabel.py
@@ -13,7 +13,7 @@ class CMultiLabel(CSprite):
least 30 pixels per line (with the default font)
"""
- def __init__(self):
+ def __init__(self, transparent=False):
CSprite.__init__(self)
self.text = 'This\nis\nsample\ntext'
#self.font = pygame.font.Font("freesansbold.ttf", 20)
@@ -21,6 +21,7 @@ class CMultiLabel(CSprite):
self.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 20)
self.fgColor = ((0x00, 0x00, 0x00))
self.bgColor = ((0xFF, 0xFF, 0xFF))
+ self.transparent = transparent
self.center = (0, 0)
self.size = (300, 150)
self.createImage()
@@ -40,6 +41,8 @@ class CMultiLabel(CSprite):
def createImage(self):
self.image = pygame.Surface(self.size)
self.image.fill(self.bgColor)
+ if self.transparent:
+ self.image.set_colorkey(self.bgColor)
self.textLines = self.text.split('\n')
numLines = len(self.textLines)
@@ -47,8 +50,10 @@ class CMultiLabel(CSprite):
for lineNum in range(numLines):
currentLine = self.textLines[lineNum]
-
- fontSurface = self.font.render(currentLine, True, self.fgColor, self.bgColor)
+ if self.transparent:
+ fontSurface = self.font.render(currentLine, True, self.fgColor)
+ else:
+ fontSurface = self.font.render(currentLine, True, self.fgColor, self.bgColor)
#center the text
xPos = (self.image.get_width() - fontSurface.get_width())/2
yPos = lineNum * vSize