30 lines
783 B
Python
30 lines
783 B
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
from wobbl_tools.pygame_tools.utils import *
|
||
|
from wobbl_tools.pygame_tools.widgets import Hover
|
||
|
|
||
|
|
||
|
class Button:
|
||
|
"""
|
||
|
Creates a button from a pygame.Rect.
|
||
|
"""
|
||
|
def __init__(self, rect: pygame.Rect, function=None, args: tuple=None, key: int=0): # key: 0 = left 1 = mouse wheel pressed 2 = right
|
||
|
self.rect = rect
|
||
|
self.function = function
|
||
|
self.args = args
|
||
|
self.key = key
|
||
|
|
||
|
self.active = True
|
||
|
|
||
|
self.hover = Hover(rect, function, args)
|
||
|
|
||
|
if buttonlist:
|
||
|
buttons.append(self)
|
||
|
|
||
|
def check(self, mouse_pos: tuple, pressed): # check if the button is pressed
|
||
|
if self.active:
|
||
|
if pressed[self.key]:
|
||
|
return self.hover.check(mouse_pos)
|
||
|
|
||
|
return False
|