|
@@ -19,8 +19,9 @@ namespace PixiEditor.Models.Tools.Tools
|
|
{
|
|
{
|
|
public class SelectTool : ReadonlyTool
|
|
public class SelectTool : ReadonlyTool
|
|
{
|
|
{
|
|
|
|
+ private readonly RectangleTool rectangleTool = new RectangleTool();
|
|
|
|
+ private readonly CircleTool circleTool = new CircleTool();
|
|
private IEnumerable<Coordinates> oldSelectedPoints;
|
|
private IEnumerable<Coordinates> oldSelectedPoints;
|
|
- private RectangleTool rectangleTool = new RectangleTool();
|
|
|
|
|
|
|
|
private static Selection ActiveSelection { get => ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection; }
|
|
private static Selection ActiveSelection { get => ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection; }
|
|
|
|
|
|
@@ -53,7 +54,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
public override void Use(Coordinates[] pixels)
|
|
public override void Use(Coordinates[] pixels)
|
|
{
|
|
{
|
|
- Select(pixels);
|
|
|
|
|
|
+ Select(pixels, Toolbar.GetEnumSetting<SelectionShape>("SelectShape").Value);
|
|
}
|
|
}
|
|
|
|
|
|
public IEnumerable<Coordinates> GetRectangleSelectionForPoints(Coordinates start, Coordinates end)
|
|
public IEnumerable<Coordinates> GetRectangleSelectionForPoints(Coordinates start, Coordinates end)
|
|
@@ -63,6 +64,14 @@ namespace PixiEditor.Models.Tools.Tools
|
|
return selection;
|
|
return selection;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public IEnumerable<Coordinates> GetCircleSelectionForPoints(Coordinates start, Coordinates end)
|
|
|
|
+ {
|
|
|
|
+ DoubleCords fixedCoordinates = ShapeTool.CalculateCoordinatesForShapeRotation(start, end);
|
|
|
|
+ List<Coordinates> selection = circleTool.CreateEllipse(fixedCoordinates.Coords1, fixedCoordinates.Coords2, 1).ToList();
|
|
|
|
+ selection.AddRange(circleTool.CalculateFillForEllipse(selection));
|
|
|
|
+ return selection;
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets coordinates of every pixel in root layer.
|
|
/// Gets coordinates of every pixel in root layer.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -81,9 +90,23 @@ namespace PixiEditor.Models.Tools.Tools
|
|
return GetRectangleSelectionForPoints(new Coordinates(0, 0), new Coordinates(document.Width - 1, document.Height - 1));
|
|
return GetRectangleSelectionForPoints(new Coordinates(0, 0), new Coordinates(document.Width - 1, document.Height - 1));
|
|
}
|
|
}
|
|
|
|
|
|
- private void Select(Coordinates[] pixels)
|
|
|
|
|
|
+ private void Select(Coordinates[] pixels, SelectionShape shape)
|
|
{
|
|
{
|
|
- IEnumerable<Coordinates> selection = GetRectangleSelectionForPoints(pixels[^1], pixels[0]);
|
|
|
|
|
|
+ IEnumerable<Coordinates> selection;
|
|
|
|
+
|
|
|
|
+ if (shape == SelectionShape.Circle)
|
|
|
|
+ {
|
|
|
|
+ selection = GetCircleSelectionForPoints(pixels[^1], pixels[0]);
|
|
|
|
+ }
|
|
|
|
+ else if (shape == SelectionShape.Rectangle)
|
|
|
|
+ {
|
|
|
|
+ selection = GetRectangleSelectionForPoints(pixels[^1], pixels[0]);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ throw new NotImplementedException($"Selection shape '{shape}' has not been implemented");
|
|
|
|
+ }
|
|
|
|
+
|
|
ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(selection, SelectionType);
|
|
ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(selection, SelectionType);
|
|
}
|
|
}
|
|
}
|
|
}
|