Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-08-22 01:56:35 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-08-22 01:56:35 (GMT)
commitae47ccaa299db13cc9cf26f6dea7411bdf014086 (patch)
tree1c8676b7e7cf3c0746af481b3dd960f0b633cc39 /src/api
parent7bfe0e94ce8981a69f01123b37ae73202122de7b (diff)
update Globe to resize method
Diffstat (limited to 'src/api')
-rw-r--r--src/api/Globe.py99
1 files changed, 50 insertions, 49 deletions
diff --git a/src/api/Globe.py b/src/api/Globe.py
index 6ab6bee..e57931f 100644
--- a/src/api/Globe.py
+++ b/src/api/Globe.py
@@ -18,24 +18,36 @@ class Globe(pygame.sprite.Sprite):
size: (width, height) of label
"""
- def __init__(self, size, text = '', fontName = "freesansbold.ttf"):
+ def __init__(self, size, text = '', pico='left', fontName = "freesansbold.ttf"):
pygame.sprite.Sprite.__init__(self)
+
self.font = pygame.font.Font(fontName, 20)
- h = size[0]
- v = size[1]
+ self.size = size
+ self.image = None
+ self.mImageMaster = None
+ self.text = text
+ self.center = (0, 0)
+ self.mPico = pico
+ self.fgColor = (0, 0, 0)
- up_left = Image.loadImage(path + 'esquina-up-left.png')
- up_right = Image.loadImage(path + 'esquina-up-right.png')
- down_left = Image.loadImage(path + 'esquina-down-left.png')
- down_right = Image.loadImage(path + 'esquina-down-right.png')
- up = Image.loadImage(path + 'borde-sin-sombra.png')
- down = Image.loadImage(path + 'borde-con-sombra.png')
- center = Image.loadImage(path + 'fondo.png')
- left = pygame.transform.rotate(up, 90)
- right = pygame.transform.rotate(down, 90)
- pico_der = Image.loadImage(path + 'pico-der.png')
- pico_izq = Image.loadImage(path + 'pico-izq.png')
+ 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
@@ -52,57 +64,44 @@ class Globe(pygame.sprite.Sprite):
y = j * 34
if (i == 0):
if (j == 0):
- self.image.blit(up_left, (x, y))
+ self.image.blit(self.mup_left, (x, y))
elif (j==(vertical - 1)):
- self.image.blit(down_left, (x, y))
+ self.image.blit(self.mdown_left, (x, y))
else:
- self.image.blit(left, (x, y))
+ self.image.blit(self.mleft, (x, y))
elif (i == (horizontal - 1)):
if (j == 0):
- self.image.blit(up_right, (x, y))
+ self.image.blit(self.mup_right, (x, y))
elif (j == (vertical - 1)):
- self.image.blit(down_right, (x, y))
+ self.image.blit(self.mdown_right, (x, y))
else:
- self.image.blit(right, (x, y))
+ self.image.blit(self.mright, (x, y))
elif (j == 0):
if not(i == 0) and not(i == (horizontal-1)):
- self.image.blit(up, (x, y))
+ self.image.blit(self.mup, (x, y))
elif (j == (vertical -1)):
if not(i == 0) and not(i == (horizontal-1)):
- self.image.blit(down, (x, y))
+ self.image.blit(self.mdown, (x, y))
else:
- self.image.blit(center, (x, y))
+ self.image.blit(self.mcenter, (x, y))
px = (h - 68) / 2
py = v - 74
- self.image.blit(pico_der, (px, py))
+ 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 = pygame.Surface((34, 34))
- #self.image.blit(down_right, (0, 0))
self.image.set_colorkey((255,255,255))
- #self.image = self.image.convert_alpha((255, 255, 255))
- #self.text = ""
- """self.fgColor = ((0x00, 0x00, 0x00))
- self.bgColor = ((0xFF, 0xFF, 0xFF))"""
- self.center = (200, 200)
- self.size = (34, 34)
- self.text = text
- x = h / 2
- y = 25
- lines = self.text.split("\n")
- for l in lines:
- text = self.font.render(l.strip(), 1, (0, 0, 0))
- textrect = text.get_rect()
- textrect.center = (x,y)
- self.image.blit(text, textrect)
- y = y + self.font.get_height() + 15
-
+ 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):
@@ -118,12 +117,14 @@ class Globe(pygame.sprite.Sprite):
self._update_image()
def _update_image(self):
- self.image = pygame.Surface(self.size)
- self.image.fill(self.bgColor)
- fontSurface = self.font.render(self.text, True, self.fgColor, self.bgColor)
- #center the text
- xPos = (self.image.get_width() - fontSurface.get_width())/2
- self.image.blit(fontSurface, (xPos, 0))
+ 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()