comparison mamba/widgets/levelbutton.py @ 322:86c5c6afdac0

Thumbnails on the level screen
author Stefano Rivera <stefano@rivera.za.net>
date Fri, 16 Sep 2011 20:01:13 +0200
parents fba74abad7b7
children cbbba6ddc77d
comparison
equal deleted inserted replaced
321:014aa3a97b2c 322:86c5c6afdac0
13 super(LevelButton, self).__init__(rect) 13 super(LevelButton, self).__init__(rect)
14 self.level = level 14 self.level = level
15 self.text = level.name 15 self.text = level.name
16 self.done = done 16 self.done = done
17 self.focussable = True 17 self.focussable = True
18 self.border = 3 18 self.border = 2
19 self.rect.width = 50 19 self.rect.width = 100
20 self.rect.height = 50 20 self.rect.height = 100
21 self.prepare() 21 self.prepare()
22 22
23 def prepare(self): 23 def prepare(self):
24 self.surface = pygame.Surface(self.rect.size, SRCALPHA) 24 self.surface = pygame.Surface(self.rect.size, SRCALPHA)
25 self.surface.fill(0) 25 self.surface.fill(0)
26 26
27 # Level Thumbnail
28 level_surface = pygame.Surface(self.level.get_size(), SRCALPHA)
29 self.level.draw(level_surface)
30 dest_rect = pygame.Rect((self.border, self.border),
31 (self.rect.width - self.border,
32 self.rect.height - self.border))
33 size = level_surface.get_rect().fit(dest_rect).size
34 level_thumbnail = pygame.transform.scale(level_surface, size)
35 self.surface.blit(level_thumbnail, dest_rect)
36
27 if self.done: 37 if self.done:
28 image = load_image('menus/tick.png') 38 image = load_image('menus/tick.png')
29 self.surface.blit(image, image.get_rect()) 39 self.surface.blit(image, image.get_rect())
30 40
31 self._text = TextWidget((0, 0), self.text, fontsize=24) 41 self._text = TextWidget((0, 0), self.text, fontsize=12)
32 self._text.prepare() 42 self._text.prepare()
43 text_rect = pygame.Rect((0, 0), self.rect.size).inflate(
44 self._text.rect.width - self.rect.width,
45 self._text.rect.height - self.rect.height)
46 text_rect.top = self.rect.height - self._text.rect.height - self.border
47 self.surface.blit(self._text.surface, text_rect)
33 48
34 color = pygame.Color(FOCUS_COLOR if self.focussed else COLOR) 49 color = pygame.Color(FOCUS_COLOR if self.focussed else COLOR)
35 pygame.draw.rect(self.surface, color, self.surface.get_rect(), 50 pygame.draw.rect(self.surface, color, self.surface.get_rect(),
36 self.border) 51 self.border + 1)
37 text_rect = pygame.Rect((0, 0), self.rect.size).inflate(
38 self._text.rect.width - self.rect.width,
39 self._text.rect.height - self.rect.height)
40 self.surface.blit(self._text.surface, text_rect)
41 self._state = (self.done, self.focussed) 52 self._state = (self.done, self.focussed)
42 53
43 def draw(self, surface): 54 def draw(self, surface):
44 if self._state != (self.done, self.focussed): 55 if self._state != (self.done, self.focussed):
45 self.prepare() 56 self.prepare()