From 1e9c3e900dd1d8331cad06ca5a8b4ae151d65f41 Mon Sep 17 00:00:00 2001 From: Alan Aguiar Date: Tue, 10 Sep 2013 01:45:47 +0000 Subject: centre text on multilabel --- 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() -- cgit v0.9.1