This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
45 lines (39 loc) · 1.61 KB
/
ui.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pygame
class BigLabel:
def __init__(self, text, pos, size):
self.size = size
self.pos = pos
self.font = pygame.font.Font('assets/Goldman-Regular.ttf', 36)
self.words = []
for word in text.splitlines():
self.words.append(word.split(' '))
self.space = self.font.size(' ')[0]
def draw(self, screen):
x, y = self.pos
for line in self.words:
for word in line:
word_surface = self.font.render(word, True, (255, 255, 255))
word_width, word_height = word_surface.get_size()
if x + word_width >= self.size[0]:
x = self.pos[0] # Resetea x
y += word_height # Inicia nueva fila
screen.blit(word_surface, (x, y))
x += word_width + self.space
x = self.pos[0] # Resetea x
y += word_height # Inicia nueva fila
class Label:
def __init__(self, text, pos = None):
font = pygame.font.Font('assets/Goldman-Regular.ttf', 36)
self.text = font.render(text, True, (255, 255, 255)) # Blanco
self.rect = self.text.get_rect()
if pos != None:
self.rect.topleft = pos
def draw(self, screen):
screen.blit(self.text, self.rect)
class Picture:
def __init__(self, img, pos, size):
self.img = pygame.image.load(img).convert_alpha()
self.img = pygame.transform.scale(self.img, (int(size[0]), int(size[1])))
self.pos = pos
def draw(self, screen):
screen.blit(self.img, self.pos)