From: adrianna Date: Fri, 9 Sep 2016 20:22:53 +0000 (+0200) Subject: added a multiply transform to use on light fittings X-Git-Tag: tabakrolletjie-v1.0.0~151 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=8dbb5023b0bac0e31d81dcd3817f259e161176e5;p=tabakrolletjie.git added a multiply transform to use on light fittings --- diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index f1a69d6..9f0005d 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -12,6 +12,7 @@ from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY from .rays import RayPolyManager from .utils import DetailedTimer from .loader import loader +from .transforms import Multiply LIGHT_FILTER = pymunk.ShapeFilter( mask=pymunk.ShapeFilter.ALL_MASKS ^ ( @@ -203,9 +204,8 @@ class BaseLight(object): def get_image(self): if self._image is None: - self._image = loader.load_image("64", self.FITTING_IMG).copy() fitting_colour = self.COLOURS[self.colour] - self._image.fill(fitting_colour, None, pgl.BLEND_RGBA_MULT) + self._image = loader.load_image("64", self.FITTING_IMG, transform=Multiply(colour=fitting_colour)) return self._image def render_fitting(self, surface): diff --git a/tabakrolletjie/transforms.py b/tabakrolletjie/transforms.py index c5eb05f..b748b6e 100644 --- a/tabakrolletjie/transforms.py +++ b/tabakrolletjie/transforms.py @@ -2,6 +2,8 @@ import pygame.surface +import pygame.locals as pgl + class Transform(object): @@ -49,3 +51,16 @@ class Overlay(Transform): over.fill(self.colour) surface.blit(over, (0, 0), None) return surface + + +class Multiply(Transform): + """ Apply a colour by multiplying. """ + + ARGS = ["colour"] + + def apply(self, surface): + mult = pygame.surface.Surface(surface.get_size()) + mult = mult.convert_alpha() + mult.fill(self.colour) + surface.blit(mult, (0, 0), None, pgl.BLEND_RGBA_MULT) + return surface