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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# -*- coding: utf-8 -*-
import pygame
import Image
path = 'assets/images/dialog/'
class Globe(pygame.sprite.Sprite):
""" a basic label
properties:
font: font to use
text: text to display
fgColor: foreground color
bgColor: background color
center: position of label's center
size: (width, height) of label
"""
def __init__(self, size, text = '', pico='left', fontName = "freesansbold.ttf"):
pygame.sprite.Sprite.__init__(self)
self.font = pygame.font.Font(fontName, 20)
self.size = size
self.image = None
self.mImageMaster = None
self.text = text
self.center = (0, 0)
self.mPico = pico
self.fgColor = (0, 0, 0)
self.mup_left = Image.loadImage(path + 'esquina-up-left.png')
self.mup_right = Image.loadImage(path + 'esquina-up-right.png')
self.mdown_left = Image.loadImage(path + 'esquina-down-left.png')
self.mdown_right = Image.loadImage(path + 'esquina-down-right.png')
self.mup = Image.loadImage(path + 'borde-sin-sombra.png')
self.mdown = Image.loadImage(path + 'borde-con-sombra.png')
self.mcenter = Image.loadImage(path + 'fondo.png')
self.mleft = pygame.transform.rotate(self.mup, 90)
self.mright = pygame.transform.rotate(self.mdown, 90)
self.mpico_der = Image.loadImage(path + 'pico-der.png')
self.mpico_izq = Image.loadImage(path + 'pico-izq.png')
self._create_image()
self._update_image()
def _create_image(self):
h = self.size[0]
v = self.size[1]
horizontal = (h - 68) / 34
vertical = (v - 68) / 34
horizontal = horizontal + 2
vertical = vertical + 2
h = horizontal * 34
v = vertical * 34 + 40
self.image = pygame.Surface((h, v))
self.image.fill((255,255,255))
for i in range(horizontal):
for j in range(vertical):
x = i * 34
y = j * 34
if (i == 0):
if (j == 0):
self.image.blit(self.mup_left, (x, y))
elif (j==(vertical - 1)):
self.image.blit(self.mdown_left, (x, y))
else:
self.image.blit(self.mleft, (x, y))
elif (i == (horizontal - 1)):
if (j == 0):
self.image.blit(self.mup_right, (x, y))
elif (j == (vertical - 1)):
self.image.blit(self.mdown_right, (x, y))
else:
self.image.blit(self.mright, (x, y))
elif (j == 0):
if not(i == 0) and not(i == (horizontal-1)):
self.image.blit(self.mup, (x, y))
elif (j == (vertical -1)):
if not(i == 0) and not(i == (horizontal-1)):
self.image.blit(self.mdown, (x, y))
else:
self.image.blit(self.mcenter, (x, y))
px = (h - 68) / 2
py = v - 74
if self.mPico == 'left':
self.image.blit(self.mpico_izq, (px, py))
elif self.mPico == 'right':
self.image.blit(self.mpico_der, (px, py))
self.image.set_colorkey((255,255,255))
self.mImageMaster = self.image.copy()
def set_center(self, aCenter):
self.center = aCenter
def set_size(self, aSize):
self.size = aSize
self._create_image()
self._update_image()
def set_fgColor(self, afgColor):
self.fgColor = afgColor
self._update_image()
def set_bgColor(self, abgColor):
self.bgColor = abgColor
self._update_image()
def set_text(self, aText):
self.text = aText
self._update_image()
def _update_image(self):
self.image = self.mImageMaster.copy()
y = 25
lines = self.text.split("\n")
for l in lines:
text = self.font.render(l.strip(), 1, self.fgColor)
xPos = (self.image.get_width() - text.get_width())/2
self.image.blit(text, (xPos, y))
y = y + self.font.get_height() + 15
def update(self):
self.rect = self.image.get_rect()
self.rect.center = self.center
|