|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
+using System.Windows.Media.Imaging;
|
|
|
using PixiEditor.Helpers.Extensions;
|
|
|
using PixiEditor.Models.DataHolders;
|
|
|
using PixiEditor.Models.Layers;
|
|
@@ -41,48 +42,43 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
public override void Use(Layer layer, List<Coordinates> coordinates, Color color)
|
|
|
{
|
|
|
int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
|
|
|
- BitmapPixelChanges pixels =
|
|
|
- BitmapPixelChanges.FromSingleColoredArray(CreateRectangle(coordinates, thickness), color);
|
|
|
+ CreateRectangle(layer, color, coordinates, thickness);
|
|
|
if (Toolbar.GetSetting<BoolSetting>("Fill").Value)
|
|
|
{
|
|
|
Color fillColor = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
|
|
|
- pixels.ChangedPixels.AddRangeOverride(
|
|
|
- BitmapPixelChanges.FromSingleColoredArray(
|
|
|
- CalculateFillForRectangle(coordinates[^1], coordinates[0], thickness), fillColor)
|
|
|
- .ChangedPixels);
|
|
|
+ DrawRectangleFill(layer, color, coordinates[^1], coordinates[0], thickness);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public IEnumerable<Coordinates> CreateRectangle(List<Coordinates> coordinates, int thickness)
|
|
|
+ public void CreateRectangle(Layer layer, Color color, List<Coordinates> coordinates, int thickness)
|
|
|
{
|
|
|
DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
|
|
|
- List<Coordinates> output = new List<Coordinates>();
|
|
|
- IEnumerable<Coordinates> rectangle = CalculateRectanglePoints(fixedCoordinates);
|
|
|
- output.AddRange(rectangle);
|
|
|
+
|
|
|
+ using var ctx = layer.LayerBitmap.GetBitmapContext();
|
|
|
+
|
|
|
+ DrawRectangle(layer, color, fixedCoordinates);
|
|
|
|
|
|
for (int i = 1; i < (int)Math.Floor(thickness / 2f) + 1; i++)
|
|
|
{
|
|
|
- output.AddRange(CalculateRectanglePoints(new DoubleCords(
|
|
|
+ DrawRectangle(layer, color, new DoubleCords(
|
|
|
new Coordinates(fixedCoordinates.Coords1.X - i, fixedCoordinates.Coords1.Y - i),
|
|
|
- new Coordinates(fixedCoordinates.Coords2.X + i, fixedCoordinates.Coords2.Y + i))));
|
|
|
+ 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(
|
|
|
+ DrawRectangle(layer, color, new DoubleCords(
|
|
|
new Coordinates(fixedCoordinates.Coords1.X + i, fixedCoordinates.Coords1.Y + i),
|
|
|
- new Coordinates(fixedCoordinates.Coords2.X - i, fixedCoordinates.Coords2.Y - i))));
|
|
|
+ new Coordinates(fixedCoordinates.Coords2.X - i, fixedCoordinates.Coords2.Y - i)));
|
|
|
}
|
|
|
-
|
|
|
- return output.Distinct();
|
|
|
}
|
|
|
|
|
|
- public IEnumerable<Coordinates> CreateRectangle(Coordinates start, Coordinates end, int thickness)
|
|
|
+ public void CreateRectangle(Layer layer, Color color, Coordinates start, Coordinates end, int thickness)
|
|
|
{
|
|
|
- return CreateRectangle(new() { end, start }, thickness);
|
|
|
+ CreateRectangle(layer, color, new() { end, start }, thickness);
|
|
|
}
|
|
|
|
|
|
- public IEnumerable<Coordinates> CalculateFillForRectangle(Coordinates start, Coordinates end, int thickness)
|
|
|
+ public void DrawRectangleFill(Layer layer, Color color, Coordinates start, Coordinates end, int thickness)
|
|
|
{
|
|
|
int offset = (int)Math.Ceiling(thickness / 2f);
|
|
|
DoubleCords fixedCords = CalculateCoordinatesForShapeRotation(start, end);
|
|
@@ -98,40 +94,33 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
if (height < 1 || width < 1)
|
|
|
{
|
|
|
- return Array.Empty<Coordinates>();
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- 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(innerCords.Coords1.X + x, innerCords.Coords1.Y + y);
|
|
|
+ layer.SetPixel(new Coordinates(innerCords.Coords1.X + x, innerCords.Coords1.Y + y), color);
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return filledCoordinates.Distinct();
|
|
|
}
|
|
|
|
|
|
- private IEnumerable<Coordinates> CalculateRectanglePoints(DoubleCords coordinates)
|
|
|
+ private void DrawRectangle(Layer layer, Color color, DoubleCords coordinates)
|
|
|
{
|
|
|
- List<Coordinates> finalCoordinates = new List<Coordinates>();
|
|
|
-
|
|
|
for (int i = coordinates.Coords1.X; i < coordinates.Coords2.X + 1; i++)
|
|
|
{
|
|
|
- finalCoordinates.Add(new Coordinates(i, coordinates.Coords1.Y));
|
|
|
- finalCoordinates.Add(new Coordinates(i, coordinates.Coords2.Y));
|
|
|
+ layer.SetPixel(new Coordinates(i, coordinates.Coords1.Y), color);
|
|
|
+ layer.SetPixel(new Coordinates(i, coordinates.Coords2.Y), color);
|
|
|
}
|
|
|
|
|
|
for (int i = coordinates.Coords1.Y + 1; i <= coordinates.Coords2.Y - 1; i++)
|
|
|
{
|
|
|
- finalCoordinates.Add(new Coordinates(coordinates.Coords1.X, i));
|
|
|
- finalCoordinates.Add(new Coordinates(coordinates.Coords2.X, i));
|
|
|
+ layer.SetPixel(new Coordinates(coordinates.Coords1.X, i), color);
|
|
|
+ layer.SetPixel(new Coordinates(coordinates.Coords2.X, i), color);
|
|
|
}
|
|
|
-
|
|
|
- return finalCoordinates;
|
|
|
}
|
|
|
}
|
|
|
}
|