-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfontobjects.py
28 lines (20 loc) · 1.01 KB
/
fontobjects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pygame
def create_text_object(text, font, color):
textsurface = font.render(str(text), True, color)
return textsurface, textsurface.get_rect()
def render_text(text, position, textsize, textcolor, fontstyle, textalign, surface):
textlabel = pygame.font.Font(str(fontstyle), textsize)
textsurface, textsurfacerect = create_text_object(text, textlabel, textcolor)
if textalign == "CENTER":
textsurfacerect.center = int(surface.get_rect().size[0] / 2), int(surface.get_rect().size[1] / 2)
else:
textsurfacerect.topleft = position
surface.blit(textsurface, textsurfacerect)
def render_text_as_label(text, position, textsize, textcolor, fontstyle, textalign, surface):
textlabel = pygame.font.Font(str(fontstyle), textsize)
textsurface, textsurfacerect = create_text_object(text, textlabel, textcolor)
if textalign == "CENTER":
textsurfacerect.center = position
else:
textsurfacerect.topleft = position
surface.blit(textsurface, textsurfacerect)