Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Examples/TestScreen.py
100644 → 100755
Empty file.
Empty file modified Examples/hawk.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Examples/run.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
##----------------------------------------------------

window.checkForInput(screen) #checks for inputs on the screen
window.checkForHover(screen) #checks for hover on the screen
window.update(screen) #updates the window to reflect the new screen
16 changes: 15 additions & 1 deletion PageElements.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ def wasClicked(self, clickLoc):
return True
return False

def wasHovered(self, mouse_pos):
if self.rect.collidepoint(mouse_pos):
return True
return False

def display(self, surface):
pygame.draw.rect(surface, self.color, self.rect)

def onClick(self, screen):
print("You've clicked a useless page element")

def onHover(self, screen):
pass

def notHovered(self, screen):
pass

def adjustToScreenSize(self, screenDims):
#call on screen size adjust event?
#https://www.pygame.org/docs/ref/display.html#:~:text=If%20the%20display%20is%20set,the%20window%20must%20be%20redrawn.
Expand Down Expand Up @@ -94,6 +105,9 @@ def onClick(self, screen):
print("a ha! You've found a useless button. Great Work")
print('The text on this button is: ' + self.text)

def onHover(self, screen):
pass

def display(self, surface):
font = pygame.font.Font('freesansbold.ttf', 14)
textSurf = font.render(self.text, True, self.textColorRGB)
Expand Down Expand Up @@ -184,4 +198,4 @@ def getCenterFromRect(rect):





Empty file modified Screen.py
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions Window.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ def checkForInput(self, screen):
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