[pitivi/ges: 17/287] Reimplements the snap function
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 17/287] Reimplements the snap function
- Date: Thu, 15 Mar 2012 16:27:15 +0000 (UTC)
commit 5499a1b8f5d1ab9ec2cad67968c64850963c5f12
Author: Mathieu Duponchelle <seeed laposte net>
Date: Sun Aug 28 20:03:06 2011 +0200
Reimplements the snap function
pitivi/timeline/timeline.py | 16 ++++++++++++++++
pitivi/ui/trackobject.py | 28 ++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index ef83f8c..aa3c69a 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1259,6 +1259,22 @@ class MoveContext(EditingContext):
self._defaultTo(final_position, priority)
EditingContext.finish(self)
+ def snapToEdge(self, start, end=None):
+ """
+ Snaps the given start/end value to the closest edge if it is within
+ the timeline's dead_band.
+
+ @param start: The start position to snap.
+ @param end: The stop position to snap.
+ @returns: The snapped value if within the dead_band.
+ """
+ edge, diff = self.edges.snapToEdge(start, end)
+
+ if self.dead_band != -1 and diff <= self.dead_band:
+ return edge
+
+ return start
+
def _defaultTo(self, position, priority):
if self._snap:
position = self.timeline.snapToEdge(position,
diff --git a/pitivi/ui/trackobject.py b/pitivi/ui/trackobject.py
index 9be4fd0..5e0d946 100644
--- a/pitivi/ui/trackobject.py
+++ b/pitivi/ui/trackobject.py
@@ -131,6 +131,32 @@ class TimelineController(controller.Controller):
#priority = int((y - self._y_offset + self._vadj.get_value()) //
#(LAYER_HEIGHT_EXPANDED + LAYER_SPACING))
#self._context.setMode(self._getMode())
+ prev = track.get_previous_track_object(self._view.element)
+
+ if prev != None:
+ prev_end = prev.get_start() + prev.get_duration()
+ offset = Zoomable.nsToPixel(prev_end)
+ offset = (x + self._hadj.get_value()) - offset
+ if offset < 15 and offset >= 0:
+ self._view.element.set_start(prev.get_start() + prev.get_duration())
+ self._view.snapped_before = True
+ return
+ elif self._view.snapped_before:
+ self._view.snapped_before = False
+
+ next = track.get_next_track_object(self._view.element)
+ if next != None:
+ offset = Zoomable.nsToPixel(next.get_start())
+ dur_offset = Zoomable.nsToPixel(duration)
+ dur_offset = (dur_offset + x + self._hadj.get_value())
+ offset = offset - dur_offset
+ if offset < 15 and offset >= 0:
+ self._view.element.set_start(next.get_start() - duration)
+ self._view.snapped_after = True
+ return
+ elif self._view.snapped_after:
+ self._view.snapped_after = False
+
self._context.editTo(position, priority)
def _getMode(self):
@@ -256,6 +282,8 @@ class TrackObject(View, goocanvas.Group, Zoomable):
self.nameheight = 0
self.is_transition = is_transition
self.app.projectManager.current.connect("selected-changed", self.selected_changed)
+ self.snapped_before = False
+ self.snapped_after = False
self.bg = goocanvas.Rect(
height=self.height,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]