From 489862f812db46d1c74a9be6e83edb2bbe039f36 Mon Sep 17 00:00:00 2001 From: Nathan Brown Date: Sun, 20 Nov 2022 12:59:29 -0800 Subject: [PATCH] Move Expansion. Add Expansion overload to Surface. (cherry picked from commit 64bfddb8daf7175fb0889f4af68a3c8ca3d97ade) --- .../Interfaces/Drawing/IDrawableContainer.cs | 8 +++++ src/Greenshot.Base/Interfaces/ISurface.cs | 1 + .../Drawing/DrawableContainerList.cs | 9 +++--- src/Greenshot.Editor/Drawing/Expansion.cs | 31 ------------------- src/Greenshot.Editor/Drawing/Surface.cs | 11 +++++++ 5 files changed, 24 insertions(+), 36 deletions(-) delete mode 100644 src/Greenshot.Editor/Drawing/Expansion.cs diff --git a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs index 27ab67425..351b1193f 100644 --- a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs +++ b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs @@ -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 { /// diff --git a/src/Greenshot.Base/Interfaces/ISurface.cs b/src/Greenshot.Base/Interfaces/ISurface.cs index 8ea5881c8..3ba27cf9b 100644 --- a/src/Greenshot.Base/Interfaces/ISurface.cs +++ b/src/Greenshot.Base/Interfaces/ISurface.cs @@ -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; } diff --git a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs index 95d75addd..4baf1ef29 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs @@ -937,11 +937,10 @@ namespace Greenshot.Editor.Drawing /// public void PushOut(Direction direction, ISurface surface, IDrawableContainer targetElement) { - var expansion = GetExpansionFromSize(direction, targetElement.Size); + Expansion expansion = GetExpansionFromSize(direction, targetElement.Size); - surface.ResizeCanvas(expansion.Left, expansion.Right, expansion.Top, expansion.Bottom); - 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 } /// - /// 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. /// /// The direction in which to expand. /// The size of the element to accommodate. /// - public static Expansion GetExpansionFromSize(Direction direction, Size elementSize) + private static Expansion GetExpansionFromSize(Direction direction, Size elementSize) { var expansion = new Expansion(); diff --git a/src/Greenshot.Editor/Drawing/Expansion.cs b/src/Greenshot.Editor/Drawing/Expansion.cs deleted file mode 100644 index 12b240b1f..000000000 --- a/src/Greenshot.Editor/Drawing/Expansion.cs +++ /dev/null @@ -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 . - */ - -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 diff --git a/src/Greenshot.Editor/Drawing/Surface.cs b/src/Greenshot.Editor/Drawing/Surface.cs index 73fe91daa..8ec5f4a3e 100644 --- a/src/Greenshot.Editor/Drawing/Surface.cs +++ b/src/Greenshot.Editor/Drawing/Surface.cs @@ -1054,6 +1054,17 @@ namespace Greenshot.Editor.Drawing _surfaceExpanded(this, null); } + /// + /// Set the canvas to a new size using the given expansion directions. + /// + /// The amount to expand in each direction. + public void ResizeCanvas(Expansion expansion) + { + var resizeEffect = new ResizeCanvasEffect(expansion.Left, expansion.Right, expansion.Top, expansion.Bottom); + ApplyBitmapEffect(resizeEffect); + _surfaceExpanded(this, null); + } + /// /// Apply a bitmap effect to the surface ///