handle different directions of crop

This commit is contained in:
Colin McMillen 2023-08-26 15:57:47 -04:00
parent 7c7976a82d
commit 32403ddeb5

View File

@ -186,15 +186,22 @@ public class CropTool : ITool {
// left, right, top, bottom
(int, int, int, int) GetCrop() {
// FIXME: this expects the start point in the top left and the end point
// in the bottom right; some sign flipping needs to occur to make anchors
// in other directions work well.
Vector2i start = mouseDragStart;
Vector2i end = mouseDragEnd;
int width = Math.Abs(end.X - start.X);
int height = Math.Abs(end.Y - start.Y);
int heightChange = Math.Min(height, (int) (width / CameraInfo.AspectRatio));
int widthChange = (int) (heightChange * CameraInfo.AspectRatio);
if (end.X < start.X) {
widthChange *= -1;
}
if (end.Y < start.Y) {
heightChange *= -1;
}
// FIXME: choose the aspect ratio based on the original image aspect ratio.
// FIXME: allow for unconstrained crop, 1:1, etc.
end.Y = Math.Min(end.Y, (int) (start.Y + (end.X - start.X) / CameraInfo.AspectRatio));
end.X = (int) (start.X + (end.Y - start.Y) * CameraInfo.AspectRatio);
end.Y = start.Y + heightChange;
end.X = start.X + widthChange;
int left = Math.Min(start.X, end.X);
int right = Math.Max(start.X, end.X);
int top = Math.Min(start.Y, end.Y);