示例#1
0
        /// <summary>
        /// Handles the <see cref="VideoTimelineSegment.HorizontalResizeDragCompletedEvent"/> attached event
        /// for a <see cref="VideoTimelineSegment"/> element.
        /// </summary>
        /// <inheritdoc cref="HorizontalResizeDragCompletedEventHandler"/>
        private void OnTrackSegmentHorizontalResizeDragCompleted(object sender, HorizontalResizeDragCompletedEventArgs e)
        {
            if (_isResizingSegment)
            {
                VideoTimelineSegment segmentElement = e.OriginalSource as VideoTimelineSegment;
                Debug.Assert(segmentElement != null);

                VideoTimelineTrack trackElement = segmentElement.ParentTrackElement;

                SegmentViewModelBase segmentViewModel = segmentElement.DataContext as SegmentViewModelBase;
                Debug.Assert(segmentViewModel != null);

                int frameDiff = (int)Math.Round(_segmentResizeAdorner.HorizontalOffset / trackElement.PixelsPerFrame);
                if (frameDiff != 0)
                {
                    if (e.HorizontalSide == HorizontalSide.Left)
                    {
                        int newStartFrame = segmentViewModel.StartFrame + frameDiff;
                        ViewModel.ChangeTrackSegmentStartFrame(segmentViewModel, newStartFrame);
                    }
                    else // e.HorizontalSide == HorizontalSide.Right
                    {
                        int newEndFrame = segmentViewModel.EndFrame + frameDiff;
                        ViewModel.ChangeTrackSegmentEndFrame(segmentViewModel, newEndFrame);
                    }
                }

                segmentElement.Clip = null;

                _segmentResizeAdorner?.Detach();
                _segmentResizeAdorner = null;

                _isResizingSegment = false;
            }

            e.Handled = true;
        }
示例#2
0
        /// <summary>
        /// Handles the <see cref="VideoTimelineSegment.HorizontalResizeDraggingEvent"/> attached event
        /// for a <see cref="VideoTimelineSegment"/> element.
        /// </summary>
        /// <inheritdoc cref="HorizontalResizeDraggingEventHandler"/>
        private void OnTrackSegmentHorizontalResizeDragging(object sender, HorizontalResizeDragEventArgs e)
        {
            e.Handled = true;

            VideoTimelineSegment segmentElement = e.OriginalSource as VideoTimelineSegment;

            Debug.Assert(segmentElement != null);

            VideoTimelineTrack trackElement = segmentElement.ParentTrackElement;

            SegmentViewModelBase segmentViewModel = segmentElement.DataContext as SegmentViewModelBase;

            Debug.Assert(segmentViewModel != null);

            int frameDiff = (int)Math.Round(e.HorizontalChange / trackElement.PixelsPerFrame);

            if (frameDiff == 0)
            {
                return;
            }

            int    proposedStartFrame = segmentViewModel.StartFrame;
            int    proposedEndFrame   = segmentViewModel.EndFrame;
            double framePixelOffset   = trackElement.PixelsPerFrame * frameDiff;
            bool   isContracting      = false;
            Rect   segmentElementClipRect;

            if (e.HorizontalSide == HorizontalSide.Left)
            {
                proposedStartFrame += frameDiff;
                if (!ViewModel.CanChangeTrackSegmentStartFrame(segmentViewModel, proposedStartFrame))
                {
                    return;
                }

                if (frameDiff > 0)
                {
                    isContracting          = true;
                    segmentElementClipRect = new Rect(framePixelOffset, 0d, segmentElement.ActualWidth - framePixelOffset, segmentElement.ActualHeight);
                }
            }
            else // e.HorizontalSide == HorizontalSide.Right
            {
                proposedEndFrame += frameDiff;
                if (!ViewModel.CanChangeTrackSegmentEndFrame(segmentViewModel, proposedEndFrame))
                {
                    return;
                }

                if (frameDiff < 0)
                {
                    isContracting = true;

                    segmentElementClipRect = new Rect(
                        new Size(segmentElement.ActualWidth + framePixelOffset, segmentElement.ActualHeight)
                        );
                }
            }

            if (isContracting)
            {
                if (segmentElement.Clip is RectangleGeometry rectangleGeometry)
                {
                    rectangleGeometry.Rect = segmentElementClipRect;
                }
                else
                {
                    segmentElement.Clip = new RectangleGeometry(segmentElementClipRect);
                }
            }
            else
            {
                segmentElement.Clip = null;
            }

            if (_segmentResizeAdorner == null)
            {
                UIElement segmentElementContainer = segmentElement.TemplatedParent as UIElement;
                Debug.Assert(segmentElementContainer != null);

                _segmentResizeAdorner = new TrackSegmentResizeAdorner(adornedElement: trackElement, segmentElement,
                                                                      segmentElementLeftCoordinate: Canvas.GetLeft(segmentElementContainer),
                                                                      attachPosition: e.HorizontalSide);
                _segmentResizeAdorner.Attach();

                _isResizingSegment = true;
            }

            _segmentResizeAdorner.HorizontalOffset       = framePixelOffset;
            _segmentResizeAdorner.ToolTipData.StartFrame = proposedStartFrame;
            _segmentResizeAdorner.ToolTipData.EndFrame   = proposedEndFrame;
        }