/// <summary> /// When the user has finished dragging out the rectangle the zoom operation is applied. /// </summary> private void ApplyDragZoomRect(Point finalContentMousePoint) { var rect = ViewportHelpers.Clip(finalContentMousePoint, _origContentMouseDownPoint, new Point(0, 0), new Point(_partDragZoomCanvas.ActualWidth, _partDragZoomCanvas.ActualHeight)); this.AnimatedZoomTo(rect); // new Rect(contentX, contentY, contentWidth, contentHeight)); FadeOutDragZoomRect(); }
/// <summary> /// Update the position and size of the rectangle that user is dragging out. /// </summary> private void SetDragZoomRect(Point pt1, Point pt2) { // // Update the coordinates of the rectangle that is being dragged out by the user. // The we offset and rescale to convert from content coordinates. // var rect = ViewportHelpers.Clip(pt1, pt2, new Point(0, 0), new Point(_partDragZoomCanvas.ActualWidth, _partDragZoomCanvas.ActualHeight)); ViewportHelpers.PositionBorderOnCanvas(_partDragZoomBorder, rect); }
/// <summary> /// Event raised on mouse up in the ZoomAndPanControl. /// </summary> protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); if (_mouseHandlingMode == MouseHandlingModeEnum.DragZooming) { var zoomAndPanControl = GetZoomAndPanControl(); var curContentPoint = e.GetPosition(_viewportCanvas); var rect = ViewportHelpers.Clip(curContentPoint, _origContentMouseDownPoint, new Point(0, 0), new Point(_viewportCanvas.Width, _viewportCanvas.Height)); zoomAndPanControl.AnimatedZoomTo(rect); _dragBorder.Visibility = Visibility.Visible; _sizingBorder.Visibility = Visibility.Hidden; } _mouseHandlingMode = MouseHandlingModeEnum.None; _viewportCanvas.ReleaseMouseCapture(); e.Handled = true; }
/// <summary> /// Event raised on mouse move in the ZoomAndPanControl. /// </summary> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (_mouseHandlingMode == MouseHandlingModeEnum.Panning) { var curContentPoint = e.GetPosition(_viewportCanvas); var rectangleDragVector = curContentPoint - _origContentMouseDownPoint; // // When in 'dragging rectangles' mode update the position of the rectangle as the user drags it. // _origContentMouseDownPoint = e.GetPosition(_viewportCanvas).Clamp(); Canvas.SetLeft(_dragBorder, Canvas.GetLeft(_dragBorder) + rectangleDragVector.X); Canvas.SetTop(_dragBorder, Canvas.GetTop(_dragBorder) + rectangleDragVector.Y); } else if (_mouseHandlingMode == MouseHandlingModeEnum.DragZooming) { var curContentPoint = e.GetPosition(_viewportCanvas); var rect = ViewportHelpers.Clip(curContentPoint, _origContentMouseDownPoint, new Point(0, 0), new Point(_viewportCanvas.Width, _viewportCanvas.Height)); ViewportHelpers.PositionBorderOnCanvas(_sizingBorder, rect); } e.Handled = true; }