Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-09-10 01:45:47 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-09-10 01:45:47 (GMT)
commit1e9c3e900dd1d8331cad06ca5a8b4ae151d65f41 (patch)
treeca68dc05a9c9d0fde8f1d989705a29c9d505ed29 /src
parenta7e975a920e9f44640a70b041babf8df2039c79c (diff)
centre text on multilabel
Diffstat (limited to 'src')
-rwxr-xr-xsrc/api/MultiLabel.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/api/MultiLabel.py b/src/api/MultiLabel.py
index 962fb19..3dee9de 100755
--- a/src/api/MultiLabel.py
+++ b/src/api/MultiLabel.py
@@ -17,6 +17,10 @@ class CMultiLabel(CLabel):
def __init__(self, fontName = "DejaVuSans.ttf", transparent=False):
CLabel.__init__(self, fontName, transparent)
+ self.vSize = 35
+
+ def set_vertical(self, aVer=35):
+ self.vSize = aVer
def _update_image(self):
self.image = pygame.Surface(self.size)
@@ -25,7 +29,9 @@ class CMultiLabel(CLabel):
self.image.set_colorkey(self.bgColor)
textLines = self.text.split('\n')
numLines = len(textLines)
- vSize = self.image.get_height() / numLines
+ #self.vSize = self.image.get_height() / numLines
+ total_text_height = self.vSize * numLines
+ fix = (self.image.get_height() - total_text_height) / 2
for lineNum in range(numLines):
currentLine = textLines[lineNum]
if self.transparent:
@@ -34,6 +40,6 @@ class CMultiLabel(CLabel):
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
+ yPos = lineNum * self.vSize + fix
self.image.blit(fontSurface, (xPos, yPos))
self.update()