public MainWindow() { InitializeComponent(); Clipboard.Clear(); DataContext = this; _screen = CopyScreen(); Canvas.Width = _screen.Width; Canvas.Height = _screen.Height; ImageMask.Source = _screen; Image.Source = _screen; Image.Visibility = Visibility.Collapsed; ResizeAdorner = new ResizeAdorner(AdornerRectangle); ResizeAdorner.ShowHandles = true; ResizeAdorner.OnHandleMouseDown += ResizeAdorner_OnHandleMouseDown; var winds = WinApi.GetWindows(); var WS_CLIPCHILDREN = 0x02000000L; var WS_BORDER = 0x00800000L; foreach (IntPtr win in winds) { var p = WinApi.GetWindowLongPtr(win, WinApi.GWL.GWL_STYLE); if (((long)p & WS_CLIPCHILDREN) == WS_CLIPCHILDREN || ((long)p & WS_BORDER) == WS_BORDER ) { WinApi.GetWindowRect(win, out WinApi.RECT rect); wins.Add(rect); } } }
private void RefreshAdorner() { var adorner = AdornerLayer.GetAdornerLayer(AdornerRectangle); if (AdornerShown && adorner != null) { adorner.InvalidateVisual(); ResizeAdorner.InvalidateVisual(); } }
public void RemoveResizeAdorner() { if (_resizingAdorner != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(_drawingCanvas); if (adornerLayer != null) { adornerLayer.Remove(_resizingAdorner); _resizingAdorner = null; } } }
private void UpdateSelection() { Deselect(); for (int i = 0; i < itemsHost.Items.Count; i++) { var uiElement = (FrameworkElement)itemsHost.ItemContainerGenerator.ContainerFromIndex(i); if (uiElement.DataContext == SelectedElement) { _resizeAdorner = new ResizeAdorner(uiElement); AdornerLayer.GetAdornerLayer(uiElement).Add(_resizeAdorner); _selection = uiElement; } } }
/// <summary> /// Removes the resize adorner. /// </summary> private void RemoveResizeAdorner() { // If the resize adorner has been created then... if (_resizingAdorner != null) { // Retrieve the resize adorner AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas); Debug.Assert(adornerLayer != null, nameof(adornerLayer) + " != null"); // Remove the resize adorner adornerLayer.Remove(_resizingAdorner); // Release the resize adorner _resizingAdorner = null; } }
private void UpdateResizeAdorner() { if (IsDrawing) { return; } if (_dragging && !_isSelecting) { return; } if (SelectedModels.Count > 1) { Rect?bounds = GetSelectedContentBounds(); if (bounds.HasValue && bounds != Rect.Empty) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(_drawingCanvas); if (adornerLayer != null) { if (_resizingAdorner == null) { _resizingAdorner = new ResizeAdorner(_drawingCanvas, this, bounds.Value); adornerLayer.Add(_resizingAdorner); //_resizingAdorner.Bounds = bounds.Value; } UpdateLayout(); adornerLayer.Update(); } } } else { RemoveResizeAdorner(); } }
/// <summary> /// Updates the resize adorner based on the specified polygon points. /// </summary> /// <param name="points">Polygon points to include in the resize adorner</param> private void UpdateResizeAdorner(ObservableCollection <PolygonPointViewModel> points) { // Get the bounds of the selected points Rect bounds = VM.GetSelectedContentBounds(points); // Get the adorner layer from the canvas AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas); // If the resize adorner is NOT null then... if (adornerLayer != null) { // Remove the resizing adorner RemoveResizeAdorner(); // If the selected shape is an ellipse and if (VM.SelectedEllipse != null) { // If the ellipse has a resize adorner associated with it then... if (VM.SelectedEllipse.ResizeAdorner != null) { // Retrieve the resize adorner from the ellipse view model _resizingAdorner = VM.SelectedEllipse.ResizeAdorner; } else { // Create a collection of point view models ObservableCollection <PolygonPointViewModel> copyPoints = new ObservableCollection <PolygonPointViewModel>(); // Create a reverse transform for the ellipse RotateTransform reverseRotateTransform = new RotateTransform(-VM.SelectedEllipse.Angle, VM.SelectedEllipse.CenterPoint.X, VM.SelectedEllipse.CenterPoint.Y); // Loop over the points on the rectangle that surrounds the ellipse foreach (PolygonPointViewModel pt in points) { // Clone the ellipse (rectangle) point PolygonPointViewModel clonedPoint = new PolygonPointViewModel(pt.PolygonPoint.Clone(), null); // Transform the point Point transformedPoint = reverseRotateTransform.Transform(pt.GetPoint()); // Update the cloned point clonedPoint.X = transformedPoint.X; clonedPoint.Y = transformedPoint.Y; // Add the point to the collection copyPoints.Add(clonedPoint); } // Determine the bounds of the resize adorner based on the transformed points bounds = VM.GetSelectedContentBounds(copyPoints); // Create the resizing adorner for the ellipse with the specified angle _resizingAdorner = new ResizeAdorner(VM.SelectedEllipse.Angle, this, canvas, VM, bounds); // Store off the resize adorner with the ellipse VM.SelectedEllipse.ResizeAdorner = _resizingAdorner; } } else { // Create the resizing adorner _resizingAdorner = new ResizeAdorner(0.0, this, canvas, VM, bounds); } // Add the resizing adorner to the canvas adornerLayer.Add(_resizingAdorner); } }