Fix3
This commit is contained in:
@@ -155,6 +155,8 @@ public class ContentCropper : ContentControl
|
|||||||
InitializeCropRect();
|
InitializeCropRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateCropRectangle();
|
||||||
|
|
||||||
PositionThumbs();
|
PositionThumbs();
|
||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
}
|
}
|
||||||
@@ -182,12 +184,14 @@ public class ContentCropper : ContentControl
|
|||||||
|
|
||||||
UpdateCropArea(width, height);
|
UpdateCropArea(width, height);
|
||||||
UpdateCropRatios();
|
UpdateCropRatios();
|
||||||
|
UpdateCropRectangle();
|
||||||
|
|
||||||
PositionThumbs();
|
PositionThumbs();
|
||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBorderPointerMoved(object? sender, PointerEventArgs args)
|
private void OnBorderPointerMoved(object? sender,
|
||||||
|
PointerEventArgs args)
|
||||||
{
|
{
|
||||||
if (!isDragging || canvas is null || border is null)
|
if (!isDragging || canvas is null || border is null)
|
||||||
{
|
{
|
||||||
@@ -201,6 +205,8 @@ public class ContentCropper : ContentControl
|
|||||||
Canvas.SetLeft(border, newX);
|
Canvas.SetLeft(border, newX);
|
||||||
Canvas.SetTop(border, newY);
|
Canvas.SetTop(border, newY);
|
||||||
|
|
||||||
|
UpdateCropRectangle();
|
||||||
|
|
||||||
PositionThumbs();
|
PositionThumbs();
|
||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
}
|
}
|
||||||
@@ -225,8 +231,7 @@ public class ContentCropper : ContentControl
|
|||||||
UpdateCropRatios();
|
UpdateCropRatios();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnThumbDragDelta(object? sender,
|
private void OnThumbDragDelta(object? sender, VectorEventArgs args)
|
||||||
VectorEventArgs args)
|
|
||||||
{
|
{
|
||||||
if (canvas is null || border is null || sender is not Thumb thumb)
|
if (canvas is null || border is null || sender is not Thumb thumb)
|
||||||
{
|
{
|
||||||
@@ -275,6 +280,7 @@ public class ContentCropper : ContentControl
|
|||||||
Canvas.SetTop(border, topPosition);
|
Canvas.SetTop(border, topPosition);
|
||||||
|
|
||||||
UpdateCropRatios();
|
UpdateCropRatios();
|
||||||
|
UpdateCropRectangle();
|
||||||
|
|
||||||
PositionThumbs();
|
PositionThumbs();
|
||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
@@ -353,19 +359,6 @@ public class ContentCropper : ContentControl
|
|||||||
rectangleBottom.Height = Math.Max(0, canvas.Height - bottomY);
|
rectangleBottom.Height = Math.Max(0, canvas.Height - bottomY);
|
||||||
Canvas.SetTop(rectangleBottom, 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)
|
private void UpdateCropArea(double width, double height)
|
||||||
{
|
{
|
||||||
@@ -408,4 +401,30 @@ public class ContentCropper : ContentControl
|
|||||||
border.PointerReleased -= OnBorderPointerReleased;
|
border.PointerReleased -= OnBorderPointerReleased;
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user