|
@@ -1,4 +1,5 @@
|
|
|
-using PixiEditor.Models.Layers;
|
|
|
+using PixiEditor.Helpers.Extensions;
|
|
|
+using PixiEditor.Models.Layers;
|
|
|
using PixiEditor.Models.Position;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -19,33 +20,42 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
|
|
|
{
|
|
|
- return BitmapPixelChanges.FromSingleColoredArray(CreateRectangle(coordinates, 1), color);
|
|
|
+ int thickness = (int)Toolbar.GetSetting("ToolSize").Value;
|
|
|
+ BitmapPixelChanges pixels = BitmapPixelChanges.FromSingleColoredArray(CreateRectangle(coordinates, thickness), color);
|
|
|
+ if ((bool)Toolbar.GetSetting("Fill").Value)
|
|
|
+ {
|
|
|
+ Color fillColor = (Color)Toolbar.GetSetting("FillColor").Value;
|
|
|
+ pixels.ChangedPixels.AddRangeOverride(
|
|
|
+ BitmapPixelChanges.FromSingleColoredArray
|
|
|
+ (CalculateFillForRectangle(coordinates[^1], coordinates[0], thickness), fillColor).ChangedPixels);
|
|
|
+ }
|
|
|
+ return pixels;
|
|
|
}
|
|
|
|
|
|
public Coordinates[] CreateRectangle(Coordinates[] coordinates, int thickness)
|
|
|
{
|
|
|
DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
|
|
|
List<Coordinates> output = new List<Coordinates>();
|
|
|
- Coordinates[] rectangle = CalculateRectanglePoints(fixedCoordinates, Filled);
|
|
|
+ Coordinates[] rectangle = CalculateRectanglePoints(fixedCoordinates);
|
|
|
output.AddRange(rectangle);
|
|
|
|
|
|
for (int i = 1; i < (int)Math.Floor(thickness / 2f) + 1; i++)
|
|
|
{
|
|
|
output.AddRange(CalculateRectanglePoints(new DoubleCords(
|
|
|
new Coordinates(fixedCoordinates.Coords1.X - i, fixedCoordinates.Coords1.Y - i),
|
|
|
- new Coordinates(fixedCoordinates.Coords2.X + i, fixedCoordinates.Coords2.Y + i)), false));
|
|
|
+ new Coordinates(fixedCoordinates.Coords2.X + i, fixedCoordinates.Coords2.Y + i))));
|
|
|
}
|
|
|
for (int i = 1; i < (int)Math.Ceiling(thickness / 2f); i++)
|
|
|
{
|
|
|
output.AddRange(CalculateRectanglePoints(new DoubleCords(
|
|
|
new Coordinates(fixedCoordinates.Coords1.X + i, fixedCoordinates.Coords1.Y + i),
|
|
|
- new Coordinates(fixedCoordinates.Coords2.X - i, fixedCoordinates.Coords2.Y - i)), false));
|
|
|
+ new Coordinates(fixedCoordinates.Coords2.X - i, fixedCoordinates.Coords2.Y - i))));
|
|
|
}
|
|
|
|
|
|
return output.Distinct().ToArray();
|
|
|
}
|
|
|
|
|
|
- private Coordinates[] CalculateRectanglePoints(DoubleCords coordinates, bool filled)
|
|
|
+ private Coordinates[] CalculateRectanglePoints(DoubleCords coordinates)
|
|
|
{
|
|
|
List<Coordinates> finalCoordinates = new List<Coordinates>();
|
|
|
|
|
@@ -59,29 +69,35 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
finalCoordinates.Add(new Coordinates(coordinates.Coords1.X, i));
|
|
|
finalCoordinates.Add(new Coordinates(coordinates.Coords2.X, i));
|
|
|
}
|
|
|
-
|
|
|
- if (filled)
|
|
|
- {
|
|
|
- finalCoordinates.AddRange(CalculatedFillForRectangle(coordinates));
|
|
|
- }
|
|
|
return finalCoordinates.ToArray();
|
|
|
}
|
|
|
|
|
|
- private Coordinates[] CalculatedFillForRectangle(DoubleCords cords)
|
|
|
+ private Coordinates[] CalculateFillForRectangle(Coordinates start, Coordinates end, int thickness)
|
|
|
{
|
|
|
- int height = cords.Coords2.Y - cords.Coords1.Y;
|
|
|
- int width = cords.Coords2.X - cords.Coords1.X;
|
|
|
+ int offset = (int)Math.Ceiling(thickness / 2f);
|
|
|
+ DoubleCords fixedCords = CalculateCoordinatesForShapeRotation(start, end);
|
|
|
+
|
|
|
+ DoubleCords innerCords = new DoubleCords
|
|
|
+ {
|
|
|
+ Coords1 = new Coordinates(fixedCords.Coords1.X + offset, fixedCords.Coords1.Y + offset),
|
|
|
+ Coords2 = new Coordinates(fixedCords.Coords2.X - (offset - 1), fixedCords.Coords2.Y - (offset - 1))
|
|
|
+ };
|
|
|
+
|
|
|
+ int height = innerCords.Coords2.Y - innerCords.Coords1.Y;
|
|
|
+ int width = innerCords.Coords2.X - innerCords.Coords1.X;
|
|
|
+
|
|
|
+ if (height < 1 || width < 1) return Array.Empty<Coordinates>();
|
|
|
Coordinates[] filledCoordinates = new Coordinates[width * height];
|
|
|
int i = 0;
|
|
|
for (int y = 0; y < height; y++)
|
|
|
{
|
|
|
for (int x = 0; x < width; x++)
|
|
|
{
|
|
|
- filledCoordinates[i] = new Coordinates(cords.Coords1.X + x, cords.Coords1.Y + y);
|
|
|
+ filledCoordinates[i] = new Coordinates(innerCords.Coords1.X + x, innerCords.Coords1.Y + y);
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
- return filledCoordinates;
|
|
|
+ return filledCoordinates.Distinct().ToArray();
|
|
|
}
|
|
|
}
|
|
|
}
|