Ejemplo n.º 1
0
        private void owner_Paint(object sender, PaintEventArgs e)
        {
            // Test if anything is visible.
            m_visibleManipulator =
                TimelineControl.CalculateRange(Owner.EditableSelection, out m_worldMin, out m_worldMax);
            if (!m_visibleManipulator)
            {
                return;
            }

            Graphics g           = e.Graphics;
            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,
                    g);
            }

            // 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.
            Region    originalClip  = g.Clip;
            Rectangle clipRectangle = Owner.VisibleClientRectangle;

            g.Clip = new Region(clipRectangle);

            // Draw the manipulator, giving client code a customization point.
            DrawManipulator(g, out m_leftHandle, out m_rightHandle);

            // Restore clipping region.
            g.Clip = originalClip;
        }
Ejemplo n.º 2
0
        // 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);
        }
Ejemplo n.º 3
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 = 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);
        }
Ejemplo n.º 4
0
        // 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);
        }
Ejemplo n.º 5
0
            /// <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);
            }