private bool IsTrackVisible(ITrack track) { TimelineLayout layout = TimelineControl.GetLayout(); RectangleF trackBounds; if (layout.TryGetBounds(new TimelinePath(track), out trackBounds)) { RectangleF clientRectF = m_timelineControl.VisibleClientRectangle; if (clientRectF.Top <= trackBounds.Bottom && clientRectF.Bottom >= trackBounds.Top) { return(true); } } return(false); }
private void owner_DrawingD2d(object sender, EventArgs e) { // Test if anything is visible. m_visibleManipulator = D2dTimelineControl.CalculateRange(Owner.EditableSelection, out m_worldMin, out m_worldMax); if (!m_visibleManipulator) { return; } D2dGraphics g = Owner.D2dGraphics; Matrix worldToView = Owner.Transform; // Make the TimelineRenderer draw the ghosts, if necessary. Must happen before // the manipulator is drawn so that snap-to info is created. if (IsScaling) { TimelineLayout layout = Owner.GetLayout(); GhostInfo[] ghosts = m_resizer.CreateGhostInfo( layout, Owner.GetDragOffset().X, worldToView); Owner.Renderer.DrawGhosts( ghosts, DraggedSide, worldToView, Owner.ClientRectangle); } // Tighten clipping region. Has to occur after DrawGhosts because the TimelineRenderer // assumes that it has to shrink the current Graphics.Clip region by the header width. try { g.PushAxisAlignedClip(Owner.VisibleClientRectangle); // Draw the manipulator, giving client code a customization point. DrawManipulator(g, out m_leftHandle, out m_rightHandle); } finally { g.PopAxisAlignedClip(); } }
// get track that contains y value (in client window coordinates, aka, screen space) private TimelinePath GetTargetTrack( float y, TimelineLayout layout, IList <ITrack> tracks) { TimelinePath testPath = new TimelinePath((ITimelineObject)null); foreach (ITrack track in tracks) { testPath.Last = track; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= y && targetBounds.Bottom >= y) { return(testPath); } } return(null); }
protected override RectangleF GetCurrentPageBounds() { TimelineLayout layout = m_timelineControl.GetLayout(); RectangleF visibleBounds = GdiUtil.InverseTransform(m_timelineControl.Transform, m_timelineControl.ClientRectangle); RectangleF result = new RectangleF(); bool firstTime = true; foreach (KeyValuePair <TimelinePath, RectangleF> pair in layout) { if (pair.Value.IntersectsWith(visibleBounds)) { if (firstTime) { firstTime = false; result = pair.Value; } else { result = RectangleF.Union(result, pair.Value); } } } return(result); }
private void DrawGroupsAndTracks(TimelinePath path, ITimeline timeline, bool expandedTimeline, ISelectionContext selection, Context c, TimelineLayout layout, RectangleF clipBounds) { RectangleF canvasBounds = clipBounds; //clipBounds minus the left-side header canvasBounds.X = HeaderWidth; canvasBounds.Width -= HeaderWidth; RectangleF bounds; foreach (IGroup group in timeline.Groups) { TimelinePath groupPath = path + group; if (!layout.TryGetBounds(groupPath, out bounds)) continue; if (bounds.IntersectsWith(clipBounds)) { DrawMode drawMode = DrawMode.Normal; if (selection.SelectionContains(groupPath)) drawMode |= DrawMode.Selected; if (expandedTimeline) Draw(group, bounds, drawMode, c); IList<ITrack> tracks = group.Tracks; bool collapsed = !expandedTimeline || (!group.Expanded && tracks.Count > 1); foreach (ITrack track in tracks) { TimelinePath trackPath = path + track; bounds = layout.GetBounds(trackPath); if (bounds.IntersectsWith(clipBounds)) { drawMode = DrawMode.Normal; if (selection.SelectionContains(trackPath)) drawMode |= DrawMode.Selected; if (collapsed) drawMode = DrawMode.Collapsed; Draw(track, bounds, drawMode, c); foreach (IInterval interval in track.Intervals) { TimelinePath intervalPath = path + interval; bounds = layout.GetBounds(intervalPath); if (bounds.IntersectsWith(canvasBounds)) { drawMode = DrawMode.Normal; if (selection.SelectionContains(intervalPath)) drawMode |= DrawMode.Selected; if (collapsed) drawMode = DrawMode.Collapsed; Draw(interval, bounds, drawMode, c); } } foreach (IKey key in track.Keys) { TimelinePath keyPath = path + key; bounds = layout.GetBounds(keyPath); if (bounds.IntersectsWith(canvasBounds)) { drawMode = DrawMode.Normal; if (selection.SelectionContains(keyPath)) drawMode |= DrawMode.Selected; if (collapsed) drawMode = DrawMode.Collapsed; Draw(key, bounds, drawMode, c); } } } } } } }
private void DrawMarkers(TimelinePath path, ITimeline timeline, ISelectionContext selection, Context c, TimelineLayout layout, RectangleF clipBounds) { RectangleF bounds; foreach (IMarker marker in timeline.Markers) { TimelinePath markerPath = path + marker; if (!layout.TryGetBounds(markerPath, out bounds)) continue; if (bounds.IntersectsWith(clipBounds)) { DrawMode drawMode = DrawMode.Normal; if (selection.SelectionContains(markerPath)) drawMode |= DrawMode.Selected; Draw(marker, bounds, drawMode, c); } } }
private void DrawSubTimeline( TimelinePath path, ITimeline timeline, bool subTimeline, bool expandedTimeline, ISelectionContext selection, TimelinePath activeGroup, TimelinePath activeTrack, TimelineLayout layout, Context c) { //if (c.TestRecursion(timeline)) // return; if (!subTimeline) m_offsetX = c.Transform.OffsetX; RectangleF clipBounds = m_graphics.ClipBounds; DrawGroupsAndTracks(path, timeline, expandedTimeline, selection, c, layout, clipBounds); // draw markers over keys, intervals, tracks, and group if (subTimeline) { // Give the Markers in the main timeline precedence; draw on top of everything. clipBounds.X = HeaderWidth; clipBounds.Width -= HeaderWidth; DrawMarkers(path, timeline, selection, c, layout, clipBounds); } // Draw the group and track handles only if the owning timeline is expanded. if (expandedTimeline) { if (m_printing) c.Graphics.TranslateTransform(m_marginBounds.Left, 0); RectangleF bounds; foreach (IGroup group in timeline.Groups) { IList<ITrack> tracks = group.Tracks; TimelinePath groupPath = path + group; bounds = layout.GetBounds(groupPath); bounds = GetGroupHandleRect(bounds, !group.Expanded); RectangleF groupLabelBounds = new RectangleF(bounds.X, bounds.Y, HeaderWidth, bounds.Height); // Draw group's move handle. DrawMoveHandle(bounds, selection.SelectionContains(groupPath), groupPath == activeGroup); // Draw expander? if (tracks.Count > 1) { RectangleF expanderRect = GetExpanderRect(bounds); m_graphics.DrawExpander( expanderRect.X, expanderRect.Y, expanderRect.Width, m_expanderBrush, group.Expanded); groupLabelBounds.X += TrackIndent; groupLabelBounds.Width -= TrackIndent; } // Draw tracks' move handles? if (group.Expanded || tracks.Count == 1) { foreach (ITrack track in tracks) { TimelinePath trackPath = path + track; bounds = layout.GetBounds(trackPath); bounds = GetTrackHandleRect(bounds); DrawMoveHandle(bounds, selection.SelectionContains(trackPath), trackPath == activeTrack); if (bounds.Width > 0f) m_graphics.DrawText(track.Name, m_trackTextFormat, bounds, m_nameBrush); } } // Draw group name. if (groupLabelBounds.Width > 0) m_graphics.DrawText(group.Name, c.TextFormat, groupLabelBounds, m_nameBrush); } if (m_printing) c.Graphics.TranslateTransform(-m_marginBounds.Left, 0); } return; }
private void DrawSubTimeline( TimelinePath path, ISelectionContext selection, TimelinePath activeGroup, TimelinePath activeTrack, TimelineLayout layout, Context c) { // Include the reference's offset into the Transform and InverseTransform properties. Matrix localToWorld = D2dTimelineControl.CalculateLocalToWorld(path); c.PushTransform(localToWorld, MatrixOrder.Prepend); // draw the row that has this timeline reference's name ITimelineReference reference = (ITimelineReference)path.Last; RectangleF clipBounds = m_graphics.ClipBounds; RectangleF bounds = layout.GetBounds(path); IHierarchicalTimeline timeline = reference.Target; if (bounds.IntersectsWith(clipBounds)) { DrawMode drawMode = DrawMode.Normal; if (selection.SelectionContains(path)) drawMode |= DrawMode.Selected; DrawTimelineReference(reference, bounds, drawMode, c); } // draw the timeline document as if it were the main document if (timeline != null) DrawSubTimeline(path, timeline, true, reference.Options.Expanded, selection, activeGroup, activeTrack, layout, c); c.PopTransform(); }
// documentTop is in timeline coordinates private void LayoutSubTimeline( TimelinePath path, ITimeline timeline, ref float documentTop, bool expandedTimeline, Context c, TimelineLayout result) { //if (c.TestRecursion(timeline)) // return; RectangleF bounds; SizeF pixelSize = c.PixelSize; float margin = pixelSize.Height * m_margin; float groupTop = documentTop; float documentBottom = groupTop; foreach (IGroup group in timeline.Groups) { bool expanded = expandedTimeline && group.Expanded; float groupBottom = groupTop; float trackTop = groupTop; foreach (ITrack track in group.Tracks) { float eventTop = trackTop + margin; float trackBottom = eventTop; foreach (IInterval interval in track.Intervals) { bounds = GetBounds(interval, eventTop, c); trackBottom = Math.Max(trackBottom, bounds.Bottom); bounds = GdiUtil.Transform(c.Transform, bounds); // add it, even if 'expandedTimeline' is false, to get the shadow effect result.Add(path + interval, bounds); } foreach (IKey key in track.Keys) { bounds = GetBounds(key, eventTop, c); trackBottom = Math.Max(trackBottom, bounds.Bottom); bounds = GdiUtil.Transform(c.Transform, bounds); // add it, even if 'expandedTimeline' is false, to get the shadow effect result.Add(path + key, bounds); } trackBottom += margin; trackBottom = Math.Max(trackBottom, trackTop + MinimumTrackSize); // need height for track, even if it's empty bounds = new RectangleF(c.Bounds.X, trackTop, c.Bounds.Width, trackBottom - trackTop); bounds = GdiUtil.Transform(c.Transform, bounds); bounds.X = c.ClientRectangle.X; // add it, even if 'expandedTimeline' is false, to get the shadow effect result.Add(path + track, bounds); if (expanded) trackTop = trackBottom; groupBottom = Math.Max(groupBottom, trackBottom); } // need height for group, even if it's empty groupBottom = Math.Max(groupBottom, groupTop + Math.Max(margin*2, MinimumTrackSize)); float groupHeight = groupBottom - groupTop; bounds = new RectangleF(0, groupTop, c.Bounds.Width, groupHeight); bounds = GdiUtil.Transform(c.Transform, bounds); bounds.X = c.ClientRectangle.X; // add it, even if 'expandedTimeline' is false, to get the shadow effect result.Add(path + group, bounds); if (expandedTimeline) groupTop = groupBottom; documentBottom = Math.Max(documentBottom, groupBottom); } if (expandedTimeline) { // Draw Markers, but limit them to be within the owning timeline. RectangleF originalBounds = c.Bounds; c.Bounds.Height = documentBottom - c.Bounds.Y; foreach (IMarker marker in timeline.Markers) { bounds = GetBounds(marker, c); bounds = GdiUtil.Transform(c.Transform, bounds); result.Add(path + marker, bounds); } c.Bounds = originalBounds; } documentTop = documentBottom; }
/// <summary> /// Prioritizes the hits, using layout and picking rectangle information. This is called after /// PrioritizeHits().</summary> /// <param name="hits">The timeline objects to sort, that intersect the given rectangle</param> /// <param name="layout">The layout</param> /// <param name="pickRect">The picking rectangle</param> protected virtual void PrioritizeHits(List<HitRecord> hits, TimelineLayout layout, RectangleF pickRect) { if (hits.Count <= 1) return; float pickCenterX = pickRect.X + pickRect.Width*0.5f; float pickCenterY = pickRect.Y + pickRect.Height*0.5f; hits.Sort((a, b) => { if (a.Type < b.Type) return -1; if (a.Type > b.Type) return 1; // The HeaderResize type doesn't have a HitPath. if (a.HitPath == null || b.HitPath == null) return 0; // They're the same type, so now sort by distance from center of picking rectangle. RectangleF aRect = layout.GetBounds(a.HitPath); RectangleF bRect = layout.GetBounds(b.HitPath); float aDist = Math.Min( Math.Abs(aRect.X + aRect.Width*0.5f - pickCenterX), Math.Abs(aRect.Y + aRect.Height*0.5f - pickCenterY)); float bDist = Math.Min( Math.Abs(bRect.X + bRect.Width * 0.5f - pickCenterX), Math.Abs(bRect.Y + bRect.Height * 0.5f - pickCenterY)); if (aDist < bDist) return -1; if (aDist > bDist) return 1; return 0; }); }
// gets objects of appropriate type that are underneath the moving selected objects private TimelinePath[] GetMoveTargets(TimelineLayout layout) { // get groups and visible tracks List<IGroup> groups = new List<IGroup>(); List<ITrack> visibleTracks = new List<ITrack>(); foreach (IGroup group in m_owner.TimelineDocument.Timeline.Groups) { groups.Add(group); IList<ITrack> tracks = group.Tracks; bool expanded = group.Expanded; bool collapsible = tracks.Count > 1; bool collapsed = collapsible && !expanded; if (!collapsed) foreach (ITrack track in tracks) visibleTracks.Add(track); } TimelinePath[] targets = new TimelinePath[m_owner.Selection.SelectionCount]; RectangleF bounds; TimelinePath testPath = new TimelinePath((ITimelineObject)null); int i = -1; foreach(TimelinePath path in m_owner.Selection.Selection) { i++; IGroup group = path.Last as IGroup; if (group != null) { foreach (IGroup targetGroup in groups) { Point p = DragPoint; testPath.Last = targetGroup; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= p.Y && targetBounds.Bottom >= p.Y) { targets[i] = new TimelinePath(testPath); break; } } continue; } ITrack track = path.Last as ITrack; if (track != null) { foreach (ITrack targetTrack in visibleTracks) { Point p = m_owner.DragPoint; testPath.Last = targetTrack; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= p.Y && targetBounds.Bottom >= p.Y) { targets[i] = new TimelinePath(testPath); break; } } if (targets[i] == null) { foreach (IGroup targetGroup in groups) { Point p = DragPoint; testPath.Last = targetGroup; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= p.Y && targetBounds.Bottom >= p.Y) { targets[i] = new TimelinePath(testPath); break; } } } continue; } IInterval interval = path.Last as IInterval; if (interval != null) { track = interval.Track; if (track != null) { testPath.Last = track; bounds = layout[testPath]; float y = bounds.Top + bounds.Height * 0.5f + DragDelta.Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); continue; } else { float y = m_owner.RectangleToClient(new Rectangle(Cursor.Position, new Size())).Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); } } IKey key = path.Last as IKey; if (key != null) { track = key.Track; if (track != null) { testPath.Last = track; bounds = layout[testPath]; float y = bounds.Top + bounds.Height * 0.5f + DragDelta.Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); continue; } else { //float y = m_owner.ClientToCanvas(m_owner.DragPoint).Y; float y = m_owner.RectangleToClient(new Rectangle(Cursor.Position, new Size())).Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); } } // ignore Markers, as they don't hit targets } return targets; }
// get track that contains y value (in client window coordinates, aka, screen space) private TimelinePath GetTargetTrack( float y, TimelineLayout layout, IList<ITrack> tracks) { TimelinePath testPath = new TimelinePath((ITimelineObject)null); foreach (ITrack track in tracks) { testPath.Last = track; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= y && targetBounds.Bottom >= y) return testPath; } return null; }
// 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 = 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 = D2dTimelineControl.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 D2dTimelineControl.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); // Pretend that drag-drop objects are in the TimelineLayout object if (m_owner.DragDropObjects != null) { foreach (ITimelineObject dragDrop in m_owner.DragDropObjects) layout[dragDrop] = GetDragDropBounds(dragDrop); } 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; valid &= m_owner.Constraints.IsStartValid(interval, ref start); valid &= m_owner.Constraints.IsLengthValid(interval, ref length); if (valid) { ITrack intervalTrack = interval.Track; if (intervalTrack != null) yOffset = layout[target].Y - layout[interval.Track].Y; else yOffset = layout[target].Y - bounds.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; valid &= m_owner.Constraints.IsStartValid(key, ref start); if (valid) { ITrack keyTrack = key.Track; if (keyTrack != null) yOffset = layout[targetTrack].Y - layout[key.Track].Y; else yOffset = layout[targetTrack].Y - bounds.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 = (DragDelta.Y < 0) ? GetLastTrack() : GetFirstTrack(); } } else if (group != null) { xOffset = 0; if (target == null) { IList<IGroup> groups = m_owner.TimelineDocument.Timeline.Groups; target = (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; }
// gets objects of appropriate type that are underneath the moving selected objects private TimelinePath[] GetMoveTargets(TimelineLayout layout) { // get groups and visible tracks List <IGroup> groups = new List <IGroup>(); List <ITrack> visibleTracks = new List <ITrack>(); foreach (IGroup group in m_owner.TimelineDocument.Timeline.Groups) { groups.Add(group); IList <ITrack> tracks = group.Tracks; bool expanded = group.Expanded; bool collapsible = tracks.Count > 1; bool collapsed = collapsible && !expanded; if (!collapsed) { foreach (ITrack track in tracks) { visibleTracks.Add(track); } } } TimelinePath[] targets = new TimelinePath[m_owner.Selection.SelectionCount]; RectangleF bounds; TimelinePath testPath = new TimelinePath((ITimelineObject)null); int i = -1; foreach (TimelinePath path in m_owner.Selection.Selection) { i++; IGroup group = path.Last as IGroup; if (group != null) { foreach (IGroup targetGroup in groups) { Point p = DragPoint; testPath.Last = targetGroup; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= p.Y && targetBounds.Bottom >= p.Y) { targets[i] = new TimelinePath(testPath); break; } } continue; } ITrack track = path.Last as ITrack; if (track != null) { foreach (ITrack targetTrack in visibleTracks) { Point p = m_owner.DragPoint; testPath.Last = targetTrack; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= p.Y && targetBounds.Bottom >= p.Y) { targets[i] = new TimelinePath(testPath); break; } } if (targets[i] == null) { foreach (IGroup targetGroup in groups) { Point p = DragPoint; testPath.Last = targetGroup; RectangleF targetBounds = layout[testPath]; if (targetBounds.Top <= p.Y && targetBounds.Bottom >= p.Y) { targets[i] = new TimelinePath(testPath); break; } } } continue; } IInterval interval = path.Last as IInterval; if (interval != null) { track = interval.Track; if (track != null) { testPath.Last = track; bounds = layout[testPath]; float y = bounds.Top + bounds.Height * 0.5f + DragDelta.Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); continue; } else { float y = m_owner.RectangleToClient(new Rectangle(Cursor.Position, new Size())).Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); } } IKey key = path.Last as IKey; if (key != null) { track = key.Track; if (track != null) { testPath.Last = track; bounds = layout[testPath]; float y = bounds.Top + bounds.Height * 0.5f + DragDelta.Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); continue; } else { //float y = m_owner.ClientToCanvas(m_owner.DragPoint).Y; float y = m_owner.RectangleToClient(new Rectangle(Cursor.Position, new Size())).Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); } } // ignore Markers, as they don't hit targets } return(targets); }
// 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 = 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 = D2dTimelineControl.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 D2dTimelineControl.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); // Pretend that drag-drop objects are in the TimelineLayout object if (m_owner.DragDropObjects != null) { foreach (ITimelineObject dragDrop in m_owner.DragDropObjects) { layout[dragDrop] = GetDragDropBounds(dragDrop); } } 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; valid &= m_owner.Constraints.IsStartValid(interval, ref start); valid &= m_owner.Constraints.IsLengthValid(interval, ref length); if (valid) { ITrack intervalTrack = interval.Track; if (intervalTrack != null) { yOffset = layout[target].Y - layout[interval.Track].Y; } else { yOffset = layout[target].Y - bounds.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; valid &= m_owner.Constraints.IsStartValid(key, ref start); if (valid) { ITrack keyTrack = key.Track; if (keyTrack != null) { yOffset = layout[targetTrack].Y - layout[key.Track].Y; } else { yOffset = layout[targetTrack].Y - bounds.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 = (DragDelta.Y < 0) ? GetLastTrack() : GetFirstTrack(); } } else if (group != null) { xOffset = 0; if (target == null) { IList <IGroup> groups = m_owner.TimelineDocument.Timeline.Groups; target = (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); }
private void PickSubTimeline( TimelinePath path, RectangleF pickRect, Context c, TimelineLayout layout, List<HitRecord> result) { RectangleF clipBounds = c.Graphics.ClipBounds; ITimelineReference reference = (ITimelineReference)path.Last; RectangleF bounds; if (!layout.TryGetBounds(path, out bounds)) return; IHierarchicalTimeline timeline = reference.Target; if (timeline != null && reference.Options.Expanded) PickSubTimeline(path, timeline, pickRect, c, layout, result); if (timeline != null && bounds.IntersectsWith(clipBounds)) { IList<IGroup> groups = timeline.Groups; bool collapsible = groups.Count > 0; bool expanded = reference.Options.Expanded; bool collapsed = collapsible && !expanded; RectangleF handleRect = GetGroupHandleRect(bounds, collapsed); RectangleF expanderRect = GetExpanderRect(handleRect); if (collapsible && expanderRect.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.GroupExpand, path)); } else if (bounds.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.Key, path)); } } else if (bounds.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.Key, path)); } }
private void PickSubTimeline( TimelinePath root, ITimeline timeline, RectangleF pickRect, Context c, TimelineLayout layout, List<HitRecord> result) { if (timeline == null) return; RectangleF clipBounds = c.Graphics.ClipBounds; RectangleF clientRectangle = c.ClientRectangle; RectangleF bounds; HitType hitType; foreach (IMarker marker in timeline.Markers) { if (!layout.TryGetBounds(root + marker, out bounds)) continue; if (bounds.IntersectsWith(clipBounds) && pickRect.Right >= HeaderWidth) { hitType = Pick(marker, bounds, pickRect, c); if (hitType != HitType.None) result.Add(new HitRecord(hitType, root + marker)); } } // If the pick is on the timescale, then let's stop here. if (pickRect.Left > HeaderWidth && pickRect.Right < clientRectangle.Width && pickRect.Bottom > 0 && pickRect.Bottom < TimeScaleHeight) { if ((result.Count == 0) && (pickRect.Height <= 2 * PickTolerance) && (pickRect.Width <= 2 * PickTolerance)) result.Add(new HitRecord(HitType.TimeScale, null)); return; } IList<IGroup> groups = timeline.Groups; for (int i = groups.Count - 1; i >= 0; i--) { IGroup group = groups[i]; if (!layout.ContainsPath(root + group)) continue; IList<ITrack> tracks = group.Tracks; bool expanded = group.Expanded; bool collapsible = tracks.Count > 1; bool collapsed = collapsible && !expanded; if (!collapsed) { for (int j = tracks.Count - 1; j >= 0; j--) { ITrack track = tracks[j]; IList<IKey> keys = track.Keys; for (int k = keys.Count - 1; k >= 0; k--) { IKey key = keys[k]; if (!layout.TryGetBounds(root + key, out bounds)) continue; if (bounds.IntersectsWith(clipBounds) && pickRect.Right >= HeaderWidth) { hitType = Pick(key, bounds, pickRect, c); if (hitType != HitType.None) result.Add(new HitRecord(hitType, root + key)); } } IList<IInterval> intervals = track.Intervals; for (int k = intervals.Count - 1; k >= 0; k--) { IInterval interval = intervals[k]; if (!layout.TryGetBounds(root + interval, out bounds)) continue; if (bounds.IntersectsWith(clipBounds) && pickRect.Right >= HeaderWidth) { hitType = Pick(interval, bounds, pickRect, c); if (hitType != HitType.None) result.Add(new HitRecord(hitType, root + interval)); } } if (!layout.TryGetBounds(root + track, out bounds)) continue; if (bounds.IntersectsWith(clipBounds)) { RectangleF handleRect = GetTrackHandleRect(bounds); if (handleRect.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.TrackMove, root + track)); } else if (bounds.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.Track, root + track)); } } } } if (!layout.TryGetBounds(root + group, out bounds)) continue; if (bounds.IntersectsWith(clipBounds)) { RectangleF handleRect = GetGroupHandleRect(bounds, collapsed); RectangleF expanderRect = GetExpanderRect(handleRect); if (collapsible && expanderRect.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.GroupExpand, root + group)); } else if (handleRect.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.GroupMove, root + group)); } else if (bounds.IntersectsWith(pickRect)) { result.Add(new HitRecord(HitType.Group, root + group)); } } } if (pickRect.Left < HeaderWidth && HeaderWidth < pickRect.Right) { result.Add(new HitRecord(HitType.HeaderResize, null)); } }
/// <summary> /// Calculates and returns the rectangles of the objects in Windows client coordinates. /// Depending on collapse/expanded states, not every ITimelineObject may be in the dictionary. /// Consider calling GetCachedLayout() for picking purposes.</summary> /// <param name="timeline">The timeline to be laid out</param> /// <param name="c">The editing context</param> /// <returns>A dictionary mapping every timeline object in the timeline to its bounding box</returns> protected TimelineLayout Layout(ITimeline timeline, Context c) { TimelineLayout result = new TimelineLayout(); SizeF pixelSize = c.PixelSize; float documentTop = pixelSize.Height * m_timeScaleHeight; LayoutSubTimeline(null, timeline, ref documentTop, true, c, result); foreach (TimelinePath path in D2dTimelineControl.GetHierarchy(timeline)) LayoutSubTimeline(path, ref documentTop, c, result); m_cachedLayout.First = timeline; m_cachedLayout.Second = result; return result; }
// documentTop is in timeline coordinates private void LayoutSubTimeline( TimelinePath path, ref float documentTop, Context c, TimelineLayout result) { SizeF pixelSize = c.PixelSize; float margin = pixelSize.Height * m_margin; // Limit Markers, etc., to being drawn within the owning timeline. RectangleF originalBounds = c.Bounds; c.Bounds.Y = documentTop; // Add a large bounding box for the whole TimelineReference row. float docRowHeight = Math.Max(margin * 2, MinimumTrackSize); RectangleF refBounds = new RectangleF(c.Bounds.X, documentTop, c.Bounds.Width, docRowHeight); documentTop += docRowHeight; // The whole timeline, with all groups and tracks laid out, and offset by the reference.Start. ITimelineReference reference = (ITimelineReference)path.Last; TimelineReferenceOptions options = reference.Options; IHierarchicalTimeline resolved = reference.Target; if (resolved != null) { Matrix localToWorld = D2dTimelineControl.CalculateLocalToWorld(path); c.PushTransform(localToWorld, MatrixOrder.Prepend); LayoutSubTimeline(path, resolved, ref documentTop, options.Expanded, c, result); c.PopTransform(); } // Now that we know the height of the tallest group, we can update the collapsed rectangle. if (!options.Expanded) { docRowHeight = Math.Max(docRowHeight, documentTop - refBounds.Y); refBounds.Height = docRowHeight; } refBounds = GdiUtil.Transform(c.Transform, refBounds); result.Add(path, refBounds); // Restore the bounds so that the horizontal scale (tick marks & numbers) is correct. c.Bounds = originalBounds; }
/// <summary> /// Creates and caches resize information, for drawing ghosts and for performing /// actual resize operations</summary> /// <param name="layout">TimelineLayout</param> /// <param name="worldDrag">Drag offset</param> /// <param name="worldToView">World to view transformation matrix</param> /// <returns>Array of GhostInfo</returns> internal GhostInfo[] CreateGhostInfo(TimelineLayout layout, float worldDrag, Matrix worldToView) { // Get snap-from point in world coordinates. float[] movingPoints = new[] { worldDrag + m_originalBoundary }; float snapOffset = m_owner.GetSnapOffset(movingPoints, null); // adjust dragOffset to snap-to nearest event worldDrag += snapOffset; DragOffsetWithSnap = worldDrag; GhostInfo[] ghosts = new GhostInfo[m_selection.Count]; IEnumerator <TimelinePath> events = m_selection.GetEnumerator(); m_worldGhostMin = float.MaxValue; m_worldGhostMax = float.MinValue; for (int i = 0; i < ghosts.Length; i++) { events.MoveNext(); IEvent curr = (IEvent)events.Current.Last; RectangleF bounds = layout[events.Current]; float viewStart = bounds.Left; float viewEnd = viewStart + bounds.Width; float worldStart = curr.Start; float worldEnd = worldStart + curr.Length; Resize( worldDrag, worldToView, ref viewStart, ref viewEnd, ref worldStart, ref worldEnd); float worldLength = worldEnd - worldStart; bounds = new RectangleF(viewStart, bounds.Y, viewEnd - viewStart, bounds.Height); if (m_worldGhostMin > worldStart) { m_worldGhostMin = worldStart; } if (m_worldGhostMax < worldEnd) { m_worldGhostMax = worldEnd; } bool valid = true; IInterval interval = curr as IInterval; if (interval != null) { TimelinePath testPath = new TimelinePath(events.Current); foreach (IInterval other in interval.Track.Intervals) { // Skip this interval if it's part of the selection because we have to assume // that the track began in a valid state and that all of the selected objects // will still be valid relative to each other. We only need to check that the // scaled objects are valid relative to the stationary objects. testPath.Last = other; if (Mode == ScaleMode.TimePeriod && m_selection.Contains(testPath)) { continue; } else if (other == interval) { continue; } if (!m_owner.Constraints.IsIntervalValid(interval, ref worldStart, ref worldLength, other)) { valid = false; break; } } } ghosts[i] = new GhostInfo(curr, null, worldStart, worldLength, bounds, valid); } m_ghosts = ghosts; return(ghosts); }