private void owner_MouseDownPicked(object sender, HitEventArgs e) { if (e.MouseEvent.Button != MouseButtons.Left) { return; } TimelinePath hitPath = e.HitRecord.HitPath; bool isResizing = false; switch (e.HitRecord.Type) { case HitType.IntervalResizeLeft: if (Owner.IsEditable(hitPath) && ( Owner.Selection.SelectionContains(hitPath) || Owner.Select <IEvent>(hitPath))) { IInterval hitInterval = e.HitRecord.HitTimelineObject as IInterval; m_resizer = new Resizer(Side.Left, ScaleMode.InPlace, hitInterval.Start, Owner); isResizing = true; } break; case HitType.IntervalResizeRight: if (Owner.IsEditable(hitPath) && ( Owner.Selection.SelectionContains(hitPath) || Owner.Select <IEvent>(hitPath))) { IInterval hitInterval = e.HitRecord.HitTimelineObject as IInterval; m_resizer = new Resizer(Side.Right, ScaleMode.InPlace, hitInterval.Start + hitInterval.Length, Owner); isResizing = true; } break; case HitType.Custom: { HitRecordObject hitManipulator = e.HitRecord.HitObject as HitRecordObject; if (hitManipulator != null) { if (hitManipulator.Side == Side.Left) { m_resizer = new Resizer(Side.Left, ScaleMode.TimePeriod, m_worldMin, Owner); } else { m_resizer = new Resizer(Side.Right, ScaleMode.TimePeriod, m_worldMax, Owner); } isResizing = true; } } break; default: m_resizer = null; break; } Owner.IsResizingSelection = isResizing; //legacy. obsolete. }
private void owner_MouseMovePicked(object sender, HitEventArgs e) { if (e.MouseEvent.Button == MouseButtons.None) { HitRecord hitRecord = e.HitRecord; TimelinePath hitPath = hitRecord.HitPath; switch (hitRecord.Type) { case HitType.IntervalResizeLeft: case HitType.IntervalResizeRight: if (Owner.IsEditable(hitPath)) { Owner.Cursor = Cursors.SizeWE; } break; //one of the scale manipulator's handles? case HitType.Custom: if (hitRecord.HitObject == m_leftHitObject || hitRecord.HitObject == m_rightHitObject) { Owner.Cursor = Cursors.SizeWE; } break; default: break; } } }
/// <summary> /// Gets the last track as determined by the associated ITimeline</summary> /// <returns>Last track as TimelinePath</returns> protected TimelinePath GetLastTrack() { TimelinePath last = null; foreach (TimelinePath track in Owner.AllTracks) { last = track; } return(last); }
/// <summary> /// Gets the last group as determined by the associated ITimeline</summary> /// <returns>Last group as TimelinePath</returns> protected TimelinePath GetLastGroup() { TimelinePath last = null; foreach (TimelinePath group in Owner.AllGroups) { last = group; } return(last); }
/// <summary> /// Adds range of tracks to selection, from anchor to given target. /// Handles selecting a track, taking into account selecting ranges of tracks.</summary> /// <param name="target">Track as TimelinePath</param> protected virtual void SelectTracks(TimelinePath target) { // add range of tracks, from anchor to target? if ((Control.ModifierKeys & Keys.Shift) != Keys.None) { if (Anchor != null && Anchor.Last is ITrack && SelectionContext != null) { SelectionContext.SetRange(GetRangeOfTracks(Anchor, target)); return; } } // simply add this target track, using the current modifier keys to determine how Owner.Select <ITrack>(target); }
private void owner_MouseMovePicked(object sender, HitEventArgs e) { string toolTipText = null; if (m_active) { e.Handled = true; if (e.HitRecord.Type == HitType.Interval && e.MouseEvent.Button == MouseButtons.None && !m_owner.IsUsingMouse && m_owner.IsEditable(e.HitRecord.HitPath)) { SetCursor(); TimelinePath hitPath = e.HitRecord.HitPath; IInterval hitObject = (IInterval)e.HitRecord.HitTimelineObject; float worldX = GdiUtil.InverseTransform(m_owner.Transform, e.MouseEvent.Location.X); //Make sure the snap-to indicator line is drawn. float delta = m_owner.GetSnapOffset(new[] { worldX }, s_snapOptions); worldX += delta; worldX = m_owner.ConstrainFrameOffset(worldX); Matrix localToWorld = TimelineControl.CalculateLocalToWorld(hitPath); if (worldX <= GdiUtil.Transform(localToWorld, hitObject.Start) || worldX >= GdiUtil.Transform(localToWorld, hitObject.Start + hitObject.Length)) { // Clear the results since a split is impossible. m_owner.GetSnapOffset(new float[] { }, s_snapOptions); } else { toolTipText = worldX.ToString(); } } } if (toolTipText != null) { m_toolTip.Show(toolTipText, m_owner, e.MouseEvent.Location); } else { m_toolTip.Hide(m_owner); } }
/// <summary> /// Adds range of groups to selection, from anchor to given target. /// Handles selecting a group, taking into account selecting ranges of groups. /// If no anchor, just selects target.</summary> /// <param name="target">Timeline path</param> protected virtual void SelectGroups(TimelinePath target) { // Add range of groups, from anchor to target? Holding down Ctrl or Alt simultaneously // still does a range selection in Visual Studio's Solution Explorer. if ((Control.ModifierKeys & Keys.Shift) != Keys.None) { if (Anchor != null && Anchor.Last is IGroup && SelectionContext != null) { SelectionContext.SetRange(GetRangeOfGroups(Anchor, target)); return; } } // simply add this target group, using the current modifier keys to determine how Owner.Select <IGroup>(target); }
/// <summary> /// Event handler for the TimelineControl.MouseDownPicked event</summary> /// <param name="sender">The TimelineControl that we are attached to</param> /// <param name="e">HitEventArgs</param> protected virtual void Owner_MouseDownPicked(object sender, HitEventArgs e) { HitRecord hitRecord = e.HitRecord; TimelinePath hitObject = hitRecord.HitPath; if (hitObject != null) { Keys modifiers = Control.ModifierKeys; if (e.MouseEvent.Button == MouseButtons.Left) { if (modifiers == Keys.None && SelectionContext != null && SelectionContext.SelectionContains(hitObject)) { // The hit object is already selected. Wait until the mouse up to see if there was // a drag or not. If no drag, then set the selection set to be this one object. m_mouseDownHitRecord = hitRecord; m_mouseDownPos = e.MouseEvent.Location; } else if (modifiers == Keys.Control) { // Either this object is not already selected or Shift key is being held down. // to be consistent with the Windows interface. m_mouseDownHitRecord = hitRecord; m_mouseDownPos = e.MouseEvent.Location; } else if ((modifiers & Keys.Alt) == 0) { // The 'Alt' key might mean something different. If no Alt key, we can update the // selection immediately. UpdateSelection(hitRecord, modifiers); } } else if (e.MouseEvent.Button == MouseButtons.Right) { if (modifiers == Keys.None && SelectionContext != null && !SelectionContext.SelectionContains(hitObject)) { // The hit object is not already selected and a right-click landed on it. Select it. UpdateSelection(hitRecord, modifiers); } } } }
// get track that contains y value 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); }
/// <summary> /// Updates the selection set, given the hit object and the modifier keys</summary> /// <param name="hitRecord">HitRecord</param> /// <param name="modifiers">Modifier keys</param> private void UpdateSelection(HitRecord hitRecord, Keys modifiers) { TimelinePath hitObject = hitRecord.HitPath; bool hitIsValidAnchor = true; switch (hitRecord.Type) { case HitType.GroupMove: SelectGroups(hitObject); break; case HitType.TrackMove: SelectTracks(hitObject); break; case HitType.Interval: case HitType.Key: case HitType.Marker: SelectEvents(hitObject); Owner.Constrain = (modifiers & Owner.ConstrainModifierKeys) != 0; break; default: Anchor = null; hitIsValidAnchor = false; break; } if (hitIsValidAnchor) { // If the Shift key is not held down or the current Anchor is null, or the user // has switched between track and group, or the user has picked an event, then // update the Anchor. IEvents are always additive with the shift key. if ((modifiers & Keys.Shift) == 0 || Anchor == null || (Anchor.Last is IGroup && hitObject.Last is ITrack) || (Anchor.Last is ITrack && hitObject.Last is IGroup) || (Anchor.Last is IEvent && hitObject.Last is IEvent)) { Anchor = hitObject; } } }
// private because this may be moved to TimelineControl private TimelinePath GetOwningTrack(TimelinePath begin) { if (begin.Last is IKey) { TimelinePath trackPath = new TimelinePath(begin); trackPath.Last = ((IKey)begin.Last).Track; return(trackPath); } if (begin.Last is IInterval) { TimelinePath trackPath = new TimelinePath(begin); trackPath.Last = ((IInterval)begin.Last).Track; return(trackPath); } if (begin.Last is ITrack) { return(begin); } return(null); }
// private because this may be moved to TimelineControl private bool Overlaps(TimelinePath path, float beginTime, float endTime) { IEvent e = (IEvent)path.Last; Matrix localToWorld = TimelineControl.CalculateLocalToWorld(path); float start = GdiUtil.Transform(localToWorld, e.Start); float length = GdiUtil.TransformVector(localToWorld, e.Length); // If the length is zero, then count an exact match with beginTime or endTime as // being an overlap. if (length == 0) { return(!( start > endTime || start + length < beginTime)); } // Otherwise, don't count an exact match. return(!( start >= endTime || start + length <= beginTime)); }
/// <summary> /// Gets the range of tracks from 'begin' to 'end', inclusive, as determined by the order /// that they are presented by the ITimelineDocument. The result always has 'begin' /// as the first ITimelineObject and 'end' as the last. If 'begin' and 'end' are the same, /// then the result has only the one ITimelineObject.</summary> /// <param name="begin">Beginning timeline path</param> /// <param name="end">Ending timeline path</param> /// <returns>Enumeration of timeline paths in the given range. /// A timeline path is a sequence of objects in timelines, e.g., groups, tracks, events.</returns> protected virtual IEnumerable <TimelinePath> GetRangeOfTracks(TimelinePath begin, TimelinePath end) { TimelinePath lastTrackToFind = null; List <TimelinePath> range = new List <TimelinePath>(); foreach (TimelinePath track in Owner.AllTracks) { if (lastTrackToFind == null) { if (track == begin) { lastTrackToFind = end; } else if (track == end) { lastTrackToFind = begin; } } if (lastTrackToFind != null) { range.Add(track); } if (track == lastTrackToFind) { break; } } if (lastTrackToFind == begin) { range.Reverse(); } return(range); }
private void owner_MouseDownPicked(object sender, HitEventArgs e) { TimelinePath hitPath = e.HitRecord.HitPath; IInterval hitInterval = e.HitRecord.HitTimelineObject as IInterval; if (m_active && e.MouseEvent.Button == MouseButtons.Left && !m_owner.IsUsingMouse && m_owner.IsEditable(hitPath)) { if (hitInterval != null && e.HitRecord.Type == HitType.Interval) { float worldX = Sce.Atf.GdiUtil.InverseTransform(m_owner.Transform, e.MouseEvent.Location.X); worldX += m_owner.GetSnapOffset(new[] { worldX }, s_snapOptions); Matrix localToWorld = TimelineControl.CalculateLocalToWorld(hitPath); float fraction = (worldX - GdiUtil.Transform(localToWorld, hitInterval.Start)) / GdiUtil.TransformVector(localToWorld, hitInterval.Length); if (m_owner.Selection.SelectionContains(hitInterval)) { SplitSelectedIntervals(fraction); } else { SplitUnselectedInterval(hitInterval, fraction); } } Active = false; e.Handled = true; //don't let subsequent listeners get this event } }
/// <summary> /// Gets the range of groups from 'begin' to 'end', inclusive, as determined by the order /// that they are presented by the ITimelineDocument. The result always has 'begin' /// as the first ITimelineObject and 'end' as the last. If 'begin' and 'end' are the same, /// then the result has only the one ITimelineObject.</summary> /// <param name="begin">Beginning timeline path</param> /// <param name="end">Ending timeline path</param> /// <returns>Enumeration of timeline paths in the given range. /// A timeline path is a sequence of objects in timelines, e.g., groups, tracks, events.</returns> protected virtual IEnumerable <TimelinePath> GetRangeOfGroups(TimelinePath begin, TimelinePath end) { TimelinePath lastGroupToFind = null; List <TimelinePath> range = new List <TimelinePath>(); foreach (TimelinePath group in Owner.AllGroups) { if (lastGroupToFind == null) { if (group == begin) { lastGroupToFind = end; } else if (group == end) { lastGroupToFind = begin; } } if (lastGroupToFind != null) { range.Add(group); } if (group == lastGroupToFind) { break; } } if (lastGroupToFind == begin) { range.Reverse(); } return(range); }
// 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> /// Gets the range of events that intersect the rectangle that encloses 'begin' and 'end'</summary> /// <param name="begin">Beginning timeline path</param> /// <param name="end">Ending timeline path</param> /// <returns>Enumeration of timeline paths that intersect the rectangle. /// A timeline path is a sequence of objects in timelines, e.g., groups, tracks, events.</returns> protected virtual IEnumerable <TimelinePath> GetRangeOfEvents(TimelinePath begin, TimelinePath end) { // Get the range of tracks between these two events. bool searchMarkers = false; System.Collections.IEnumerable rangeOfTracks; if (begin.Last is IMarker || end.Last is IMarker) { rangeOfTracks = Owner.AllTracks; searchMarkers = true; } else { TimelinePath beginTrack = GetOwningTrack(begin); TimelinePath endTrack = GetOwningTrack(end); rangeOfTracks = GetRangeOfTracks(beginTrack, endTrack); } // Get the range of times to look for. float beginStart, beginEnd; TimelineControl.CalculateRange(begin, out beginStart, out beginEnd); float endStart, endEnd; TimelineControl.CalculateRange(end, out endStart, out endEnd); float beginTime = Math.Min(beginStart, endStart); float endTime = Math.Max(beginEnd, endEnd); // Look through all the IEvents of these tracks. List <TimelinePath> range = new List <TimelinePath>(); foreach (TimelinePath testPath in rangeOfTracks) { ITrack track = (ITrack)testPath.Last; foreach (IKey key in track.Keys) { testPath.Last = key; if (Overlaps(testPath, beginTime, endTime)) { range.Add(new TimelinePath(testPath)); } } foreach (IInterval interval in track.Intervals) { testPath.Last = interval; if (Overlaps(testPath, beginTime, endTime)) { range.Add(new TimelinePath(testPath)); } } } // Look for markers? if (searchMarkers) { foreach (TimelinePath testPath in Owner.AllMarkers) { if (Overlaps(testPath, beginTime, endTime)) { range.Add(testPath); } } } return(range); }
// 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 = m_owner.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; } } 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 + m_owner.DragDelta.Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); continue; } } 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 + m_owner.DragDelta.Y; targets[i] = GetTargetTrack(y, layout, visibleTracks); continue; } } // ignore Markers, as they don't hit targets } return(targets); }
/// <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); }