private bool MoveSnapFilter(IEvent testEvent, TimelineControl.SnapOptions options) { ITimelineReference movingReference = options.FilterContext as ITimelineReference; if (movingReference == null) { return(true); } IHierarchicalTimeline movingTimeline = movingReference.Target; if (movingTimeline == null) { return(true); } ITimeline owningTimeline = null; if (testEvent is ITimelineReference) { owningTimeline = ((ITimelineReference)testEvent).Parent; } else if (testEvent is IInterval) { owningTimeline = ((IInterval)testEvent).Track.Group.Timeline; } else if (testEvent is IKey) { owningTimeline = ((IKey)testEvent).Track.Group.Timeline; } else if (testEvent is IMarker) { owningTimeline = ((IMarker)testEvent).Timeline; } // Is the reference being compared to an object that it owns? Never snap! if (owningTimeline == movingTimeline) { return(false); } // Is the reference being compared against a sibling object? Snap away. if (owningTimeline == movingReference.Parent) { return(true); } // to-do: support a true hierarchy. We can't support directed acyclic graphs because // the Layout implementation uses a Dictionary of ITimelineObjects and the same object // can't have multiple layout rectangles. We could support a tree hierarchy, though. //// The test object may be a grandchild of the moving reference. Look for a parent. //owningTimeline = owningTimeline.Parent; return(true); }
// Only client-specific code can create a new ITimelineReference and add it. internal void AddReference(ITimelineReference reference) { GetChildList<ITimelineReference>(Schema.timelineType.timelineRefChild).Add(reference); }
private void Insert(ITimelineObject droppedItem, ITimelineObject dropTarget) { if (m_timelineDocument == null) { return; } // TimelineControl maintains target group and track ITimeline targetTimeline = m_timelineDocument.Timeline; IGroup targetGroup = m_timelineControl.TargetGroup != null ? (IGroup)m_timelineControl.TargetGroup.Last : null; ITrack targetTrack = m_timelineControl.TargetTrack != null ? (ITrack)m_timelineControl.TargetTrack.Last : null; // in case of drag and drop, use drop target instead if (dropTarget != null) { GetTrackAndGroup(dropTarget, out targetTrack, out targetGroup); } // Work up from insertion point to get target key/interval, track, group, timeline ITimelineReference reference = droppedItem.As <ITimelineReference>(); if (reference != null) { ((Timeline)targetTimeline).AddReference(reference); return; } IGroup group = droppedItem.As <IGroup>(); if (group != null) { // if this is a new group, add a default track if (group.Tracks.Count == 0) { ITrack emptyTrack = group.CreateTrack(); if (emptyTrack != null) { group.Tracks.Add(emptyTrack); } } targetTimeline.Groups.Add(group); return; } IMarker marker = droppedItem.As <IMarker>(); if (marker != null) { targetTimeline.Markers.Add(marker); return; } // Must be track or interval; get the target group, or create one. ITrack track = droppedItem.As <ITrack>(); IEvent ev = droppedItem.As <IEvent>(); if (track != null || ev != null) { IList <IGroup> groups = targetTimeline.Groups; if (targetGroup == null) { targetGroup = targetTimeline.CreateGroup(); groups.Add(targetGroup); } if (track != null) { targetGroup.Tracks.Add(track); } else //if (ev != null) { // interval or key; get the target track or create one if (targetTrack == null) { targetTrack = targetGroup.CreateTrack(); targetGroup.Tracks.Add(targetTrack); } IInterval interval = droppedItem.As <IInterval>(); if (interval != null) { targetTrack.Intervals.Add(interval); } else { IKey key = droppedItem.As <IKey>(); if (key != null) { targetTrack.Keys.Add(key); } } } } }
/// <summary> /// Draws the origin symbol for the timeline reference that indicates the zero-point for that timeline</summary> /// <param name="reference">The timeline reference object that may or may not be resolved</param> /// <param name="originRect">The suggested bounding rectangle for the origin symbol, in screen space</param> /// <param name="drawMode">Drawing mode</param> /// <param name="c">Drawing context</param> protected virtual void DrawReferenceOrigin(ITimelineReference reference, RectangleF originRect, DrawMode drawMode, Context c) { Color originColor; if (drawMode == DrawMode.Normal) originColor = Color.Black; else originColor = Color.Gray; c.Graphics.DrawLines(new[] { new PointF(originRect.X + originRect.Width * 0.5f, originRect.Y), new PointF(originRect.X, originRect.Y + originRect.Height * 0.5f), new PointF(originRect.X + originRect.Width * 0.5f, originRect.Bottom), new PointF(originRect.Right, originRect.Y + originRect.Height * 0.5f), new PointF(originRect.X + originRect.Width * 0.5f, originRect.Y) }, originColor, 1.0f); }
/// <summary> /// Draws the text label for the timeline reference</summary> /// <param name="reference">The timeline reference object that may or may not be resolved</param> /// <param name="labelBounds">The bounding rectangle for the label, in screen space</param> /// <param name="drawMode">Drawing mode</param> /// <param name="c">Drawing context</param> protected virtual void DrawReferenceLabel(ITimelineReference reference, RectangleF labelBounds, DrawMode drawMode, Context c) { c.Graphics.DrawText(reference.Name, c.TextFormat, labelBounds, m_nameBrush); }
/// <summary> /// Draws the background of a timeline reference</summary> /// <param name="reference">The timeline reference object that may or may not be resolved</param> /// <param name="bounds">The bounding rectangle, in screen space, that was created during the layout phase</param> /// <param name="drawMode">Drawing mode</param> /// <param name="c">Drawing context</param> protected virtual void DrawReferenceBackground(ITimelineReference reference, RectangleF bounds, DrawMode drawMode, Context c) { if (drawMode == DrawMode.Normal) m_generalSolidColorBrush.Color = reference.Color; else m_generalSolidColorBrush.Color = Color.LightCoral; c.Graphics.FillRectangle(bounds, m_generalSolidColorBrush); }
/// <summary> /// Draws a timeline reference</summary> /// <param name="reference">The timeline reference object that may or may not be resolved</param> /// <param name="bounds">The bounding rectangle, in screen space, that was created during the layout phase</param> /// <param name="drawMode">Drawing mode</param> /// <param name="c">Drawing context</param> protected virtual void DrawTimelineReference(ITimelineReference reference, RectangleF bounds, DrawMode drawMode, Context c) { DrawReferenceBackground(reference, bounds, drawMode, c); RectangleF labelBounds = new RectangleF(bounds.X, bounds.Y, HeaderWidth, bounds.Height); IHierarchicalTimeline timeline = reference.Target; IList<IGroup> groups; bool expanded = false; bool collapsible = false; bool collapsed = false; if (timeline != null) { groups = timeline.Groups; expanded = reference.Options.Expanded; collapsible = groups.Count > 0; collapsed = collapsible && !expanded; } if (collapsible) { labelBounds.X += TrackIndent; labelBounds.Width -= TrackIndent; } DrawReferenceLabel(reference, labelBounds, drawMode, c); // Draw an origin point to show how much the referenced timeline has been offset. RectangleF originRect = bounds; float screenStart = GdiUtil.Transform(c.Transform, 0) + bounds.X; originRect.X = screenStart - 4; originRect.Width = 8; originRect.Height = 16; if (originRect.X + originRect.Width >= HeaderWidth && originRect.X <= c.ClientRectangle.Width) { DrawReferenceOrigin(reference, originRect, drawMode, c); } if (timeline != null) { bounds = GetGroupHandleRect(bounds, collapsed); if (collapsible) { RectangleF expanderRect = GetExpanderRect(bounds); m_graphics.DrawExpander( expanderRect.X, expanderRect.Y, expanderRect.Width, m_expanderBrush, expanded); } } }
/// <summary> /// Moves the objects represented by the current ghosts to be at the position of /// the ghosts</summary> protected virtual void MoveSelection() { // To avoid setting the dirty bit in custom applications. // http://sf.ship.scea.com/sf/go/artf22506 PointF dragOffset = m_owner.GetDragOffset(); if ((dragOffset.X == 0.0f) && (dragOffset.Y == 0.0f)) { return; } // If we're dragging up, then don't create new tracks if (dragOffset.Y < 0) { foreach (GhostInfo ghost in m_ghosts) { if (!ghost.Valid) { return; } } } // If Control key is being held down, then we're in copy mode. bool tryToCopy = (Control.ModifierKeys == Keys.Control); m_owner.TransactionContext.DoTransaction(delegate { ITimeline timeline = m_owner.TimelineDocument.Timeline; Dictionary <ITrack, ITrack> newTrackMap = new Dictionary <ITrack, ITrack>(); List <Sce.Atf.Pair <ITrack, IEvent> > toAdd = new List <Sce.Atf.Pair <ITrack, IEvent> >(); for (int i = 0; i < m_ghosts.Length; i++) { GhostInfo ghost = m_ghosts[i]; ITimelineObject ghostCopy = null; if (tryToCopy) { ICloneable cloneable = ghost.Object as ICloneable; if (cloneable != null) { ghostCopy = cloneable.Clone() as ITimelineObject; } } ITimelineReference reference = ghost.Object as ITimelineReference; if (reference != null) { if (ghostCopy != null) { reference = (ITimelineReference)ghostCopy; } reference.Start = ghost.Start; if (ghostCopy != null && timeline is IHierarchicalTimelineList) { ((IHierarchicalTimelineList)timeline).References.Add(reference); } continue; } IInterval interval = ghost.Object as IInterval; if (interval != null) { if (ghostCopy != null) { interval = (IInterval)ghostCopy; } interval.Start = ghost.Start; interval.Length = ghost.Length; ITrack target = (ITrack)ghost.Target; if (target != interval.Track) { if (target == null) { target = CreateTargetTrack(interval.Track, newTrackMap); } if (ghostCopy == null) { interval.Track.Intervals.Remove(interval); } toAdd.Add(new Sce.Atf.Pair <ITrack, IEvent>(target, interval)); } continue; } IKey key = ghost.Object as IKey; if (key != null) { if (ghostCopy != null) { key = (IKey)ghostCopy; } key.Start = ghost.Start; ITrack target = (ITrack)ghost.Target; if (target != key.Track) { if (target == null) { target = CreateTargetTrack(key.Track, newTrackMap); } if (ghostCopy == null) { key.Track.Keys.Remove(key); } toAdd.Add(new Sce.Atf.Pair <ITrack, IEvent>(target, key)); } continue; } IMarker marker = ghost.Object as IMarker; if (marker != null) { if (ghost.Valid && marker.Start != ghost.Start) { if (ghostCopy != null) { IMarker markerCopy = (IMarker)ghostCopy; markerCopy.Start = ghost.Start; marker.Timeline.Markers.Add(markerCopy); } else { marker.Start = ghost.Start; } } continue; } ITrack track = ghost.Object as ITrack; if (track != null) { ITrack target = (ITrack)ghost.Target; if (target != null && target != track) { if (ghostCopy != null) { track = (ITrack)ghostCopy; } int index = target.Group.Tracks.IndexOf(target); if (ghostCopy == null) { track.Group.Tracks.Remove(track); } target.Group.Tracks.Insert(index, track); } continue; } IGroup group = ghost.Object as IGroup; if (group != null) { IGroup target = (IGroup)ghost.Target; if (target != null && target != group) { if (ghostCopy != null) { group = (IGroup)ghostCopy; } int index = m_owner.TimelineDocument.Timeline.Groups.IndexOf(target); if (ghostCopy == null) { m_owner.TimelineDocument.Timeline.Groups.Remove(group); } m_owner.TimelineDocument.Timeline.Groups.Insert(index, group); } continue; } } // So that when multiple intervals from multiple tracks are relocated to a different // set of tracks, we need to remove them all and then add them all. If the remove and // adds are done in pairs, one by one, then the events can step on each other. artf32260 foreach (Sce.Atf.Pair <ITrack, IEvent> trackEventPair in toAdd) { if (trackEventPair.Second is IInterval) { trackEventPair.First.Intervals.Add((IInterval)trackEventPair.Second); } else { trackEventPair.First.Keys.Add((IKey)trackEventPair.Second); } } }, "Move Events".Localize("Move Manipulator's undo / redo description for moving timeline events")); }
// gets move information, for drawing ghosts and for performing actual move operation private GhostInfo[] GetMoveGhostInfo(Matrix worldToView, TimelineLayout layout) { // get start and y offsets in timeline space PointF dragOffset = m_owner.GetDragOffset(); // Get snapping points along the timeline (in world coordinates). List <float> movingPoints = new List <float>(2); TimelinePath snapperPath; if (m_mouseMoveHitRecord != null) { snapperPath = m_mouseMoveHitRecord.HitPath;//use the last clicked event (interval, key or marker) } else { snapperPath = m_owner.Selection.LastSelected as TimelinePath;//moving a group or track, for example } IEvent snapperEvent = snapperPath != null ? snapperPath.Last as IEvent : null; if (snapperEvent != null) { Matrix localToWorld = TimelineControl.CalculateLocalToWorld(snapperPath); float worldStart = GdiUtil.Transform(localToWorld, snapperEvent.Start + dragOffset.X); movingPoints.Add(worldStart); if (snapperEvent.Length > 0.0f) { movingPoints.Add(GdiUtil.Transform(localToWorld, snapperEvent.Start + dragOffset.X + snapperEvent.Length)); } } // Get the offset from one of the world snap points to the closest non-selected object. float snapOffset; try { s_snapOptions.FilterContext = snapperEvent; s_snapOptions.Filter = new TimelineControl.SnapFilter(MoveSnapFilter); snapOffset = m_owner.GetSnapOffset(movingPoints, s_snapOptions); } finally { s_snapOptions.FilterContext = null; s_snapOptions.Filter = null; } // adjust dragOffset to "snap-to" nearest event dragOffset.X += snapOffset; // get offsets in client space float xOffset = dragOffset.X * worldToView.Elements[0]; float yOffset = dragOffset.Y * worldToView.Elements[3]; TimelinePath[] targets = GetMoveTargets(layout); GhostInfo[] ghosts = new GhostInfo[targets.Length]; int i = -1; foreach (TimelinePath path in m_owner.Selection.Selection) { i++; ITimelineObject timelineObject = path.Last; RectangleF bounds = layout[path]; TimelinePath targetPath = targets[i]; ITimelineObject target = targetPath != null ? targetPath.Last : null; float start = 0; float length = 0; bool valid = true; IInterval interval = timelineObject as IInterval; IKey key = timelineObject as IKey; IMarker marker = timelineObject as IMarker; ITrack track = timelineObject as ITrack; IGroup group = timelineObject as IGroup; ITimelineReference reference = timelineObject as ITimelineReference; if (interval != null) { ITrack targetTrack = target as ITrack; start = interval.Start + dragOffset.X; length = interval.Length; valid = targetTrack != null && m_owner.Constraints.IsStartValid(interval, ref start) && m_owner.Constraints.IsLengthValid(interval, ref length); if (valid) { yOffset = layout[target].Y - layout[interval.Track].Y; TimelinePath testPath = new TimelinePath(targetPath); foreach (IInterval other in targetTrack.Intervals) { // skip selected intervals, since they are moving too testPath.Last = other; if (m_owner.Selection.SelectionContains(testPath)) { continue; } if (!m_owner.Constraints.IsIntervalValid(interval, ref start, ref length, other)) { valid = false; break; } } } } else if (reference != null) { // don't allow for vertical repositioning yet start = reference.Start + dragOffset.X; valid = true; } else if (key != null) { start = key.Start + dragOffset.X; ITrack targetTrack = target as ITrack; valid = targetTrack != null && m_owner.Constraints.IsStartValid(key, ref start); if (valid) { yOffset = layout[targetTrack].Y - layout[key.Track].Y; } } else if (marker != null) { start = marker.Start + dragOffset.X; yOffset = 0; valid = m_owner.Constraints.IsStartValid(marker, ref start); } else if (track != null) { xOffset = 0; if (target == null) { target = (m_owner.DragDelta.Y < 0) ? GetLastTrack() : GetFirstTrack(); } } else if (group != null) { xOffset = 0; if (target == null) { IList <IGroup> groups = m_owner.TimelineDocument.Timeline.Groups; target = (m_owner.DragDelta.Y < 0) ? groups[0] : groups[groups.Count - 1]; } } bounds.Offset(xOffset, yOffset); ghosts[i] = new GhostInfo(timelineObject, target, start, length, bounds, valid); } return(ghosts); }
/// <summary> /// Draws a timeline reference</summary> /// <param name="reference">The timeline reference object that may or may not be resolved</param> /// <param name="bounds">The bounding rectangle, in screen space, that was created during the layout phase</param> /// <param name="drawMode">Drawing mode</param> /// <param name="c">Drawing context</param> protected virtual void DrawTimelineReference(ITimelineReference reference, RectangleF bounds, DrawMode drawMode, Context c) { Graphics g = c.Graphics; Color originColor; if (drawMode == DrawMode.Normal) { using (Brush brush = new SolidBrush(reference.Color)) g.FillRectangle(brush, bounds); originColor = Color.Black; } else { originColor = Color.Gray; } RectangleF labelBounds = new RectangleF(bounds.X, bounds.Y, m_headerWidth, bounds.Height); IHierarchicalTimeline timeline = reference.Target; IList<IGroup> groups; bool expanded = false; bool collapsible = false; bool collapsed = false; if (timeline != null) { groups = timeline.Groups; expanded = reference.Options.Expanded; collapsible = groups.Count > 0; collapsed = collapsible && !expanded; } if (collapsible) { labelBounds.X += TrackIndent; labelBounds.Width -= TrackIndent; } g.DrawString(reference.Name, c.Font, SystemBrushes.WindowText, labelBounds, s_groupLabelFormat); // Draw an origin point to show how much the referenced timeline has been offset. RectangleF originRect = bounds; float screenStart = GdiUtil.Transform(c.Transform, reference.Start) + bounds.X; originRect.X = screenStart - 4; originRect.Width = 8; originRect.Height = 16; if (originRect.X + originRect.Width >= m_headerWidth && originRect.X <= c.ClientRectangle.Width) { using (Pen pen = new Pen(originColor)) { g.DrawLines(pen, new[] { new PointF(originRect.X + originRect.Width * 0.5f, originRect.Y), new PointF(originRect.X, originRect.Y + originRect.Height * 0.5f), new PointF(originRect.X + originRect.Width * 0.5f, originRect.Bottom), new PointF(originRect.Right, originRect.Y + originRect.Height * 0.5f), new PointF(originRect.X + originRect.Width * 0.5f, originRect.Y) }); } } if (timeline != null) { bounds = GetGroupHandleRect(bounds, collapsed); if (collapsible) { RectangleF expanderRect = GetExpanderRect(bounds); GdiUtil.DrawExpander( (int)expanderRect.X, (int)expanderRect.Y, (int)expanderRect.Width, Pens.DimGray, expanded, g); } } }
private void _MoveSelection(bool tryToCopy, bool createTracksAndGroups) { ITimeline timeline = m_owner.TimelineDocument.Timeline; Dictionary <ITrack, ITrack> newTrackMap = new Dictionary <ITrack, ITrack>(); List <Sce.Atf.Pair <ITrack, IEvent> > toAdd = new List <Sce.Atf.Pair <ITrack, IEvent> >(); for (int i = 0; i < m_ghosts.Length; i++) { GhostInfo ghost = m_ghosts[i]; ITimelineObject ghostCopy = null; if (tryToCopy) { ICloneable cloneable = ghost.Object as ICloneable; if (cloneable != null) { ghostCopy = cloneable.Clone() as ITimelineObject; } } ITimelineReference reference = ghost.Object as ITimelineReference; if (reference != null) { if (ghostCopy != null) { reference = (ITimelineReference)ghostCopy; } reference.Start = ghost.Start; if (ghostCopy != null && timeline is IHierarchicalTimelineList) { ((IHierarchicalTimelineList)timeline).References.Add(reference); } continue; } IInterval interval = ghost.Object as IInterval; if (interval != null) { if (ghostCopy != null) { interval = (IInterval)ghostCopy; } interval.Start = ghost.Start; interval.Length = ghost.Length; ITrack target = (ITrack)ghost.Target; if (target != interval.Track && createTracksAndGroups) { if (target == null) { target = CreateTargetTrack(interval.Track, newTrackMap); } if (ghostCopy == null) { interval.Track.Intervals.Remove(interval); } toAdd.Add(new Sce.Atf.Pair <ITrack, IEvent>(target, interval)); } continue; } IKey key = ghost.Object as IKey; if (key != null) { if (ghostCopy != null) { key = (IKey)ghostCopy; } key.Start = ghost.Start; ITrack target = (ITrack)ghost.Target; if (target != key.Track && createTracksAndGroups) { if (target == null) { target = CreateTargetTrack(key.Track, newTrackMap); } if (ghostCopy == null) { key.Track.Keys.Remove(key); } toAdd.Add(new Sce.Atf.Pair <ITrack, IEvent>(target, key)); } continue; } IMarker marker = ghost.Object as IMarker; if (marker != null) { if (ghost.Valid && marker.Start != ghost.Start) { if (ghostCopy != null) { IMarker markerCopy = (IMarker)ghostCopy; markerCopy.Start = ghost.Start; marker.Timeline.Markers.Add(markerCopy); } else { marker.Start = ghost.Start; } } continue; } ITrack track = ghost.Object as ITrack; if (track != null) { var targetTrack = ghost.Target as ITrack; if (targetTrack != null && targetTrack != track) { if (ghostCopy != null) { track = (ITrack)ghostCopy; } int index = targetTrack.Group.Tracks.IndexOf(targetTrack); if (ghostCopy == null) { track.Group.Tracks.Remove(track); } targetTrack.Group.Tracks.Insert(index, track); } else { var targetGroup = ghost.Target as IGroup; if (targetGroup != null) { // the track was dragged to an empty group. http://tracker.ship.scea.com/jira/browse/WWSATF-1371 if (ghostCopy != null) { track = (ITrack)ghostCopy; } else { track.Group.Tracks.Remove(track); } targetGroup.Tracks.Insert(0, track); } } continue; } IGroup group = ghost.Object as IGroup; if (group != null) { IGroup target = (IGroup)ghost.Target; if (target != null && target != group) { if (ghostCopy != null) { group = (IGroup)ghostCopy; } int index = m_owner.TimelineDocument.Timeline.Groups.IndexOf(target); if (ghostCopy == null) { m_owner.TimelineDocument.Timeline.Groups.Remove(group); } m_owner.TimelineDocument.Timeline.Groups.Insert(index, group); } continue; } } // So that when multiple intervals from multiple tracks are relocated to a different // set of tracks, we need to remove them all and then add them all. If the remove and // adds are done in pairs, one by one, then the events can step on each other. artf32260 foreach (Sce.Atf.Pair <ITrack, IEvent> trackEventPair in toAdd) { if (trackEventPair.Second is IInterval) { trackEventPair.First.Intervals.Add((IInterval)trackEventPair.Second); } else { trackEventPair.First.Keys.Add((IKey)trackEventPair.Second); } } }
// Only client-specific code can create a new ITimelineReference and add it. internal void AddReference(ITimelineReference reference) { GetChildList <ITimelineReference>(Schema.timelineType.timelineRefChild).Add(reference); }