1 """ Tabakutilities. """
6 import pygame.locals as pgl
8 from .constants import DEBUG
9 from .loader import loader
12 def debug_timer(label, debug=False):
13 """ A decorator for printing how long a function took if debug is true.
17 def wrapper(*args, **kw):
18 start_time = time.time()
22 duration = time.time() - start_time
24 print "%s [%g seconds]" % (label, duration)
29 class DetailedTimer(object):
30 """ A detailed timer for overly complex functions.
32 def __init__(self, title, debug=False):
37 # fast funtions with the correct signature
44 print "---- %s ----" % self.title
45 self.times.append(time.time())
49 print " %s: %s" % (label, now - self.times[-1])
50 self.times.append(now)
56 print " %s: %s" % ("total", time.time() - self.times[0])
60 def shadowed_text(text, font_name, size, offset=4):
61 font_black = loader.load_font(font_name, size=size)
62 font_white = loader.load_font(font_name, size=size)
63 background = font_black.render(text, True, (0, 0, 0))
64 foreground = font_white.render(text, True, (255, 255, 255))
65 new_size = (background.get_width() + offset,
66 background.get_height() + offset)
67 base = pygame.surface.Surface(new_size, pgl.SWSURFACE).convert_alpha()
68 base.fill((0, 0, 0, 0))
69 base.blit(background, (offset, offset), None)
70 base.blit(foreground, (0, 0), None)