-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextDisplayQuestionWrap.py
More file actions
43 lines (38 loc) · 1.65 KB
/
Copy pathtextDisplayQuestionWrap.py
File metadata and controls
43 lines (38 loc) · 1.65 KB
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
import pygame
from pygame.locals import *
class Pane:
def __init__(self, text_input, fontSize, xdim, ydim, x_top_left, y_top_left):
self.white = (255, 255, 255)
self.font = pygame.font.SysFont('freesansbold.ttf', fontSize)
self.xdim = xdim
self.ydim = ydim
self.x_top_left = x_top_left
self.y_top_left = y_top_left
self.text_input = text_input
self.text_surface_object = self.font.render(
self.text_input, True, self.white)
self.text_rect = self.text_surface_object.get_rect(
center=(self.x_top_left, self.y_top_left))
self.text_surface_object2 = self.font.render(
"", True, self.white)
self.text_rect2 = self.text_surface_object2.get_rect(
center=(self.x_top_left, self.y_top_left+self.ydim/2))
def setText(self, s1, s2):
self.text_surface_object = self.font.render(s1, True, self.white)
self.text_rect = self.text_surface_object.get_rect(
center=(self.x_top_left, self.y_top_left))
self.text_surface_object2 = self.font.render(s2, True, self.white)
self.text_rect2 = self.text_surface_object2.get_rect(
center=(self.x_top_left, self.y_top_left+self.ydim/2))
def addText(self, text):
size_x, size_y = self.font.size(text)
if size_x > self.xdim:
s1 = text[:len(text)//2]
s2 = text[len(text)//2:]
else:
s1 = text
s2 = ""
self.setText(s1, s2)
def draw(self, surface):
surface.blit(self.text_surface_object, self.text_rect)
surface.blit(self.text_surface_object2, self.text_rect2)