def check(self, event=None): # function to scheck and interact with the user
if self.off:
return False
if event is None: # checking for mouse input
mousepos = pygame.mouse.get_pos()
mouseclick = pygame.mouse.get_pressed() # gets button press status and position
if mouseclick[0]:
if not self.lock:
if check_mouse_round_rect(mousepos, self.rect, self.radius) and mouseclick[0]:
self.typing = True # if the user is clicking and inside the box then the user is typing
else:
self.typing = False # if the user has clicked somewhere else they are no longer typing
self.lock = True
else:
self.lock = False
else:
if not self.typing: # checking keyboard inputs and scroll wheel
return False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN: # returns text if enter is pressed
return self.text
elif event.key != pygame.K_BACKSPACE and event.key != 9 and event.key != 27:# if the event.key isnt backspace or a special button (eg ctrl)
if event.key < 256: #
if self.charLimit is None or len(self.text) < self.charLimit:
self.text += event.unicode.encode('ascii', 'replace') # inupts the character key and converts it to ascii format before adding it to the text in the box
elif event.key == pygame.K_BACKSPACE: # if the key was backspace then it deletes the last character
self.text = self.text[:len(self.text)-1]
elif event.type == pygame.MOUSEBUTTONDOWN: # if a button has been pressed and that button is a mousewheel, offset the text so it appears to scroll
if event.button == 4:
if self.offSet + 4 > self.height - self.rect[3]:
pass
else:
self.offSet += 4
elif event.button == 5:
if self.offSet - 4 < 0:
pass
else:
self.offSet -= 4
return False
评论列表
文章目录