mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Fix drawing (dragging) a new element on the surface, which happened after the previous larger PR. Note: the adorners are somehow not visible yet. [skip ci]
This commit is contained in:
parent
13e2e67e7c
commit
acdbdeca3c
7 changed files with 72 additions and 147 deletions
|
@ -78,7 +78,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
||||||
_boundsAfterResize = _boundsBeforeResize;
|
_boundsAfterResize = _boundsBeforeResize;
|
||||||
|
|
||||||
// calculate scaled rectangle
|
// calculate scaled rectangle
|
||||||
ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());
|
_boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());
|
||||||
|
|
||||||
// apply scaled bounds to this DrawableContainer
|
// apply scaled bounds to this DrawableContainer
|
||||||
Owner.ApplyBounds(_boundsAfterResize);
|
Owner.ApplyBounds(_boundsAfterResize);
|
||||||
|
|
|
@ -101,7 +101,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
||||||
_boundsAfterResize = _boundsBeforeResize;
|
_boundsAfterResize = _boundsBeforeResize;
|
||||||
|
|
||||||
// calculate scaled rectangle
|
// calculate scaled rectangle
|
||||||
ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());
|
_boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());
|
||||||
|
|
||||||
// apply scaled bounds to this DrawableContainer
|
// apply scaled bounds to this DrawableContainer
|
||||||
Owner.ApplyBounds(_boundsAfterResize);
|
Owner.ApplyBounds(_boundsAfterResize);
|
||||||
|
|
|
@ -250,7 +250,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor());
|
_boundsAfterResize = ScaleHelper.Scale(_boundsBeforeResize, x, y, GetAngleRoundProcessor());
|
||||||
|
|
||||||
// apply scaled bounds to this DrawableContainer
|
// apply scaled bounds to this DrawableContainer
|
||||||
ApplyBounds(_boundsAfterResize);
|
ApplyBounds(_boundsAfterResize);
|
||||||
|
|
|
@ -488,7 +488,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
public virtual bool IsConfirmable => false;
|
public virtual bool IsConfirmable => false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make a following bounds change on this drawablecontainer undoable!
|
/// Make a following bounds change on this DrawableContainer undoable!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="allowMerge">true means allow the moves to be merged</param>
|
/// <param name="allowMerge">true means allow the moves to be merged</param>
|
||||||
public virtual void MakeBoundsChangeUndoable(bool allowMerge)
|
public virtual void MakeBoundsChangeUndoable(bool allowMerge)
|
||||||
|
@ -514,7 +514,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// <returns>true if the event is handled, false if the surface needs to handle it</returns>
|
/// <returns>true if the event is handled, false if the surface needs to handle it</returns>
|
||||||
public virtual bool HandleMouseDown(int x, int y)
|
public virtual bool HandleMouseDown(int x, int y)
|
||||||
{
|
{
|
||||||
_boundsBeforeResize = _boundsBeforeResize.MoveTo(x, y);
|
_boundsBeforeResize = Bounds.MoveTo(x, y);
|
||||||
Left = x;
|
Left = x;
|
||||||
Top = y;
|
Top = y;
|
||||||
return true;
|
return true;
|
||||||
|
@ -531,9 +531,9 @@ namespace Greenshot.Editor.Drawing
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
||||||
// reset "workbench" rectangle to current bounds
|
// reset "workbench" rectangle to current bounds
|
||||||
_boundsAfterResize = _boundsBeforeResize;
|
_boundsAfterResize = new NativeRectFloat(_boundsBeforeResize.Left, _boundsBeforeResize.Top, x - _boundsAfterResize.Left, y - _boundsAfterResize.Top);
|
||||||
|
|
||||||
ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor());
|
_boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, x, y, GetAngleRoundProcessor());
|
||||||
|
|
||||||
// apply scaled bounds to this DrawableContainer
|
// apply scaled bounds to this DrawableContainer
|
||||||
ApplyBounds(_boundsAfterResize);
|
ApplyBounds(_boundsAfterResize);
|
||||||
|
@ -668,7 +668,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
|
|
||||||
protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor()
|
protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor()
|
||||||
{
|
{
|
||||||
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
return ScaleHelper.ShapeAngleRoundBehavior.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool HasContextMenu => true;
|
public virtual bool HasContextMenu => true;
|
||||||
|
|
|
@ -117,7 +117,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
|
|
||||||
protected override ScaleHelper.IDoubleProcessor GetAngleRoundProcessor()
|
protected override ScaleHelper.IDoubleProcessor GetAngleRoundProcessor()
|
||||||
{
|
{
|
||||||
return ScaleHelper.LineAngleRoundBehavior.Instance;
|
return ScaleHelper.LineAngleRoundBehavior.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1096,13 +1096,8 @@ namespace Greenshot.Editor.Forms
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is a "work-around" for the MouseWheel event which doesn't get to the panel
|
/// This is a "work-around" for the MouseWheel event which doesn't get to the panel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender">object</param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e">MouseEventArgs</param>
|
||||||
/// <summary>
|
|
||||||
/// This is a "work-around" for the MouseWheel event which doesn't get to the panel
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void PanelMouseWheel(object sender, MouseEventArgs e)
|
private void PanelMouseWheel(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (System.Windows.Forms.Control.ModifierKeys.Equals(Keys.Control))
|
if (System.Windows.Forms.Control.ModifierKeys.Equals(Keys.Control))
|
||||||
|
|
|
@ -59,13 +59,13 @@ namespace Greenshot.Editor.Helpers
|
||||||
/// <param name="targetSize">the target size of the element</param>
|
/// <param name="targetSize">the target size of the element</param>
|
||||||
/// <param name="crop">in case the aspect ratio of currentSize and targetSize differs: shall the scaled size fit into targetSize (i.e. that one of its dimensions is smaller - false) or vice versa (true)</param>
|
/// <param name="crop">in case the aspect ratio of currentSize and targetSize differs: shall the scaled size fit into targetSize (i.e. that one of its dimensions is smaller - false) or vice versa (true)</param>
|
||||||
/// <returns>a new SizeF object indicating the width and height the element should be scaled to</returns>
|
/// <returns>a new SizeF object indicating the width and height the element should be scaled to</returns>
|
||||||
public static SizeF GetScaledSize(SizeF currentSize, SizeF targetSize, bool crop)
|
public static NativeSizeFloat GetScaledSize(NativeSizeFloat currentSize, NativeSizeFloat targetSize, bool crop)
|
||||||
{
|
{
|
||||||
float wFactor = targetSize.Width / currentSize.Width;
|
float wFactor = targetSize.Width / currentSize.Width;
|
||||||
float hFactor = targetSize.Height / currentSize.Height;
|
float hFactor = targetSize.Height / currentSize.Height;
|
||||||
|
|
||||||
float factor = crop ? Math.Max(wFactor, hFactor) : Math.Min(wFactor, hFactor);
|
float factor = crop ? Math.Max(wFactor, hFactor) : Math.Min(wFactor, hFactor);
|
||||||
return new SizeF(currentSize.Width * factor, currentSize.Height * factor);
|
return new NativeSizeFloat(currentSize.Width * factor, currentSize.Height * factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -75,58 +75,39 @@ namespace Greenshot.Editor.Helpers
|
||||||
/// <param name="targetRect">the rectangle reference for alignment of the element</param>
|
/// <param name="targetRect">the rectangle reference for alignment of the element</param>
|
||||||
/// <param name="alignment">the System.Drawing.ContentAlignment value indicating how the element is to be aligned should the width or height differ from targetSize</param>
|
/// <param name="alignment">the System.Drawing.ContentAlignment value indicating how the element is to be aligned should the width or height differ from targetSize</param>
|
||||||
/// <returns>a new RectangleF object with Location aligned aligned to targetRect</returns>
|
/// <returns>a new RectangleF object with Location aligned aligned to targetRect</returns>
|
||||||
public static RectangleF GetAlignedRectangle(RectangleF currentRect, RectangleF targetRect, ContentAlignment alignment)
|
public static NativeRectFloat GetAlignedRectangle(NativeRectFloat currentRect, NativeRectFloat targetRect, ContentAlignment alignment)
|
||||||
{
|
{
|
||||||
RectangleF newRect = new RectangleF(targetRect.Location, currentRect.Size);
|
var newRect = new NativeRectFloat(targetRect.Location, currentRect.Size);
|
||||||
switch (alignment)
|
return alignment switch
|
||||||
{
|
{
|
||||||
case ContentAlignment.TopCenter:
|
// TODO: Can ContentAlignment be replaced with Positions?
|
||||||
newRect.X = (targetRect.Width - currentRect.Width) / 2;
|
ContentAlignment.TopCenter => newRect.ChangeX((targetRect.Width - currentRect.Width) / 2),
|
||||||
break;
|
ContentAlignment.TopRight => newRect.ChangeX(targetRect.Width - currentRect.Width),
|
||||||
case ContentAlignment.TopRight:
|
ContentAlignment.MiddleLeft => newRect.ChangeY((targetRect.Height - currentRect.Height) / 2),
|
||||||
newRect.X = targetRect.Width - currentRect.Width;
|
ContentAlignment.MiddleCenter => newRect.ChangeY((targetRect.Height - currentRect.Height) / 2).ChangeX((targetRect.Width - currentRect.Width) / 2),
|
||||||
break;
|
ContentAlignment.MiddleRight => newRect.ChangeY((targetRect.Height - currentRect.Height) / 2).ChangeX(targetRect.Width - currentRect.Width),
|
||||||
case ContentAlignment.MiddleLeft:
|
ContentAlignment.BottomLeft => newRect.ChangeY(targetRect.Height - currentRect.Height),
|
||||||
newRect.Y = (targetRect.Height - currentRect.Height) / 2;
|
ContentAlignment.BottomCenter => newRect.ChangeY(targetRect.Height - currentRect.Height).ChangeX((targetRect.Width - currentRect.Width) / 2),
|
||||||
break;
|
ContentAlignment.BottomRight => newRect.ChangeY(targetRect.Height - currentRect.Height).ChangeX(targetRect.Width - currentRect.Width),
|
||||||
case ContentAlignment.MiddleCenter:
|
_ => newRect
|
||||||
newRect.Y = (targetRect.Height - currentRect.Height) / 2;
|
};
|
||||||
newRect.X = (targetRect.Width - currentRect.Width) / 2;
|
|
||||||
break;
|
|
||||||
case ContentAlignment.MiddleRight:
|
|
||||||
newRect.Y = (targetRect.Height - currentRect.Height) / 2;
|
|
||||||
newRect.X = targetRect.Width - currentRect.Width;
|
|
||||||
break;
|
|
||||||
case ContentAlignment.BottomLeft:
|
|
||||||
newRect.Y = targetRect.Height - currentRect.Height;
|
|
||||||
break;
|
|
||||||
case ContentAlignment.BottomCenter:
|
|
||||||
newRect.Y = targetRect.Height - currentRect.Height;
|
|
||||||
newRect.X = (targetRect.Width - currentRect.Width) / 2;
|
|
||||||
break;
|
|
||||||
case ContentAlignment.BottomRight:
|
|
||||||
newRect.Y = targetRect.Height - currentRect.Height;
|
|
||||||
newRect.X = targetRect.Width - currentRect.Width;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return newRect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates target size of a given rectangle scaled by dragging one of its handles (corners)
|
/// Calculates target size of a given rectangle scaled by dragging one of its handles (corners)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="originalRectangle">bounds of the current rectangle, scaled values will be written to this reference</param>
|
/// <param name="originalRectangle">bounds of the current rectangle</param>
|
||||||
/// <param name="resizeHandlePosition">position of the handle/gripper being used for resized, see constants in Gripper.cs, e.g. Gripper.POSITION_TOP_LEFT</param>
|
/// <param name="resizeHandlePosition">position of the handle/gripper being used for resized, see constants in Gripper.cs, e.g. Gripper.POSITION_TOP_LEFT</param>
|
||||||
/// <param name="resizeHandleCoords">coordinates of the used handle/gripper</param>
|
/// <param name="resizeHandleCoords">coordinates of the used handle/gripper</param>
|
||||||
/// <param name="options">ScaleOptions to use when scaling</param>
|
/// <param name="options">ScaleOptions to use when scaling</param>
|
||||||
public static void Scale(ref NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords, ScaleOptions? options)
|
/// <returns>NativeRectFloat scaled originalRectangle</returns>
|
||||||
|
public static NativeRectFloat Scale(NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords, ScaleOptions? options)
|
||||||
{
|
{
|
||||||
options ??= GetScaleOptions();
|
options ??= GetScaleOptions();
|
||||||
|
|
||||||
if ((options & ScaleOptions.Rational) == ScaleOptions.Rational)
|
if ((options & ScaleOptions.Rational) == ScaleOptions.Rational)
|
||||||
{
|
{
|
||||||
AdjustCoordsForRationalScale(originalRectangle, resizeHandlePosition, ref resizeHandleCoords);
|
resizeHandleCoords = AdjustCoordsForRationalScale(originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((options & ScaleOptions.Centered) == ScaleOptions.Centered)
|
if ((options & ScaleOptions.Centered) == ScaleOptions.Centered)
|
||||||
|
@ -135,96 +116,40 @@ namespace Greenshot.Editor.Helpers
|
||||||
float rectCenterX = originalRectangle.Left + originalRectangle.Width / 2;
|
float rectCenterX = originalRectangle.Left + originalRectangle.Width / 2;
|
||||||
float rectCenterY = originalRectangle.Top + originalRectangle.Height / 2;
|
float rectCenterY = originalRectangle.Top + originalRectangle.Height / 2;
|
||||||
// scale rectangle using handle coordinates
|
// scale rectangle using handle coordinates
|
||||||
Scale(ref originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
originalRectangle = Scale(originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
||||||
// mirror handle coordinates via rectangle center coordinates
|
// mirror handle coordinates via rectangle center coordinates
|
||||||
resizeHandleCoords = resizeHandleCoords.Offset(-2 * (resizeHandleCoords.X - rectCenterX), -2 * (resizeHandleCoords.Y - rectCenterY));
|
resizeHandleCoords = resizeHandleCoords.Offset(-2 * (resizeHandleCoords.X - rectCenterX), -2 * (resizeHandleCoords.Y - rectCenterY));
|
||||||
// scale again with opposing handle and mirrored coordinates
|
// scale again with opposing handle and mirrored coordinates
|
||||||
resizeHandlePosition = (Positions) ((((int) resizeHandlePosition) + 4) % 8);
|
resizeHandlePosition = (Positions) ((((int) resizeHandlePosition) + 4) % 8);
|
||||||
Scale(ref originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
originalRectangle = Scale(originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Scale(ref originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
originalRectangle = Scale(originalRectangle, resizeHandlePosition, resizeHandleCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return originalRectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates target size of a given rectangle scaled by dragging one of its handles (corners)
|
/// Calculates target size of a given rectangle scaled by dragging one of its handles (corners)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="originalRectangle">bounds of the current rectangle, scaled values will be written to this reference</param>
|
/// <param name="originalRectangle">bounds of the current rectangle</param>
|
||||||
/// <param name="resizeHandlePosition">position of the handle/gripper being used for resized, see constants in Gripper.cs, e.g. Gripper.POSITION_TOP_LEFT</param>
|
/// <param name="resizeHandlePosition">position of the handle/gripper being used for resized, see constants in Gripper.cs, e.g. Gripper.POSITION_TOP_LEFT</param>
|
||||||
/// <param name="resizeHandleCoords">coordinates of the used handle/gripper</param>
|
/// <param name="resizeHandleCoords">coordinates of the used handle/gripper</param>
|
||||||
private static void Scale(ref NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords)
|
/// <returns>NativeRectFloat with the scaled originalRectangle</returns>
|
||||||
|
private static NativeRectFloat Scale(NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords)
|
||||||
{
|
{
|
||||||
switch (resizeHandlePosition)
|
return resizeHandlePosition switch
|
||||||
{
|
{
|
||||||
case Positions.TopLeft:
|
Positions.TopLeft => new NativeRectFloat(resizeHandleCoords.X, resizeHandleCoords.Y, originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X, originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y),
|
||||||
originalRectangle = new NativeRectFloat(
|
Positions.TopCenter => new NativeRectFloat(originalRectangle.X, resizeHandleCoords.Y, originalRectangle.Width, originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y),
|
||||||
resizeHandleCoords.X,
|
Positions.TopRight => new NativeRectFloat(originalRectangle.X, resizeHandleCoords.Y, resizeHandleCoords.X - originalRectangle.Left, originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y),
|
||||||
resizeHandleCoords.Y,
|
Positions.MiddleLeft => new NativeRectFloat(resizeHandleCoords.X, originalRectangle.Y, originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X, originalRectangle.Height),
|
||||||
originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X,
|
Positions.MiddleRight => new NativeRectFloat(originalRectangle.X, originalRectangle.Y, resizeHandleCoords.X - originalRectangle.Left, originalRectangle.Height), Positions.BottomLeft => new NativeRectFloat(resizeHandleCoords.X, originalRectangle.Y, originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X, resizeHandleCoords.Y - originalRectangle.Top),
|
||||||
originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y);
|
Positions.BottomCenter => new NativeRectFloat(originalRectangle.X, originalRectangle.Y, originalRectangle.Width, resizeHandleCoords.Y - originalRectangle.Top), Positions.BottomRight => new NativeRectFloat(originalRectangle.X, originalRectangle.Y, resizeHandleCoords.X - originalRectangle.Left, resizeHandleCoords.Y - originalRectangle.Top),
|
||||||
break;
|
_ => throw new ArgumentException("Position cannot be handled: " + resizeHandlePosition)
|
||||||
|
};
|
||||||
case Positions.TopCenter:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
originalRectangle.X,
|
|
||||||
resizeHandleCoords.Y,
|
|
||||||
originalRectangle.Width,
|
|
||||||
originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Positions.TopRight:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
originalRectangle.X,
|
|
||||||
resizeHandleCoords.Y,
|
|
||||||
resizeHandleCoords.X - originalRectangle.Left,
|
|
||||||
originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Positions.MiddleLeft:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
resizeHandleCoords.X,
|
|
||||||
originalRectangle.Y,
|
|
||||||
originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X,
|
|
||||||
originalRectangle.Height);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Positions.MiddleRight:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
originalRectangle.X,
|
|
||||||
originalRectangle.Y,
|
|
||||||
resizeHandleCoords.X - originalRectangle.Left,
|
|
||||||
originalRectangle.Height);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Positions.BottomLeft:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
resizeHandleCoords.X,
|
|
||||||
originalRectangle.Y,
|
|
||||||
originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X,
|
|
||||||
resizeHandleCoords.Y - originalRectangle.Top);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Positions.BottomCenter:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
originalRectangle.X,
|
|
||||||
originalRectangle.Y,
|
|
||||||
originalRectangle.Width,
|
|
||||||
resizeHandleCoords.Y - originalRectangle.Top);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Positions.BottomRight:
|
|
||||||
originalRectangle = new NativeRectFloat(
|
|
||||||
originalRectangle.X,
|
|
||||||
originalRectangle.Y,
|
|
||||||
resizeHandleCoords.X - originalRectangle.Left,
|
|
||||||
resizeHandleCoords.Y - originalRectangle.Top);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new ArgumentException("Position cannot be handled: " + resizeHandlePosition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -235,37 +160,40 @@ namespace Greenshot.Editor.Helpers
|
||||||
/// </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>
|
||||||
/// <param name="resizeHandleCoords">coordinates of the used handle/gripper, adjusted coordinates will be written to this reference</param>
|
/// <param name="resizeHandleCoords">coordinates of the used handle/gripper</param>
|
||||||
private static void AdjustCoordsForRationalScale(NativeRectFloat originalRectangle, Positions resizeHandlePosition, ref NativePointFloat resizeHandleCoords)
|
/// <returns>NativePointFloat with the adjusted coordinates</returns>
|
||||||
|
private static NativePointFloat AdjustCoordsForRationalScale(NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords)
|
||||||
{
|
{
|
||||||
SizeF selectedRectangle, newSize;
|
NativeSizeFloat selectedRectangle, newSize;
|
||||||
|
|
||||||
switch (resizeHandlePosition)
|
switch (resizeHandlePosition)
|
||||||
{
|
{
|
||||||
case Positions.TopLeft:
|
case Positions.TopLeft:
|
||||||
selectedRectangle = new SizeF(originalRectangle.Right - resizeHandleCoords.X, originalRectangle.Bottom - resizeHandleCoords.Y);
|
selectedRectangle = new NativeSizeFloat(originalRectangle.Right - resizeHandleCoords.X, originalRectangle.Bottom - resizeHandleCoords.Y);
|
||||||
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
||||||
resizeHandleCoords = new NativePointFloat(originalRectangle.Right - newSize.Width, originalRectangle.Bottom - newSize.Height);
|
resizeHandleCoords = new NativePointFloat(originalRectangle.Right - newSize.Width, originalRectangle.Bottom - newSize.Height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Positions.TopRight:
|
case Positions.TopRight:
|
||||||
selectedRectangle = new SizeF(resizeHandleCoords.X - originalRectangle.Left, originalRectangle.Bottom - resizeHandleCoords.Y);
|
selectedRectangle = new NativeSizeFloat(resizeHandleCoords.X - originalRectangle.Left, originalRectangle.Bottom - resizeHandleCoords.Y);
|
||||||
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
||||||
resizeHandleCoords = new NativePointFloat(originalRectangle.Left + newSize.Width, originalRectangle.Bottom - newSize.Height);
|
resizeHandleCoords = new NativePointFloat(originalRectangle.Left + newSize.Width, originalRectangle.Bottom - newSize.Height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Positions.BottomLeft:
|
case Positions.BottomLeft:
|
||||||
selectedRectangle = new SizeF(originalRectangle.Right - resizeHandleCoords.X, resizeHandleCoords.Y - originalRectangle.Top);
|
selectedRectangle = new NativeSizeFloat(originalRectangle.Right - resizeHandleCoords.X, resizeHandleCoords.Y - originalRectangle.Top);
|
||||||
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
||||||
resizeHandleCoords = new NativePointFloat(originalRectangle.Right - newSize.Width, originalRectangle.Top + newSize.Height);
|
resizeHandleCoords = new NativePointFloat(originalRectangle.Right - newSize.Width, originalRectangle.Top + newSize.Height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Positions.BottomRight:
|
case Positions.BottomRight:
|
||||||
selectedRectangle = new SizeF(resizeHandleCoords.X - originalRectangle.Left, resizeHandleCoords.Y - originalRectangle.Top);
|
selectedRectangle = new NativeSizeFloat(resizeHandleCoords.X - originalRectangle.Left, resizeHandleCoords.Y - originalRectangle.Top);
|
||||||
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle);
|
||||||
resizeHandleCoords = new NativePointFloat(originalRectangle.Left + newSize.Width, originalRectangle.Top + newSize.Height);
|
resizeHandleCoords = new NativePointFloat(originalRectangle.Left + newSize.Width, originalRectangle.Top + newSize.Height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resizeHandleCoords;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -299,21 +227,21 @@ namespace Greenshot.Editor.Helpers
|
||||||
return newSize;
|
return newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize)
|
public static NativeRectFloat Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY)
|
||||||
{
|
{
|
||||||
Scale(boundsBeforeResize, cursorX, cursorY, ref boundsAfterResize, null);
|
return Scale(boundsBeforeResize, cursorX, cursorY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize, IDoubleProcessor angleRoundBehavior)
|
public static NativeRectFloat Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY, IDoubleProcessor angleRoundBehavior)
|
||||||
{
|
{
|
||||||
Scale(boundsBeforeResize, Positions.TopLeft, cursorX, cursorY, ref boundsAfterResize, angleRoundBehavior);
|
return Scale(boundsBeforeResize, Positions.TopLeft, cursorX, cursorY, angleRoundBehavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Scale(NativeRect boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize,
|
public static NativeRectFloat Scale(NativeRect boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, IDoubleProcessor angleRoundBehavior)
|
||||||
IDoubleProcessor angleRoundBehavior)
|
|
||||||
{
|
{
|
||||||
ScaleOptions opts = GetScaleOptions();
|
ScaleOptions opts = GetScaleOptions();
|
||||||
|
|
||||||
|
NativeRectFloat result = boundsBeforeResize;
|
||||||
bool rationalScale = (opts & ScaleOptions.Rational) == ScaleOptions.Rational;
|
bool rationalScale = (opts & ScaleOptions.Rational) == ScaleOptions.Rational;
|
||||||
bool centeredScale = (opts & ScaleOptions.Centered) == ScaleOptions.Centered;
|
bool centeredScale = (opts & ScaleOptions.Centered) == ScaleOptions.Centered;
|
||||||
|
|
||||||
|
@ -328,17 +256,19 @@ namespace Greenshot.Editor.Helpers
|
||||||
|
|
||||||
int dist = GeometryHelper.Distance2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY);
|
int dist = GeometryHelper.Distance2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY);
|
||||||
|
|
||||||
boundsAfterResize = boundsAfterResize
|
result = result
|
||||||
.ChangeWidth((int)Math.Round(dist * Math.Cos(angle / 180 * Math.PI)))
|
.ChangeWidth((int)Math.Round(dist * Math.Cos(angle / 180 * Math.PI)))
|
||||||
.ChangeHeight((int) Math.Round(dist * Math.Sin(angle / 180 * Math.PI)));
|
.ChangeHeight((int) Math.Round(dist * Math.Sin(angle / 180 * Math.PI)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (centeredScale)
|
if (centeredScale)
|
||||||
{
|
{
|
||||||
float wdiff = boundsAfterResize.Width - boundsBeforeResize.Width;
|
float wdiff = result.Width - result.Width;
|
||||||
float hdiff = boundsAfterResize.Height - boundsBeforeResize.Height;
|
float hdiff = result.Height - result.Height;
|
||||||
boundsAfterResize = boundsAfterResize.Inflate(wdiff, hdiff);
|
result = result.Inflate(wdiff, hdiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <returns>the current ScaleOptions depending on modifier keys held down</returns>
|
/// <returns>the current ScaleOptions depending on modifier keys held down</returns>
|
||||||
|
@ -359,7 +289,7 @@ namespace Greenshot.Editor.Helpers
|
||||||
|
|
||||||
public class ShapeAngleRoundBehavior : IDoubleProcessor
|
public class ShapeAngleRoundBehavior : IDoubleProcessor
|
||||||
{
|
{
|
||||||
public static ShapeAngleRoundBehavior Instance = new();
|
public static readonly ShapeAngleRoundBehavior INSTANCE = new();
|
||||||
|
|
||||||
private ShapeAngleRoundBehavior()
|
private ShapeAngleRoundBehavior()
|
||||||
{
|
{
|
||||||
|
@ -373,7 +303,7 @@ namespace Greenshot.Editor.Helpers
|
||||||
|
|
||||||
public class LineAngleRoundBehavior : IDoubleProcessor
|
public class LineAngleRoundBehavior : IDoubleProcessor
|
||||||
{
|
{
|
||||||
public static LineAngleRoundBehavior Instance = new();
|
public static readonly LineAngleRoundBehavior INSTANCE = new();
|
||||||
|
|
||||||
private LineAngleRoundBehavior()
|
private LineAngleRoundBehavior()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue