comparison pyink/frameline.py @ 966:ca993c473379

Function of removing key frames
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 18 Nov 2010 11:20:24 +0800
parents dbb5462c471f
children 5c013e3cadd0
comparison
equal deleted inserted replaced
965:dbb5462c471f 966:ca993c473379
352 win.draw_line(gc, line_x2, 0, line_x2, w_h) 352 win.draw_line(gc, line_x2, 0, line_x2, w_h)
353 win.draw_line(gc, line_x1, w_h - 1, line_x2, w_h - 1) 353 win.draw_line(gc, line_x1, w_h - 1, line_x2, w_h - 1)
354 win.draw_line(gc, line_x1, 0, line_x2, 0) 354 win.draw_line(gc, line_x1, 0, line_x2, 0)
355 pass 355 pass
356 356
357 ## \brief Find the range a continous tween.
358 #
359 def _find_tween_range(self, key_pos):
360 first_pos = key_pos
361 while first_pos and self._keys[first_pos].left_tween:
362 first_pos = first_pos - 1
363 pass
364
365 max_pos = len(self._keys) - 1
366
367 last_pos = key_pos
368 while last_pos < max_pos and self._keys[last_pos].right_tween:
369 last_pos = last_pos + 1
370 pass
371
372 return first_pox, last_pos
373
357 ## \brief Redraw a frame specified by an index. 374 ## \brief Redraw a frame specified by an index.
358 # 375 #
359 def _redraw_frame(self, frame_idx): 376 def _redraw_frame(self, frame_idx):
360 keys = [key.idx for key in self._keys] 377 keys = [key.idx for key in self._keys]
361 if len(keys): 378 if len(keys):
374 key = None 391 key = None
375 pass 392 pass
376 393
377 if key and (key.right_tween or \ 394 if key and (key.right_tween or \
378 (key.left_tween and key.idx == frame_idx)): 395 (key.left_tween and key.idx == frame_idx)):
379 first_key = last_key = key 396 #
380 first_pos = last_pos = pos 397 # in tween
381 while first_pos > 0 and first_key.left_tween: 398 #
382 first_pos = first_pos - 1 399 first_pos, last_pos = self._find_tween_range(pos)
383 first_key = self._keys[first_pos] 400 first_key = self._keys[first_pos]
384 pass 401 last_key = self._keys[last_pos]
385 max_pos = len(self._keys) - 1 402
386 while last_pos < max_pos and last_key.right_tween:
387 last_pos = last_pos + 1
388 last_key = self._keys[last_pos]
389 pass
390
391 self._draw_tween(first_key, last_key) 403 self._draw_tween(first_key, last_key)
392 self._draw_bottom_line(first_key.idx, last_key.idx + 1) 404 self._draw_bottom_line(first_key.idx, last_key.idx + 1)
393 405
394 for i in range(first_pos, last_pos + 1): 406 for i in range(first_pos, last_pos + 1):
395 key = self._keys[i] 407 key = self._keys[i]
396 self._draw_keyframe(key.idx) 408 self._draw_keyframe(key.idx)
397 pass 409 pass
398 pass 410 pass
399 else: 411 else: # not in tween
400 self._draw_normal_frame(frame_idx) 412 self._draw_normal_frame(frame_idx)
401 self._draw_bottom_line(frame_idx, frame_idx + 1) 413 self._draw_bottom_line(frame_idx, frame_idx + 1)
402 if key and (key.idx == frame_idx): 414 if key and (key.idx == frame_idx):
403 self._draw_keyframe(frame_idx) 415 self._draw_keyframe(frame_idx)
404 pass 416 pass
464 pass 476 pass
465 if insert_pos < (len(self._keys) - 1) and \ 477 if insert_pos < (len(self._keys) - 1) and \
466 self._keys[insert_pos + 1].left_tween: 478 self._keys[insert_pos + 1].left_tween:
467 key.right_tween = True 479 key.right_tween = True
468 pass 480 pass
481
482 self._draw_keyframe(idx)
483 pass
484
485 def rm_keyframe(self, idx):
486 key = self._keys[idx]
487 del self._keys[idx]
488
489 if key.right_tween ^ key.left_tween:
490 #
491 # tween in one side
492 #
493 if key.right_tween:
494 right_key = self._keys[idx]
495 right_key.left_tween = False
496 rdraw_range = (right_key.idx, idx + 1)
497 else:
498 left_key = self._keys[idx - 1]
499 left_key.right_key = False
500 redraw_range = (idx, left_key.idx + 1)
501 pass
502
503 for i in range(*redraw_range):
504 self._redraw_frame(i)
505 pass
506 else:
507 self._redraw_frame(idx)
508 pass
469 pass 509 pass
470 510
471 ## Tween the key frame specified by an index and the key frame at right. 511 ## Tween the key frame specified by an index and the key frame at right.
472 # 512 #
473 # \see http://www.entheosweb.com/Flash/shape_tween.asp 513 # \see http://www.entheosweb.com/Flash/shape_tween.asp
501 self._active_frame = -1 541 self._active_frame = -1
502 pass 542 pass
503 543
504 def set_num_frames(self, num): 544 def set_num_frames(self, num):
505 self._num_frames = num 545 self._num_frames = num
546 pass
547
548 def reset(self):
549 self._keys = []
506 pass 550 pass
507 551
508 def __len__(self): 552 def __len__(self):
509 return self._num_frames 553 return self._num_frames
510 pass 554 pass