mirror of
https://github.com/Astatin3/autoPlanner.git
synced 2026-06-08 15:48:00 -06:00
Tabs
This commit is contained in:
@@ -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:
|
||||
|
||||
+27
-1
@@ -1 +1,27 @@
|
||||
# class menu:
|
||||
pg = None
|
||||
render = None
|
||||
|
||||
class menu:
|
||||
name = "Menu"
|
||||
|
||||
def __init__(self, tmppg, tmprender):
|
||||
global pg
|
||||
pg = tmppg
|
||||
global render
|
||||
render = tmprender
|
||||
|
||||
def mouseDown(self, pos):
|
||||
pass
|
||||
|
||||
def mouseUp(self, pos):
|
||||
pass
|
||||
|
||||
def mouseMove(self, pos):
|
||||
pass
|
||||
|
||||
def doubleClick(self, pos):
|
||||
pass
|
||||
|
||||
def load(self):
|
||||
render.clear()
|
||||
pg.display.update()
|
||||
+32
-15
@@ -4,9 +4,13 @@ from pygame.locals import *
|
||||
nodeColor = (255, 255, 255)
|
||||
nodeRadius = 15
|
||||
|
||||
rotNodeDist = 30
|
||||
rotNodeDist = 35
|
||||
rotNodeColor = (255, 0, 255)
|
||||
rotNodeRadius = 5
|
||||
rotNodeRadius = 10
|
||||
|
||||
nodeSquareRadius = 35
|
||||
nodeSquareColor = (127, 127, 127, 0.5)
|
||||
nodeSquareWidth = 3
|
||||
|
||||
lineApproximationLineColor = (127, 127, 127, 0.5)
|
||||
lineApproximationLineWidth = 3
|
||||
@@ -14,8 +18,6 @@ lineApproximationLineWidth = 3
|
||||
curveEditPointColor = (0, 255, 255)
|
||||
curveEditPointRadius = 5
|
||||
|
||||
name = "Path Editor"
|
||||
|
||||
nodes = []
|
||||
curveEditPoints = []
|
||||
nodeRotations = []
|
||||
@@ -24,23 +26,38 @@ clickType = -1
|
||||
clickIndex = -1
|
||||
|
||||
pg = None
|
||||
pathRenderer = None
|
||||
render = None
|
||||
|
||||
|
||||
def refresh():
|
||||
pathRenderer.render(nodes, curveEditPoints)
|
||||
render.render(nodes, curveEditPoints)
|
||||
|
||||
for i in range(0,len(curveEditPoints)):
|
||||
pathRenderer.line(lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
|
||||
pathRenderer.line(lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
|
||||
render.line(lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
|
||||
render.line(lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
|
||||
#bezier(nodes[i], curveEditPoints[i], nodes[i+1])
|
||||
pathRenderer.circle(curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
|
||||
render.circle(curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
|
||||
for i in range(0,len(nodeRotations)):
|
||||
posX = (math.sin(nodeRotations[i])*rotNodeDist) + nodes[i][0]
|
||||
posY = (math.cos(nodeRotations[i])*rotNodeDist) + nodes[i][1]
|
||||
pathRenderer.circle(rotNodeColor, (posX, posY), rotNodeRadius)
|
||||
render.circle(rotNodeColor, (posX, posY), rotNodeRadius)
|
||||
|
||||
rect1 = ((math.sin(nodeRotations[i] + math.pi*-0.25)*nodeSquareRadius) + nodes[i][0],
|
||||
(math.cos(nodeRotations[i] + math.pi*-0.25)*nodeSquareRadius) + nodes[i][1])
|
||||
rect2 = ((math.sin(nodeRotations[i] + math.pi*0.25)*nodeSquareRadius) + nodes[i][0],
|
||||
(math.cos(nodeRotations[i] + math.pi*0.25)*nodeSquareRadius) + nodes[i][1])
|
||||
rect3 = ((math.sin(nodeRotations[i] + math.pi*0.75)*nodeSquareRadius) + nodes[i][0],
|
||||
(math.cos(nodeRotations[i] + math.pi*0.75)*nodeSquareRadius) + nodes[i][1])
|
||||
rect4 = ((math.sin(nodeRotations[i] + math.pi*1.25)*nodeSquareRadius) + nodes[i][0],
|
||||
(math.cos(nodeRotations[i] + math.pi*1.25)*nodeSquareRadius) + nodes[i][1])
|
||||
|
||||
render.line(nodeSquareColor, rect1, rect2, nodeSquareWidth)
|
||||
render.line(nodeSquareColor, rect2, rect3, nodeSquareWidth)
|
||||
render.line(nodeSquareColor, rect3, rect4, nodeSquareWidth)
|
||||
render.line(nodeSquareColor, rect4, rect1, nodeSquareWidth)
|
||||
for pos in nodes:
|
||||
pathRenderer.circle(nodeColor, pos, nodeRadius)
|
||||
|
||||
render.circle(nodeColor, pos, nodeRadius)
|
||||
pg.display.update()
|
||||
|
||||
def getElemAt(pos):
|
||||
@@ -84,14 +101,14 @@ def points2rad(center, pos):
|
||||
return -math.atan2(diffY, diffX) - (math.pi/2)
|
||||
|
||||
class pathEditor:
|
||||
|
||||
def __init__(self, tmppg, tmppathRenderer):
|
||||
name = "Path Editor"
|
||||
def __init__(self, tmppg, tmprender):
|
||||
global pg
|
||||
pg = tmppg
|
||||
# global screen
|
||||
# screen = tmpscreen
|
||||
global pathRenderer
|
||||
pathRenderer = tmppathRenderer
|
||||
global render
|
||||
render = tmprender
|
||||
|
||||
refresh()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ curvePointCount = 300
|
||||
curvePointColor = (255, 255, 0)
|
||||
curvePointRadius = 2
|
||||
|
||||
class pathRenderer():
|
||||
class render():
|
||||
def __init__(self, pg, screen, offsetY):
|
||||
self.pg = pg
|
||||
self.screen = screen
|
||||
@@ -35,14 +35,17 @@ class pathRenderer():
|
||||
px = p0[0]*(1-t)**2 + 2*(1-t)*t*p1[0] + p2[0]*t**2
|
||||
py = p0[1]*(1-t)**2 + 2*(1-t)*t*p1[1] + p2[1]*t**2
|
||||
self.circle(curvePointColor, (px, py), curvePointRadius)
|
||||
|
||||
|
||||
def clear(self):
|
||||
self.pg.draw.rect(self.screen, (0, 0, 0), self.rect)
|
||||
|
||||
def render(self, nodes, curveEditPoints):
|
||||
self.pg.draw.rect(self.screen, (0, 0, 0), self.rect)
|
||||
self.screen.blit(self.fieldImg, self.rect)
|
||||
for i in range(0,len(curveEditPoints)):
|
||||
# self.pg.draw.line(self.screen, lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
|
||||
# self.pg.draw.line(self.screen, lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
|
||||
self.bezier(nodes[i], curveEditPoints[i], nodes[i+1])
|
||||
# self.pg.draw.circle(self.screen, curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
|
||||
# self.pg.draw.line(self.screen, lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
|
||||
# self.pg.draw.line(self.screen, lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
|
||||
self.bezier(nodes[i], curveEditPoints[i], nodes[i+1])
|
||||
# self.pg.draw.circle(self.screen, curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
|
||||
self.pg.display.update()
|
||||
|
||||
Reference in New Issue
Block a user