annotate pyink/frameline.py @ 1150:6586cd10c92f

Refactory frameline.py
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 26 Dec 2010 19:17:12 +0800
parents 3ec0ad89e443
children d333baa702a9
rev   line source
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
1 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; fill-column: 79 -*-
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
2 # vim: sw=4:ts=8:sts=4:textwidth=79
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3 import pygtk
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 pygtk.require("2.0")
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 import gtk
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 import gtk.gdk
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
7 import pango
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 import gobject
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 def color_to_rgb(v):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 return (((v >> 16) & 0xff) * 65535 / 0xff,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12 ((v >> 8) & 0xff) * 65535 / 0xff,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 (v & 0xff) * 65535 / 0xff)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 class keyframe(object):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 def __init__(self, frame_idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 self.idx = frame_idx
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18 self.left_tween = False
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19 self.right_tween = False
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 self.right_tween_type = 0
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
21 self.ref = ''
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
25 class frameruler(gtk.DrawingArea):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
26 _type = 0
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
27 _frame_width = 10 # Width for each frame is 10 pixels
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
28 _mark_color = 0x808080 # color of mark lines
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
29 _number_color = 0x000000 # color of frame number
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
30 _number_sz = 8 # font size of frame number
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
31
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
32 def __new__(clz, *args):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
33 if not frameruler._type:
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
34 frameruler._type = gobject.type_register(frameruler)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
35 pass
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
36 fr = gobject.new(frameruler._type)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
37 return fr
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
38
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
39 def __init__(self, num_frames=20):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
40 self.connect('expose_event', self._fr_expose)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
41 self._num_frames = num_frames
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
42 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
43
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
44 def _fr_expose(self, widget, event):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
45 self.update()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
46 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
47
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
48 def queue_draw(self):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
49 print 'queue_draw'
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
50 self.update()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
51 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
52
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
53 def queue_draw_area(self, x, y, w, h):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
54 print 'queue_draw_area'
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
55 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
56
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
57 def update(self):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
58 win = self.window
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
59 w_x, w_y, w_w, w_h, depth = win.get_geometry()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
60
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
61 gc = gtk.gdk.GC(win)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
62
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
63 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
64 # Set color of mark lines
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
65 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
66 color_rgb = color_to_rgb(self._mark_color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
67 color = gtk.gdk.Color(*color_rgb)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
68 gc.set_rgb_fg_color(color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
69
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
70 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
71 # Mark mark lines
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
72 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
73 mark_h = w_h / 10
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
74 for i in range(self._num_frames):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
75 mark_x = (i + 1) * self._frame_width
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
76 win.draw_line(gc, mark_x, 0, mark_x, mark_h)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
77 win.draw_line(gc, mark_x, w_h - mark_h - 1, mark_x, w_h - 1)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
78 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
79
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
80 win.draw_line(gc, 0, w_h - 1, w_w, w_h -1)
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
81
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
82 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
83 # Set color of frame number
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
84 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
85 color_rgb = color_to_rgb(self._number_color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
86 color = gtk.gdk.Color(*color_rgb)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
87 gc.set_rgb_fg_color(color)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
88
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
89 font_desc = pango.FontDescription()
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
90 font_desc.set_size(self._number_sz * pango.SCALE)
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
91
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
92 number_y = (w_h - self._number_sz) / 2
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
93
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
94 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
95 # Draw frame number
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
96 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
97 layout = self.create_pango_layout('1')
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
98 layout.set_font_description(font_desc)
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
99 win.draw_layout(gc, 0, number_y, layout)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
100 for i in range(4, self._num_frames, 5):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
101 mark_x = i * self._frame_width
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
102 layout.set_text(str(i + 1))
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
103 win.draw_layout(gc, mark_x, number_y, layout)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
104 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
105 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
106 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
107
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
108 ## Show frame status of a layer
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
109 #
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
110 # \section frameline_sigs Signals
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
111 # - 'frame-button-pree' for user press on a frame.
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
112 # - callback(widget, frame_idx, button)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
113 #
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
114 # All methos that change state of the frameline, must call methods to update
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
115 # the screen.
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
116 #
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
117 class frameline(gtk.DrawingArea):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
118 _type = 0
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
119 _frame_width = 10 # Width for each frame is 10 pixels
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
120 _select_color = 0xee2222 # color of border of selected frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
121 _key_mark_color = 0x000000 # color of marks for key frames.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
122 _key_mark_sz = 4 # width and height of a key frame mark
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
123 _tween_color = 0x808080 # color of tween line
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
124 # bg colors of tween frames
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
125 _tween_bgcolors = [0x80ff80, 0xff8080, 0xffff80]
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
126 # Colors for normal frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
127 _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
128 _normal_border = 0xaaaaaa # border color of normal frames.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
129 _active_border = 0xff3030 # border color of an active frame
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
130 _hover_border_color = 0xa0a0a0 # border when the pointer over a frame
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
131
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
132 # tween types
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
133 TWEEN_TYPE_NONE = 0
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
134 TWEEN_TYPE_MOVE = 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
135 TWEEN_TYPE_SHAPE = 2
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
136
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
137 FRAME_BUT_PRESS = 'frame-button-press'
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
138
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
139 def __new__(clz, *args):
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
140 if not frameline._type:
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
141 frameline._type = gobject.type_register(frameline)
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
142 but_press = gobject.signal_new(frameline.FRAME_BUT_PRESS,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
143 frameline._type,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
144 gobject.SIGNAL_RUN_FIRST,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
145 gobject.TYPE_NONE,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
146 (gobject.TYPE_INT,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
147 gobject.TYPE_INT))
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
148 frameline._sig_frame_but_press = but_press
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
149 pass
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
150 fl_obj = gobject.new(frameline._type)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
151 return fl_obj
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
152
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
153 def __init__(self, num_frames=20):
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
154 self.connect('button-press-event', self._press_hdl)
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
155 self.connect('expose-event', self._fl_expose)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
156 self.connect('motion-notify-event', self._motion_hdl)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
157 self._num_frames = num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
158 self._keys = []
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
159 self._active_frame = -1
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
160 self._last_hover = -1 # frame index of last hover
968
a715301b5879 Start drawing after an expose event
Thinker K.F. Li <thinker@codemud.net>
parents: 967
diff changeset
161 self._drawing = False
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
162 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
163
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
164 def __len__(self):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
165 return self._num_frames
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
166
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
167 def _find_keyframe(self, idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
168 key_indic = [key.idx for key in self._keys]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
169 key_pos = key_indic.index(idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
170 return key_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
171
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
172 def _find_keyframe_floor(self, frame_idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
173 pos = 0
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
174 keys = [key.idx for key in self._keys]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
175 keys.append(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
176 keys.sort()
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
177 keys.reverse()
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
178 pos = (len(keys) - 1) - keys.index(frame_idx) - 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
179 return pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
180
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
181 ## \brief Find the range a continous tween.
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
182 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
183 def _find_tween_range(self, key_pos):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
184 key = self._keys[key_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
185 if not (key.left_tween or key.right_tween):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
186 raise ValueError, 'the keyframe is not in a tween'
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
187
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
188 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
189 # Initialize tween type and first_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
190 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
191 if key.right_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
192 tween_type = key.right_tween_type
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
193 first_pos = key_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
194 else:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
195 # key.left_tween is True since the key is in a tween.
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
196 first_pos = key_pos -1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
197 key = self._keys[first_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
198 tween_type = key.right_tween_type
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
199 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
200
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
201 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
202 # Find first_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
203 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
204 while first_pos and key.left_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
205 right_pos = first_pos - 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
206 right_key = self._keys[right_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
207 if right_key.right_tween_type != tween_type:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
208 break
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
209 first_pos = right_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
210 key = right_key
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
211 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
212
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
213 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
214 # Find last_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
215 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
216 max_pos = len(self._keys) - 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
217 last_pos = key_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
218 key = self._keys[last_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
219 while last_pos < max_pos and self._keys[last_pos].right_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
220 if key.right_tween_type != tween_type:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
221 break
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
222 last_pos = last_pos + 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
223 key = self._keys[last_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
224 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
225
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
226 return first_pos, last_pos
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
227
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
228 def _press_hdl(self, widget, event):
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
229 frame = event.x / self._frame_width
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
230 but = event.button
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
231 self.emit(frameline.FRAME_BUT_PRESS, frame, but)
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
232 pass
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
233
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
234 def hide_hover(self):
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
235 if self._active_frame != self._last_hover:
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
236 self._draw_normal_frame(self._last_hover)
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
237 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
238 pass
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
239
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
240 def _motion_hdl(self, widget, event):
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
241 frame_idx = int(event.x / self._frame_width)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
242 if self._last_hover != -1:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
243 self._draw_frame(self._last_hover)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
244 if self._last_hover == self._active_frame:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
245 self._draw_active_frame()
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
246 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
247 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
248
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
249 if frame_idx < self._num_frames and frame_idx >= 0:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
250 self._draw_hover_frame(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
251 if self._last_hover == self._active_frame:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
252 self._draw_active_frame()
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
253 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
254 self._last_hover = frame_idx
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
255 else:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
256 self._last_hover = -1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
257 pass
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
258 pass
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
259
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
260 def _fl_expose(self, widget, event):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
261 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
262 x, y, w, h, depth = win.get_geometry()
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
263 if not hasattr(self, '_gc'):
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
264 self._gc = gtk.gdk.GC(win)
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
265 #
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
266 # register for button press event
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
267 #
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
268 emask = win.get_events()
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
269 emask = emask | gtk.gdk.BUTTON_PRESS_MASK | \
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
270 gtk.gdk.POINTER_MOTION_MASK
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
271 win.set_events(emask)
968
a715301b5879 Start drawing after an expose event
Thinker K.F. Li <thinker@codemud.net>
parents: 967
diff changeset
272 self._drawing = True
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
273 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
274 self.update()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
275 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
276
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
277 def _draw_tween(self, first_pos, last_pos):
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
278 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
279 w_x, w_y, w_w, w_h, depth = win.get_geometry()
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
280 first_key = self._keys[first_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
281 last_key = self._keys[last_pos]
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
282
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
283 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
284 # Get background color of a tween
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
285 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
286 bg_idx = first_key.right_tween_type
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
287 bg_color_v = self._tween_bgcolors[bg_idx]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
288 bg_color_rgb = color_to_rgb(bg_color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
289 bg_color = gtk.gdk.Color(*bg_color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
290
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
291 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
292 gc.set_rgb_fg_color(bg_color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
293
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
294 draw_x = first_key.idx * self._frame_width + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
295 draw_w = (last_key.idx - first_key.idx + 1) * self._frame_width - 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
296
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
297 win.draw_rectangle(gc, True, draw_x, 0, draw_w, w_h)
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
298
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
299 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
300 # Set color of tween line
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
301 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
302 line_v = self._tween_color
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
303 line_rgb = color_to_rgb(line_v)
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
304 line_color = gtk.gdk.Color(*line_rgb)
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
305 gc.set_rgb_fg_color(line_color)
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
306
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
307 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
308 # Draw tween line
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
309 #
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
310 line_x1 = int((first_key.idx + 0.5) * self._frame_width)
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
311 line_x2 = line_x1 + (last_key.idx - first_key.idx) * self._frame_width
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
312 line_y = int(w_h * 2 / 3)
945
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
313 win.draw_line(gc, line_x1, line_y, line_x2, line_y)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
314 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
315
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
316 def _draw_normal_frame(self, idx):
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
317 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
318 w_x, w_y, w_w, w_h, depth = win.get_geometry()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
319
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
320 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
321 bg_idx = idx % len(self._normal_bgcolors)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
322 rgb = color_to_rgb(self._normal_bgcolors[bg_idx])
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
323 color = gtk.gdk.Color(*rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
324 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
325
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
326 f_x = self._frame_width * idx
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
327 win.draw_rectangle(gc, True, f_x + 1, 0, self._frame_width - 1, w_h)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
328 next_f_x = f_x + self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
329
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
330 border_rgb = color_to_rgb(self._normal_border)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
331 border_color = gtk.gdk.Color(*border_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
332 gc.set_rgb_fg_color(border_color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
333 gc.set_line_attributes(1, gtk.gdk.LINE_SOLID,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
334 gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
335 win.draw_line(gc, next_f_x, 0, next_f_x, w_h)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
336 pass
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
337
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
338 ## \brief Draw a bottom line from start to the point before stop frame.
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
339 #
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
340 def _draw_bottom_line(self, start_idx, stop_idx):
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
341 win = self.window
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
342 w_x, w_y, w_w, w_h, depth = win.get_geometry()
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
343 gc = self._gc
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
344
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
345 border_rgb = color_to_rgb(self._normal_border)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
346 border_color = gtk.gdk.Color(*border_rgb)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
347 gc.set_rgb_fg_color(border_color)
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
348 start_x = start_idx * self._frame_width
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
349 stop_x = stop_idx * self._frame_width
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
350 win.draw_line(gc, start_x, w_h - 1, stop_x, w_h - 1)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
351 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
352
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
353 def _draw_active(self, idx):
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
354 win = self.window
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
355 w_x, w_y, w_w, w_h, depth = win.get_geometry()
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
356
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
357 color_v = self._active_border
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
358 color_rgb = color_to_rgb(color_v)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
359 color = gtk.gdk.Color(*color_rgb)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
360
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
361 gc = self._gc
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
362 gc.set_rgb_fg_color(color)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
363
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
364 line_x1 = idx * self._frame_width
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
365 line_x2 = line_x1 + self._frame_width
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
366
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
367 win.draw_line(gc, line_x1, 0, line_x1, w_h)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
368 win.draw_line(gc, line_x2, 0, line_x2, w_h)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
369 win.draw_line(gc, line_x1, w_h - 1, line_x2, w_h - 1)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
370 win.draw_line(gc, line_x1, 0, line_x2, 0)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
371 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
372
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
373 def _draw_keyframe(self, frame_idx):
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
374 # Only keyframes that is not right-side of NONE type tween should be
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
375 # draw.
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
376 pos = self._find_keyframe(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
377 key = self._keys[pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
378 if key.left_tween and not key.right_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
379 left_key = self._keys[pos - 1]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
380 if left_key.right_tween_type == 0:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
381 return
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
382 pass
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
383
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
384 win = self.window
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
385 w_x, w_y, w_w, w_h, depth = win.get_geometry()
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
386
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
387 color_v = self._key_mark_color
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
388 color_rgb = color_to_rgb(color_v)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
389 color = gtk.gdk.Color(*color_rgb)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
390
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
391 gc = self._gc
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
392 gc.set_rgb_fg_color(color)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
393
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
394 mark_sz = self._key_mark_sz
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
395 mark_x = int((frame_idx + 0.5) * self._frame_width - mark_sz / 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
396 mark_y = w_h * 2 / 3 - mark_sz / 2
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
397
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
398 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
399 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
400
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
401 def _draw_keyframes(self):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
402 for key in self._keys:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
403 self._draw_keyframe(key.idx)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
404 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
405 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
406
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
407 ## \brief Show a mark for the pointer for a frame.
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
408 #
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
409 def _draw_hover(self, frame_idx):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
410 win = self.window
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
411 w_x, w_y, w_w, w_h, depth = win.get_geometry()
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
412 gc = self._gc
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
413
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
414 color_rgb = color_to_rgb(self._hover_border_color)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
415 color = gtk.gdk.Color(*color_rgb)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
416 gc.set_rgb_fg_color(color)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
417
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
418 line_x1 = frame_idx * self._frame_width + 1
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
419 line_x2 = line_x1 + self._frame_width - 2
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
420
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
421 win.draw_line(gc, line_x1, 1, line_x1, w_h - 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
422 win.draw_line(gc, line_x2, 1, line_x2, w_h - 2)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
423 win.draw_line(gc, line_x1, 1, line_x2, 1)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
424 win.draw_line(gc, line_x1, w_h - 2, line_x2, w_h - 2)
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
425 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
426
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
427 ## \brief Redraw a frame specified by an index.
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
428 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
429 def _draw_frame(self, frame_idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
430 if not self._drawing:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
431 return
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
432
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
433 pos = self._find_keyframe_floor(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
434 try:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
435 key = self._keys[pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
436 except IndexError:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
437 key = None
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
438 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
439
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
440 if key and (key.right_tween or
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
441 (key.left_tween and key.idx == frame_idx)):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
442 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
443 # in tween
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
444 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
445 first_pos, last_pos = self._find_tween_range(pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
446 first_key = self._keys[first_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
447 last_key = self._keys[last_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
448
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
449 self._draw_tween_of_key(first_pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
450 else: # not in tween
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
451 self._draw_normal_frame(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
452 self._draw_bottom_line(frame_idx, frame_idx + 1)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
453 if key and (key.idx == frame_idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
454 self._draw_keyframe(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
455 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
456 pass
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
457 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
458
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
459 def _draw_all_frames(self):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
460 if not self._drawing:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
461 return
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
462
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
463 i = 0
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
464 key_pos = 0
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
465 try:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
466 key = self._keys[key_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
467 except IndexError:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
468 key = keyframe(self._num_frames)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
469 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
470 num_frames = self._num_frames
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
471 while i < num_frames:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
472 if key.idx == i and key.right_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
473 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
474 # Skip tween keys
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
475 #
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
476 first_tween_pos, last_tween_pos = \
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
477 self._find_tween_range(key_pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
478 self._draw_tween(first_tween_pos, last_tween_pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
479 last_tween_key = self._keys[last_tween_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
480 i = last_tween_key.idx + 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
481 else:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
482 self._draw_normal_frame(i)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
483 if key.idx == i:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
484 key_pos = key_pos+1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
485 try:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
486 key = self._keys[key_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
487 except:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
488 key = keyframe(self._num_frames)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
489 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
490 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
491 i = i + 1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
492 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
493 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
494
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
495 self._draw_bottom_line(0, num_frames)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
496
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
497 self._draw_keyframes()
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
498 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
499
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
500 def _draw_tween_of_key(self, key_pos):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
501 if not self._drawing:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
502 return
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
503
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
504 first_pos, last_pos = self._find_tween_range(key_pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
505 first_key = self._keys[first_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
506 last_key = self._keys[last_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
507
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
508 self._draw_tween(first_pos, last_pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
509 self._draw_bottom_line(first_key.idx, last_key.idx + 1)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
510
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
511 for i in range(first_pos, last_pos + 1):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
512 key = self._keys[i]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
513 self._draw_keyframe(key.idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
514 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
515 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
516
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
517 def _draw_active_frame(self):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
518 if not self._drawing:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
519 return
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
520
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
521 if self._active_frame == -1:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
522 return
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
523
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
524 self._draw_active(self._active_frame)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
525 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
526
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
527 def _draw_hover_frame(self, frame_idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
528 if not self._drawing:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
529 return
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
530 self._draw_hover(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
531 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
532
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
533 def set_tween_type(self, frame_idx, tween_type):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
534 pos = self._find_keyframe(frame_idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
535 key = self._keys[pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
536 assert key.right_tween
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
537
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
538 key.right_tween_type = tween_type
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
539 self._draw_tween_of_key(pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
540
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
541 self._draw_active_frame()
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
542 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
543
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
544 def update(self):
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
545 if not self._drawing:
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
546 return
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
547
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
548 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
549 x, y, w, h, depth = win.get_geometry()
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
550 self._draw_all_frames()
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
551 self._draw_active_frame()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
552 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
553
947
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
554 ## Add a key frame
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
555 #
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
556 # A key frame is the frame that user specify actions. For
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
557 # example, move a object or add new objects at the frame.
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
558 def add_keyframe(self, idx, ref=None):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
559 try:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
560 pos = self._find_keyframe(idx) # it is not already a keyframe.
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
561 except ValueError:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
562 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
563 else:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
564 raise ValueError, 'the frame is already a key frame'
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
565
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
566 key_indic = [key.idx for key in self._keys]
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
567 key_indic.append(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
568 key_indic.sort()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
569 insert_pos = key_indic.index(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
570
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
571 key = keyframe(idx)
972
8a7e5914a84b Add addScenes to generate scene definition according to the current framelines.
wycc
parents: 971
diff changeset
572 key.ref = ref
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
573 self._keys[insert_pos:insert_pos] = [key]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
574 if insert_pos > 0 and self._keys[insert_pos - 1].right_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
575 key.left_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
576 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
577 if insert_pos < (len(self._keys) - 1) and \
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
578 self._keys[insert_pos + 1].left_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
579 key.right_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
580 pass
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
581
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
582 if self._drawing:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
583 self._draw_keyframe(idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
584 pass
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
585 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
586
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
587 def rm_keyframe(self, idx):
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
588 key_pos = self._find_keyframe(idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
589 key = self._keys[key_pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
590 del self._keys[key_pos]
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
591
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
592 if key.right_tween ^ key.left_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
593 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
594 # tween in one side
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
595 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
596 if key.right_tween:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
597 right_key = self._keys[key_pos]
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
598 right_key.left_tween = False
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
599 redraw_range = (right_key.idx, idx + 1)
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
600 else:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
601 left_key = self._keys[key_pos - 1]
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
602 left_key.right_key = False
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
603 redraw_range = (idx, left_key.idx + 1)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
604 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
605 for i in range(*redraw_range):
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
606 self._draw_frame(i)
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
607 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
608 else:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
609 self._draw_frame(idx)
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
610 pass
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
611
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
612 self._draw_active_frame()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
613 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
614
946
f82ac6740a32 change wording in doc
Thinker K.F. Li <thinker@codemud.net>
parents: 945
diff changeset
615 ## Tween the key frame specified by an index and the key frame at right.
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
616 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
617 # \see http://www.entheosweb.com/Flash/shape_tween.asp
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
618 def tween(self, idx, tween_type=TWEEN_TYPE_NONE):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
619 pos = self._find_keyframe(idx)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
620 key = self._keys[pos]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
621
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
622 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
623 right_key = self._keys[pos + 1]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
624 except IndexError:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
625 raise ValueError, 'no right key frame'
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
626
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
627 key.right_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
628 right_key.left_tween = True
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
629 key.right_tween_type = tween_type
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
630
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
631 self._draw_tween_of_key(pos)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
632 self._draw_active_frame()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
633 pass
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
634
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
635 def get_tween_type(self, idx):
1120
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 977
diff changeset
636 for i in range(0,len(self._keys)):
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 977
diff changeset
637 key = self._keys[i]
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 977
diff changeset
638 if key.left_tween is True: continue
214e1f628d63 Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
wycc
parents: 977
diff changeset
639 if key.idx == idx:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
640 return key.right_tween_type
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
641 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
642 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
643
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
644 def get_frame_blocks(self):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
645 blocks = []
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
646 for pos, key in enumerate(self._keys):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
647 if key.right_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
648 next_key = self._keys[pos + 1]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
649 block = (key.idx, next_key.idx, key.right_tween_type)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
650 elif not key.left_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
651 block = (key.idx, key.idx, 0)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
652 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
653 blocks.append(block)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
654 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
655 return blocks
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
656
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
657 def get_frame_block(self, idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
658 pos = self._find_keyframe_floor(idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
659 if pos != -1:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
660 key = self._keys[pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
661 if key.idx == idx:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
662 return key.idx, key.idx, 0
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
663 elif key.right_tween:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
664 next_key = self._keys[pos + 1]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
665 return key.idx, next_key.idx, key.right_tween_type
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
666 pass
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
667 raise ValueError, \
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
668 'the frame specified by idx is not in any tween or a key frame'
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
669
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
670 def get_frame_data(self, idx):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
671 pos = self._find_keyframe(idx)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
672 key = self._keys[pos]
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
673 return key.ref
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
674
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
675 ## Set active frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
676 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
677 # The active frame is the frame that is working on.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
678 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
679 def active_frame(self, idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
680 if idx < 0 or idx >= self._num_frames:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
681 raise IndexError, 'value of index (%d) is out of range' % (idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
682
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
683 if self._active_frame != -1:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
684 self._draw_frame(self._active_frame)
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
685 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
686 self._active_frame = idx
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
687 self._draw_active_frame()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
688 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
689
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
690 def deactive(self):
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
691 self._draw_frame(self._active_frame)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
692 self._active_frame = -1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
693 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
694
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
695 def set_num_frames(self, num):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
696 self._num_frames = num
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
697 self._
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
698 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
699
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
700 def reset(self):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
701 self._keys = []
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
702 self._active_frame = -1
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1131
diff changeset
703 self._draw_all_frames()
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
704 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
705
967
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
706 ## \brief Start future drawing actions
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
707 #
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
708 def start_drawing(self):
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
709 self._drawing = True
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
710 pass
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
711
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
712 ## \brief Stop any future drawing actions
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
713 #
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
714 # When doing massive udpate, to stop drawing the screen make
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
715 # application more effecient. The screen is updated by calling
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
716 # update() method after massive update and calliing start_drawing().
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
717 #
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
718 def stop_drawing(self):
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
719 self._drawing = False
5c013e3cadd0 Provide the facility to stop drawing for massive content update.
Thinker K.F. Li <thinker@codemud.net>
parents: 966
diff changeset
720 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
721 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
722
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
723 if __name__ == '__main__':
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
724 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
725 fr = frameruler(40)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
726 fr.set_size_request(300, 20)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
727
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
728 fl = frameline(40)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
729 fl.set_size_request(300, 20)
977
5cefabccfb76 Generate the last key frame correct.
wycc
parents: 972
diff changeset
730 fl.add_keyframe(15)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
731 fl.add_keyframe(3)
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
732 fl.tween(3)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
733 fl.add_keyframe(9)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
734 fl.add_keyframe(20)
971
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
735 fl.tween(9)
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
736 fl.active_frame(1)
a4c0aff915ad Fix the rm_keyframe to search the keyframe.
wycc
parents: 970
diff changeset
737 fl.rm_keyframe(15)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
738 print 'num of frames: %d' % (len(fl))
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
739
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
740 def press_sig(fl, frame, but):
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
741 print 'press_sig button %d for frame %d' % (but, frame)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
742 pass
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
743 fl.connect(frameline.FRAME_BUT_PRESS, press_sig)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
744
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
745 box = gtk.VBox()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
746
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
747 box.pack_start(fr, False)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
748 box.pack_start(fl, False)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
749 window.add(box)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
750
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
751 fr.show()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
752 fl.show()
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
753 box.show()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
754 window.show()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
755 gtk.main()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
756 pass