Example #1
0
        //TODO: This has not been revisited yet.

        /*
         * private void MouseMove_DragMoving_OLD(MouseEventArgs e)
         * {
         * Point gridLocation = TranslateLocation(e.Location);
         *
         * // if we don't have anything selected, there's no point dragging anything...
         * if (SelectedElements.Count() == 0)
         * return;
         *
         * Point d = new Point(e.X - m_lastMouseLocation.X, e.Y - m_lastMouseLocation.Y);
         * m_lastMouseLocation = e.Location;
         *
         * // calculate the points at which we should start dragging; ie. account for any selected elements.
         * // (we subtract VisibleTimeStart to make it relative to the control, instead of the grid canvas.)
         * TimeSpan earliestTime = GetEarliestTimeForElements(SelectedElements);
         * TimeSpan latestTime = GetLatestTimeForElements(SelectedElements);
         * int leftBoundary = (int)timeToPixels(earliestTime - VisibleTimeStart + DragTimeLeftOver);
         * int rightBoundary = (int)timeToPixels(latestTime - VisibleTimeStart + DragTimeLeftOver);
         *
         * // if the mouse moved left, only add it to the scroll size if:
         * // 1) the elements are hard left (or more) in the viewport
         * // 2) the elements are hard right, and we are moving right. This provides deceleration.
         * //    Cap this value to 0.
         * if (d.X < 0)
         * {
         * if (leftBoundary <= 0)
         *  m_dragAutoscrollDistance.Width += d.X;
         * else if (rightBoundary >= ClientSize.Width && m_dragAutoscrollDistance.Width > 0)
         *  m_dragAutoscrollDistance.Width = Math.Max(0, m_dragAutoscrollDistance.Width + d.X);
         * }
         *
         * // if the mouse moved right, do the inverse of the above rules.
         * if (d.X > 0)
         * {
         * if (rightBoundary >= ClientSize.Width)
         *  m_dragAutoscrollDistance.Width += d.X;
         * else if (leftBoundary <= 0 && m_dragAutoscrollDistance.Width < 0)
         *  m_dragAutoscrollDistance.Width = Math.Min(0, m_dragAutoscrollDistance.Width + d.X);
         * }
         *
         * // if the left and right boundaries are within the viewport, then stop all
         * // horizontal scrolling. This can happen if the user scrolls, and mouse-wheels
         * // (to zoom out). the control is stuck scrolling, and can't be stopped.
         * if (leftBoundary > 0 && rightBoundary < ClientSize.Width)
         * m_dragAutoscrollDistance.Width = 0;
         *
         * m_dragAutoscrollDistance.Height = (e.Y < 0) ? e.Y : ((e.Y > ClientSize.Height) ? e.Y - ClientSize.Height : 0);
         *
         * // if we're scrolling, start the timer if needed. If not, vice-versa.
         * if (m_dragAutoscrollDistance.Width != 0 || m_dragAutoscrollDistance.Height != 0)
         * {
         * if (!ScrollTimer.Enabled)
         *  ScrollTimer.Start();
         * }
         * else
         * {
         * if (ScrollTimer.Enabled)
         *  ScrollTimer.Stop();
         * }
         *
         * // only move the elements here if we aren't going to be auto-dragging while scrolling in the timer events.
         * if (d.X != 0 && m_dragAutoscrollDistance.Width == 0)
         * {
         * TimeSpan desiredMoveTime = DragTimeLeftOver + pixelsToTime(d.X);
         * TimeSpan realMoveTime = OffsetElementsByTime(SelectedElements, desiredMoveTime);
         * DragTimeLeftOver = desiredMoveTime - realMoveTime;
         * }
         *
         * // if we've moved vertically, we may need to move elements between rows
         * if (d.Y != 0 && !ResizingElement)
         * {
         * MoveElementsVerticallyToLocation(SelectedElements, gridLocation);
         * }
         * }
         */


        /// <summary>
        /// Handles mouse move events while in the "Moving" state.
        /// </summary>
        /// <param name="gridLocation">Mouse location on the grid.</param>
        private void MouseMove_DragMoving(Point gridLocation)
        {
            // if we don't have anything selected, there's no point dragging anything...
            if (!SelectedElements.Any())
            {
                return;
            }

            TimeSpan dt = pixelsToTime(gridLocation.X - m_elemMoveInfo.InitialGridLocation.X);
            int      dy = gridLocation.Y - m_elemMoveInfo.InitialGridLocation.Y;

            // If we didn't move, get outta here.
            if (dt == TimeSpan.Zero && dy == 0)
            {
                return;
            }


            // Calculate what our actual dt value will be.
            TimeSpan earliest = m_elemMoveInfo.OriginalElements.Values.Min(x => x.StartTime);

            if ((earliest + dt) < TimeSpan.Zero)
            {
                dt = -earliest;
            }

            TimeSpan latest = m_elemMoveInfo.OriginalElements.Values.Max(x => x.EndTime);

            if ((latest + dt) > TimeInfo.TotalTime)
            {
                dt = TimeInfo.TotalTime - latest;
            }

            // modify the dt time based on snap points (ie. marks, and borders of other elements)
            dt = FindSnapTimeForElements(SelectedElements, dt, ResizeZone.None);

            foreach (var elem in SelectedElements)
            {
                // Get this elemenent's original times (before resize started)
                ElementTimeInfo orig = m_elemMoveInfo.OriginalElements[elem];
                elem.StartTime = orig.StartTime + dt;
                //Control when the time changed event happens.
                elem.UpdateNotifyTimeChanged();
            }

            // if we've moved vertically, we may need to move elements between rows
            if (dy != 0)
            {
                SuppressInvalidate = true;
                MoveElementsVerticallyToLocation(SelectedElements, gridLocation);
                SuppressInvalidate = false;
            }

            Invalidate();
        }
Example #2
0
        private void MouseMove_HResizing(Point gridLocation, Point delta)
        {
            TimeSpan dt = pixelsToTime(gridLocation.X - m_elemMoveInfo.InitialGridLocation.X);

            if (dt == TimeSpan.Zero)
            {
                return;
            }

            // Modifidy our dt, if necessary.

            // modify the dt time based on snap points (ie. marks, and borders of other elements)
            dt = FindSnapTimeForElements(SelectedElements, dt, m_mouseResizeZone);

            // Ensure minimum size
            TimeSpan shortest = m_elemMoveInfo.OriginalElements.Values.Min(x => x.Duration);

            // Check boundary conditions
            switch (m_mouseResizeZone)
            {
            case ResizeZone.Front:
                // Clip earliest element StartTime at zero
                TimeSpan earliest = m_elemMoveInfo.OriginalElements.Values.Min(x => x.StartTime);
                if ((earliest + dt) < TimeSpan.Zero)
                {
                    dt = -earliest;
                }

                // Ensure the shortest meets minimum width (in px)
                if (timeToPixels(shortest - dt) < MinElemWidthPx)
                {
                    dt = shortest - pixelsToTime(MinElemWidthPx);
                }
                break;

            case ResizeZone.Back:
                // Clip latest element EndTime at TotalTime
                TimeSpan latest = m_elemMoveInfo.OriginalElements.Values.Max(x => x.EndTime);
                if ((latest + dt) > TimeInfo.TotalTime)
                {
                    dt = TimeInfo.TotalTime - latest;
                }

                // Ensure the shortest meets minimum width (in px)
                if (timeToPixels(shortest + dt) < MinElemWidthPx)
                {
                    dt = pixelsToTime(MinElemWidthPx) - shortest;
                }
                break;
            }


            // Apply dt to all selected elements.
            foreach (var elem in SelectedElements)
            {
                // Get this elemenent's original times (before resize started)
                ElementTimeInfo orig = m_elemMoveInfo.OriginalElements[elem];

                switch (m_mouseResizeZone)
                {
                case ResizeZone.Front:
                    elem.StartTime = orig.StartTime + dt;
                    elem.EndTime   = orig.EndTime;
                    break;

                case ResizeZone.Back:
                    elem.EndTime = orig.EndTime + dt;
                    break;
                }
            }

            Invalidate();
        }