forked from MrCoachFowler/PyUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.py
More file actions
executable file
·64 lines (49 loc) · 1.86 KB
/
Copy pathWindow.py
File metadata and controls
executable file
·64 lines (49 loc) · 1.86 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pygame
from time import sleep
class Window:
def __init__(self, title="Test App", colorRGB=False):
pygame.init()
self.screenDims = (800,600)
self.screen = pygame.display.set_mode(self.screenDims, pygame.RESIZABLE)
pygame.display.set_caption(title)
self.color = (0, 0, 0)
if colorRGB:
self.color = colorRGB
self.screen.fill(self.color)
def setColor(self, colorRGB):
self.screen.fill(colorRGB)
def update(self, screenObj=False):
if screenObj:
self.screen.fill(screenObj.color)
screenObj.display(self.screenDims)
else:
self.screen.fill(self.color)
pygame.display.flip()
if screenObj:
if screenObj.waitForNextFrame:
sleep(screenObj.waitForNextFrame)
screenObj.waitForNextFrame = 0
def checkForInput(self, screen):
#check for inputs
for event in pygame.event.get():
#handle various inputs
##quit type
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
clickLoc = pygame.mouse.get_pos()
for e in screen.elements[::-1]:
if e.wasClicked(clickLoc):
e.onClick(screen)
return
if event.type == pygame.VIDEORESIZE:
self.screenDims = self.screen.get_size()
def checkForHover(self, screen):
mouse_pos = pygame.mouse.get_pos()
for e in screen.elements[::-1]:
if pygame.mouse.get_focused() != False:
if e.wasHovered(mouse_pos):
e.onHover(screen)
else:
e.notHovered(screen)
return