Advertisement
BigYellowCactus

Fontrenderer from Regnancy

Apr 27th, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import pygame
  5.  
  6.  
  7. def blurSurf(surface, amt):
  8.     scale = 1.0 / float(amt)
  9.     surf_size = surface.get_size()
  10.     scale_size = (int(surf_size[0] * scale), int(surf_size[1] * scale))
  11.     surf = pygame.transform.smoothscale(surface, scale_size)
  12.     surf = pygame.transform.smoothscale(surf, surf_size)
  13.     return surf
  14.  
  15.  
  16. class Fontrenderer(object):
  17.  
  18.     def __init__(self):
  19.         self.s_c = {}
  20.         self.c = {}
  21.  
  22.     def render(self, font, text, color, surf, pos):
  23.  
  24.         if not (font, text, str(color)) in self.s_c.keys():
  25.             (self.s_c)[(font, text, str(color))] = blurSurf(font.render(text.decode('utf-8'),
  26.                     True, (0, 0, 0)), 1.6)
  27.  
  28.         ss = (self.s_c)[(font, text, str(color))]
  29.         surf.blit(ss, (pos[0] + 1, pos[1] + 2))
  30.  
  31.         if not (font, text, str(color)) in self.c.keys():
  32.             (self.c)[(font, text, str(color))] = font.render(text.decode('utf-8'),
  33.                     True, color)
  34.  
  35.         s = (self.c)[(font, text, str(color))]
  36.         surf.blit(s, pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement