added a UI class to better organize UI creation

This commit is contained in:
2024-08-28 20:10:17 -04:00
parent 9d6c19cfd5
commit 5cb8101495
2 changed files with 42 additions and 34 deletions

View File

@@ -2,7 +2,7 @@ import pygame
import pygame_widgets
from Shapes import *
from Scene import Scene
from UI import create_ui, SceneManager
from UI import AnimatorUI
WINDOW_W = 500
WINDOW_H = 500
@@ -13,40 +13,26 @@ file_data = ""
pygame.init()
window = pygame.display.set_mode((WINDOW_W, WINDOW_H))
sceneManager: SceneManager = create_ui(window, WINDOW_W, WINDOW_H)
ui = AnimatorUI(window)
clock = pygame.time.Clock()
selected_meshes = []
run = True
trackMouseMotion = False
while run:
clock.tick(60)
window.fill((255, 255, 255))
current_scene: Scene = sceneManager.get_current_scene()
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 2: # middle mouse click
trackMouseMotion = True
elif event.button == 1: # left click
sceneManager.click_mesh(pygame.mouse.get_pos())
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 2: # middle mouse release
trackMouseMotion = False
elif trackMouseMotion and event.type == pygame.MOUSEMOTION:
mouseMovement = pygame.mouse.get_rel()
current_scene.euler_angles[0] -= mouseMovement[1]
current_scene.euler_angles[1] -= mouseMovement[0]
pygame_widgets.update(events)
if not trackMouseMotion:
pygame.mouse.get_rel()
# if the event isn't handled above as a global event, let the ui handle it
else:
ui.update_interaction(event)
sceneManager.draw()
pygame_widgets.update(events)
ui.draw()
pygame.display.flip()
pygame.quit()