From cf53327142d4ca69cba54a086ae3895c633b3b2c Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Thu, 10 Oct 2024 23:16:00 +0100 Subject: [PATCH] Fix3 --- .../ContentCropper/ContentCropper.cs | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/Toolkit.UI.Controls.Avalonia/ContentCropper/ContentCropper.cs b/Toolkit.UI.Controls.Avalonia/ContentCropper/ContentCropper.cs index 6006de2..ee69b53 100644 --- a/Toolkit.UI.Controls.Avalonia/ContentCropper/ContentCropper.cs +++ b/Toolkit.UI.Controls.Avalonia/ContentCropper/ContentCropper.cs @@ -155,6 +155,8 @@ public class ContentCropper : ContentControl InitializeCropRect(); } + UpdateCropRectangle(); + PositionThumbs(); RenderOverLays(); } @@ -182,12 +184,14 @@ public class ContentCropper : ContentControl UpdateCropArea(width, height); UpdateCropRatios(); + UpdateCropRectangle(); PositionThumbs(); RenderOverLays(); } - private void OnBorderPointerMoved(object? sender, PointerEventArgs args) + private void OnBorderPointerMoved(object? sender, + PointerEventArgs args) { if (!isDragging || canvas is null || border is null) { @@ -201,6 +205,8 @@ public class ContentCropper : ContentControl Canvas.SetLeft(border, newX); Canvas.SetTop(border, newY); + UpdateCropRectangle(); + PositionThumbs(); RenderOverLays(); } @@ -225,8 +231,7 @@ public class ContentCropper : ContentControl UpdateCropRatios(); } - private void OnThumbDragDelta(object? sender, - VectorEventArgs args) + private void OnThumbDragDelta(object? sender, VectorEventArgs args) { if (canvas is null || border is null || sender is not Thumb thumb) { @@ -275,6 +280,7 @@ public class ContentCropper : ContentControl Canvas.SetTop(border, topPosition); UpdateCropRatios(); + UpdateCropRectangle(); PositionThumbs(); RenderOverLays(); @@ -353,19 +359,6 @@ public class ContentCropper : ContentControl rectangleBottom.Height = Math.Max(0, canvas.Height - bottomY); Canvas.SetTop(rectangleBottom, bottomY); } - private void UpdateCropRatios() - { - if (canvas == null || border == null) - { - return; - } - - cropLeftRatio = Canvas.GetLeft(border) / canvas.Width; - cropTopRatio = Canvas.GetTop(border) / canvas.Height; - cropWidthRatio = border.Width / canvas.Width; - cropHeightRatio = border.Height / canvas.Height; - } - private void UpdateCropArea(double width, double height) { @@ -408,4 +401,30 @@ public class ContentCropper : ContentControl border.PointerReleased -= OnBorderPointerReleased; border.PointerReleased += OnBorderPointerReleased; } + + private void UpdateCropRatios() + { + if (canvas == null || border == null) + { + return; + } + + cropLeftRatio = Canvas.GetLeft(border) / canvas.Width; + cropTopRatio = Canvas.GetTop(border) / canvas.Height; + cropWidthRatio = border.Width / canvas.Width; + cropHeightRatio = border.Height / canvas.Height; + } + + private void UpdateCropRectangle() + { + if (canvas is null || border is null) + { + return; + } + + double left = Canvas.GetLeft(border); + double top = Canvas.GetTop(border); + + CropRectangle = new Rect(left, top, border.Width, border.Height); + } }