1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# -*- coding: utf-8 -*-
import pygame
class CMultiLabel(pygame.sprite.Sprite):
""" accepts a list of strings, creates a multi-line
label to display text
same properties as label except textLines
is a list of strings. There is no text
property.
Set the size manually. Vertical size should be at
least 30 pixels per line (with the default font)
"""
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.textLines = ["This", "is", "sample", "text"]
#self.font = pygame.font.Font("freesansbold.ttf", 20)
#TODO: Esto no debe ir aca. Porque este no anda y el de CSuperSprite si ?
#pygame.font.init()
#print "CMultilabel"
#print pygame.font.get_init()
self.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 30)
self.fgColor = ((0x00, 0x00, 0x00))
self.bgColor = ((0xFF, 0xFF, 0xFF))
self.center = (100, 100)
self.size = (150, 100)
self.createImage()
def createImage(self):
self.image = pygame.Surface(self.size)
self.image.fill(self.bgColor)
numLines = len(self.textLines)
vSize = self.image.get_height() / numLines
for lineNum in range(numLines):
currentLine = self.textLines[lineNum]
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
self.image.blit(fontSurface, (xPos, yPos))
self.rect = self.image.get_rect()
self.rect.center = self.center
#def update(self):
#print "update de multilabel"
|