70ff036160618b51c2c5cd3651310172a23f6a36
[tabakrolletjie.git] / tabakrolletjie / transforms.py
1 """ Image transformations for use with the image loader. """
2
3 import pygame.surface
4
5
6 class Transform(object):
7
8     ARGS = []
9
10     def __init__(self, **kw):
11         for k in self.ARGS:
12             setattr(self, k, kw.pop(k))
13         assert not kw
14         self.hash = "%s: <%s>" % (
15             self.__class__.__name__,
16             ", ".join("%s=%s" % (k, getattr(self, k)) for k in self.ARGS))
17         return
18
19     def apply(self, surface):
20         raise NotImplementedError("Transforms should implement .apply")
21
22
23 class NullTransform(Transform):
24     """ Do nothing. """
25
26     def apply(self, surface):
27         return surface
28
29
30 class Overlay(Transform):
31     """ Apply a colour overlay. """
32
33     ARGS = ["colour"]
34
35     def apply(self, surface):
36         over = pygame.surface.Surface(surface.get_size())
37         over = over.convert_alpha()
38         over.fill(self.colour)
39         surface.blit(over, (0, 0), None)
40         return surface