protected override void OnMouseDrag(Event evt, TimelineWindow.TimelineState state, TimelineClipHandle handle) { ManipulateEdges edges = ManipulateEdges.Both; float delta = evt.get_delta().x / state.timeAreaScale.x; TimelineUndo.PushUndo(handle.clip.clip.parentTrack, "Trim Clip"); TimelineClipHandle.DragDirection direction = handle.direction; if (direction != TimelineClipHandle.DragDirection.Right) { if (direction == TimelineClipHandle.DragDirection.Left) { double num = this.m_FrameSnap.ApplyOffset(handle.clip.clip.start, delta, state); if (num > 0.0) { double num2 = num - handle.clip.clip.start; handle.clip.clip.start = num; if (handle.clip.clip.duration - num2 > TimelineClip.kMinDuration) { handle.clip.clip.duration -= num2; } } edges = ManipulateEdges.Left; } } else { double val = this.m_FrameSnap.ApplyOffset(handle.clip.clip.duration, delta, state); handle.clip.clip.duration = Math.Max(val, TimelineClip.kMinDuration); edges = ManipulateEdges.Right; } if (this.m_MagnetEngine != null && evt.get_modifiers() != 1) { this.m_MagnetEngine.Snap(evt.get_delta().x, edges); } }
public SnapEngine(IAttractable attractable, IAttractionHandler attractionHandler, ManipulateEdges manipulateEdges, WindowState state, Vector2 mousePosition, IEnumerable <ISnappable> snappables = null) { m_Attractable = attractable; m_ManipulateEdges = manipulateEdges; m_AttractionHandler = attractionHandler; m_State = state; m_CurrentTimes = m_GrabbedTimes = new TimeBoundaries(m_Attractable.start, m_Attractable.end); m_GrabbedTime = m_State.PixelToTime(mousePosition.x); // Add Time zero as Magnet AddMagnet(0.0, true, state); // Add current Time as Magnet // case1157280 only add current time as magnet if visible if (TimelineWindow.instance.currentMode.ShouldShowTimeCursor(m_State)) { AddMagnet(state.editSequence.time, true, state); } if (state.IsEditingASubTimeline()) { // Add start and end of evaluable range as Magnets // This includes the case where the master timeline has a fixed length var range = state.editSequence.GetEvaluableRange(); AddMagnet(range.start, true, state); AddMagnet(range.end, true, state); } else if (state.masterSequence.asset.durationMode == TimelineAsset.DurationMode.FixedLength) { // Add end sequence Time as Magnet AddMagnet(state.masterSequence.asset.duration, true, state); } if (snappables == null) { snappables = GetVisibleSnappables(m_State); } foreach (var snappable in snappables) { if (!attractable.ShouldSnapTo(snappable)) { continue; } var edges = snappable.SnappableEdgesFor(attractable, manipulateEdges); foreach (var edge in edges) { AddMagnet(edge.time, edge.showSnapHint, state); } } }
public IEnumerable <Edge> SnappableEdgesFor(IAttractable attractable, ManipulateEdges manipulateEdges) { var edges = new List <Edge>(); var attractableGUI = attractable as TimelineMarkerGUI; var canAddEdges = !(attractableGUI != null && attractableGUI.parent == parent); if (canAddEdges) { edges.Add(new Edge(time)); } return(edges); }
public void OnAttractedEdge(IAttractable attractable, ManipulateEdges manipulateEdges, AttractedEdge edge, double time) { var clipGUI = attractable as TimelineClipGUI; if (clipGUI == null) { return; } var clipItem = ItemsUtils.ToItem(clipGUI.clip); if (manipulateEdges == ManipulateEdges.Right) { bool affectTimeScale = Event.current.modifiers == EventModifiers.Shift; // TODO Do not use Event.current from here. EditMode.TrimEnd(clipItem, time, affectTimeScale); } else if (manipulateEdges == ManipulateEdges.Left) { EditMode.TrimStart(clipItem, time); } }
protected bool MouseDownInternal(Event evt, WindowState state, TimelineClipHandle handle) { if (handle == null) { return(false); } if (handle.clipGUI.clip != null && !handle.clipGUI.clip.clipCaps.HasAny(ClipCaps.Blending)) { return(false); } m_Edges = ManipulateEdges.Right; if (handle.trimDirection == TrimEdge.Start) { m_Edges = ManipulateEdges.Left; } if (m_Edges == ManipulateEdges.Left && handle.clipGUI.clip.hasBlendIn || m_Edges == ManipulateEdges.Right && handle.clipGUI.clip.hasBlendOut) { return(false); } m_IsCaptured = true; m_UndoSaved = false; m_EaseClipHandler = handle; m_Clip = handle.clipGUI.clip; m_OriginalValue = m_Edges == ManipulateEdges.Left ? m_Clip.easeInDuration : m_Clip.easeOutDuration; // Change cursor only when OnGUI Process (not in test) if (GUIUtility.guiDepth > 0) { TimelineCursors.SetCursor(m_Edges == ManipulateEdges.Left ? TimelineCursors.CursorType.MixRight : TimelineCursors.CursorType.MixLeft); } state.AddCaptured(this); return(true); }
public void OnAttractedEdge(IAttractable attractable, ManipulateEdges manipulateEdges, AttractedEdge edge, double time) { var clipGUI = attractable as TimelineClipGUI; if (clipGUI == null) { return; } var clipItem = ItemsUtils.ToItem(clipGUI.clip); if (manipulateEdges == ManipulateEdges.Right) { bool affectTimeScale = IsAffectingTimeScale(clipGUI.clip); EditMode.TrimEnd(clipItem, time, affectTimeScale); } else if (manipulateEdges == ManipulateEdges.Left) { bool affectTimeScale = IsAffectingTimeScale(clipGUI.clip); EditMode.TrimStart(clipItem, time, affectTimeScale); } }
public void OnAttractedEdge(IAttractable attractable, ManipulateEdges manipulateEdges, AttractedEdge edge, double time) { double offset; if (edge == AttractedEdge.Right) { var duration = end - start; var startTime = time - duration; startTime = EditMode.AdjustStartTime(m_State, m_RightMostMovingItems, startTime); offset = startTime + duration - end; } else { if (edge == AttractedEdge.Left) { time = EditMode.AdjustStartTime(m_State, m_LeftMostMovingItems, time); } offset = time - start; } if (start + offset < 0.0) { offset = -start; } if (!offset.Equals(0.0)) { foreach (var grabbedClips in movingItems) { grabbedClips.start += offset; } EditMode.UpdateMove(); RefreshPreviewItems(); } }
public void Snap(float offsetInPixels, ManipulateEdges edges) { this.m_ManipulateEdges = edges; if (offsetInPixels <= -MagnetEngine.k_Epsilon || offsetInPixels >= MagnetEngine.k_Epsilon) { if (this.m_Magnets.Count != 0) { SnapState snapState = this.m_SnapState; if (snapState != SnapState.Free) { if (snapState == SnapState.Snapped) { this.ProcessSnappedState(offsetInPixels); } } else { this.ProcessFreeState(offsetInPixels); } } } }
public IEnumerable <Edge> SnappableEdgesFor(IAttractable attractable, ManipulateEdges manipulateEdges) { var edges = new List <Edge>(); bool canAddEdges = !parent.muted; if (canAddEdges) { // Hack: Trim Start in Ripple mode should not have any snap point added if (EditMode.editType == EditMode.EditType.Ripple && manipulateEdges == ManipulateEdges.Left) { return(edges); } if (attractable != this) { if (EditMode.editType == EditMode.EditType.Ripple) { bool skip = false; // Hack: Since Trim End and Move in Ripple mode causes other snap point to move on the same track (which is not supported), disable snapping for this special cases... // TODO Find a proper way to have different snap edges for each edit mode. if (manipulateEdges == ManipulateEdges.Right) { var otherClipGUI = attractable as TimelineClipGUI; skip = otherClipGUI != null && otherClipGUI.parent == parent; } else if (manipulateEdges == ManipulateEdges.Both) { var moveHandler = attractable as MoveItemHandler; skip = moveHandler != null && moveHandler.movingItems.Any(clips => clips.targetTrack == clip.parentTrack && clip.start >= clips.start); } if (skip) { return(edges); } } AddEdge(edges, clip.start); AddEdge(edges, clip.end); } else { if (manipulateEdges == ManipulateEdges.Right) { var d = TimelineHelpers.GetClipAssetEndTime(clip); if (d < double.MaxValue) { if (clip.SupportsLooping()) { var l = TimelineHelpers.GetLoopDuration(clip); var shownTime = TimelineWindow.instance.state.timeAreaShownRange; do { AddEdge(edges, d, false); d += l; }while (d < shownTime.y); } else { AddEdge(edges, d, false); } } } if (manipulateEdges == ManipulateEdges.Left) { var clipInfo = AnimationClipCurveCache.Instance.GetCurveInfo(clip.animationClip); if (clipInfo != null && clipInfo.keyTimes.Any()) { AddEdge(edges, clip.FromLocalTimeUnbound(clipInfo.keyTimes.Min()), false); } } } } return(edges); }