mirror of
https://github.com/greenshot/greenshot
synced 2025-08-24 07:06:23 -07:00
Extract GetExpansionFromSize method
(cherry picked from commit c1360823e78f1aea87b5c287209b8e6b0db41210) (cherry picked from commit c2df37eac74e9739e25e67397375135a76f46511)
This commit is contained in:
parent
7c2fdd7c2d
commit
b37815c5d9
2 changed files with 64 additions and 21 deletions
|
@ -982,29 +982,10 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// <param name="targetElement"></param>
|
/// <param name="targetElement"></param>
|
||||||
public void PushOut(Direction direction, ISurface surface, IDrawableContainer targetElement)
|
public void PushOut(Direction direction, ISurface surface, IDrawableContainer targetElement)
|
||||||
{
|
{
|
||||||
int left = 0, right = 0, top = 0, bottom = 0;
|
var expansion = GetExpansionFromSize(direction, targetElement.Size);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
surface.ResizeCanvas(left, right, top, bottom);
|
surface.ResizeCanvas(expansion.Left, expansion.Right, expansion.Top, expansion.Bottom);
|
||||||
|
|
||||||
// Move target object
|
|
||||||
SnapToEdge(direction, surface, targetElement);
|
SnapToEdge(direction, surface, targetElement);
|
||||||
|
|
||||||
if (direction == Direction.LEFT || direction == Direction.RIGHT)
|
if (direction == Direction.LEFT || direction == Direction.RIGHT)
|
||||||
|
@ -1014,5 +995,36 @@ namespace Greenshot.Editor.Drawing
|
||||||
|
|
||||||
surface.DeselectAllElements();
|
surface.DeselectAllElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate the one-directional expansion needed to accommodate an element of the given size.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">The direction in which to expand.</param>
|
||||||
|
/// <param name="elementSize">The size of the element to accommodate.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
31
src/Greenshot.Editor/Drawing/Expansion.cs
Normal file
31
src/Greenshot.Editor/Drawing/Expansion.cs
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Greenshot.Editor.Drawing
|
||||||
|
{
|
||||||
|
public struct Expansion
|
||||||
|
{
|
||||||
|
public int Left;
|
||||||
|
public int Right;
|
||||||
|
public int Top;
|
||||||
|
public int Bottom;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue