private void AdornerOnMouseMove(object sender, MouseEventArgs e) { var point = e.GetPosition(_canvas); var newPosition = _currentToolState.OnMouseMove(point); if (newPosition.HasValue) { _cropTool.Redraw(newPosition.Value.Left, newPosition.Value.Top, newPosition.Value.Width, newPosition.Value.Height); } }
public CropService(FrameworkElement adornedElement) { if (adornedElement == null) { return; } // Make sure menus are hidden when cropping UILogic.UC.Close_UserControls(); // Show context menu _ = new CropContextMenu(); canvas = new Canvas { Height = adornedElement.ActualHeight, Width = adornedElement.ActualWidth }; cropAdorner = new CropAdorner(adornedElement, canvas); var adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement); Debug.Assert(adornerLayer != null, nameof(adornerLayer) + " != null"); adornerLayer.Add(cropAdorner); var cropShape = new CropShape( new Rectangle { Height = 4, Width = 4, Stroke = (SolidColorBrush)Application.Current.Resources["MainColorBrush"], StrokeThickness = 2 } ); cropTool = new CropTool(canvas); createState = new CreateState(cropTool, canvas); completeState = new CompleteState(); dragState = new DragState(cropTool, canvas); currentToolState = completeState; cropAdorner.PreviewMouseLeftButtonDown += AdornerOnMouseLeftButtonDown; cropAdorner.PreviewMouseMove += AdornerOnMouseMove; cropAdorner.PreviewMouseLeftButtonUp += AdornerOnMouseLeftButtonUp; cropTool.Redraw(0, 0, 0, 0); }
public CropService(FrameworkElement adornedElement) { _canvas = new Canvas { Height = adornedElement.ActualHeight, Width = adornedElement.ActualWidth }; _cropAdorner = new CropAdorner(adornedElement, _canvas); var adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement); Debug.Assert(adornerLayer != null, nameof(adornerLayer) + " != null"); adornerLayer.Add(_cropAdorner); var cropShape = new CropShape( new Rectangle { Height = 0, Width = 0, Stroke = Brushes.Black, StrokeThickness = 1.5 }, new Rectangle { Stroke = Brushes.White, StrokeDashArray = new DoubleCollection(new double[] { 4, 4 }) } ); _cropTool = new CropTool(_canvas); _createState = new CreateState(_cropTool, _canvas); _completeState = new CompleteState(); _dragState = new DragState(_cropTool, _canvas); _currentToolState = _completeState; _cropAdorner.MouseLeftButtonDown += AdornerOnMouseLeftButtonDown; _cropAdorner.MouseMove += AdornerOnMouseMove; _cropAdorner.MouseLeftButtonUp += AdornerOnMouseLeftButtonUp; _cropTool.Redraw(0, 0, 0, 0); }