diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b6533ddd7..f5b9f2e1c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -46,7 +46,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Base/Greenshot.Base.csproj b/src/Greenshot.Base/Greenshot.Base.csproj index 805098491..a698b8e0b 100644 --- a/src/Greenshot.Base/Greenshot.Base.csproj +++ b/src/Greenshot.Base/Greenshot.Base.csproj @@ -6,13 +6,13 @@ - - - - - - - + + + + + + + diff --git a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs index 523684232..263d5a31e 100644 --- a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs +++ b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs @@ -100,8 +100,10 @@ namespace Greenshot.Editor.Drawing.Adorners // reset "workbench" rectangle to current bounds _boundsAfterResize = _boundsBeforeResize; + var scaleOptions = (Owner as IHaveScaleOptions)?.GetScaleOptions(); + // calculate scaled rectangle - _boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions()); + _boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, Position, new NativePointFloat(mouseEventArgs.X, mouseEventArgs.Y), scaleOptions); // apply scaled bounds to this DrawableContainer Owner.ApplyBounds(_boundsAfterResize); diff --git a/src/Greenshot.Editor/Drawing/CropContainer.cs b/src/Greenshot.Editor/Drawing/CropContainer.cs index c513b171f..eb2f7179e 100644 --- a/src/Greenshot.Editor/Drawing/CropContainer.cs +++ b/src/Greenshot.Editor/Drawing/CropContainer.cs @@ -248,7 +248,7 @@ namespace Greenshot.Editor.Drawing _boundsBeforeResize.Left, _boundsBeforeResize.Top, x - _boundsAfterResize.Left, y - _boundsAfterResize.Top); - _boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, Positions.TopLeft, x, y, GetAngleRoundProcessor()); + _boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, x, y, GetAngleRoundProcessor()); break; } } diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs index c9737f9e3..cac23dc3a 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs @@ -533,7 +533,8 @@ namespace Greenshot.Editor.Drawing // reset "workbench" rectangle to current bounds _boundsAfterResize = new NativeRectFloat(_boundsBeforeResize.Left, _boundsBeforeResize.Top, x - _boundsAfterResize.Left, y - _boundsAfterResize.Top); - _boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, Positions.TopLeft, x, y, GetAngleRoundProcessor()); + var scaleOptions = (this as IHaveScaleOptions)?.GetScaleOptions(); + _boundsAfterResize = ScaleHelper.Scale(_boundsAfterResize, x, y, GetAngleRoundProcessor(), scaleOptions); // apply scaled bounds to this DrawableContainer ApplyBounds(_boundsAfterResize); @@ -666,9 +667,9 @@ namespace Greenshot.Editor.Drawing Height = points[1].Y - points[0].Y; } - protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() + protected virtual IDoubleProcessor GetAngleRoundProcessor() { - return ScaleHelper.ShapeAngleRoundBehavior.INSTANCE; + return ShapeAngleRoundBehavior.INSTANCE; } public virtual bool HasContextMenu => true; diff --git a/src/Greenshot.Editor/Drawing/LineContainer.cs b/src/Greenshot.Editor/Drawing/LineContainer.cs index ef4a68707..f48dddec7 100644 --- a/src/Greenshot.Editor/Drawing/LineContainer.cs +++ b/src/Greenshot.Editor/Drawing/LineContainer.cs @@ -115,9 +115,9 @@ namespace Greenshot.Editor.Drawing return false; } - protected override ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() + protected override IDoubleProcessor GetAngleRoundProcessor() { - return ScaleHelper.LineAngleRoundBehavior.INSTANCE; + return LineAngleRoundBehavior.INSTANCE; } } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Helpers/IDoubleProcessor.cs b/src/Greenshot.Editor/Helpers/IDoubleProcessor.cs new file mode 100644 index 000000000..beb426c68 --- /dev/null +++ b/src/Greenshot.Editor/Helpers/IDoubleProcessor.cs @@ -0,0 +1,28 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: https://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Greenshot.Editor.Helpers +{ + public interface IDoubleProcessor + { + double Process(double d); + } +} \ No newline at end of file diff --git a/src/Greenshot.Editor/Helpers/IHaveScaleOptions.cs b/src/Greenshot.Editor/Helpers/IHaveScaleOptions.cs new file mode 100644 index 000000000..3f1ed03ff --- /dev/null +++ b/src/Greenshot.Editor/Helpers/IHaveScaleOptions.cs @@ -0,0 +1,28 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom, Francis Noel + * + * For more information see: https://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Greenshot.Editor.Helpers +{ + public interface IHaveScaleOptions + { + ScaleOptions GetScaleOptions(); + } +} diff --git a/src/Greenshot.Editor/Helpers/LineAngleRoundBehavior.cs b/src/Greenshot.Editor/Helpers/LineAngleRoundBehavior.cs new file mode 100644 index 000000000..6811f66cf --- /dev/null +++ b/src/Greenshot.Editor/Helpers/LineAngleRoundBehavior.cs @@ -0,0 +1,39 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: https://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; + +namespace Greenshot.Editor.Helpers +{ + public class LineAngleRoundBehavior : IDoubleProcessor + { + public static readonly LineAngleRoundBehavior INSTANCE = new(); + + private LineAngleRoundBehavior() + { + } + + public double Process(double angle) + { + return Math.Round(angle / 15) * 15; + } + } +} \ No newline at end of file diff --git a/src/Greenshot.Editor/Helpers/ScaleHelper.cs b/src/Greenshot.Editor/Helpers/ScaleHelper.cs index 63f25d0a0..8403bd939 100644 --- a/src/Greenshot.Editor/Helpers/ScaleHelper.cs +++ b/src/Greenshot.Editor/Helpers/ScaleHelper.cs @@ -33,25 +33,6 @@ namespace Greenshot.Editor.Helpers /// public static class ScaleHelper { - [Flags] - public enum ScaleOptions - { - /// - /// Default scale behavior. - /// - Default = 0x00, - - /// - /// Scale a rectangle in two our four directions, mirrored at it's center coordinates - /// - Centered = 0x01, - - /// - /// Scale a rectangle maintaining it's aspect ratio - /// - Rational = 0x02 - } - /// /// calculates the Size an element must be resized to, in order to fit another element, keeping aspect ratio /// @@ -231,18 +212,18 @@ namespace Greenshot.Editor.Helpers /// Scale the boundsBeforeResize with the specified position and new location, using the angle angleRoundBehavior /// /// NativeRect - /// Positions /// int /// int /// IDoubleProcessor + /// ScaleOptions /// NativeRectFloat - public static NativeRectFloat Scale(NativeRect boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, IDoubleProcessor angleRoundBehavior) + public static NativeRectFloat Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY, IDoubleProcessor angleRoundBehavior, ScaleOptions? scaleOptions = null) { - ScaleOptions opts = GetScaleOptions(); + scaleOptions ??= GetScaleOptions(); NativeRectFloat result = boundsBeforeResize; - bool rationalScale = (opts & ScaleOptions.Rational) == ScaleOptions.Rational; - bool centeredScale = (opts & ScaleOptions.Centered) == ScaleOptions.Centered; + bool rationalScale = (scaleOptions & ScaleOptions.Rational) == ScaleOptions.Rational; + bool centeredScale = (scaleOptions & ScaleOptions.Centered) == ScaleOptions.Centered; if (rationalScale) { @@ -280,38 +261,5 @@ namespace Greenshot.Editor.Helpers if (maintainAspectRatio) opts |= ScaleOptions.Rational; return opts; } - - public interface IDoubleProcessor - { - double Process(double d); - } - - public class ShapeAngleRoundBehavior : IDoubleProcessor - { - public static readonly ShapeAngleRoundBehavior INSTANCE = new(); - - private ShapeAngleRoundBehavior() - { - } - - public double Process(double angle) - { - return Math.Round((angle + 45) / 90) * 90 - 45; - } - } - - public class LineAngleRoundBehavior : IDoubleProcessor - { - public static readonly LineAngleRoundBehavior INSTANCE = new(); - - private LineAngleRoundBehavior() - { - } - - public double Process(double angle) - { - return Math.Round(angle / 15) * 15; - } - } } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Helpers/ScaleOptions.cs b/src/Greenshot.Editor/Helpers/ScaleOptions.cs new file mode 100644 index 000000000..1f47f5c02 --- /dev/null +++ b/src/Greenshot.Editor/Helpers/ScaleOptions.cs @@ -0,0 +1,44 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: https://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; + +namespace Greenshot.Editor.Helpers +{ + [Flags] + public enum ScaleOptions + { + /// + /// Default scale behavior. + /// + Default = 0x00, + + /// + /// Scale a rectangle in two our four directions, mirrored at it's center coordinates + /// + Centered = 0x01, + + /// + /// Scale a rectangle maintaining it's aspect ratio + /// + Rational = 0x02 + } +} \ No newline at end of file diff --git a/src/Greenshot.Editor/Helpers/ShapeAngleRoundBehavior.cs b/src/Greenshot.Editor/Helpers/ShapeAngleRoundBehavior.cs new file mode 100644 index 000000000..ba173df9f --- /dev/null +++ b/src/Greenshot.Editor/Helpers/ShapeAngleRoundBehavior.cs @@ -0,0 +1,39 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: https://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; + +namespace Greenshot.Editor.Helpers +{ + public class ShapeAngleRoundBehavior : IDoubleProcessor + { + public static readonly ShapeAngleRoundBehavior INSTANCE = new(); + + private ShapeAngleRoundBehavior() + { + } + + public double Process(double angle) + { + return Math.Round((angle + 45) / 90) * 90 - 45; + } + } +} \ No newline at end of file diff --git a/src/Greenshot.Plugin.Office/Greenshot.Plugin.Office.csproj b/src/Greenshot.Plugin.Office/Greenshot.Plugin.Office.csproj index fdb555adc..347a58339 100644 --- a/src/Greenshot.Plugin.Office/Greenshot.Plugin.Office.csproj +++ b/src/Greenshot.Plugin.Office/Greenshot.Plugin.Office.csproj @@ -78,23 +78,23 @@ - + true runtime - + true runtime - + true runtime - + true runtime - + true runtime diff --git a/src/Greenshot/App.config b/src/Greenshot/App.config index 80b985a5c..ab8a7c40c 100644 --- a/src/Greenshot/App.config +++ b/src/Greenshot/App.config @@ -11,8 +11,7 @@ - - + \ No newline at end of file diff --git a/src/Greenshot/Greenshot.csproj b/src/Greenshot/Greenshot.csproj index 78fa3f6c6..fc4dd90d1 100644 --- a/src/Greenshot/Greenshot.csproj +++ b/src/Greenshot/Greenshot.csproj @@ -17,7 +17,7 @@ - +