Mercurial > pyntnclick
comparison pyntnclick/widgets/base.py @ 717:3b2d1adca59c pyntnclick
Pull a bunch of draw logic out of rect_drawer and over to the widgets
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sun, 05 Aug 2012 21:50:34 +0200 |
parents | e9265818a96c |
children | efa58c92b304 |
comparison
equal
deleted
inserted
replaced
716:38f537b0ee82 | 717:3b2d1adca59c |
---|---|
1 import collections | 1 import collections |
2 | 2 |
3 import pygame | 3 import pygame |
4 from pygame.locals import (MOUSEBUTTONDOWN, MOUSEBUTTONUP, | 4 from pygame.locals import (MOUSEBUTTONDOWN, MOUSEBUTTONUP, |
5 MOUSEMOTION, SRCALPHA, USEREVENT) | 5 MOUSEMOTION, SRCALPHA, USEREVENT, |
6 BLEND_RGBA_MIN) | |
6 | 7 |
7 from pyntnclick.engine import UserEvent | 8 from pyntnclick.engine import UserEvent |
8 | 9 |
9 | 10 |
10 class Widget(object): | 11 class Widget(object): |
251 self.visible = True | 252 self.visible = True |
252 | 253 |
253 def draw(self, surface): | 254 def draw(self, surface): |
254 if self.visible: | 255 if self.visible: |
255 surface.blit(self.image, self.rect) | 256 surface.blit(self.image, self.rect) |
257 | |
258 | |
259 class TranslucentImage(Image): | |
260 """Image that can also be translucent""" | |
261 | |
262 def __init__(self, rect, gd, image): | |
263 super(TranslucentImage, self).__init__(rect, gd, image) | |
264 self.translucent = False | |
265 surf = pygame.surface.Surface((self.rect.width, self.rect.height), | |
266 SRCALPHA).convert_alpha() | |
267 surf.fill(pygame.color.Color(255, 255, 255, 96)) | |
268 surf.blit(self.image, (0, 0), None, BLEND_RGBA_MIN) | |
269 self.trans_image = surf | |
270 | |
271 def draw(self, surface): | |
272 if self.visible: | |
273 if self.translucent: | |
274 surface.blit(self.trans_image, self.rect) | |
275 else: | |
276 surface.blit(self.image, self.rect) |