Add project files.
This commit is contained in:
34
Examples/Nodify.Shapes/Canvas/UndoRedo/MoveShapesAction.cs
Normal file
34
Examples/Nodify.Shapes/Canvas/UndoRedo/MoveShapesAction.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Nodify.UndoRedo;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
|
||||
namespace Nodify.Shapes.Canvas.UndoRedo
|
||||
{
|
||||
public class MoveShapesAction : IAction
|
||||
{
|
||||
private readonly IReadOnlyCollection<ShapeViewModel> _shapes;
|
||||
private readonly Vector _offset;
|
||||
|
||||
public string? Label => "Move shapes";
|
||||
|
||||
public MoveShapesAction(IReadOnlyCollection<ShapeViewModel> shapes, Vector offset)
|
||||
{
|
||||
_shapes = shapes;
|
||||
_offset = offset;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
=> ApplyOffset(_offset);
|
||||
|
||||
public void Undo()
|
||||
=> ApplyOffset(-_offset);
|
||||
|
||||
private void ApplyOffset(Vector offset)
|
||||
{
|
||||
foreach (var shape in _shapes)
|
||||
{
|
||||
shape.Location += offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Examples/Nodify.Shapes/Canvas/UndoRedo/ResizeShapesAction.cs
Normal file
53
Examples/Nodify.Shapes/Canvas/UndoRedo/ResizeShapesAction.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Nodify.UndoRedo;
|
||||
|
||||
namespace Nodify.Shapes.Canvas.UndoRedo
|
||||
{
|
||||
public class ResizeShapesAction : IAction
|
||||
{
|
||||
private readonly IReadOnlyCollection<ShapeViewModel> _resizedShapes;
|
||||
private readonly Dictionary<ShapeViewModel, Size> _initialSizes;
|
||||
private Dictionary<ShapeViewModel, Size>? _finalSizes;
|
||||
private readonly Dictionary<ShapeViewModel, Point> _initialLocations;
|
||||
private Dictionary<ShapeViewModel, Point>? _finalLocations;
|
||||
|
||||
public ResizeShapesAction(CanvasViewModel canvas)
|
||||
{
|
||||
_resizedShapes = canvas.SelectedShapes;
|
||||
_initialSizes = _resizedShapes.ToDictionary(x => x, x => new Size(x.Width, x.Height));
|
||||
_initialLocations = _resizedShapes.ToDictionary(x => x, x => x.Location);
|
||||
}
|
||||
|
||||
public string? Label => "Resize shapes";
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
_finalLocations?.ForEach(x => x.Key.Location = x.Value);
|
||||
|
||||
_finalSizes?.ForEach(x =>
|
||||
{
|
||||
x.Key.Width = x.Value.Width;
|
||||
x.Key.Height = x.Value.Height;
|
||||
});
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
_initialSizes.ForEach(x =>
|
||||
{
|
||||
x.Key.Width = x.Value.Width;
|
||||
x.Key.Height = x.Value.Height;
|
||||
});
|
||||
|
||||
_initialLocations.ForEach(x => x.Key.Location = x.Value);
|
||||
}
|
||||
|
||||
public void SaveSizes()
|
||||
{
|
||||
_finalLocations = _resizedShapes.ToDictionary(x => x, x => x.Location);
|
||||
_finalSizes = _resizedShapes.ToDictionary(x => x, x => new Size(x.Width, x.Height));
|
||||
}
|
||||
}
|
||||
}
|
||||
59
Examples/Nodify.Shapes/Canvas/UndoRedo/SelectShapesAction.cs
Normal file
59
Examples/Nodify.Shapes/Canvas/UndoRedo/SelectShapesAction.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Nodify.UndoRedo;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Nodify.Shapes.Canvas.UndoRedo
|
||||
{
|
||||
public class SelectShapesAction : IAction
|
||||
{
|
||||
public string? Label => "Select shapes";
|
||||
|
||||
private readonly IReadOnlyCollection<ShapeViewModel> _nodes;
|
||||
private readonly CanvasViewModel _canvas;
|
||||
|
||||
public SelectShapesAction(IReadOnlyCollection<ShapeViewModel> nodes, CanvasViewModel canvas)
|
||||
{
|
||||
_nodes = nodes;
|
||||
_canvas = canvas;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
_canvas.SelectedShapes.AddRange(_nodes);
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
_canvas.SelectedShapes.RemoveRange(_nodes);
|
||||
}
|
||||
|
||||
public override string? ToString()
|
||||
=> Label;
|
||||
}
|
||||
|
||||
public class DeselectShapesAction : IAction
|
||||
{
|
||||
public string? Label => "Deselect shapes";
|
||||
|
||||
private readonly IReadOnlyCollection<ShapeViewModel> _nodes;
|
||||
private readonly CanvasViewModel _canvas;
|
||||
|
||||
public DeselectShapesAction(IReadOnlyCollection<ShapeViewModel> nodes, CanvasViewModel canvas)
|
||||
{
|
||||
_nodes = nodes;
|
||||
_canvas = canvas;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
_canvas.SelectedShapes.RemoveRange(_nodes);
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
_canvas.SelectedShapes.AddRange(_nodes);
|
||||
}
|
||||
|
||||
public override string? ToString()
|
||||
=> Label;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user