Preliminary shape editing
This commit is contained in:
parent
270982cce8
commit
cd2899bb20
|
|
@ -110,6 +110,7 @@ def onMouseDownGroup(self, x, y,button=1,clicks=1):
|
||||||
if svlgui.MODE in [" ", "s"]:
|
if svlgui.MODE in [" ", "s"]:
|
||||||
if self.hitTest(x, y):
|
if self.hitTest(x, y):
|
||||||
self.clicked = True
|
self.clicked = True
|
||||||
|
|
||||||
elif svlgui.MODE in ["r", "e", "p"]:
|
elif svlgui.MODE in ["r", "e", "p"]:
|
||||||
if svlgui.MODE=="r":
|
if svlgui.MODE=="r":
|
||||||
# 'c' stands for 'current'
|
# 'c' stands for 'current'
|
||||||
|
|
@ -117,7 +118,17 @@ def onMouseDownGroup(self, x, y,button=1,clicks=1):
|
||||||
elif svlgui.MODE=="e":
|
elif svlgui.MODE=="e":
|
||||||
self.cshape = ellipse(x, y, 0, 0)
|
self.cshape = ellipse(x, y, 0, 0)
|
||||||
elif svlgui.MODE=="p":
|
elif svlgui.MODE=="p":
|
||||||
self.cshape = shape(x, y)
|
# self.cshape = shape(x, y)
|
||||||
|
self.cshape = svlgui.Line(svlgui.Point(x, y),svlgui.Point(x,y))
|
||||||
|
for i in self.lines:
|
||||||
|
if abs(self.cshape.endpoint1.x-i.endpoint1.x)<10 and abs(self.cshape.endpoint1.y-i.endpoint1.y)<10:
|
||||||
|
self.cshape.connection1 = i.endpoint1
|
||||||
|
break
|
||||||
|
elif abs(self.cshape.endpoint1.x-i.endpoint2.x)<10 and abs(self.cshape.endpoint1.y-i.endpoint2.y)<10:
|
||||||
|
self.cshape.connection1 = i.endpoint2
|
||||||
|
break
|
||||||
|
self.lines.append(self.cshape)
|
||||||
|
return
|
||||||
#self.cshape.rotation = 5
|
#self.cshape.rotation = 5
|
||||||
self.cshape.initx,self.cshape.inity = x, y
|
self.cshape.initx,self.cshape.inity = x, y
|
||||||
self.add(self.cshape)
|
self.add(self.cshape)
|
||||||
|
|
@ -184,9 +195,16 @@ def onMouseUpGroup(self, x, y,button=1,clicks=1):
|
||||||
undo_stack[-1] = undo_stack[-1].complete({"obj":cobj, "frame":self.activelayer.currentframe, "layer":self.activelayer})
|
undo_stack[-1] = undo_stack[-1].complete({"obj":cobj, "frame":self.activelayer.currentframe, "layer":self.activelayer})
|
||||||
clear(redo_stack)
|
clear(redo_stack)
|
||||||
elif svlgui.MODE=="p":
|
elif svlgui.MODE=="p":
|
||||||
print len(self.cshape.shapedata)
|
'''print len(self.cshape.shapedata)
|
||||||
self.cshape.shapedata = misc_funcs.simplify_shape(self.cshape.shapedata, svlgui.PMODE.split()[-1],1)
|
self.cshape.shapedata = misc_funcs.simplify_shape(self.cshape.shapedata, svlgui.PMODE.split()[-1],1)
|
||||||
print len(self.cshape.shapedata)
|
print len(self.cshape.shapedata)'''
|
||||||
|
for i in self.lines:
|
||||||
|
if abs(self.cshape.endpoint2.x-i.endpoint1.x)<10 and abs(self.cshape.endpoint2.y-i.endpoint1.y)<10:
|
||||||
|
self.cshape.connection2 = i.endpoint1
|
||||||
|
break
|
||||||
|
elif abs(self.cshape.endpoint2.x-i.endpoint2.x)<10 and abs(self.cshape.endpoint2.y-i.endpoint2.y)<10:
|
||||||
|
self.cshape.connection2 = i.endpoint2
|
||||||
|
break
|
||||||
self.cshape = None
|
self.cshape = None
|
||||||
MainWindow.stage.draw()
|
MainWindow.stage.draw()
|
||||||
def onMouseUpObj(self, x, y,button=1,clicks=1):
|
def onMouseUpObj(self, x, y,button=1,clicks=1):
|
||||||
|
|
@ -245,7 +263,9 @@ def onMouseDragGroup(self, x, y,button=1,clicks=1):
|
||||||
y=y-self.cshape.inity
|
y=y-self.cshape.inity
|
||||||
self.cshape.shapedata = [["M",x/2,0],["C",4*x/5,0,x,y/5,x,y/2],["C",x,4*y/5,4*x/5,y,x/2,y],["C",x/5,y,0,4*y/5,0,y/2],["C",0,y/5,x/5,0,x/2,0]]
|
self.cshape.shapedata = [["M",x/2,0],["C",4*x/5,0,x,y/5,x,y/2],["C",x,4*y/5,4*x/5,y,x/2,y],["C",x/5,y,0,4*y/5,0,y/2],["C",0,y/5,x/5,0,x/2,0]]
|
||||||
elif svlgui.MODE == "p":
|
elif svlgui.MODE == "p":
|
||||||
self.cshape.shapedata.append(["L",x-self.cshape.initx,y-self.cshape.inity])
|
# self.cshape.shapedata.append(["L",x-self.cshape.initx,y-self.cshape.inity])
|
||||||
|
self.cshape.endpoint2.x = x
|
||||||
|
self.cshape.endpoint2.y = y
|
||||||
def onMouseDragObj(self, x, y,button=1,clicks=1):
|
def onMouseDragObj(self, x, y,button=1,clicks=1):
|
||||||
if svlgui.MODE==" ":
|
if svlgui.MODE==" ":
|
||||||
self.x = x-self.initx
|
self.x = x-self.initx
|
||||||
|
|
|
||||||
115
svlgui.py
115
svlgui.py
|
|
@ -176,6 +176,8 @@ LINECOLOR = Color("#990099")
|
||||||
FILLCOLOR = Color("#00FF00")
|
FILLCOLOR = Color("#00FF00")
|
||||||
TEXTCOLOR = Color("#000000")
|
TEXTCOLOR = Color("#000000")
|
||||||
|
|
||||||
|
LINEWIDTH = 2
|
||||||
|
|
||||||
#Magic. Detect platform and select appropriate toolkit. To be used throughout code.
|
#Magic. Detect platform and select appropriate toolkit. To be used throughout code.
|
||||||
if sys.platform=="linux2":
|
if sys.platform=="linux2":
|
||||||
id = platform.machine()
|
id = platform.machine()
|
||||||
|
|
@ -2548,6 +2550,9 @@ class Group (object):
|
||||||
self.tempgroup = None
|
self.tempgroup = None
|
||||||
self.is_mc = False
|
self.is_mc = False
|
||||||
self.name = "g"+str(int(random.random()*10000))+str(SITER)
|
self.name = "g"+str(int(random.random()*10000))+str(SITER)
|
||||||
|
self.lines = []
|
||||||
|
self.fills = []
|
||||||
|
self.activepoint = None
|
||||||
if "onload" in kwargs:
|
if "onload" in kwargs:
|
||||||
kwargs["onload"](self)
|
kwargs["onload"](self)
|
||||||
def draw(self,cr=None,transform=None,rect=None):
|
def draw(self,cr=None,transform=None,rect=None):
|
||||||
|
|
@ -2568,6 +2573,8 @@ class Group (object):
|
||||||
cr.pencolor = Color([0,0,1]).pygui
|
cr.pencolor = Color([0,0,1]).pygui
|
||||||
cr.stroke_rect([sorted([self.startx,self.cx])[0], sorted([self.starty,self.cy])[0], \
|
cr.stroke_rect([sorted([self.startx,self.cx])[0], sorted([self.starty,self.cy])[0], \
|
||||||
sorted([self.startx,self.cx])[1], sorted([self.starty,self.cy])[1]])
|
sorted([self.startx,self.cx])[1], sorted([self.starty,self.cy])[1]])
|
||||||
|
for i in self.lines:
|
||||||
|
i.draw(cr, rect=rect)
|
||||||
def add(self, *args):
|
def add(self, *args):
|
||||||
self.activelayer.add(*args)
|
self.activelayer.add(*args)
|
||||||
def add_frame(self, populate):
|
def add_frame(self, populate):
|
||||||
|
|
@ -2639,6 +2646,18 @@ class Group (object):
|
||||||
self.tempgroup = None
|
self.tempgroup = None
|
||||||
self.activelayer.currentselect = None
|
self.activelayer.currentselect = None
|
||||||
self.startx, self.starty = x, y
|
self.startx, self.starty = x, y
|
||||||
|
if MODE in " s":
|
||||||
|
for i in self.lines:
|
||||||
|
if abs(x-i.endpoint1.x)<10 and abs(y-i.endpoint1.y)<10:
|
||||||
|
i.endpoint1.x = x
|
||||||
|
i.endpoint1.y = y
|
||||||
|
self.activepoint = i.endpoint1
|
||||||
|
return
|
||||||
|
elif abs(x-i.endpoint2.x)<10 and abs(y-i.endpoint2.y)<10:
|
||||||
|
i.endpoint2.x = x
|
||||||
|
i.endpoint2.y = y
|
||||||
|
self.activepoint = i.endpoint2
|
||||||
|
return
|
||||||
self.selecting = True
|
self.selecting = True
|
||||||
else:
|
else:
|
||||||
self.onMouseDown(self, x, y, button=button, clicks=clicks)
|
self.onMouseDown(self, x, y, button=button, clicks=clicks)
|
||||||
|
|
@ -2656,6 +2675,25 @@ class Group (object):
|
||||||
if self.activelayer.level and MODE in [" ", "s"]:
|
if self.activelayer.level and MODE in [" ", "s"]:
|
||||||
if self.activelayer.currentselect:
|
if self.activelayer.currentselect:
|
||||||
self.activelayer.currentselect._onMouseUp(x, y, button=button, clicks=clicks)
|
self.activelayer.currentselect._onMouseUp(x, y, button=button, clicks=clicks)
|
||||||
|
elif self.activepoint:
|
||||||
|
for i in self.lines:
|
||||||
|
if abs(self.activepoint.x-i.endpoint1.x)<10 and abs(self.activepoint.y-i.endpoint1.y)<10:
|
||||||
|
try:
|
||||||
|
[j for j in self.lines if self.activepoint==j.endpoint1][0].assign(i.endpoint1, 1)
|
||||||
|
except IndexError:
|
||||||
|
try:
|
||||||
|
[j for j in self.lines if self.activepoint==j.endpoint2][0].assign(i.endpoint1, 2)
|
||||||
|
break
|
||||||
|
except IndexError: pass
|
||||||
|
if abs(self.activepoint.x-i.endpoint2.x)<10 and abs(self.activepoint.y-i.endpoint2.y)<10:
|
||||||
|
try:
|
||||||
|
[j for j in self.lines if self.activepoint==j.endpoint1][0].assign(i.endpoint2, 1)
|
||||||
|
except IndexError:
|
||||||
|
try:
|
||||||
|
[j for j in self.lines if self.activepoint==j.endpoint2][0].assign(i.endpoint2, 2)
|
||||||
|
break
|
||||||
|
except IndexError: pass
|
||||||
|
break
|
||||||
elif abs(self.startx-x)>4 or abs(self.starty-y)>4:
|
elif abs(self.startx-x)>4 or abs(self.starty-y)>4:
|
||||||
objs = []
|
objs = []
|
||||||
for i in reversed(self.currentFrame()):
|
for i in reversed(self.currentFrame()):
|
||||||
|
|
@ -2690,6 +2728,9 @@ class Group (object):
|
||||||
if self.activelayer.level and MODE in [" ", "s"]:
|
if self.activelayer.level and MODE in [" ", "s"]:
|
||||||
if self.activelayer.currentselect:
|
if self.activelayer.currentselect:
|
||||||
self.activelayer.currentselect._onMouseDrag(x, y, button=button)
|
self.activelayer.currentselect._onMouseDrag(x, y, button=button)
|
||||||
|
elif self.activepoint:
|
||||||
|
self.activepoint.x = x
|
||||||
|
self.activepoint.y = y
|
||||||
else:
|
else:
|
||||||
self.onMouseDrag(self, x, y, button=button)
|
self.onMouseDrag(self, x, y, button=button)
|
||||||
def onMouseDrag(self, self1, x, y, button=1, clicks=1):
|
def onMouseDrag(self, self1, x, y, button=1, clicks=1):
|
||||||
|
|
@ -2828,6 +2869,80 @@ class TemporaryGroup(Group):
|
||||||
elif key=="down_arrow":
|
elif key=="down_arrow":
|
||||||
self1.y+=1
|
self1.y+=1
|
||||||
|
|
||||||
|
class Point(object):
|
||||||
|
"""represents an x,y point, might store other data in the future"""
|
||||||
|
def __init__(self, x, y):
|
||||||
|
super(Point, self).__init__()
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
|
||||||
|
|
||||||
|
class Line(object):
|
||||||
|
"""Use Lines to build Shapes while allowing paintbucketing."""
|
||||||
|
def __init__(self, endpoint1, endpoint2, connection1 = None, connection2 = None):
|
||||||
|
super(Line, self).__init__()
|
||||||
|
self.endpoint1 = endpoint1
|
||||||
|
self.endpoint2 = endpoint2
|
||||||
|
self.connection1 = connection1
|
||||||
|
self.connection2 = connection2
|
||||||
|
self.linecolor = LINECOLOR
|
||||||
|
self.linewidth = LINEWIDTH
|
||||||
|
def assign(self, point, which):
|
||||||
|
if which==1:
|
||||||
|
self.connection1 = point
|
||||||
|
elif which==2:
|
||||||
|
self.connection2 = point
|
||||||
|
def draw(self, cr=None, transform=None, rect=None):
|
||||||
|
if self.connection1:
|
||||||
|
self.endpoint1 = self.connection1
|
||||||
|
if self.connection2:
|
||||||
|
self.endpoint2 = self.connection2
|
||||||
|
if SYSTEM=="gtk":
|
||||||
|
cr.save()
|
||||||
|
cr.set_source(self.linecolor.cairo)
|
||||||
|
cr.set_line_width(max(self.linewidth,1))
|
||||||
|
cr.move_to(self.endpoint1.x,self.endpoint2.y)
|
||||||
|
cr.line_to(self.endpoint2.x,self.endpoint2.y)
|
||||||
|
cr.stroke()
|
||||||
|
cr.restore()
|
||||||
|
elif SYSTEM=="android":
|
||||||
|
global tb
|
||||||
|
tb+="cr.save()\n"
|
||||||
|
tb+="cr.lineWidth = "+str(max(self.linewidth,1))+"\n"
|
||||||
|
tb+="cr.moveTo("+str(self.endpoint1.x)+","+str(self.endpoint1.y)+")\n"
|
||||||
|
tb+="cr.lineTo("+str(self.endpoint2.x)+","+str(self.endpoint2.y)+")\n"
|
||||||
|
tb+="cr.stroke()\n"
|
||||||
|
tb+="cr.restore()\n"
|
||||||
|
elif SYSTEM=="osx":
|
||||||
|
if USING_GL:
|
||||||
|
cr.save()
|
||||||
|
glColor3f(1.0,0.0,0.0)
|
||||||
|
glBegin(GL_LINES)
|
||||||
|
cr.x, cr.y = (self.endpoint1.x, self.endpoint1.y)
|
||||||
|
glVertex2f(cr.x, -cr.y)
|
||||||
|
point = (self.endpoint2.x, self.endpoint2.y)
|
||||||
|
glVertex2f(point[0], -point[1]) # because OpenGL swaps y coords
|
||||||
|
cr.x, cr.y = point
|
||||||
|
glEnd()
|
||||||
|
cr.restore()
|
||||||
|
else:
|
||||||
|
cr.gsave()
|
||||||
|
cr.newpath()
|
||||||
|
cr.pencolor = self.linecolor.pygui
|
||||||
|
cr.pensize = max(self.linewidth,1)
|
||||||
|
cr.moveto(self.endpoint1.x, self.endpoint1.y)
|
||||||
|
cr.lineto(self.endpoint2.x,self.endpoint2.y)
|
||||||
|
cr.stroke()
|
||||||
|
cr.grestore()
|
||||||
|
elif SYSTEM=="html":
|
||||||
|
tb = ""
|
||||||
|
tb+="cr.save()\n"
|
||||||
|
tb+="cr.lineWidth = "+str(max(self.linewidth,1))+"\n"
|
||||||
|
tb+="cr.moveTo("+str(self.endpoint1.x)+","+str(self.endpoint1.y)+")\n"
|
||||||
|
tb+="cr.lineTo("+str(self.endpoint2.x)+","+str(self.endpoint2.y)+")\n"
|
||||||
|
tb+="cr.stroke()\n"
|
||||||
|
tb+="cr.restore()\n"
|
||||||
|
jscommunicate(tb)
|
||||||
|
|
||||||
def set_cursor(curs, widget=None):
|
def set_cursor(curs, widget=None):
|
||||||
if SYSTEM == "osx":
|
if SYSTEM == "osx":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue