fix 2
This commit is contained in:
@@ -137,25 +137,29 @@ public class ContentCropper : ContentControl
|
|||||||
canvas.Width = newContentWidth;
|
canvas.Width = newContentWidth;
|
||||||
canvas.Height = newContentHeight;
|
canvas.Height = newContentHeight;
|
||||||
|
|
||||||
// Calculate new positions and sizes based on updated ratios
|
if (border.Width > 0 && border.Height > 0)
|
||||||
double newCropLeft = cropLeftRatio * newContentWidth;
|
|
||||||
double newCropTop = cropTopRatio * newContentHeight;
|
|
||||||
double newCropWidth = cropWidthRatio * newContentWidth;
|
|
||||||
double newCropHeight = cropHeightRatio * newContentHeight;
|
|
||||||
|
|
||||||
// Check if the crop rectangle was resized or moved, and update accordingly
|
|
||||||
if (border.Width != newCropWidth || border.Height != newCropHeight)
|
|
||||||
{
|
{
|
||||||
|
double newCropLeft = cropLeftRatio * newContentWidth;
|
||||||
|
double newCropTop = cropTopRatio * newContentHeight;
|
||||||
|
double newCropWidth = cropWidthRatio * newContentWidth;
|
||||||
|
double newCropHeight = cropHeightRatio * newContentHeight;
|
||||||
|
|
||||||
border.Width = newCropWidth;
|
border.Width = newCropWidth;
|
||||||
border.Height = newCropHeight;
|
border.Height = newCropHeight;
|
||||||
|
|
||||||
Canvas.SetLeft(border, newCropLeft);
|
Canvas.SetLeft(border, newCropLeft);
|
||||||
Canvas.SetTop(border, newCropTop);
|
Canvas.SetTop(border, newCropTop);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InitializeCropRect();
|
||||||
|
}
|
||||||
|
|
||||||
PositionThumbs();
|
PositionThumbs();
|
||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void InitializeCropRect()
|
private void InitializeCropRect()
|
||||||
{
|
{
|
||||||
if (canvas is null || Content is not Control content)
|
if (canvas is null || Content is not Control content)
|
||||||
@@ -177,6 +181,9 @@ public class ContentCropper : ContentControl
|
|||||||
canvas.Height = height;
|
canvas.Height = height;
|
||||||
|
|
||||||
UpdateCropArea(width, height);
|
UpdateCropArea(width, height);
|
||||||
|
UpdateCropRatios();
|
||||||
|
|
||||||
|
PositionThumbs();
|
||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +205,8 @@ public class ContentCropper : ContentControl
|
|||||||
RenderOverLays();
|
RenderOverLays();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBorderPointerPressed(object? sender, PointerPressedEventArgs args)
|
private void OnBorderPointerPressed(object? sender,
|
||||||
|
PointerPressedEventArgs args)
|
||||||
{
|
{
|
||||||
if (!isDragging && border is not null)
|
if (!isDragging && border is not null)
|
||||||
{
|
{
|
||||||
@@ -210,13 +218,15 @@ public class ContentCropper : ContentControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBorderPointerReleased(object? sender, PointerReleasedEventArgs args)
|
private void OnBorderPointerReleased(object? sender,
|
||||||
|
PointerReleasedEventArgs args)
|
||||||
{
|
{
|
||||||
isDragging = false;
|
isDragging = false;
|
||||||
UpdateCropRatios();
|
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)
|
if (canvas is null || border is null || sender is not Thumb thumb)
|
||||||
{
|
{
|
||||||
@@ -343,7 +353,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()
|
private void UpdateCropRatios()
|
||||||
{
|
{
|
||||||
if (canvas == null || border == null)
|
if (canvas == null || border == null)
|
||||||
@@ -357,6 +366,7 @@ public class ContentCropper : ContentControl
|
|||||||
cropHeightRatio = border.Height / canvas.Height;
|
cropHeightRatio = border.Height / canvas.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void UpdateCropArea(double width, double height)
|
private void UpdateCropArea(double width, double height)
|
||||||
{
|
{
|
||||||
if (canvas == null || border == null)
|
if (canvas == null || border == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user