From: Neil Date: Sat, 10 Sep 2016 13:38:11 +0000 (+0200) Subject: Drop-shadow helper X-Git-Tag: tabakrolletjie-v1.0.0~97^2~9 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=3dfbd74e5b821ea7e7ca78ce3b0f4f38c2e556bb;p=tabakrolletjie.git Drop-shadow helper --- diff --git a/tabakrolletjie/utils.py b/tabakrolletjie/utils.py index 0775204..6be4469 100644 --- a/tabakrolletjie/utils.py +++ b/tabakrolletjie/utils.py @@ -2,8 +2,11 @@ import functools import time +import pygame.surface +import pygame.locals as pgl from .constants import DEBUG +from .loader import loader def debug_timer(label, debug=False): @@ -52,3 +55,17 @@ class DetailedTimer(object): def end(self): print " %s: %s" % ("total", time.time() - self.times[0]) print "---- ----" + + +def shadowed_text(text, font_name, size, offset=4): + font_black = loader.load_font(font_name, size=size) + font_white = loader.load_font(font_name, size=size) + background = font_black.render(text, True, (0, 0, 0)) + foreground = font_white.render(text, True, (255, 255, 255)) + new_size = (background.get_width() + offset, + background.get_height() + offset) + base = pygame.surface.Surface(new_size, pgl.SWSURFACE).convert_alpha() + base.fill((0, 0, 0, 0)) + base.blit(background, (offset, offset), None) + base.blit(foreground, (0, 0), None) + return base