annotate pyink/frameline.py @ 966:ca993c473379

Function of removing key frames
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 18 Nov 2010 11:20:24 +0800
parents dbb5462c471f
children 5c013e3cadd0
rev   line source
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 import pygtk
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2 pygtk.require("2.0")
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3 import gtk
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 import gtk.gdk
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
5 import pango
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 import gobject
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 def color_to_rgb(v):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9 return (((v >> 16) & 0xff) * 65535 / 0xff,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 ((v >> 8) & 0xff) * 65535 / 0xff,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 (v & 0xff) * 65535 / 0xff)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 class keyframe(object):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 def __init__(self, frame_idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 self.idx = frame_idx
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 self.left_tween = False
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 self.right_tween = False
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18 self.right_tween_type = 0
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
22 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
23 _type = 0
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
24 _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
25 _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
26 _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
27 _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
28
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
29 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
30 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
31 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
32 pass
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
33 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
34 return fr
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
35
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
36 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
37 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
38 self._num_frames = num_frames
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
39 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
40
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
41 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
42 self.update()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
43 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
44
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
45 def queue_draw(self):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
46 print 'queue_draw'
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
47 self.update()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
48 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
49
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
50 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
51 print 'queue_draw_area'
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
52 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
53
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
54 def update(self):
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
55 win = self.window
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
56 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
57
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
58 gc = gtk.gdk.GC(win)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
59
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
60 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
61 # 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
62 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
63 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
64 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
65 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
66
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
67 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
68 # Mark mark lines
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
69 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
70 mark_h = w_h / 10
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
71 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
72 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
73 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
74 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
75 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
76
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
77 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
78
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
79 #
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
80 # 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
81 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
82 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
83 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
84 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
85
949
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
86 font_desc = pango.FontDescription()
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
87 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
88
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
89 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
90
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 # Draw frame number
c9bf47cc621f Set font size for frame number in frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 948
diff changeset
93 #
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
102 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
103 pass
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
104
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
105 ## Show frame status of a layer
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106 #
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
107 # \section frameline_sigs Signals
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
108 # - '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
109 # - callback(widget, frame_idx, button)
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
110 #
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
111 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
112 _type = 0
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
113 _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
114 _select_color = 0xee2222 # color of border of selected frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
115 _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
116 _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
117 _tween_color = 0x808080 # color of tween line
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
118 _tween_bgcolors = [0x80ff80, 0xff8080] # bg colors of tween frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
119 # Colors for normal frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
120 _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
121 _normal_border = 0xaaaaaa # border color of normal frames.
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
122 _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
123 _hover_border_color = 0xa0a0a0 # border when the pointer over a frame
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
124
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
125 FRAME_BUT_PRESS = 'frame-button-press'
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
126
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
127 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
128 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
129 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
130 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
131 frameline._type,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
132 gobject.SIGNAL_RUN_FIRST,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
133 gobject.TYPE_NONE,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
134 (gobject.TYPE_INT,
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
135 gobject.TYPE_INT))
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
136 frameline._sig_frame_but_press = but_press
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
137 pass
952
88bf64efcc1d rename _type_id to _type, it is GGbject type actually
Thinker K.F. Li <thinker@codemud.net>
parents: 951
diff changeset
138 fl_obj = gobject.new(frameline._type)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
139 return fl_obj
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
140
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
141 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
142 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
143 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
144 self.connect('motion-notify-event', self._motion_hdl)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
145 self._num_frames = num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
146 self._keys = []
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
147 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
148 self._last_hover = -1 # frame index of last hover
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
149 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
150
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
151 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
152 frame = event.x / self._frame_width
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
153 but = event.button
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
154 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
155 pass
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
156
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
157 def _motion_hdl(self, widget, event):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
158 frame = int(event.x / self._frame_width)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
159 self._draw_hover(frame)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
160 pass
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
161
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
162 def _fl_expose(self, widget, event):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
163 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
164 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
165 if not hasattr(self, '_gc'):
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
166 self._gc = gtk.gdk.GC(win)
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
167 #
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
168 # register for button press event
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
169 #
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
170 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
171 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
172 gtk.gdk.POINTER_MOTION_MASK
951
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
173 win.set_events(emask)
e06a8d90592c Handle button press event for frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 950
diff changeset
174 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
175 self.update()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
176 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
177
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
178 def _draw_tween(self, first_key, last_key):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
179 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
180 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
181
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
182 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
183 # Get background color of a tween
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
184 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
185 bg_idx = first_key.right_tween_type
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
186 bg_color_v = self._tween_bgcolors[bg_idx]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
187 bg_color_rgb = color_to_rgb(bg_color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
188 bg_color = gtk.gdk.Color(*bg_color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
189
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
190 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
191 gc.set_rgb_fg_color(bg_color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
192
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
193 draw_x = first_key.idx * self._frame_width + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
194 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
195
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
196 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
197
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
198 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
199 # Set color of tween line
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
200 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
201 line_v = self._tween_color
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
202 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
203 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
204 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
205
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
206 #
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
207 # Draw tween line
8db3dd03508f Draw line to connect continious tween frames
Thinker K.F. Li <thinker@codemud.net>
parents: 944
diff changeset
208 #
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
209 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
210 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
211 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
212 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
213 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
214
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
215 def _draw_normal_frame(self, idx):
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
216 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
217 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
218
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
219 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
220 bg_idx = idx % len(self._normal_bgcolors)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
221 rgb = color_to_rgb(self._normal_bgcolors[bg_idx])
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
222 color = gtk.gdk.Color(*rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
223 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
224
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
225 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
226 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
227 next_f_x = f_x + self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
228
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
229 border_rgb = color_to_rgb(self._normal_border)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
230 border_color = gtk.gdk.Color(*border_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
231 gc.set_rgb_fg_color(border_color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
232 gc.set_line_attributes(1, gtk.gdk.LINE_SOLID,
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
233 gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
234 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
235 pass
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
236
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
237 ## \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
238 #
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
239 def _draw_bottom_line(self, start, stop):
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
240 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
241 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
242 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
243
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
244 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
245 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
246 gc.set_rgb_fg_color(border_color)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
247 start_x = start * self._frame_width
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
248 stop_x = stop * self._frame_width
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
249 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
250 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
251
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
252 def _draw_all_frames(self):
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
253 win = self.window
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
254 w_x, w_y, w_w, 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
255 gc = self._gc
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
256
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
257 i = 0
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
258 key_i = 0
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
259 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
260 key = self._keys[key_i]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
261 except IndexError:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
262 key = keyframe(self._num_frames)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
263 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
264 num_frames = self._num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
265 while i < num_frames:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
266 if key.idx == i:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
267 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
268 # Skip tween keys
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
269 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
270 first_tween_key = key
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
271 while key.idx == i or key.left_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
272 last_tween_key = key
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
273 key_i = key_i + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
274 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
275 key = self._keys[key_i]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
276 except IndexError:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
277 key = keyframe(self._num_frames)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
278 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
279 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
280
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
281 if first_tween_key != last_tween_key:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
282 self._draw_tween(first_tween_key, last_tween_key)
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 i = last_tween_key.idx + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
285 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
286 else:
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
287 self._draw_normal_frame(i)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
288 i = i + 1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
289 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
290 pass
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
291
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
292 self._draw_bottom_line(0, num_frames)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
293 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
294
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
295 def _draw_keyframe(self, frame_idx):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
296 win = self.window
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
297 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
298
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
299 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
300 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
301 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
302
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
303 gc = self._gc
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
304 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
305
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
306 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
307 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
308 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
309
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
310 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
311 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
312
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
313 def _draw_keyframes(self):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
314 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
315 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
316
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
317 color_v = self._key_mark_color
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
318 color_rgb = color_to_rgb(color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
319 color = gtk.gdk.Color(*color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
320
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
321 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
322 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
323
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
324 for key in self._keys:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
325 mark_sz = self._key_mark_sz
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
326 mark_x = int((key.idx + 0.5) * self._frame_width - mark_sz / 2)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
327 mark_y = w_h * 2 / 3 - mark_sz / 2
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
328
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
329 win.draw_rectangle(gc, True, mark_x, mark_y, mark_sz, mark_sz)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
330 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
331 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
332
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
333 def _draw_active(self):
965
dbb5462c471f Do not draw active frame when it is not set
Thinker K.F. Li <thinker@codemud.net>
parents: 958
diff changeset
334 if self._active_frame == -1:
dbb5462c471f Do not draw active frame when it is not set
Thinker K.F. Li <thinker@codemud.net>
parents: 958
diff changeset
335 return
dbb5462c471f Do not draw active frame when it is not set
Thinker K.F. Li <thinker@codemud.net>
parents: 958
diff changeset
336
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
337 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
338 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
339
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
340 color_v = self._active_border
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
341 color_rgb = color_to_rgb(color_v)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
342 color = gtk.gdk.Color(*color_rgb)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
343
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
344 gc = self._gc
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
345 gc.set_rgb_fg_color(color)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
346
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
347 idx = self._active_frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
348 line_x1 = idx * self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
349 line_x2 = line_x1 + self._frame_width
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
350
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
351 win.draw_line(gc, line_x1, 0, line_x1, w_h)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
352 win.draw_line(gc, line_x2, 0, line_x2, w_h)
950
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
353 win.draw_line(gc, line_x1, w_h - 1, line_x2, w_h - 1)
1bb0780f1036 Add more border line to frameline and frameruler
Thinker K.F. Li <thinker@codemud.net>
parents: 949
diff changeset
354 win.draw_line(gc, line_x1, 0, line_x2, 0)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
355 pass
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
356
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
357 ## \brief Find the range a continous tween.
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
358 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
359 def _find_tween_range(self, key_pos):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
360 first_pos = key_pos
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
361 while first_pos and self._keys[first_pos].left_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
362 first_pos = first_pos - 1
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
363 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
364
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
365 max_pos = len(self._keys) - 1
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
366
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
367 last_pos = key_pos
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
368 while last_pos < max_pos and self._keys[last_pos].right_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
369 last_pos = last_pos + 1
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
370 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
371
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
372 return first_pox, last_pos
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
373
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
374 ## \brief Redraw a frame specified by an index.
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
375 #
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
376 def _redraw_frame(self, frame_idx):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
377 keys = [key.idx for key in self._keys]
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
378 if len(keys):
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
379 try:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
380 pos = keys.index(frame_idx)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
381 except ValueError:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
382 keys.append(frame_idx)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
383 keys.sort()
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
384 pos = keys.index(frame_idx) - 1
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
385 pass
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
386 if pos < 0:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
387 pos = 0
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
388 pass
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
389 key = self._keys[pos]
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
390 else:
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
391 key = None
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
392 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
393
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
394 if key and (key.right_tween or \
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
395 (key.left_tween and key.idx == frame_idx)):
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
396 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
397 # in tween
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
398 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
399 first_pos, last_pos = self._find_tween_range(pos)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
400 first_key = self._keys[first_pos]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
401 last_key = self._keys[last_pos]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
402
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
403 self._draw_tween(first_key, last_key)
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
404 self._draw_bottom_line(first_key.idx, last_key.idx + 1)
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
405
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
406 for i in range(first_pos, last_pos + 1):
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
407 key = self._keys[i]
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
408 self._draw_keyframe(key.idx)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
409 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
410 pass
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
411 else: # not in tween
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
412 self._draw_normal_frame(frame_idx)
958
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
413 self._draw_bottom_line(frame_idx, frame_idx + 1)
7631dbbbb2be Fix bug for no any key frame in a frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 954
diff changeset
414 if key and (key.idx == frame_idx):
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
415 self._draw_keyframe(frame_idx)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
416 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
417 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
418 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
419
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
420 ## \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
421 #
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
422 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
423 if self._last_hover != -1:
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
424 self._redraw_frame(self._last_hover)
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
425 pass
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
426
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
427 self._draw_active()
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
428
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
429 win = self.window
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
430 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
431 gc = self._gc
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
432
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
433 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
434 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
435 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
436
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
437 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
438 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
439
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
440 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
441 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
442 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
443 win.draw_line(gc, line_x1, w_h - 2, 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
444
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
445 self._last_hover = frame_idx
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
446 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
447
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
448 def update(self):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
449 win = self.window
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
450 x, y, w, h, depth = win.get_geometry()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
451
954
75bc6d9f4e0a Show hover mark when the pointer over a frame
Thinker K.F. Li <thinker@codemud.net>
parents: 953
diff changeset
452 self._draw_all_frames()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
453 self._draw_keyframes()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
454 if self._active_frame != -1:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
455 self._draw_active()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
456 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
457 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
458
947
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
459 ## Add a key frame
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
460 #
a8ddbb6dac9e Doc key frame
Thinker K.F. Li <thinker@codemud.net>
parents: 946
diff changeset
461 # 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
462 # example, move a object or add new objects at the frame.
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
463 def add_keyframe(self, idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
464 key_indic = [key.idx for key in self._keys]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
465 if idx in key_indic:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
466 return
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
467
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
468 key_indic.append(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
469 key_indic.sort()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
470 insert_pos = key_indic.index(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
471
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
472 key = keyframe(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
473 self._keys[insert_pos:insert_pos] = [key]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
474 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
475 key.left_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
476 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
477 if insert_pos < (len(self._keys) - 1) and \
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
478 self._keys[insert_pos + 1].left_tween:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
479 key.right_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
480 pass
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
481
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
482 self._draw_keyframe(idx)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
483 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
484
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
485 def rm_keyframe(self, idx):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
486 key = self._keys[idx]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
487 del self._keys[idx]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
488
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
489 if key.right_tween ^ key.left_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
490 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
491 # tween in one side
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
492 #
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
493 if key.right_tween:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
494 right_key = self._keys[idx]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
495 right_key.left_tween = False
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
496 rdraw_range = (right_key.idx, idx + 1)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
497 else:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
498 left_key = self._keys[idx - 1]
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
499 left_key.right_key = False
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
500 redraw_range = (idx, left_key.idx + 1)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
501 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
502
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
503 for i in range(*redraw_range):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
504 self._redraw_frame(i)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
505 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
506 else:
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
507 self._redraw_frame(idx)
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
508 pass
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
509 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
510
946
f82ac6740a32 change wording in doc
Thinker K.F. Li <thinker@codemud.net>
parents: 945
diff changeset
511 ## 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
512 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
513 # \see http://www.entheosweb.com/Flash/shape_tween.asp
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
514 def tween(self, idx, _type=0):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
515 key_indic = [key.idx for key in self._keys]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
516 pos = key_indic.index(idx)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
517 key = self._keys[pos]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
518
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
519 try:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
520 right_key = self._keys[pos + 1]
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
521 except IndexError:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
522 raise ValueError, 'No right key frame'
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
523
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
524 key.right_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
525 right_key.left_tween = True
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
526 key.right_tween_type = _type
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
527 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
528
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
529 ## Set active frame
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
530 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
531 # 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
532 #
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
533 def active_frame(self, idx):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
534 if idx < 0 or idx >= self._num_frames:
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
535 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
536
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
537 self._active_frame = idx
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
538 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
539
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
540 def deactive(self):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
541 self._active_frame = -1
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
542 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
543
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
544 def set_num_frames(self, num):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
545 self._num_frames = num
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
546 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
547
966
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
548 def reset(self):
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
549 self._keys = []
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
550 pass
ca993c473379 Function of removing key frames
Thinker K.F. Li <thinker@codemud.net>
parents: 965
diff changeset
551
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
552 def __len__(self):
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
553 return self._num_frames
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
554 pass
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
555
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
556 if __name__ == '__main__':
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
557 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
558 fr = frameruler(40)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
559 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
560
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
561 fl = frameline(40)
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
562 fl.set_size_request(300, 20)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
563 fl.add_keyframe(3)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
564 fl.add_keyframe(9)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
565 fl.add_keyframe(15)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
566 fl.add_keyframe(20)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
567 fl.tween(3)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
568 fl.tween(15, 1)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
569 fl.active_frame(15)
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
570 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
571
953
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
572 def press_sig(fl, frame, but):
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
573 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
574 pass
2346d3238e03 frame-button-press event of frameline
Thinker K.F. Li <thinker@codemud.net>
parents: 952
diff changeset
575 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
576
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
577 box = gtk.VBox()
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
578
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
579 box.pack_start(fr, False)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
580 box.pack_start(fl, False)
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
581 window.add(box)
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
582
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
583 fr.show()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
584 fl.show()
948
518c61784355 Add frameruler to show ruler for framelines
Thinker K.F. Li <thinker@codemud.net>
parents: 947
diff changeset
585 box.show()
944
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
586 window.show()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
587 gtk.main()
b0edd13779ee Implement a frameline widget
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
588 pass