diff --git a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs index 88bca90f1..d62643195 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs @@ -982,29 +982,10 @@ namespace Greenshot.Editor.Drawing /// public void PushOut(Direction direction, ISurface surface, IDrawableContainer targetElement) { - int left = 0, right = 0, top = 0, bottom = 0; - - switch (direction) - { - case Direction.LEFT: - left = targetElement.Width; - break; - case Direction.RIGHT: - right = targetElement.Width; - break; - case Direction.TOP: - top = targetElement.Height; - break; - case Direction.BOTTOM: - bottom = targetElement.Height; - break; - default: - break; - } + var expansion = GetExpansionFromSize(direction, targetElement.Size); - surface.ResizeCanvas(left, right, top, bottom); + surface.ResizeCanvas(expansion.Left, expansion.Right, expansion.Top, expansion.Bottom); - // Move target object SnapToEdge(direction, surface, targetElement); if (direction == Direction.LEFT || direction == Direction.RIGHT) @@ -1014,5 +995,36 @@ namespace Greenshot.Editor.Drawing surface.DeselectAllElements(); } + + /// + /// Calculate the one-directional expansion needed to accommodate an element of the given size. + /// + /// The direction in which to expand. + /// The size of the element to accommodate. + /// + public static Expansion GetExpansionFromSize(Direction direction, Size elementSize) + { + var expansion = new Expansion(); + + switch (direction) + { + case Direction.LEFT: + expansion.Left = elementSize.Width; + break; + case Direction.RIGHT: + expansion.Right = elementSize.Width; + break; + case Direction.TOP: + expansion.Top = elementSize.Height; + break; + case Direction.BOTTOM: + expansion.Bottom = elementSize.Height; + break; + default: + break; + } + + return expansion; + } } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Drawing/Expansion.cs b/src/Greenshot.Editor/Drawing/Expansion.cs new file mode 100644 index 000000000..12b240b1f --- /dev/null +++ b/src/Greenshot.Editor/Drawing/Expansion.cs @@ -0,0 +1,31 @@ +/* + * 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.Drawing +{ + public struct Expansion + { + public int Left; + public int Right; + public int Top; + public int Bottom; + } +} \ No newline at end of file