Buttons (PE.Buttons)
PE.Buttons.ButtonTexture
class usage:
store 3 sliced button texture, which the upper slice is regular, the middle one is hover and the bottom slice is click.
ButtonTexture.__init__(self, image: pygame.Surface)
function actions:
initializing the class
​
parameters:
image - image to slice (pygame.Surface)
​
PE.Buttons.Button
class usage:
a button that you can hover with your mouse on and click it.
​
Button.__init__(self, pos=(0, 0), size=(20, 10), img=None, text="", text_color=(0, 0, 0), text_size=20, font='freesansbold.ttf', hover_color=(255, 255, 255, 100), click_color=(0, 0, 0, 100), back_color=(200, 200, 200))
function actions:
initializing the class
​
parameters:
pos - button position (vector 2 like)
size - button size (vector 2 like)
img - button texture (None - use back color, pygame.Surface - tint an image, pe.Buttons.ButtonTexture - use button texture) (None/pe.Buttons.ButtonTexture/pygame.Surface)
text - the text that will be on the button (use "" - empty string to disable text) (str)
text_color - the color of the text on the button (color like)
text_size - the text height (int)
font - the path of the font file to use for the text (str/path like)
hover_color - the color of the background/tint when mouse hover (disabled when using button texture) (color like)
click_color - the color of the background/tint when mouse click (disabled when using button texture) (color like)
back_color - the color of the background when the texture (img parameter) is None (color like)
​
Button.is_clicked(self, workspace: pygame.Surface)
function actions:
check for mouse click
​
parameters:
workspace - the surface to compare the render resolution to (A.K.A. the window) (pygame.Surface)
​
returns:
is the button clicked (bool)
​
recommended place in script:
at the main loop, between the screen filling and the button rendering.
Button.is_hovered(self, workspace: pygame.Surface)
included in the Button.is_clicked() function
​
function actions:
check for mouse hover
​
parameters:
workspace - the surface to compare the render resolution to (A.K.A. the window) (pygame.Surface)
​
returns:
is the mouse hover the button (bool)
​
recommended place in script:
at the main loop, between the screen filling and the button rendering.
Button.show(self, workspace: pygame.Surface)
function actions:
put the button on a surface
​
parameters:
workspace - the surface to put the button on (pygame.Surface)
​
recommended place in script:
at the main loop, before the screen update
Button.change_variables(self,...)
function actions:
change the button parameters without creating another
​
parameters:
same as __init__
​
PE.Buttons.init(screen_size_)
automated function, updates global data
​
function actions:
update render resolution
​
function usage:
used by PE.init() function to update render resolution for gifs.
​
parameters:
screen_size_ - new render resolution
PE.Buttons.frame_click()
function actions:
make sure that the click function will be activated only once per click.
​
recommended place in script:
the last line of the main loop.
