Info_edupage/UI/Objects/nr_objects/Text.py

36 lines
1.4 KiB
Python
Raw Normal View History

2021-09-01 22:22:18 +02:00
import pygame
class Text:
2021-09-06 18:32:02 +02:00
object_type = "nr"
2021-09-01 22:22:18 +02:00
def __init__(self, position, text, font_size, color, scene, font_name="calibri", bold=True):
self.position = position
self.text = text
self.font_size = font_size
self.font_name = font_name
self.bold = bold
self.color = color
self.scene = scene
self.scalar = self.scene.matrix[0, 0]
self.font = pygame.font.SysFont(self.font_name, max(1, int(self.font_size * self.scalar)), self.bold)
self.rendered_text = self.font.render(self.text, False, self.color)
self.blit_position = self.scene.matrix @ self.position
self.blit_position[0] -= self.rendered_text.get_width() / 2
self.blit_position[1] -= self.rendered_text.get_height() / 2
def blit(self):
if self.scalar != self.scene.matrix[0, 0]:
self.scalar = self.scene.matrix[0, 0]
self.font = pygame.font.SysFont(self.font_name, max(1, int(self.font_size * self.scalar)), self.bold)
self.rendered_text = self.font.render(self.text, False, self.color)
self.blit_position = self.scene.matrix @ self.position
self.blit_position[0] -= self.rendered_text.get_width() / 2
self.blit_position[1] -= self.rendered_text.get_height() / 2
self.scene.s.blit(self.rendered_text, self.blit_position)