Drop-shadow helper
authorNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 13:38:11 +0000 (15:38 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 13:39:30 +0000 (15:39 +0200)
tabakrolletjie/utils.py

index 0775204345e60a94146164feb2966bdecb886642..6be4469ecf8b404fc8032cb3f2bddb8dcacf0250 100644 (file)
@@ -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