mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Revert "Fix Objects Growing near Infinity when Scaling w Aspect Ratio Maintained"
This reverts commit fb843fb
, committed to this branch uninentionally
This commit is contained in:
parent
fb843fb414
commit
18794fb4ce
1 changed files with 27 additions and 66 deletions
|
@ -218,10 +218,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adjusts resizeHandleCoords so that aspect ratio is kept after resizing a given rectangle with provided arguments.
|
/// Adjusts resizeHandleCoords so that aspect ratio is kept after resizing a given rectangle with provided arguments
|
||||||
/// An adjustment can always be done in two ways, e.g. *in*crease width until fit or *de*crease height until fit.
|
|
||||||
/// To avoid objects growing near infinity unexpectedly in certain combinations, the adjustment will choose the
|
|
||||||
/// option resulting in the smaller rectangle.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="originalRectangle">bounds of the current rectangle</param>
|
/// <param name="originalRectangle">bounds of the current rectangle</param>
|
||||||
/// <param name="resizeHandlePosition">position of the handle/gripper being used for resized, see Position</param>
|
/// <param name="resizeHandlePosition">position of the handle/gripper being used for resized, see Position</param>
|
||||||
|
@ -229,24 +226,16 @@ namespace Greenshot.Helpers {
|
||||||
private static void adjustCoordsForRationalScale(RectangleF originalRectangle, Positions resizeHandlePosition, ref PointF resizeHandleCoords) {
|
private static void adjustCoordsForRationalScale(RectangleF originalRectangle, Positions resizeHandlePosition, ref PointF resizeHandleCoords) {
|
||||||
float originalRatio = originalRectangle.Width / originalRectangle.Height;
|
float originalRatio = originalRectangle.Width / originalRectangle.Height;
|
||||||
float newWidth, newHeight, newRatio;
|
float newWidth, newHeight, newRatio;
|
||||||
int flippedRatioSign;
|
|
||||||
switch(resizeHandlePosition) {
|
switch(resizeHandlePosition) {
|
||||||
|
|
||||||
case Positions.TopLeft:
|
case Positions.TopLeft:
|
||||||
newWidth = originalRectangle.Right - resizeHandleCoords.X;
|
newWidth = originalRectangle.Right - resizeHandleCoords.X;
|
||||||
newHeight = originalRectangle.Bottom - resizeHandleCoords.Y;
|
newHeight = originalRectangle.Bottom - resizeHandleCoords.Y;
|
||||||
newRatio = newWidth / newHeight;
|
newRatio = newWidth / newHeight;
|
||||||
flippedRatioSign = Math.Sign(newRatio) * Math.Sign(originalRatio);
|
if(newRatio > originalRatio) { // FIXME
|
||||||
if (Math.Abs(newRatio) > Math.Abs(originalRatio)) {
|
resizeHandleCoords.X = originalRectangle.Right - newHeight * originalRatio;
|
||||||
// scaled rectangle (ratio) would be wider than original
|
} else if(newRatio < originalRatio) {
|
||||||
// keep height and tweak width to maintain aspect ratio
|
resizeHandleCoords.Y = originalRectangle.Bottom - newWidth / originalRatio;
|
||||||
float tweakedWidth = newHeight * originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.X = originalRectangle.Right - tweakedWidth;
|
|
||||||
} else if(Math.Abs(newRatio) < Math.Abs(originalRatio)) {
|
|
||||||
// scaled rectangle (ratio) would be taller than original
|
|
||||||
// keep width and tweak height to maintain aspect ratio
|
|
||||||
float tweakedHeight = newWidth / originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.Y = originalRectangle.Bottom - tweakedHeight;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -254,19 +243,10 @@ namespace Greenshot.Helpers {
|
||||||
newWidth = resizeHandleCoords.X - originalRectangle.Left;
|
newWidth = resizeHandleCoords.X - originalRectangle.Left;
|
||||||
newHeight = originalRectangle.Bottom - resizeHandleCoords.Y;
|
newHeight = originalRectangle.Bottom - resizeHandleCoords.Y;
|
||||||
newRatio = newWidth / newHeight;
|
newRatio = newWidth / newHeight;
|
||||||
flippedRatioSign = Math.Sign(newRatio) * Math.Sign(originalRatio);
|
if(newRatio > originalRatio) { // FIXME
|
||||||
|
resizeHandleCoords.X = newHeight * originalRatio + originalRectangle.Left;
|
||||||
if (Math.Abs(newRatio) > Math.Abs(originalRatio)) {
|
} else if(newRatio < originalRatio) {
|
||||||
// scaled rectangle (ratio) would be wider than original
|
resizeHandleCoords.Y = originalRectangle.Bottom - newWidth / originalRatio;
|
||||||
// keep height and tweak width to maintain aspect ratio
|
|
||||||
float tweakedWidth = newHeight * originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.X = originalRectangle.Left + tweakedWidth;
|
|
||||||
}
|
|
||||||
else if (Math.Abs(newRatio) < Math.Abs(originalRatio)) {
|
|
||||||
// scaled rectangle (ratio) would be taller than original
|
|
||||||
// keep width and tweak height to maintain aspect ratio
|
|
||||||
float tweakedHeight = newWidth / originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.Y = originalRectangle.Bottom - tweakedHeight;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -274,19 +254,10 @@ namespace Greenshot.Helpers {
|
||||||
newWidth = originalRectangle.Right - resizeHandleCoords.X;
|
newWidth = originalRectangle.Right - resizeHandleCoords.X;
|
||||||
newHeight = resizeHandleCoords.Y - originalRectangle.Top;
|
newHeight = resizeHandleCoords.Y - originalRectangle.Top;
|
||||||
newRatio = newWidth / newHeight;
|
newRatio = newWidth / newHeight;
|
||||||
flippedRatioSign = Math.Sign(newRatio) * Math.Sign(originalRatio);
|
if(newRatio > originalRatio) {
|
||||||
|
resizeHandleCoords.X = originalRectangle.Right - newHeight * originalRatio;
|
||||||
if (Math.Abs(newRatio) > Math.Abs(originalRatio)) {
|
} else if(newRatio < originalRatio) {
|
||||||
// scaled rectangle (ratio) would be wider than original
|
resizeHandleCoords.Y = newWidth / originalRatio + originalRectangle.Top;
|
||||||
// keep height and tweak width to maintain aspect ratio
|
|
||||||
float tweakedWidth = newHeight * originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.X = originalRectangle.Right - tweakedWidth;
|
|
||||||
}
|
|
||||||
else if (Math.Abs(newRatio) < Math.Abs(originalRatio)) {
|
|
||||||
// scaled rectangle (ratio) would be taller than original
|
|
||||||
// keep width and tweak height to maintain aspect ratio
|
|
||||||
float tweakedHeight = newWidth / originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.Y = originalRectangle.Top + tweakedHeight;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -294,20 +265,10 @@ namespace Greenshot.Helpers {
|
||||||
newWidth = resizeHandleCoords.X - originalRectangle.Left;
|
newWidth = resizeHandleCoords.X - originalRectangle.Left;
|
||||||
newHeight = resizeHandleCoords.Y - originalRectangle.Top;
|
newHeight = resizeHandleCoords.Y - originalRectangle.Top;
|
||||||
newRatio = newWidth / newHeight;
|
newRatio = newWidth / newHeight;
|
||||||
flippedRatioSign = Math.Sign(newRatio) * Math.Sign(originalRatio);
|
if(newRatio > originalRatio) {
|
||||||
|
resizeHandleCoords.X = newHeight * originalRatio + originalRectangle.Left;
|
||||||
if (Math.Abs(newRatio) > Math.Abs(originalRatio)) {
|
} else if(newRatio < originalRatio) {
|
||||||
// scaled rectangle (ratio) would be wider than original
|
resizeHandleCoords.Y = newWidth / originalRatio + originalRectangle.Top;
|
||||||
// keep height and tweak width to maintain aspect ratio
|
|
||||||
float tweakedWidth = newHeight * originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.X = originalRectangle.Left + tweakedWidth;
|
|
||||||
}
|
|
||||||
else if (Math.Abs(newRatio) < Math.Abs(originalRatio)) {
|
|
||||||
// TODO this is the same code as else if for topleft!
|
|
||||||
// scaled rectangle (ratio) would be taller than original
|
|
||||||
// keep width and tweak height to maintain aspect ratio
|
|
||||||
float tweakedHeight = newWidth / originalRatio * flippedRatioSign;
|
|
||||||
resizeHandleCoords.Y = originalRectangle.Top + tweakedHeight;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue