Initial work on scaling tool.

This commit is contained in:
Skyler Lehmkuhl 2012-09-11 09:52:45 -04:00
parent a7ee308b71
commit d4e08afbcd
3 changed files with 65 additions and 29 deletions

View File

@ -159,8 +159,15 @@ def onMouseDragGroup(self, x, y):
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])
def onMouseDragObj(self, x, y): def onMouseDragObj(self, x, y):
if svlgui.MODE==" ":
self.x = x-self.initx self.x = x-self.initx
self.y = y-self.inity self.y = y-self.inity
elif svlgui.MODE=="s":
print ((self.maxx/2.0+self.minx)-x)/(self.maxx/2.0)
self.xscale = ((self.maxx/2.0+self.minx)-x)/(self.maxx/2.0)
self.yscale = ((self.maxy/2.0+self.miny)-y)/(self.maxy/2.0)
# self.x = (self.x+self.maxx/2)-((self.maxx/2)*self.xscale)
# self.yscale = y/100.0
def onMouseDragText(self, x, y): def onMouseDragText(self, x, y):
self.x = x-self.initx self.x = x-self.initx
self.y = y-self.inity self.y = y-self.inity

View File

@ -228,7 +228,7 @@ class MainWindowOSX:
self.toolbox.buttons[5][0].onPress = lambda self1: svlgui.ColorSelectionWindow("line")#,linegroup)#,self.linecanvas) self.toolbox.buttons[5][0].onPress = lambda self1: svlgui.ColorSelectionWindow("line")#,linegroup)#,self.linecanvas)
self.toolbox.buttons[5][1].onPress = lambda self1: svlgui.ColorSelectionWindow("fill")#,linegroup)#,self.fillcanvas) self.toolbox.buttons[5][1].onPress = lambda self1: svlgui.ColorSelectionWindow("fill")#,linegroup)#,self.fillcanvas)
self.toolbox.buttons[0][1]._int().enabled = False self.toolbox.buttons[0][1]._int().enabled = False
self.toolbox.buttons[1][0]._int().enabled = False # self.toolbox.buttons[1][0]._int().enabled = False
self.toolbox.buttons[3][0]._int().enabled = False self.toolbox.buttons[3][0]._int().enabled = False
self.toolbox.buttons[4][0]._int().enabled = False self.toolbox.buttons[4][0]._int().enabled = False
self.scriptwindow = svlgui.TextView() self.scriptwindow = svlgui.TextView()

View File

@ -67,6 +67,9 @@ EDITING = True
CURRENTTEXT = None CURRENTTEXT = None
#Scaling - whether the user is resizing an object
SCALING = False
#Library. Contatins all objects whether displayed or not. #Library. Contatins all objects whether displayed or not.
Library = [] Library = []
@ -1532,7 +1535,8 @@ class Shape (object):
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot)) cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
else: else:
pass pass
cr.translate(self.x,self.y) # cr.translate(self.x,self.y)
cr.translate(self.x/(self.xscale*1.0),self.y/(self.yscale*1.0))
cr.rotate(self.rotation) cr.rotate(self.rotation)
cr.scale(self.xscale*1.0, self.yscale*1.0) cr.scale(self.xscale*1.0, self.yscale*1.0)
cr.newpath() cr.newpath()
@ -1593,7 +1597,7 @@ class Shape (object):
def scale(self, width, height): def scale(self, width, height):
try: try:
xfactor = width/self.maxx xfactor = width/self.maxx
yfactor = height/maxy yfactor = height/self.maxy
def scale_section(section): def scale_section(section):
try: try:
if section[0] in ["M", "L"]: if section[0] in ["M", "L"]:
@ -1842,8 +1846,8 @@ class framewrapper (object):
self.x = obj.x = x self.x = obj.x = x
self.y = obj.y = y self.y = obj.y = y
self.rot = obj.rot = rot self.rot = obj.rot = rot
self.scalex = obj.scalex = scalex self.scalex = self.xscale = obj.scalex = scalex
self.scaley = obj.scaley = scaley self.scaley = self.yscale = obj.scaley = scaley
self.level = False # don't try to descend into a framewrapper self.level = False # don't try to descend into a framewrapper
self.type = obj.__class__.__name__ self.type = obj.__class__.__name__
if obj.__class__.__name__=="Shape": if obj.__class__.__name__=="Shape":
@ -1862,6 +1866,8 @@ class framewrapper (object):
self.obj.rot = self.rot self.obj.rot = self.rot
self.obj.scalex = self.scalex self.obj.scalex = self.scalex
self.obj.scaley = self.scaley self.obj.scaley = self.scaley
self.obj.xscale = self.xscale
self.obj.yscale = self.yscale
if self.type=="Shape": if self.type=="Shape":
self.obj.filled = self.filled self.obj.filled = self.filled
self.obj.linecolor = self.linecolor self.obj.linecolor = self.linecolor
@ -1886,6 +1892,7 @@ class framewrapper (object):
return self.obj.maxx return self.obj.maxx
def getmaxy(self): def getmaxy(self):
return self.obj.maxy return self.obj.maxy
minx = property(getminx) minx = property(getminx)
miny = property(getminy) miny = property(getminy)
maxx = property(getmaxx) maxx = property(getmaxx)
@ -1913,7 +1920,7 @@ class frame:
self.type="Group" self.type="Group"
self.parent = parent self.parent = parent
self.actions = '' self.actions = ''
def add(self, obj, x, y, rot=0, scalex=0, scaley=0): def add(self, obj, x, y, rot=0, scalex=1, scaley=1):
self.objs.append(framewrapper(obj, x, y, rot, scalex, scaley, self.objs)) self.objs.append(framewrapper(obj, x, y, rot, scalex, scaley, self.objs))
def play(self, group, cr, currentselect,transform,rect): def play(self, group, cr, currentselect,transform,rect):
if SYSTEM=="gtk": if SYSTEM=="gtk":
@ -1984,6 +1991,19 @@ class frame:
currentselect.maxx+currentselect.x+2, currentselect.maxx+currentselect.x+2,
currentselect.maxy+currentselect.y+2]) currentselect.maxy+currentselect.y+2])
cr.stroke() cr.stroke()
if MODE=="s":
cr.newpath()
cr.pencolor = Colors.rgb(1,1,1)
cr.fillcolor = Colors.rgb(0,0,0)
cr.rect([currentselect.minx-5,currentselect.miny-5,
currentselect.minx+5,currentselect.miny+5])
cr.rect([currentselect.maxx+currentselect.x-5,currentselect.miny-5,
currentselect.maxx+currentselect.x+5,currentselect.miny+5])
cr.rect([currentselect.maxx+currentselect.x-5,currentselect.maxy+currentselect.y-5,
currentselect.maxx+currentselect.x+5,currentselect.maxy+currentselect.y+5])
cr.rect([currentselect.minx-5,currentselect.maxy+currentselect.y-5,
currentselect.minx+5,currentselect.maxy+currentselect.y+5])
cr.fill_stroke()
cr.grestore() cr.grestore()
cr.grestore() cr.grestore()
elif SYSTEM=="html": elif SYSTEM=="html":
@ -2104,7 +2124,7 @@ class Layer:
def parse_obj(obj): def parse_obj(obj):
obj.x=obj.x-self.x obj.x=obj.x-self.x
obj.y=obj.y-self.y obj.y=obj.y-self.y
self.frames[self.currentframe].add(obj, obj.x, obj.y, obj.rotation,0,0) self.frames[self.currentframe].add(obj, obj.x, obj.y, obj.rotation,1,1)
self.objs.append(obj) self.objs.append(obj)
[parse_obj(obj) for obj in args] [parse_obj(obj) for obj in args]
def delete(self,*args): def delete(self,*args):
@ -2147,6 +2167,10 @@ class Layer:
self.currentselect._onMouseDown(self.currentselect, x, y) self.currentselect._onMouseDown(self.currentselect, x, y)
else: else:
if MODE in [" ", "s", "b"]: if MODE in [" ", "s", "b"]:
if self.currentselect and MODE=="s":
if self.currentselect.minx-5<x<self.currentselect.minx+5:
print "hey!"
else:
for i in reversed(self.currentFrame()): for i in reversed(self.currentFrame()):
test = False test = False
if i.hitTest(x, y): if i.hitTest(x, y):
@ -2344,6 +2368,10 @@ class Group (object):
self.activelayer.currentselect._onMouseDown(self.activelayer.currentselect, x, y) self.activelayer.currentselect._onMouseDown(self.activelayer.currentselect, x, y)
else: else:
if MODE in [" ", "s", "b"]: if MODE in [" ", "s", "b"]:
if self.activelayer.currentselect and MODE=="s":
if self.activelayer.currentselect.minx-5<x<self.activelayer.currentselect.minx+5:
SCALING = True
else:
test = False test = False
for i in reversed(self.currentFrame()): for i in reversed(self.currentFrame()):
if i.hitTest(x, y): if i.hitTest(x, y):
@ -2361,6 +2389,7 @@ class Group (object):
def onMouseDown(self, self1, x, y): def onMouseDown(self, self1, x, y):
pass pass
def _onMouseUp(self,x,y): def _onMouseUp(self,x,y):
SCALING = False
x, y = self.localtransform(x, y) x, y = self.localtransform(x, y)
if self.activelayer.level and MODE in [" ", "s"]: if self.activelayer.level and MODE in [" ", "s"]:
if self.activelayer.currentselect: if self.activelayer.currentselect: