Files
autoPlanner/main.py
T

105 lines
2.6 KiB
Python
Raw Normal View History

2024-03-12 15:36:46 -06:00
import math
2024-03-14 12:35:36 -06:00
from copy import copy
2024-03-12 15:36:46 -06:00
import pygame as pg
from pygame.locals import *
from sys import exit
import numpy as np
2024-03-13 14:59:45 -07:00
import src.render as render
import src.menu as menu
2024-03-13 13:10:09 -07:00
import src.pathEditor as pathEditor
2024-03-14 12:35:36 -06:00
import src.buttonEditor as buttonEditor
import src.export as export
2024-03-12 15:36:46 -06:00
2024-03-13 13:10:09 -07:00
doubleClickDuration = 200
2024-03-12 15:36:46 -06:00
pg.init()
2024-03-13 14:59:45 -07:00
pg.font.init()
2024-03-12 15:36:46 -06:00
2024-03-13 13:10:09 -07:00
topBarHeight = 40
2024-03-14 12:35:36 -06:00
bottomBarHeight = 60
2024-03-12 15:36:46 -06:00
2024-03-13 13:10:09 -07:00
screen_width = 1200
screen_height = (screen_width * (643/1286)) + topBarHeight + bottomBarHeight
2024-03-12 15:36:46 -06:00
2024-03-14 12:35:36 -06:00
screen = pg.display.set_mode((screen_width, screen_height))#, pg.RESIZABLE)
2024-03-12 15:36:46 -06:00
pg.display.set_caption("Auto Planner")
2024-03-14 12:35:36 -06:00
render = render.render(pg, screen, topBarHeight, bottomBarHeight)
2024-03-12 15:36:46 -06:00
2024-03-14 12:35:36 -06:00
tabIndex = 0
2024-03-13 13:10:09 -07:00
tabs = [
2024-03-14 12:35:36 -06:00
menu.menu(pg, render),
pathEditor.pathEditor(render),
buttonEditor.buttonEditor(render, pathEditor),
export.export(pg, render)
2024-03-13 13:10:09 -07:00
]
2024-03-12 15:36:46 -06:00
2024-03-14 12:35:36 -06:00
tabs[tabIndex].load()
def addTab(i):
x1 = i * (screen_width/(len(tabs)))
x2 = (screen_width/(len(tabs)))
rect = (x1, 0, x2, topBarHeight)
def getIsSelected():
global tabIndex
return tabIndex == i
def onClick(pos):
global tabIndex
tabIndex = i
tabs[tabIndex].load()
render.renderElements(pos)
pg.display.update()
render.addButton(rect, tabs[i].name, getIsSelected, onClick)
for i in range(len(tabs)):
addTab(i)
render.renderElements((screen_width/2, screen_height/2))
2024-03-12 15:36:46 -06:00
running = True
last_click = -1
2024-03-13 13:10:09 -07:00
def offsetPos(pos):
return (pos[0],pos[1])
2024-03-12 15:36:46 -06:00
while running:
for event in pg.event.get():
2024-03-14 12:35:36 -06:00
if event.type == pg.MOUSEMOTION:
2024-03-13 13:10:09 -07:00
pos = pg.mouse.get_pos()
2024-03-14 12:35:36 -06:00
render.renderElements(pos)
if pos[1] > topBarHeight:
tabs[tabIndex].mouseMove(offsetPos(pos))
# refreshTabs(pos)
elif event.type == pg.MOUSEBUTTONDOWN:
pos = pg.mouse.get_pos()
render.clickElement(pos)
2024-03-13 14:59:45 -07:00
if pos[1] > topBarHeight:
2024-03-13 13:10:09 -07:00
now = pg.time.get_ticks()
if now - last_click <= doubleClickDuration:
tabs[tabIndex].doubleClick(offsetPos(pos))
else:
tabs[tabIndex].mouseDown(offsetPos(pos))
last_click = pg.time.get_ticks()
2024-03-14 12:35:36 -06:00
# else:
# clickTab(pos)
2024-03-12 15:36:46 -06:00
2024-03-14 12:35:36 -06:00
elif event.type == pg.MOUSEBUTTONUP:
2024-03-13 13:10:09 -07:00
pos = pg.mouse.get_pos()
2024-03-13 14:59:45 -07:00
if pos[1] > topBarHeight:
2024-03-13 13:10:09 -07:00
tabs[tabIndex].mouseUp(offsetPos(pos))
2024-03-12 15:36:46 -06:00
2024-03-14 12:35:36 -06:00
elif event.type == pg.KEYDOWN:
tabs[tabIndex].keyDown(event.key)
elif event.type == pg.QUIT:
2024-03-12 15:36:46 -06:00
running = False
2024-03-13 13:10:09 -07:00
2024-03-12 15:36:46 -06:00
pg.quit()