From 3dfbd74e5b821ea7e7ca78ce3b0f4f38c2e556bb Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 10 Sep 2016 15:38:11 +0200 Subject: [PATCH] Drop-shadow helper --- tabakrolletjie/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 -- 2.34.1