public CroppingAdorner(UIElement adornedElement, Rect rcInit) : base(adornedElement) { _vc = new VisualCollection(this); _prCropMask = new PuncturedRect(); _prCropMask.IsHitTestVisible = false; _prCropMask.RectInterior = rcInit; _prCropMask.Fill = Fill; _vc.Add(_prCropMask); _cnvThumbs = new Canvas(); _cnvThumbs.HorizontalAlignment = HorizontalAlignment.Stretch; _cnvThumbs.VerticalAlignment = VerticalAlignment.Stretch; _vc.Add(_cnvThumbs); BuildCorner(ref _crtTop, Cursors.SizeNS); BuildCorner(ref _crtBottom, Cursors.SizeNS); BuildCorner(ref _crtLeft, Cursors.SizeWE); BuildCorner(ref _crtRight, Cursors.SizeWE); //BuildCorner(ref _crtTopLeft, Cursors.SizeNWSE); //BuildCorner(ref _crtTopRight, Cursors.SizeNESW); //BuildCorner(ref _crtBottomLeft, Cursors.SizeNESW); //BuildCorner(ref _crtBottomRight, Cursors.SizeNWSE); //BuildCorner(ref _crtTop, Cursors.Arrow); //BuildCorner(ref _crtBottom, Cursors.Arrow); //BuildCorner(ref _crtLeft, Cursors.Arrow); //BuildCorner(ref _crtRight, Cursors.Arrow); BuildCorner(ref _crtTopLeft, Cursors.Arrow); BuildCorner(ref _crtTopRight, Cursors.Arrow); BuildCorner(ref _crtBottomLeft, Cursors.Arrow); BuildCorner(ref _crtBottomRight, Cursors.Arrow); // Add handlers for Cropping. //_crtBottomLeft.DragDelta += new DragDeltaEventHandler(HandleBottomLeft); //_crtBottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight); //_crtTopLeft.DragDelta += new DragDeltaEventHandler(HandleTopLeft); //_crtTopRight.DragDelta += new DragDeltaEventHandler(HandleTopRight); _crtTop.DragDelta += new DragDeltaEventHandler(HandleTop); _crtBottom.DragDelta += new DragDeltaEventHandler(HandleBottom); _crtRight.DragDelta += new DragDeltaEventHandler(HandleRight); _crtLeft.DragDelta += new DragDeltaEventHandler(HandleLeft); // We have to keep the clipping interior withing the bounds of the adorned element // so we have to track it's size to guarantee that... FrameworkElement fel = adornedElement as FrameworkElement; if (fel != null) { fel.SizeChanged += new SizeChangedEventHandler(AdornedElement_SizeChanged); } }
private static object CoerceRectInterior(DependencyObject d, object value) { PuncturedRect pr = (PuncturedRect)d; Rect rcExterior = pr.RectExterior; Rect rcProposed = (Rect)value; double left = Math.Max(rcProposed.Left, rcExterior.Left); double top = Math.Max(rcProposed.Top, rcExterior.Top); double width = Math.Min(rcProposed.Right, rcExterior.Right) - left; double height = Math.Min(rcProposed.Bottom, rcExterior.Bottom) - top; rcProposed = new Rect(left, top, width, height); return(rcProposed); }
public CroppingAdorner(UIElement adornedElement, Rect rcInit) : base(adornedElement) { _vc = new VisualCollection(this); _prCropMask = new PuncturedRect(); _prCropMask.IsHitTestVisible = false; _prCropMask.RectInterior = rcInit; _prCropMask.Fill = Fill; _vc.Add(_prCropMask); _cnvThumbs = new Canvas(); _cnvThumbs.HorizontalAlignment = HorizontalAlignment.Stretch; _cnvThumbs.VerticalAlignment = VerticalAlignment.Stretch; _vc.Add(_cnvThumbs); BuildCorner(ref _crtTop, Cursors.SizeNS); BuildCorner(ref _crtBottom, Cursors.SizeNS); BuildCorner(ref _crtLeft, Cursors.SizeWE); BuildCorner(ref _crtRight, Cursors.SizeWE); BuildCorner(ref _crtTopLeft, Cursors.SizeNWSE); BuildCorner(ref _crtTopRight, Cursors.SizeNESW); BuildCorner(ref _crtBottomLeft, Cursors.SizeNESW); BuildCorner(ref _crtBottomRight, Cursors.SizeNWSE); //DPS: Move BuildMove(ref _crtMove, Cursors.Hand); // Add handlers for Cropping. _crtBottomLeft.DragDelta += new DragDeltaEventHandler(HandleBottomLeft); _crtBottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight); _crtTopLeft.DragDelta += new DragDeltaEventHandler(HandleTopLeft); _crtTopRight.DragDelta += new DragDeltaEventHandler(HandleTopRight); _crtTop.DragDelta += new DragDeltaEventHandler(HandleTop); _crtBottom.DragDelta += new DragDeltaEventHandler(HandleBottom); _crtRight.DragDelta += new DragDeltaEventHandler(HandleRight); _crtLeft.DragDelta += new DragDeltaEventHandler(HandleLeft); //DPS: Manejador para el movimiento _crtMove.DragDelta += new DragDeltaEventHandler(HandleMove); // We have to keep the clipping interior withing the bounds of the adorned element // so we have to track it's size to guarantee that... FrameworkElement fel = adornedElement as FrameworkElement; if (fel != null) { fel.SizeChanged += new SizeChangedEventHandler(AdornedElement_SizeChanged); } }