comparison pyink/MBScene.py @ 1125:5b2394f67ad0

Add shape tween support.
author wycc
date Sat, 11 Dec 2010 21:08:51 +0800
parents aad659b6b625
children b65ac686a7c5
comparison
equal deleted inserted replaced
1124:b5ff72dbc910 1125:5b2394f67ad0
547 print "translate" 547 print "translate"
548 fields = t[10:].split(',') 548 fields = t[10:].split(',')
549 x = float(fields[0]) 549 x = float(fields[0])
550 fields = fields[1].split(')') 550 fields = fields[1].split(')')
551 y = float(fields[0]) 551 y = float(fields[0])
552 return [1,0,x,0,1,y] 552 return [1,0,0,1,x,y]
553 elif t[0:6] == 'matrix': 553 elif t[0:6] == 'matrix':
554 print "matrix" 554 print "matrix"
555 fields=t[7:].split(')') 555 fields=t[7:].split(')')
556 fields = fields[0].split(',') 556 fields = fields[0].split(',')
557 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] 557 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])]
558 except: 558 except:
559 traceback.print_exc() 559 #traceback.print_exc()
560 return [1,0,0,0,1,0] 560 return [1,0,0,1,0,0]
561
562 def invA(self,m):
563 d = m[0]*m[3]-m[2]*m[1]
564 return [m[3]/d, m[1]/d, -m[2]/d, m[0]/d, (m[1]*m[5]-m[4]*m[3])/d, (m[4]*m[2]-m[0]*m[5])/d]
565 def mulA(self,a,b):
566 return [a[0]*b[0]+a[1]*b[2],
567 a[0]*b[1]+a[1]*b[3],
568 a[2]*b[0]+a[3]*b[2],
569 a[2]*b[1]+a[3]*b[3],
570 a[0]*b[4]+a[1]*b[5]+a[4],
571 a[2]*b[4]+a[3]*b[5]+a[5]]
561 572
562 573
563 def updateTweenObject(self,obj,typ,s,d,p): 574 def updateTweenObject(self,obj,typ,s,d,p):
564 """ 575 """
565 Generate tweened object in the @obj by using s and d in the @p percent 576 Generate tweened object in the @obj by using s and d in the @p percent
587 tx = (dx-sx)*p 598 tx = (dx-sx)*p
588 ty = (dy-sy)*p 599 ty = (dy-sy)*p
589 print tx,ty 600 print tx,ty
590 top.setAttribute("transform","translate(%g,%g)" % (tx,ty),True) 601 top.setAttribute("transform","translate(%g,%g)" % (tx,ty),True)
591 except: 602 except:
603 #traceback.print_exc()
604 pass
605 pass
606 elif typ == 'scale':
607 newobj = s.duplicate(self.desktop.doc().rdoc)
608 top = self.desktop.doc().rdoc.createElement("svg:g")
609 top.appendChild(newobj)
610 obj.appendChild(top)
611 if s.name() == 'svg:g':
612 # Parse the translate or matrix
613 sm = self.parseTransform(s)
614 dm = self.parseTransform(d)
615 # r(1)*A = B
616 # ==> r(1) = B * inv(A)
617 r1 = self.mulA(dm,self.invA(sm))
618 t0 = 1+ (r1[0]-1)*p
619 t1 = r1[1]*p
620 t2 = r1[2]*p
621 t3 = 1+(r1[3]-1)*p
622 t4 = r1[4]*p
623 t5 = r1[5]*p
624
625 print "scale: %g %g %g %g %g %g" % (t0,t1,t2,t3,t4,t5)
626 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (t0,t1,t2,t3,t4,t5),True)
627 else:
628 try:
629 sw = float(s.attribute("width"))
630 sh = float(s.attribute("height"))
631 dw = float(d.attribute("width"))
632 dh = float(d.attribute("height"))
633 tx = (dw-sw)*p+sw
634 ty = (dh-sh)*p+sh
635 print tx,ty
636 top.setAttribute("transform","matrix(%g,0,0,%g,0,0)" % (tx,ty),True)
637 except:
592 traceback.print_exc() 638 traceback.print_exc()
593 pass 639 pass
594 pass 640 pass
641
595 pass 642 pass
596 def enterGroup(self,obj): 643 def enterGroup(self,obj):
597 for l in self.layers: 644 for l in self.layers:
598 for s in l.node.childList(): 645 for s in l.node.childList():
599 if s.getId() == obj.attribute("id"): 646 if s.getId() == obj.attribute("id"):