handle different directions of crop
This commit is contained in:
parent
7c7976a82d
commit
32403ddeb5
17
Program.cs
17
Program.cs
@ -186,15 +186,22 @@ public class CropTool : ITool {
|
|||||||
|
|
||||||
// left, right, top, bottom
|
// left, right, top, bottom
|
||||||
(int, int, int, int) GetCrop() {
|
(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 start = mouseDragStart;
|
||||||
Vector2i end = mouseDragEnd;
|
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: choose the aspect ratio based on the original image aspect ratio.
|
||||||
// FIXME: allow for unconstrained crop, 1:1, etc.
|
// FIXME: allow for unconstrained crop, 1:1, etc.
|
||||||
end.Y = Math.Min(end.Y, (int) (start.Y + (end.X - start.X) / CameraInfo.AspectRatio));
|
end.Y = start.Y + heightChange;
|
||||||
end.X = (int) (start.X + (end.Y - start.Y) * CameraInfo.AspectRatio);
|
end.X = start.X + widthChange;
|
||||||
int left = Math.Min(start.X, end.X);
|
int left = Math.Min(start.X, end.X);
|
||||||
int right = Math.Max(start.X, end.X);
|
int right = Math.Max(start.X, end.X);
|
||||||
int top = Math.Min(start.Y, end.Y);
|
int top = Math.Min(start.Y, end.Y);
|
||||||
|
Loading…
Reference in New Issue
Block a user