Mercurial > MadButterfly
diff pyink/frameline.py @ 1214:e55499f7505a
Fix the issues with multiple framelines
- For multiple framelines, user move mouse from one frameline to
another, the frame is not showed correctly.
- Old implementation always draw normal frame on the frameline
where mouse just leaving.
- It is fixed by detecting leave-notify event and removing hover
mark.
- When user active a frame on a frameline that is not what old active
frame is at, the old active frame is not deactivated.
- It is fixed by calling frameline.deactive() of a frameline when a
frame is activated on another frameline.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 05 Jan 2011 17:56:14 +0800 |
parents | 1d476b35dc79 |
children | 8e372ae69010 |
line wrap: on
line diff
--- a/pyink/frameline.py Tue Jan 04 13:06:56 2011 +0800 +++ b/pyink/frameline.py Wed Jan 05 17:56:14 2011 +0800 @@ -223,12 +223,12 @@ gc = self._gc gc.set_rgb_fg_color(color) - line_x1 = idx * self._frame_width - line_x2 = line_x1 + self._frame_width + line_x1 = idx * self._frame_width + 1 + line_x2 = line_x1 + self._frame_width - 2 - win.draw_line(gc, line_x1, 0, line_x1, w_h) - win.draw_line(gc, line_x2, 0, line_x2, w_h) - win.draw_line(gc, line_x1, w_h - 1, line_x2, w_h - 1) + win.draw_line(gc, line_x1, 0, line_x1, w_h - 2) + win.draw_line(gc, line_x2, 0, line_x2, w_h - 2) + win.draw_line(gc, line_x1, w_h - 2, line_x2, w_h - 2) win.draw_line(gc, line_x1, 0, line_x2, 0) pass @@ -261,13 +261,13 @@ color = gtk.gdk.Color(*color_rgb) gc.set_rgb_fg_color(color) - line_x1 = frame_idx * self._frame_width + 1 - line_x2 = line_x1 + self._frame_width - 2 + line_x1 = frame_idx * self._frame_width + 2 + line_x2 = line_x1 + self._frame_width - 4 - win.draw_line(gc, line_x1, 1, line_x1, w_h - 2) - win.draw_line(gc, line_x2, 1, line_x2, w_h - 2) + win.draw_line(gc, line_x1, 1, line_x1, w_h - 3) + win.draw_line(gc, line_x2, 1, line_x2, w_h - 3) win.draw_line(gc, line_x1, 1, line_x2, 1) - win.draw_line(gc, line_x1, w_h - 2, line_x2, w_h - 2) + win.draw_line(gc, line_x1, w_h - 3, line_x2, w_h - 3) pass pass @@ -295,6 +295,7 @@ self._keys = [] self._active_frame = -1 self._drawing = False + self._last_hover = -1 # frame index of last hover pass def _draw_keyframe(self, frame_idx): @@ -427,9 +428,25 @@ def _draw_hover_frame(self, frame_idx): if not self._drawing: return - self._draw_hover(frame_idx) - pass - + + if self._last_hover != -1: + self._draw_frame(self._last_hover) + if self._last_hover == self._active_frame: + self._draw_active_frame() + pass + pass + + if frame_idx < self._num_frames and frame_idx >= 0: + self._draw_hover(frame_idx) + if self._last_hover == self._active_frame: + self._draw_active_frame() + pass + self._last_hover = frame_idx + else: + self._last_hover = -1 + pass + pass + ## \brief Start future drawing actions # def start_drawing(self): @@ -492,8 +509,8 @@ self.connect('button-press-event', self._press_hdl) self.connect('expose-event', self._fl_expose) - self.connect('motion-notify-event', self._motion_hdl) - self._last_hover = -1 # frame index of last hover + self.connect('motion-notify-event', self._motion_n_leave_hdl) + self.connect('leave-notify-event', self._motion_n_leave_hdl) pass def __len__(self): @@ -566,32 +583,16 @@ self.emit(frameline.FRAME_BUT_PRESS, frame, but) pass - def hide_hover(self): - if self._active_frame != self._last_hover: - self._draw_normal_frame(self._last_hover) + def _motion_n_leave_hdl(self, widget, event): + if event.type == gtk.gdk.LEAVE_NOTIFY: + frame_idx = -1 + else: + frame_idx = int(event.x / self._frame_width) pass + + self._draw_hover_frame(frame_idx) pass - def _motion_hdl(self, widget, event): - frame_idx = int(event.x / self._frame_width) - if self._last_hover != -1: - self._draw_frame(self._last_hover) - if self._last_hover == self._active_frame: - self._draw_active_frame() - pass - pass - - if frame_idx < self._num_frames and frame_idx >= 0: - self._draw_hover_frame(frame_idx) - if self._last_hover == self._active_frame: - self._draw_active_frame() - pass - self._last_hover = frame_idx - else: - self._last_hover = -1 - pass - pass - def _fl_expose(self, widget, event): win = self.window self.start_drawing() @@ -870,6 +871,15 @@ self._active_frame = -1 self._draw_all_frames() pass + + ## \brief Called when mouse leave the widget. + # + # This is here for buggy pygtk. It does not send leave-notify-event. We + # need this to workaround. + # + def mouse_leave(self): + self._draw_hover_frame(-1) + pass pass if __name__ == '__main__':