-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
112 lines (85 loc) · 2.88 KB
/
main.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import math
from copy import copy
import pygame as pg
from pygame.locals import *
from sys import exit
import numpy as np
import src.render as render
import src.pathEditor as pathEditor
import src.buttonEditor as buttonEditor
import src.export as export
doubleClickDuration = 200
pg.init()
pg.font.init()
topBarHeight = 40
bottomBarHeight = 60
screen_width = 1200
screen_height = (screen_width * (643/1286)) + topBarHeight + bottomBarHeight
screen = pg.display.set_mode((screen_width, screen_height))#, pg.RESIZABLE)
pg.display.set_caption("Auto Planner")
render = render.render(pg, screen, topBarHeight, bottomBarHeight)
tabIndex = 0
tabs = [
pathEditor.pathEditor(render),
buttonEditor.buttonEditor(render, pathEditor),
export.export(pg, render, buttonEditor)
]
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 getIsVisible():
return True
def onClick(pos):
global tabIndex
tabs[tabIndex].unload()
tabIndex = i
tabs[tabIndex].load()
render.renderElements(pos)
pg.display.update()
render.addButton(rect, tabs[i].name, getIsSelected, getIsVisible, onClick)
for i in range(len(tabs)):
addTab(i)
render.renderElements((screen_width/2, screen_height/2))
running = True
last_click = -1
def offsetPos(pos):
return (pos[0],pos[1])
while running:
for event in pg.event.get():
if event.type == pg.MOUSEMOTION:
pos = pg.mouse.get_pos()
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)
if pos[1] > topBarHeight:
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()
# else:
# clickTab(pos)
elif event.type == pg.MOUSEBUTTONUP:
pos = pg.mouse.get_pos()
if pos[1] > topBarHeight:
tabs[tabIndex].mouseUp(offsetPos(pos))
elif event.type == pg.KEYDOWN:
tabs[tabIndex].keyDown(event.key)
if event.key == pg.K_TAB:
tabs[tabIndex].unload()
tabIndex = (tabIndex + 1) % len(tabs)
tabs[tabIndex].load()
render.renderElements(pg.mouse.get_pos())
elif event.type == pg.QUIT:
running = False
pg.quit()