-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputBox.py
More file actions
34 lines (30 loc) · 1.23 KB
/
Copy pathinputBox.py
File metadata and controls
34 lines (30 loc) · 1.23 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
import pygame
import util
# inputBox class
class InputBox():
def __init__(self, text_input, font_size, x, y):
print("in init")
self.font = pygame.font.Font(util.resourcePath(
'fonts/freesansbold.ttf'), font_size)
# color for when receiving user input
self.active_color = (83, 239, 252)
# color for when in passive state
self.passive_color = (38, 54, 150)
self.x_pos = x
self.y_pos = y
self.text_input = text_input
self.input_rect = pygame.Rect(self.x_pos, self.y_pos, 140, 32)
self.current_color = self.passive_color
self.text = self.font.render(self.text_input, True, (255, 255, 255))
self.clicked = False
self.text_surface_width = 0
def draw(self, surface, text_input):
# draw rectangle
pygame.draw.rect(surface, self.current_color, self.input_rect)
# render text surface for box
text_surface = self.font.render(
text_input, True, (255, 255, 255))
# show input
surface.blit(text_surface, (self.input_rect.x+5, self.input_rect.y-1))
self.input_rect.w = max(100, text_surface.get_width()+10)
self.text_surface_width = text_surface.get_width()