Stop passing Surface in to DrawableContainer

(cherry picked from commit ee435c90836a3b008768a8c5d722590f7602120f)
This commit is contained in:
Nathan Brown 2022-11-20 13:00:32 -08:00
commit c2b4a58644
3 changed files with 13 additions and 11 deletions

View file

@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Dapplo.Windows.Common.Structs;
@ -133,6 +134,6 @@ namespace Greenshot.Base.Interfaces.Drawing
/// </summary>
/// <param name="direction">Direction in which to move the container.</param>
/// <param name="surface">The surface the container belongs to.</param>
void SnapToEdge(Direction direction, ISurface surface);
void SnapToEdge(Direction direction, Size surfaceSize);
}
}

View file

@ -690,10 +690,9 @@ namespace Greenshot.Editor.Drawing
/// </summary>
/// <param name="direction">Direction in which to move the container.</param>
/// <param name="surface">The surface the container belongs to.</param>
public void SnapToEdge(Direction direction, ISurface surface)
public void SnapToEdge(Direction direction, Size surfaceSize)
{
Size surfaceBounds = new(surface.Image.Width, surface.Image.Height);
NativeRectFloat newBounds = GetLocationAfterSnap(direction, this.Bounds, surfaceBounds);
NativeRectFloat newBounds = GetLocationAfterSnap(direction, this.Bounds, surfaceSize);
this.MakeBoundsChangeUndoable(allowMerge: false);
this.ApplyBounds(newBounds);

View file

@ -922,9 +922,9 @@ namespace Greenshot.Editor.Drawing
///
public void SnapAllToEdge(Direction direction, ISurface surface)
{
foreach (IDrawableContainer item in this)
foreach (IDrawableContainer container in this)
{
item.SnapToEdge(direction, surface);
SnapContainerToEdge(direction, surface, container);
}
surface.DeselectAllElements();
}
@ -939,17 +939,19 @@ namespace Greenshot.Editor.Drawing
{
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);
else if (direction == Direction.TOP || direction == Direction.BOTTOM)
targetElement.SnapToEdge(Direction.LEFT, surface);
SnapContainerToEdge(direction, surface, targetElement);
surface.DeselectAllElements();
}
private void SnapContainerToEdge(Direction direction, ISurface surface, IDrawableContainer targetElement)
{
Size surfaceBounds = new(surface.Image.Width, surface.Image.Height);
targetElement.SnapToEdge(direction, surfaceBounds);
}
/// <summary>
/// Calculate the directional expansion needed to accommodate an element of the given size.
/// </summary>