Fixed crash: pygame.Surface has no collidepoint().
This commit is contained in:
parent
9f8c4ce1a7
commit
b758d46139
1 changed files with 13 additions and 10 deletions
23
pg.py
23
pg.py
|
@ -23,8 +23,9 @@ class Hover:
|
|||
def __init__(self, function=None, ca=None, position: tuple=None, size: tuple=None):
|
||||
self.function = function
|
||||
self.ca = ca
|
||||
self.x, self.y = position
|
||||
self.w, self.h = size
|
||||
if not position is None and not size is None:
|
||||
self.x, self.y = position
|
||||
self.w, self.h = size
|
||||
self.active = True
|
||||
|
||||
def check(self, mouse_pos: tuple):
|
||||
|
@ -32,7 +33,7 @@ class Hover:
|
|||
mx, my = mouse_pos
|
||||
|
||||
if not self.ca is None:
|
||||
if self.ca.position((mx, my)):
|
||||
if self.ca.collidepoint((mx, my)):
|
||||
if self.function is None:
|
||||
return True
|
||||
|
||||
|
@ -59,8 +60,9 @@ class Hover:
|
|||
|
||||
class Button:
|
||||
def __init__(self, function=None, ca=None, position: tuple=None, size: tuple=None, key: int=0): # ca = collide able, key: 0 = left 1 = mouse wheel pressed 2 = right
|
||||
self.x, self.y = position
|
||||
self.width, self.height = size
|
||||
if not position is None and not size is None:
|
||||
self.x, self.y = position
|
||||
self.width, self.height = size
|
||||
self.function = function
|
||||
self.active = True
|
||||
self.ca = ca
|
||||
|
@ -80,8 +82,9 @@ class Button:
|
|||
|
||||
|
||||
class TextButton:
|
||||
def __init__(self, text: str, function=None, key: int=0, text_color: tuple=white, bg_color: tuple=gray, font: pygame.font.Font=default_font, padding: int=8):
|
||||
def __init__(self, text: str, pos: tuple, function=None, key: int=0, text_color: tuple=white, bg_color: tuple=gray, font: pygame.font.Font=default_font, padding: int=8):
|
||||
self.text = text
|
||||
self.pos = pos
|
||||
self.function = function
|
||||
self.text_color = text_color
|
||||
self.bg_color = bg_color
|
||||
|
@ -102,12 +105,12 @@ class TextButton:
|
|||
w, h = self.text_object.get_size()
|
||||
w, h = w + self.padding * 2, h + self.padding * 2
|
||||
|
||||
return pygame.Surface((w, h))
|
||||
return pygame.Rect(self.pos, (w, h))
|
||||
|
||||
def blit(self, surface: pygame.Surface, pos: tuple):
|
||||
x, y = pos
|
||||
def blit(self, surface: pygame.Surface):
|
||||
x, y = self.pos
|
||||
|
||||
surface.blit(self.background, pos)
|
||||
pygame.draw.rect(surface, self.bg_color, self.background)
|
||||
surface.blit(self.text_object, (x + self.padding, y + self.padding))
|
||||
|
||||
def check(self, mouse_pos, pressed):
|
||||
|
|
Loading…
Reference in a new issue