This commit is contained in:
Michael Mikovsky
2024-03-13 14:59:45 -07:00
parent e538a8c382
commit 2dab7295ac
4 changed files with 105 additions and 33 deletions
+37 -11
View File
@@ -4,12 +4,14 @@ from pygame.locals import *
from sys import exit
import numpy as np
import src.pathRenderer as pathRenderer
import src.render as render
import src.menu as menu
import src.pathEditor as pathEditor
doubleClickDuration = 200
pg.init()
pg.font.init()
topBarHeight = 40
bottomBarHeight = 40
@@ -20,23 +22,46 @@ screen_height = (screen_width * (643/1286)) + topBarHeight + bottomBarHeight
screen = pg.display.set_mode((screen_width, screen_height))
pg.display.set_caption("Auto Planner")
pathR = pathRenderer.pathRenderer(pg, screen, topBarHeight)
pathR = render.render(pg, screen, topBarHeight)
tabIndex = 0
tabIndex = 1
tabs = [
menu.menu(pg, pathR),
pathEditor.pathEditor(pg, pathR)
]
def refresh():
pass
def isInRect(pos, rect):
return pos[0] >= rect[0] and \
pos[0] <= rect[2] and \
pos[1] >= rect[1] and \
pos[1] <= rect[3]
def refreshTabs(pos):
for i in range(len(tabs)):
# color = i * (255/(len(tabs)-1))
# color = (color, color, color)
x1 = i * (screen_width/(len(tabs)))
x2 = (i+1) * (screen_width/(len(tabs)))
rect = (x1, 0, x2, topBarHeight)
if i == tabIndex:
color = (255, 255, 255)
elif isInRect(pos, rect):
color = (127,127,127)
else:
color = (63,63,63)
pg.draw.rect(screen, color, rect)
pg.display.update()
refreshTabs((screen_width/2, screen_height/2))
running = True
last_click = -1
# clickType = -1
# clickIndex = -1
def offsetPos(pos):
return (pos[0],pos[1])
@@ -45,7 +70,7 @@ while running:
if event.type == pg.MOUSEBUTTONDOWN:
pos = pg.mouse.get_pos()
if pos[1] > topBarHeight and pos[1] < (screen.get_width()-bottomBarHeight):
if pos[1] > topBarHeight:
now = pg.time.get_ticks()
if now - last_click <= doubleClickDuration:
tabs[tabIndex].doubleClick(offsetPos(pos))
@@ -55,12 +80,13 @@ while running:
if event.type == pg.MOUSEMOTION:
pos = pg.mouse.get_pos()
if pos[1] > topBarHeight and pos[1] < (screen.get_width()-bottomBarHeight):
if pos[1] > topBarHeight:
tabs[tabIndex].mouseMove(offsetPos(pos))
refreshTabs(pos)
if event.type == pg.MOUSEBUTTONUP:
pos = pg.mouse.get_pos()
if pos[1] > topBarHeight and pos[1] < (screen.get_width()-bottomBarHeight):
if pos[1] > topBarHeight:
tabs[tabIndex].mouseUp(offsetPos(pos))
if event.type == pg.QUIT: