comparison pyink/frameline.py @ 972:8a7e5914a84b

Add addScenes to generate scene definition according to the current framelines.
author wycc
date Sat, 20 Nov 2010 11:44:19 +0800
parents a4c0aff915ad
children 5cefabccfb76
comparison
equal deleted inserted replaced
971:a4c0aff915ad 972:8a7e5914a84b
14 def __init__(self, frame_idx): 14 def __init__(self, frame_idx):
15 self.idx = frame_idx 15 self.idx = frame_idx
16 self.left_tween = False 16 self.left_tween = False
17 self.right_tween = False 17 self.right_tween = False
18 self.right_tween_type = 0 18 self.right_tween_type = 0
19 self.ref=''
19 pass 20 pass
20 pass 21 pass
21 22
22 class frameruler(gtk.DrawingArea): 23 class frameruler(gtk.DrawingArea):
23 _type = 0 24 _type = 0
399 last_pos = key_pos 400 last_pos = key_pos
400 while last_pos < max_pos and self._keys[last_pos].right_tween: 401 while last_pos < max_pos and self._keys[last_pos].right_tween:
401 last_pos = last_pos + 1 402 last_pos = last_pos + 1
402 pass 403 pass
403 404
404 return first_pox, last_pos 405 return first_pos, last_pos
405 406
406 ## \brief Redraw a frame specified by an index. 407 ## \brief Redraw a frame specified by an index.
407 # 408 #
408 def _redraw_frame(self, frame_idx): 409 def _redraw_frame(self, frame_idx):
409 if not self._drawing: 410 if not self._drawing:
438 self._draw_tween(first_key, last_key) 439 self._draw_tween(first_key, last_key)
439 self._draw_bottom_line(first_key.idx, last_key.idx + 1) 440 self._draw_bottom_line(first_key.idx, last_key.idx + 1)
440 441
441 for i in range(first_pos, last_pos + 1): 442 for i in range(first_pos, last_pos + 1):
442 key = self._keys[i] 443 key = self._keys[i]
443 print "frame %d type=%d" % (key.idx,key.right_tween_type)
444 if key.left_tween is False or lastkey.right_tween_type != frameline._tween_type_none: 444 if key.left_tween is False or lastkey.right_tween_type != frameline._tween_type_none:
445 self._draw_keyframe(key.idx) 445 self._draw_keyframe(key.idx)
446 lasykey = key 446 lastkey = key
447 pass 447 pass
448 pass 448 pass
449 else: # not in tween 449 else: # not in tween
450 self._draw_normal_frame(frame_idx) 450 self._draw_normal_frame(frame_idx)
451 self._draw_bottom_line(frame_idx, frame_idx + 1) 451 self._draw_bottom_line(frame_idx, frame_idx + 1)
502 502
503 ## Add a key frame 503 ## Add a key frame
504 # 504 #
505 # A key frame is the frame that user specify actions. For 505 # A key frame is the frame that user specify actions. For
506 # example, move a object or add new objects at the frame. 506 # example, move a object or add new objects at the frame.
507 def add_keyframe(self, idx): 507 def add_keyframe(self, idx,ref):
508 key_indic = [key.idx for key in self._keys] 508 key_indic = [key.idx for key in self._keys]
509 if idx in key_indic: 509 if idx in key_indic:
510 return 510 return
511 511
512 key_indic.append(idx) 512 key_indic.append(idx)
513 key_indic.sort() 513 key_indic.sort()
514 insert_pos = key_indic.index(idx) 514 insert_pos = key_indic.index(idx)
515 515
516 key = keyframe(idx) 516 key = keyframe(idx)
517 key.ref = ref
517 self._keys[insert_pos:insert_pos] = [key] 518 self._keys[insert_pos:insert_pos] = [key]
518 if insert_pos > 0 and self._keys[insert_pos - 1].right_tween: 519 if insert_pos > 0 and self._keys[insert_pos - 1].right_tween:
519 key.left_tween = True 520 key.left_tween = True
520 pass 521 pass
521 if insert_pos < (len(self._keys) - 1) and \ 522 if insert_pos < (len(self._keys) - 1) and \
533 idx = i 534 idx = i
534 found = True 535 found = True
535 break 536 break
536 if not found: return 537 if not found: return
537 key = self._keys[idx] 538 key = self._keys[idx]
538 del self._keys[idx]
539 539
540 if key.right_tween ^ key.left_tween: 540 if key.right_tween ^ key.left_tween:
541 # 541 #
542 # tween in one side 542 # tween in one side
543 # 543 #
556 pass 556 pass
557 else: 557 else:
558 self._redraw_frame(idx) 558 self._redraw_frame(idx)
559 pass 559 pass
560 560
561 del self._keys[idx]
561 self._draw_active() 562 self._draw_active()
562 pass 563 pass
563 564
564 ## Tween the key frame specified by an index and the key frame at right. 565 ## Tween the key frame specified by an index and the key frame at right.
565 # 566 #
605 606
606 def reset(self): 607 def reset(self):
607 self._keys = [] 608 self._keys = []
608 pass 609 pass
609 610
611 def addScenes(self,rdoc,node):
612 for i in range(0,len(self._keys)):
613 key = self._keys[i]
614 if key.left_tween is True: return
615 if key.right_tween is True:
616 ss = rdoc.createElement("ns0:scene")
617 node.appendChild(ss)
618 print "[%d:%d]" % (key.idx, self._keys[i+1].idx-1)
619 ss.setAttribute("start", str(key.idx+1),True)
620 ss.setAttribute("ref",key.ref.attribute("id"),True)
621 ss.setAttribute("end", str(self._keys[i+1].idx+1),True)
622 else:
623 ss = rdoc.createElement("ns0:scene")
624 node.appendChild(ss)
625 ss.setAttribute("start", str(key.idx+1),True)
626 ss.setAttribute("ref",key.ref.attribute("id"),True)
627
628
610 ## \brief Start future drawing actions 629 ## \brief Start future drawing actions
611 # 630 #
612 def start_drawing(self): 631 def start_drawing(self):
613 self._drawing = True 632 self._drawing = True
614 pass 633 pass