Move Expansion. Add Expansion overload to Surface.

(cherry picked from commit 64bfddb8daf7175fb0889f4af68a3c8ca3d97ade)
This commit is contained in:
Nathan Brown 2022-11-20 12:59:29 -08:00
commit 489862f812
5 changed files with 24 additions and 36 deletions

View file

@ -37,6 +37,14 @@ namespace Greenshot.Base.Interfaces.Drawing
BOTTOM,
}
public struct Expansion
{
public int Left;
public int Right;
public int Top;
public int Bottom;
}
public interface IDrawableContainer : INotifyPropertyChanged, IDisposable
{
/// <summary>

View file

@ -205,6 +205,7 @@ namespace Greenshot.Base.Interfaces
void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message);
void ResizeCanvas(int left, int right, int top, int bottom);
void ResizeCanvas(Expansion expansion);
void ApplyBitmapEffect(IEffect effect);
void RemoveCursor();
bool HasCursor { get; }

View file

@ -937,11 +937,10 @@ namespace Greenshot.Editor.Drawing
/// <param name="targetElement"></param>
public void PushOut(Direction direction, ISurface surface, IDrawableContainer targetElement)
{
var expansion = GetExpansionFromSize(direction, targetElement.Size);
surface.ResizeCanvas(expansion.Left, expansion.Right, expansion.Top, expansion.Bottom);
Expansion expansion = GetExpansionFromSize(direction, targetElement.Size);
targetElement.SnapToEdge(direction, surface);
surface.ResizeCanvas(expansion);
if (direction == Direction.LEFT || direction == Direction.RIGHT)
targetElement.SnapToEdge(Direction.TOP, surface);
@ -952,12 +951,12 @@ namespace Greenshot.Editor.Drawing
}
/// <summary>
/// Calculate the one-directional expansion needed to accommodate an element of the given size.
/// Calculate the 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)
private static Expansion GetExpansionFromSize(Direction direction, Size elementSize)
{
var expansion = new Expansion();

View file

@ -1,31 +0,0 @@
/*
* 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;
}
}

View file

@ -1054,6 +1054,17 @@ namespace Greenshot.Editor.Drawing
_surfaceExpanded(this, null);
}
/// <summary>
/// Set the canvas to a new size using the given expansion directions.
/// </summary>
/// <param name="expansion">The amount to expand in each direction.</param>
public void ResizeCanvas(Expansion expansion)
{
var resizeEffect = new ResizeCanvasEffect(expansion.Left, expansion.Right, expansion.Top, expansion.Bottom);
ApplyBitmapEffect(resizeEffect);
_surfaceExpanded(this, null);
}
/// <summary>
/// Apply a bitmap effect to the surface
/// </summary>