mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
Small code cleanup of the places I already touched in this PR.
This commit is contained in:
parent
747a51e512
commit
8bc6fbdcc4
10 changed files with 175 additions and 195 deletions
|
@ -136,7 +136,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make a following bounds change on this containerlist undoable!
|
/// Make a following bounds change on this DrawableContainerList undoable!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="allowMerge">true means allow the moves to be merged</param>
|
/// <param name="allowMerge">true means allow the moves to be merged</param>
|
||||||
public void MakeBoundsChangeUndoable(bool allowMerge)
|
public void MakeBoundsChangeUndoable(bool allowMerge)
|
||||||
|
@ -301,16 +301,14 @@ namespace Greenshot.Editor.Drawing
|
||||||
{
|
{
|
||||||
return Rectangle.Empty;
|
return Rectangle.Empty;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
var result = this[0].DrawingBounds;
|
|
||||||
for (int i = 1; i < Count; i++)
|
|
||||||
{
|
|
||||||
result = Rectangle.Union(result, this[i].DrawingBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
var result = this[0].DrawingBounds;
|
||||||
|
for (int i = 1; i < Count; i++)
|
||||||
|
{
|
||||||
|
result = Rectangle.Union(result, this[i].DrawingBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +317,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g">the to the bitmap related Graphics object</param>
|
/// <param name="g">the to the bitmap related Graphics object</param>
|
||||||
/// <param name="bitmap">Bitmap to draw</param>
|
/// <param name="bitmap">Bitmap to draw</param>
|
||||||
/// <param name="renderMode">the rendermode in which the element is to be drawn</param>
|
/// <param name="renderMode">the RenderMode in which the element is to be drawn</param>
|
||||||
/// <param name="clipRectangle"></param>
|
/// <param name="clipRectangle"></param>
|
||||||
public void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, Rectangle clipRectangle)
|
public void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, Rectangle clipRectangle)
|
||||||
{
|
{
|
||||||
|
@ -584,9 +582,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dc = this[index1];
|
(this[index1], this[index2]) = (this[index2], this[index1]);
|
||||||
this[index1] = this[index2];
|
|
||||||
this[index2] = dc;
|
|
||||||
Parent.Modified = true;
|
Parent.Modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -711,7 +711,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
BinaryFormatter binaryRead = new BinaryFormatter();
|
BinaryFormatter binaryRead = new BinaryFormatter();
|
||||||
IDrawableContainerList loadedElements = (IDrawableContainerList) binaryRead.Deserialize(streamRead);
|
IDrawableContainerList loadedElements = (IDrawableContainerList) binaryRead.Deserialize(streamRead);
|
||||||
loadedElements.Parent = this;
|
loadedElements.Parent = this;
|
||||||
// Make sure the steplabels are sorted accoring to their number
|
// Make sure the steplabels are sorted according to their number
|
||||||
_stepLabels.Sort((p1, p2) => p1.Number.CompareTo(p2.Number));
|
_stepLabels.Sort((p1, p2) => p1.Number.CompareTo(p2.Number));
|
||||||
DeselectAllElements();
|
DeselectAllElements();
|
||||||
AddElements(loadedElements);
|
AddElements(loadedElements);
|
||||||
|
@ -1119,16 +1119,15 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// <param name="message">Message itself</param>
|
/// <param name="message">Message itself</param>
|
||||||
public void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message)
|
public void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message)
|
||||||
{
|
{
|
||||||
if (_surfaceMessage != null)
|
if (_surfaceMessage == null) return;
|
||||||
|
|
||||||
|
var eventArgs = new SurfaceMessageEventArgs
|
||||||
{
|
{
|
||||||
var eventArgs = new SurfaceMessageEventArgs
|
Message = message,
|
||||||
{
|
MessageType = messageType,
|
||||||
Message = message,
|
Surface = this
|
||||||
MessageType = messageType,
|
};
|
||||||
Surface = this
|
_surfaceMessage(source, eventArgs);
|
||||||
};
|
|
||||||
_surfaceMessage(source, eventArgs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1136,16 +1135,15 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">Who send</param>
|
/// <param name="source">Who send</param>
|
||||||
/// <param name="color">new color</param>
|
/// <param name="color">new color</param>
|
||||||
public void UpdateForegroundColorEvent(object source, Color color)
|
private void UpdateForegroundColorEvent(object source, Color color)
|
||||||
{
|
{
|
||||||
if (_foregroundColorChanged != null)
|
if (_foregroundColorChanged == null) return;
|
||||||
|
|
||||||
|
var eventArgs = new SurfaceForegroundColorEventArgs
|
||||||
{
|
{
|
||||||
var eventArgs = new SurfaceForegroundColorEventArgs
|
Color = color,
|
||||||
{
|
};
|
||||||
Color = color,
|
_foregroundColorChanged(source, eventArgs);
|
||||||
};
|
|
||||||
_foregroundColorChanged(source, eventArgs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1153,16 +1151,15 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">Who send</param>
|
/// <param name="source">Who send</param>
|
||||||
/// <param name="color">new color</param>
|
/// <param name="color">new color</param>
|
||||||
public void UpdateBackgroundColorEvent(object source, Color color)
|
private void UpdateBackgroundColorEvent(object source, Color color)
|
||||||
{
|
{
|
||||||
if (_lineThicknessChanged != null)
|
if (_lineThicknessChanged == null) return;
|
||||||
|
|
||||||
|
var eventArgs = new SurfaceBackgroundColorEventArgs
|
||||||
{
|
{
|
||||||
var eventArgs = new SurfaceBackgroundColorEventArgs
|
Color = color,
|
||||||
{
|
};
|
||||||
Color = color,
|
_backgroundColorChanged(source, eventArgs);
|
||||||
};
|
|
||||||
_backgroundColorChanged(source, eventArgs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1170,16 +1167,15 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">Who send</param>
|
/// <param name="source">Who send</param>
|
||||||
/// <param name="thickness">new thickness</param>
|
/// <param name="thickness">new thickness</param>
|
||||||
public void UpdateLineThicknessEvent(object source, int thickness)
|
private void UpdateLineThicknessEvent(object source, int thickness)
|
||||||
{
|
{
|
||||||
if (_lineThicknessChanged != null)
|
if (_lineThicknessChanged == null) return;
|
||||||
|
|
||||||
|
var eventArgs = new SurfaceLineThicknessEventArgs
|
||||||
{
|
{
|
||||||
var eventArgs = new SurfaceLineThicknessEventArgs
|
Thickness = thickness,
|
||||||
{
|
};
|
||||||
Thickness = thickness,
|
_lineThicknessChanged(source, eventArgs);
|
||||||
};
|
|
||||||
_lineThicknessChanged(source, eventArgs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1187,23 +1183,22 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">Who send</param>
|
/// <param name="source">Who send</param>
|
||||||
/// <param name="hasShadow">has shadow</param>
|
/// <param name="hasShadow">has shadow</param>
|
||||||
public void UpdateShadowEvent(object source, bool hasShadow)
|
private void UpdateShadowEvent(object source, bool hasShadow)
|
||||||
{
|
{
|
||||||
if (_shadowChanged != null)
|
if (_shadowChanged == null) return;
|
||||||
{
|
|
||||||
var eventArgs = new SurfaceShadowEventArgs
|
var eventArgs = new SurfaceShadowEventArgs
|
||||||
{
|
{
|
||||||
HasShadow = hasShadow,
|
HasShadow = hasShadow,
|
||||||
};
|
};
|
||||||
_shadowChanged(source, eventArgs);
|
_shadowChanged(source, eventArgs);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Crop the surface
|
/// Crop the surface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cropRectangle">rectangle that remains</param>
|
/// <param name="cropRectangle">rectangle that remains</param>
|
||||||
/// <returns></returns>
|
/// <returns>bool</returns>
|
||||||
public bool ApplyCrop(Rectangle cropRectangle)
|
public bool ApplyCrop(Rectangle cropRectangle)
|
||||||
{
|
{
|
||||||
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Default)) return false;
|
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Default)) return false;
|
||||||
|
@ -1224,7 +1219,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix matrix = new Matrix();
|
var matrix = new Matrix();
|
||||||
matrix.Translate(-cropRectangle.Left, -cropRectangle.Top, MatrixOrder.Append);
|
matrix.Translate(-cropRectangle.Left, -cropRectangle.Top, MatrixOrder.Append);
|
||||||
// Make undoable
|
// Make undoable
|
||||||
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
|
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
|
||||||
|
@ -1246,8 +1241,8 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// Splits the image in 3 parts(top, middle, bottom). Crop out the middle and joins top and bottom.
|
/// Splits the image in 3 parts(top, middle, bottom). Crop out the middle and joins top and bottom.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cropRectangle">rectangle of the middle part</param>
|
/// <param name="cropRectangle">rectangle of the middle part</param>
|
||||||
/// <returns></returns>
|
/// <returns>bool</returns>
|
||||||
public bool ApplyHorizontalCrop(Rectangle cropRectangle)
|
private bool ApplyHorizontalCrop(Rectangle cropRectangle)
|
||||||
{
|
{
|
||||||
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Horizontal)) return false;
|
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Horizontal)) return false;
|
||||||
|
|
||||||
|
@ -1255,12 +1250,12 @@ namespace Greenshot.Editor.Drawing
|
||||||
var topRectangle = new Rectangle(0, 0, Image.Size.Width, cropRectangle.Top);
|
var topRectangle = new Rectangle(0, 0, Image.Size.Width, cropRectangle.Top);
|
||||||
var bottomRectangle = new Rectangle(0, cropRectangle.Top + cropRectangle.Height, Image.Size.Width, Image.Size.Height - cropRectangle.Top - cropRectangle.Height);
|
var bottomRectangle = new Rectangle(0, cropRectangle.Top + cropRectangle.Height, Image.Size.Width, Image.Size.Height - cropRectangle.Top - cropRectangle.Height);
|
||||||
|
|
||||||
Bitmap tmpNewimage;
|
Bitmap newImage;
|
||||||
List<Bitmap> imageParts = new List<Bitmap>();
|
var imageParts = new List<Bitmap>();
|
||||||
// Make sure we have information, this this fails
|
// Make sure we have information, this this fails
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tmpNewimage = new Bitmap(Image.Size.Width, Image.Size.Height - cropRectangle.Height);
|
newImage = new Bitmap(Image.Size.Width, Image.Size.Height - cropRectangle.Height);
|
||||||
|
|
||||||
if (topRectangle.Height > 0)
|
if (topRectangle.Height > 0)
|
||||||
{
|
{
|
||||||
|
@ -1280,7 +1275,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
ex.Data.Add("Pixelformat", Image.PixelFormat);
|
ex.Data.Add("Pixelformat", Image.PixelFormat);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
using Graphics g = Graphics.FromImage(tmpNewimage);
|
using Graphics g = Graphics.FromImage(newImage);
|
||||||
|
|
||||||
var insertPositionTop = 0;
|
var insertPositionTop = 0;
|
||||||
foreach (var image in imageParts)
|
foreach (var image in imageParts)
|
||||||
|
@ -1290,16 +1285,16 @@ namespace Greenshot.Editor.Drawing
|
||||||
image.Dispose();
|
image.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix matrix = new Matrix();
|
var matrix = new Matrix();
|
||||||
matrix.Translate(0, -(cropRectangle.Top + cropRectangle.Height), MatrixOrder.Append);
|
matrix.Translate(0, -(cropRectangle.Top + cropRectangle.Height), MatrixOrder.Append);
|
||||||
// Make undoable
|
// Make undoable
|
||||||
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
|
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
|
||||||
|
|
||||||
// Do not dispose otherwise we can't undo the image!
|
// Do not dispose otherwise we can't undo the image!
|
||||||
SetImage(tmpNewimage, false);
|
SetImage(newImage, false);
|
||||||
|
|
||||||
_elements.Transform(matrix);
|
_elements.Transform(matrix);
|
||||||
if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpNewimage.Size)))
|
if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
|
||||||
{
|
{
|
||||||
_surfaceSizeChanged(this, null);
|
_surfaceSizeChanged(this, null);
|
||||||
}
|
}
|
||||||
|
@ -1313,20 +1308,20 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// Splits the image in 3 parts(left, middle, right). Crop out the middle and joins top and bottom.
|
/// Splits the image in 3 parts(left, middle, right). Crop out the middle and joins top and bottom.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cropRectangle">rectangle of the middle part</param>
|
/// <param name="cropRectangle">rectangle of the middle part</param>
|
||||||
/// <returns></returns>
|
/// <returns>bool</returns>
|
||||||
public bool ApplyVerticalCrop(Rectangle cropRectangle)
|
private bool ApplyVerticalCrop(Rectangle cropRectangle)
|
||||||
{
|
{
|
||||||
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Vertical)) return false;
|
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Vertical)) return false;
|
||||||
|
|
||||||
var imageRectangle = new Rectangle(Point.Empty, Image.Size);
|
var imageRectangle = new Rectangle(Point.Empty, Image.Size);
|
||||||
var leftRectangle = new Rectangle(0, 0, cropRectangle.Left, Image.Size.Height);
|
var leftRectangle = new Rectangle(0, 0, cropRectangle.Left, Image.Size.Height);
|
||||||
var rightRectangle = new Rectangle(cropRectangle.Left + cropRectangle.Width, 0, Image.Size.Width - cropRectangle.Width - cropRectangle.Left, Image.Size.Height);
|
var rightRectangle = new Rectangle(cropRectangle.Left + cropRectangle.Width, 0, Image.Size.Width - cropRectangle.Width - cropRectangle.Left, Image.Size.Height);
|
||||||
Bitmap tmpNewimage;
|
Bitmap newImage;
|
||||||
List<Bitmap> imageParts = new List<Bitmap>();
|
var imageParts = new List<Bitmap>();
|
||||||
// Make sure we have information, this this fails
|
// Make sure we have information, this this fails
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tmpNewimage = new Bitmap(Image.Size.Width - cropRectangle.Width, Image.Size.Height);
|
newImage = new Bitmap(Image.Size.Width - cropRectangle.Width, Image.Size.Height);
|
||||||
|
|
||||||
if (leftRectangle.Width > 0)
|
if (leftRectangle.Width > 0)
|
||||||
{
|
{
|
||||||
|
@ -1346,7 +1341,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
ex.Data.Add("Pixelformat", Image.PixelFormat);
|
ex.Data.Add("Pixelformat", Image.PixelFormat);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
using Graphics g = Graphics.FromImage(tmpNewimage);
|
using Graphics g = Graphics.FromImage(newImage);
|
||||||
|
|
||||||
var insertPositionLeft = 0;
|
var insertPositionLeft = 0;
|
||||||
foreach (var image in imageParts)
|
foreach (var image in imageParts)
|
||||||
|
@ -1355,18 +1350,17 @@ namespace Greenshot.Editor.Drawing
|
||||||
insertPositionLeft += image.Width;
|
insertPositionLeft += image.Width;
|
||||||
image.Dispose();
|
image.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Matrix matrix = new Matrix();
|
var matrix = new Matrix();
|
||||||
matrix.Translate(-cropRectangle.Left - cropRectangle.Width, 0, MatrixOrder.Append);
|
matrix.Translate(-cropRectangle.Left - cropRectangle.Width, 0, MatrixOrder.Append);
|
||||||
// Make undoable
|
// Make undoable
|
||||||
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
|
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
|
||||||
|
|
||||||
// Do not dispose otherwise we can't undo the image!
|
// Do not dispose otherwise we can't undo the image!
|
||||||
SetImage(tmpNewimage, false);
|
SetImage(newImage, false);
|
||||||
|
|
||||||
_elements.Transform(matrix);
|
_elements.Transform(matrix);
|
||||||
if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpNewimage.Size)))
|
if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
|
||||||
{
|
{
|
||||||
_surfaceSizeChanged(this, null);
|
_surfaceSizeChanged(this, null);
|
||||||
}
|
}
|
||||||
|
@ -1404,15 +1398,14 @@ namespace Greenshot.Editor.Drawing
|
||||||
{
|
{
|
||||||
foreach (IAdorner adorner in drawableContainer.Adorners)
|
foreach (IAdorner adorner in drawableContainer.Adorners)
|
||||||
{
|
{
|
||||||
if (adorner.IsActive || adorner.HitTest(mouseEventArgs.Location))
|
if (!adorner.IsActive && !adorner.HitTest(mouseEventArgs.Location)) continue;
|
||||||
|
|
||||||
|
if (adorner.Cursor != null)
|
||||||
{
|
{
|
||||||
if (adorner.Cursor != null)
|
Cursor = adorner.Cursor;
|
||||||
{
|
|
||||||
Cursor = adorner.Cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
return adorner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return adorner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1643,48 +1636,47 @@ namespace Greenshot.Editor.Drawing
|
||||||
|
|
||||||
Cursor = DrawingMode != DrawingModes.None ? Cursors.Cross : Cursors.Default;
|
Cursor = DrawingMode != DrawingModes.None ? Cursors.Cross : Cursors.Default;
|
||||||
|
|
||||||
if (_mouseDown)
|
if (!_mouseDown) return;
|
||||||
|
|
||||||
|
if (_mouseDownElement != null)
|
||||||
{
|
{
|
||||||
if (_mouseDownElement != null)
|
// an element is currently dragged
|
||||||
|
_mouseDownElement.Invalidate();
|
||||||
|
selectedElements.Invalidate();
|
||||||
|
// Move the element
|
||||||
|
if (_mouseDownElement.Selected)
|
||||||
{
|
{
|
||||||
// an element is currently dragged
|
if (!_isSurfaceMoveMadeUndoable)
|
||||||
_mouseDownElement.Invalidate();
|
|
||||||
selectedElements.Invalidate();
|
|
||||||
// Move the element
|
|
||||||
if (_mouseDownElement.Selected)
|
|
||||||
{
|
{
|
||||||
if (!_isSurfaceMoveMadeUndoable)
|
// Only allow one undoable per mouse-down/move/up "cycle"
|
||||||
{
|
_isSurfaceMoveMadeUndoable = true;
|
||||||
// Only allow one undoable per mouse-down/move/up "cycle"
|
selectedElements.MakeBoundsChangeUndoable(false);
|
||||||
_isSurfaceMoveMadeUndoable = true;
|
|
||||||
selectedElements.MakeBoundsChangeUndoable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dragged element has been selected before -> move all
|
|
||||||
selectedElements.MoveBy(currentMouse.X - _mouseStart.X, currentMouse.Y - _mouseStart.Y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!_isSurfaceMoveMadeUndoable)
|
|
||||||
{
|
|
||||||
// Only allow one undoable per mouse-down/move/up "cycle"
|
|
||||||
_isSurfaceMoveMadeUndoable = true;
|
|
||||||
_mouseDownElement.MakeBoundsChangeUndoable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dragged element is not among selected elements -> just move dragged one
|
|
||||||
_mouseDownElement.MoveBy(currentMouse.X - _mouseStart.X, currentMouse.Y - _mouseStart.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mouseStart = currentMouse;
|
// dragged element has been selected before -> move all
|
||||||
_mouseDownElement.Invalidate();
|
selectedElements.MoveBy(currentMouse.X - _mouseStart.X, currentMouse.Y - _mouseStart.Y);
|
||||||
_modified = true;
|
|
||||||
}
|
}
|
||||||
else if (_drawingElement != null)
|
else
|
||||||
{
|
{
|
||||||
_drawingElement.HandleMouseMove(currentMouse.X, currentMouse.Y);
|
if (!_isSurfaceMoveMadeUndoable)
|
||||||
_modified = true;
|
{
|
||||||
|
// Only allow one undoable per mouse-down/move/up "cycle"
|
||||||
|
_isSurfaceMoveMadeUndoable = true;
|
||||||
|
_mouseDownElement.MakeBoundsChangeUndoable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// dragged element is not among selected elements -> just move dragged one
|
||||||
|
_mouseDownElement.MoveBy(currentMouse.X - _mouseStart.X, currentMouse.Y - _mouseStart.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_mouseStart = currentMouse;
|
||||||
|
_mouseDownElement.Invalidate();
|
||||||
|
_modified = true;
|
||||||
|
}
|
||||||
|
else if (_drawingElement != null)
|
||||||
|
{
|
||||||
|
_drawingElement.HandleMouseMove(currentMouse.X, currentMouse.Y);
|
||||||
|
_modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2018,7 +2010,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (makeUndoable && elementToRemove.IsUndoable)
|
if (makeUndoable && elementToRemove is { IsUndoable: true })
|
||||||
{
|
{
|
||||||
MakeUndoable(new DeleteElementMemento(this, elementToRemove), false);
|
MakeUndoable(new DeleteElementMemento(this, elementToRemove), false);
|
||||||
}
|
}
|
||||||
|
@ -2085,11 +2077,9 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CutSelectedElements()
|
public void CutSelectedElements()
|
||||||
{
|
{
|
||||||
if (HasSelectedElements)
|
if (!HasSelectedElements) return;
|
||||||
{
|
ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements);
|
||||||
ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements);
|
RemoveSelectedElements();
|
||||||
RemoveSelectedElements();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -2097,61 +2087,57 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopySelectedElements()
|
public void CopySelectedElements()
|
||||||
{
|
{
|
||||||
if (HasSelectedElements)
|
if (!HasSelectedElements) return;
|
||||||
{
|
ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements);
|
||||||
ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called to confirm/cancel "confirmable" elements, like the crop-container.
|
/// This method is called to confirm/cancel "confirmable" elements, like the crop-container.
|
||||||
/// Called when pressing enter or using the "check" in the editor.
|
/// Called when pressing enter or using the "check" in the editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="confirm"></param>
|
/// <param name="confirm">bool</param>
|
||||||
public void ConfirmSelectedConfirmableElements(bool confirm)
|
public void ConfirmSelectedConfirmableElements(bool confirm)
|
||||||
{
|
{
|
||||||
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
|
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
|
||||||
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
|
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
|
||||||
foreach (IDrawableContainer dc in selectedDCs)
|
foreach (IDrawableContainer dc in selectedDCs)
|
||||||
{
|
{
|
||||||
if (dc.Equals(_cropContainer))
|
if (!dc.Equals(_cropContainer)) continue;
|
||||||
|
DrawingMode = DrawingModes.None;
|
||||||
|
// No undo memento for the cropcontainer itself, only for the effect
|
||||||
|
RemoveElement(_cropContainer, false);
|
||||||
|
if (confirm)
|
||||||
{
|
{
|
||||||
DrawingMode = DrawingModes.None;
|
if (dc is CropContainer e)
|
||||||
// No undo memento for the cropcontainer itself, only for the effect
|
|
||||||
RemoveElement(_cropContainer, false);
|
|
||||||
if (confirm)
|
|
||||||
{
|
{
|
||||||
if (dc is CropContainer e)
|
switch (e.GetFieldValue(FieldType.CROPMODE))
|
||||||
{
|
{
|
||||||
switch (e.GetFieldValue(FieldType.CROPMODE))
|
case CropContainer.CropModes.Horizontal:
|
||||||
{
|
{
|
||||||
case CropContainer.CropModes.Horizontal:
|
ApplyHorizontalCrop(_cropContainer.Bounds);
|
||||||
{
|
break;
|
||||||
ApplyHorizontalCrop(_cropContainer.Bounds);
|
}
|
||||||
break;
|
case CropContainer.CropModes.Vertical:
|
||||||
}
|
{
|
||||||
case CropContainer.CropModes.Vertical:
|
ApplyVerticalCrop(_cropContainer.Bounds);
|
||||||
{
|
break;
|
||||||
ApplyVerticalCrop(_cropContainer.Bounds);
|
}
|
||||||
break;
|
default:
|
||||||
}
|
{
|
||||||
default:
|
ApplyCrop(_cropContainer.Bounds);
|
||||||
{
|
break;
|
||||||
ApplyCrop(_cropContainer.Bounds);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ApplyCrop(_cropContainer.Bounds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
_cropContainer.Dispose();
|
{
|
||||||
_cropContainer = null;
|
ApplyCrop(_cropContainer.Bounds);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cropContainer.Dispose();
|
||||||
|
_cropContainer = null;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2337,13 +2323,13 @@ namespace Greenshot.Editor.Drawing
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the rectangle bounding all selected elements (in surface coordinates space),
|
/// Get the rectangle bounding all selected elements (in surface coordinates space),
|
||||||
/// or empty rectangle if nothing is selcted.
|
/// or empty rectangle if nothing is selected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rectangle GetSelectionRectangle()
|
public Rectangle GetSelectionRectangle()
|
||||||
=> ToSurfaceCoordinates(selectedElements.DrawingBounds);
|
=> ToSurfaceCoordinates(selectedElements.DrawingBounds);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Duplicate all the selecteded elements
|
/// Duplicate all the selected elements
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DuplicateSelectedElements()
|
public void DuplicateSelectedElements()
|
||||||
{
|
{
|
||||||
|
@ -2680,7 +2666,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
return _elements.CanPushDown(selectedElements);
|
return _elements.CanPushDown(selectedElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Element_FieldChanged(object sender, FieldChangedEventArgs e)
|
private void Element_FieldChanged(object sender, FieldChangedEventArgs e)
|
||||||
{
|
{
|
||||||
selectedElements.HandleFieldChangedEvent(sender, e);
|
selectedElements.HandleFieldChangedEvent(sender, e);
|
||||||
}
|
}
|
||||||
|
@ -2738,20 +2724,18 @@ namespace Greenshot.Editor.Drawing
|
||||||
{
|
{
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
Point[] points =
|
||||||
{
|
{
|
||||||
Point[] points =
|
rc.Location, rc.Location + rc.Size
|
||||||
{
|
};
|
||||||
rc.Location, rc.Location + rc.Size
|
_inverseZoomMatrix.TransformPoints(points);
|
||||||
};
|
return new Rectangle(
|
||||||
_inverseZoomMatrix.TransformPoints(points);
|
points[0].X,
|
||||||
return new Rectangle(
|
points[0].Y,
|
||||||
points[0].X,
|
points[1].X - points[0].X,
|
||||||
points[0].Y,
|
points[1].Y - points[0].Y
|
||||||
points[1].X - points[0].X,
|
);
|
||||||
points[1].Y - points[0].Y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,7 +44,7 @@ namespace Greenshot.Editor.Memento
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
//if (disposing) { }
|
//if (disposing) { }
|
||||||
_drawableContainer = null;
|
_drawableContainer = null;
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Greenshot.Editor.Memento
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace Greenshot.Editor.Memento
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Greenshot.Editor.Memento
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!disposing) return;
|
if (!disposing) return;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Greenshot.Editor.Memento
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,30 +34,30 @@ namespace Greenshot.Editor.Memento
|
||||||
{
|
{
|
||||||
private readonly List<Point> _points = new();
|
private readonly List<Point> _points = new();
|
||||||
private readonly List<Size> _sizes = new();
|
private readonly List<Size> _sizes = new();
|
||||||
private IDrawableContainerList _listOfdrawableContainer;
|
private IDrawableContainerList _listOfDrawableContainer;
|
||||||
|
|
||||||
private void StoreBounds()
|
private void StoreBounds()
|
||||||
{
|
{
|
||||||
foreach (IDrawableContainer drawableContainer in _listOfdrawableContainer)
|
foreach (IDrawableContainer drawableContainer in _listOfDrawableContainer)
|
||||||
{
|
{
|
||||||
_points.Add(drawableContainer.Location);
|
_points.Add(drawableContainer.Location);
|
||||||
_sizes.Add(drawableContainer.Size);
|
_sizes.Add(drawableContainer.Size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawableContainerBoundsChangeMemento(IDrawableContainerList listOfdrawableContainer)
|
public DrawableContainerBoundsChangeMemento(IDrawableContainerList listOfDrawableContainer)
|
||||||
{
|
{
|
||||||
_listOfdrawableContainer = listOfdrawableContainer;
|
_listOfDrawableContainer = listOfDrawableContainer;
|
||||||
StoreBounds();
|
StoreBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer)
|
public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer)
|
||||||
{
|
{
|
||||||
_listOfdrawableContainer = new DrawableContainerList
|
_listOfDrawableContainer = new DrawableContainerList
|
||||||
{
|
{
|
||||||
drawableContainer
|
drawableContainer
|
||||||
};
|
};
|
||||||
_listOfdrawableContainer.Parent = drawableContainer.Parent;
|
_listOfDrawableContainer.Parent = drawableContainer.Parent;
|
||||||
StoreBounds();
|
StoreBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,21 +66,21 @@ namespace Greenshot.Editor.Memento
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
_listOfdrawableContainer?.Dispose();
|
_listOfDrawableContainer?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
_listOfdrawableContainer = null;
|
_listOfDrawableContainer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Merge(IMemento otherMemento)
|
public bool Merge(IMemento otherMemento)
|
||||||
{
|
{
|
||||||
if (otherMemento is not DrawableContainerBoundsChangeMemento other) return false;
|
if (otherMemento is not DrawableContainerBoundsChangeMemento other) return false;
|
||||||
|
|
||||||
if (ObjectExtensions.CompareLists(_listOfdrawableContainer, other._listOfdrawableContainer))
|
if (ObjectExtensions.CompareLists(_listOfDrawableContainer, other._listOfDrawableContainer))
|
||||||
{
|
{
|
||||||
// Lists are equal, as we have the state already we can ignore the new memento
|
// Lists are equal, as we have the state already we can ignore the new memento
|
||||||
return true;
|
return true;
|
||||||
|
@ -91,10 +91,10 @@ namespace Greenshot.Editor.Memento
|
||||||
|
|
||||||
public IMemento Restore()
|
public IMemento Restore()
|
||||||
{
|
{
|
||||||
var oldState = new DrawableContainerBoundsChangeMemento(_listOfdrawableContainer);
|
var oldState = new DrawableContainerBoundsChangeMemento(_listOfDrawableContainer);
|
||||||
for (int index = 0; index < _listOfdrawableContainer.Count; index++)
|
for (int index = 0; index < _listOfDrawableContainer.Count; index++)
|
||||||
{
|
{
|
||||||
IDrawableContainer drawableContainer = _listOfdrawableContainer[index];
|
IDrawableContainer drawableContainer = _listOfDrawableContainer[index];
|
||||||
// Before
|
// Before
|
||||||
drawableContainer.Invalidate();
|
drawableContainer.Invalidate();
|
||||||
drawableContainer.Left = _points[index].X;
|
drawableContainer.Left = _points[index].X;
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace Greenshot.Editor.Memento
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!disposing) return;
|
if (!disposing) return;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Greenshot.Editor.Memento
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue