Browse Source

Convert rectangletool to skia

Equbuxu 3 years ago
parent
commit
6d26fa1354

+ 23 - 0
PixiEditor/Helpers/Extensions/Int32RectEx.cs

@@ -27,5 +27,28 @@ namespace PixiEditor.Helpers.Extensions
 
 
             return new Int32Rect(maxX1, maxY1, width, height);
             return new Int32Rect(maxX1, maxY1, width, height);
         }
         }
+
+        public static Int32Rect Expand(this Int32Rect rect, Int32Rect other)
+        {
+            int rectX2 = rect.X + rect.Width;
+            int rectY2 = rect.Y + rect.Height;
+
+            int otherX2 = other.X + other.Width;
+            int otherY2 = other.Y + other.Height;
+
+            int minX1 = Math.Min(rect.X, other.X);
+            int minY1 = Math.Min(rect.Y, other.Y);
+
+            int maxX2 = Math.Max(rectX2, otherX2);
+            int maxY2 = Math.Max(rectY2, otherY2);
+
+            int width = maxX2 - minX1;
+            int height = maxY2 - minY1;
+
+            if (width <= 0 || height <= 0)
+                return Int32Rect.Empty;
+
+            return new Int32Rect(minX1, minY1, width, height);
+        }
     }
     }
 }
 }

+ 3 - 6
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -1,15 +1,11 @@
-using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.DataHolders;
-using PixiEditor.Models.ImageManipulation;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
-using PixiEditor.Models.Undo;
 using SkiaSharp;
 using SkiaSharp;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.Linq;
 using System.Windows.Input;
 using System.Windows.Input;
 
 
 namespace PixiEditor.Models.Controllers
 namespace PixiEditor.Models.Controllers
@@ -92,7 +88,7 @@ namespace PixiEditor.Models.Controllers
             int thickness = sizeSetting != null ? sizeSetting.Value : 1;
             int thickness = sizeSetting != null ? sizeSetting.Value : 1;
 
 
             bool shiftDown = Keyboard.IsKeyDown(Key.LeftShift);
             bool shiftDown = Keyboard.IsKeyDown(Key.LeftShift);
-           
+
             if (shiftDown && tool.UsesShift)
             if (shiftDown && tool.UsesShift)
             {
             {
                 bool mouseInLine = MouseCordsNotInLine(mouseMoveCords, thickness);
                 bool mouseInLine = MouseCordsNotInLine(mouseMoveCords, thickness);
@@ -189,6 +185,7 @@ namespace PixiEditor.Models.Controllers
                 {
                 {
                     Manager.ActiveDocument.GeneratePreviewLayer();
                     Manager.ActiveDocument.GeneratePreviewLayer();
                 }
                 }
+
                 // TODO: Use on preview layer
                 // TODO: Use on preview layer
                 ((BitmapOperationTool)Manager.SelectedTool).Use(
                 ((BitmapOperationTool)Manager.SelectedTool).Use(
                     Manager.ActiveDocument.ActiveLayer,
                     Manager.ActiveDocument.ActiveLayer,

+ 32 - 4
PixiEditor/Models/Controllers/LayerStackRenderer.cs

@@ -15,6 +15,7 @@ namespace PixiEditor.Models.Controllers
     public class LayerStackRenderer : INotifyPropertyChanged, IDisposable
     public class LayerStackRenderer : INotifyPropertyChanged, IDisposable
     {
     {
         private SKPaint BlendingPaint { get; } = new SKPaint() { BlendMode = SKBlendMode.SrcOver };
         private SKPaint BlendingPaint { get; } = new SKPaint() { BlendMode = SKBlendMode.SrcOver };
+        private SKPaint ClearPaint { get; } = new SKPaint() { BlendMode = SKBlendMode.Src, Color = SKColors.Transparent };
 
 
         private ObservableCollection<Layer> layers;
         private ObservableCollection<Layer> layers;
         private LayerStructure structure;
         private LayerStructure structure;
@@ -70,6 +71,7 @@ namespace PixiEditor.Models.Controllers
             finalSurface.Dispose();
             finalSurface.Dispose();
             backingSurface.Dispose();
             backingSurface.Dispose();
             BlendingPaint.Dispose();
             BlendingPaint.Dispose();
+            ClearPaint.Dispose();
             layers.CollectionChanged -= OnLayersChanged;
             layers.CollectionChanged -= OnLayersChanged;
         }
         }
 
 
@@ -91,23 +93,49 @@ namespace PixiEditor.Models.Controllers
 
 
         private void Update(Int32Rect dirtyRectangle)
         private void Update(Int32Rect dirtyRectangle)
         {
         {
-            finalSurface.SkiaSurface.Canvas.Clear();
+            //finalSurface.SkiaSurface.Canvas.Clear();
+
+            dirtyRectangle = dirtyRectangle.Intersect(new Int32Rect(0, 0, finalBitmap.PixelWidth, finalBitmap.PixelHeight));
+            finalSurface.SkiaSurface.Canvas.DrawRect(
+                new SKRect(
+                    dirtyRectangle.X, dirtyRectangle.Y,
+                    dirtyRectangle.X + dirtyRectangle.Width,
+                    dirtyRectangle.Y + dirtyRectangle.Height
+                    ),
+                ClearPaint
+                );
             foreach (var layer in layers)
             foreach (var layer in layers)
             {
             {
                 if (!LayerStructureUtils.GetFinalLayerIsVisible(layer, structure))
                 if (!LayerStructureUtils.GetFinalLayerIsVisible(layer, structure))
                     continue;
                     continue;
                 BlendingPaint.Color = new SKColor(255, 255, 255, (byte)(LayerStructureUtils.GetFinalLayerOpacity(layer, structure) * 255));
                 BlendingPaint.Color = new SKColor(255, 255, 255, (byte)(LayerStructureUtils.GetFinalLayerOpacity(layer, structure) * 255));
+
+                Int32Rect layerRect = new Int32Rect(layer.OffsetX, layer.OffsetY, layer.Width, layer.Height);
+                Int32Rect layerPortion = layerRect.Intersect(dirtyRectangle);
+
+                finalSurface.SkiaSurface.Canvas.DrawImage(
+                    layer.LayerBitmap.SkiaSurface.Snapshot(),
+                    new SKRect(
+                        layerPortion.X - layer.OffsetX,
+                        layerPortion.Y - layer.OffsetY,
+                        layerPortion.X - layer.OffsetX + layerPortion.Width,
+                        layerPortion.Y - layer.OffsetY + layerPortion.Height),
+                    new SKRect(
+                        layerPortion.X,
+                        layerPortion.Y,
+                        layerPortion.X + layerPortion.Width,
+                        layerPortion.Y + layerPortion.Height
+                    ),
+                    BlendingPaint);/*
                 layer.LayerBitmap.SkiaSurface.Draw(
                 layer.LayerBitmap.SkiaSurface.Draw(
                     finalSurface.SkiaSurface.Canvas,
                     finalSurface.SkiaSurface.Canvas,
                     layer.OffsetX,
                     layer.OffsetX,
                     layer.OffsetY,
                     layer.OffsetY,
-                    BlendingPaint);
+                    BlendingPaint);*/
             }
             }
             finalBitmap.Lock();
             finalBitmap.Lock();
             finalSurface.SkiaSurface.Draw(backingSurface.Canvas, 0, 0, Surface.ReplacingPaint);
             finalSurface.SkiaSurface.Draw(backingSurface.Canvas, 0, 0, Surface.ReplacingPaint);
 
 
-            dirtyRectangle = dirtyRectangle.Intersect(new Int32Rect(0, 0, finalBitmap.PixelWidth, finalBitmap.PixelHeight));
-
             finalBitmap.AddDirtyRect(dirtyRectangle);
             finalBitmap.AddDirtyRect(dirtyRectangle);
             finalBitmap.Unlock();
             finalBitmap.Unlock();
         }
         }

+ 55 - 68
PixiEditor/Models/Tools/Tools/MoveTool.cs

@@ -1,5 +1,4 @@
-using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.Controllers;
+using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.ImageManipulation;
 using PixiEditor.Models.ImageManipulation;
@@ -65,33 +64,29 @@ namespace PixiEditor.Models.Tools.Tools
 
 
         public override void AfterAddedUndo(UndoManager undoManager)
         public override void AfterAddedUndo(UndoManager undoManager)
         {

         {

-            //if (currentSelection == null || currentSelection.Length == 0)

-            //{

-            //    return;

-            //}

-

+            //if (currentSelection == null || currentSelection.Length == 0)
+            //{
+            //    return;
+            //}
             //Change changes = undoManager.UndoStack.Peek();

             //Change changes = undoManager.UndoStack.Peek();

-

-            //// Inject to default undo system change custom changes made by this tool

-            //foreach (var item in startPixelColors)

-            //{

-            //    BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);

-            //    BitmapPixelChanges afterMovePixels = BitmapPixelChanges.FromArrays(currentSelection, endPixelColors[item.Key]);

-            //    Guid layerGuid = item.Key;

+            //// Inject to default undo system change custom changes made by this tool
+            //foreach (var item in startPixelColors)
+            //{
+            //    BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
+            //    BitmapPixelChanges afterMovePixels = BitmapPixelChanges.FromArrays(currentSelection, endPixelColors[item.Key]);
+            //    Guid layerGuid = item.Key;
             //    var oldValue = (LayerChange[])changes.OldValue;

             //    var oldValue = (LayerChange[])changes.OldValue;

-

-            //    if (oldValue.Any(x => x.LayerGuid == layerGuid))

-            //    {

-            //        var layer = oldValue.First(x => x.LayerGuid == layerGuid);

-            //        layer.PixelChanges.ChangedPixels.AddRangeOverride(afterMovePixels.ChangedPixels);

-            //        layer.PixelChanges.ChangedPixels

+            //    if (oldValue.Any(x => x.LayerGuid == layerGuid))
+            //    {
+            //        var layer = oldValue.First(x => x.LayerGuid == layerGuid);
+            //        layer.PixelChanges.ChangedPixels.AddRangeOverride(afterMovePixels.ChangedPixels);
+            //        layer.PixelChanges.ChangedPixels
             //            .AddRangeOverride(beforeMovePixels.ChangedPixels);

             //            .AddRangeOverride(beforeMovePixels.ChangedPixels);

-

-            //        ((LayerChange[])changes.NewValue).First(x => x.LayerGuid == layerGuid).PixelChanges.ChangedPixels

-            //            .AddRangeNewOnly(BitmapPixelChanges

+            //        ((LayerChange[])changes.NewValue).First(x => x.LayerGuid == layerGuid).PixelChanges.ChangedPixels
+            //            .AddRangeNewOnly(BitmapPixelChanges
             //                .FromSingleColoredArray(startSelection, SKColors.Transparent)
             //                .FromSingleColoredArray(startSelection, SKColors.Transparent)
-            //                .ChangedPixels);

-            //    }

+            //                .ChangedPixels);
+            //    }
             //}
             //}
         }
         }
 
 
@@ -101,44 +96,40 @@ namespace PixiEditor.Models.Tools.Tools
         {
         {
             if (currentSelection != null && currentSelection.Length == 0)
             if (currentSelection != null && currentSelection.Length == 0)
             {
             {
-                BitmapManager.ActiveDocument.UndoManager.AddUndoChange(new Change(

-                    ApplyOffsets,

-                    new object[] { startingOffsets },

-                    ApplyOffsets,

-                    new object[] { GetOffsets(affectedLayers) },

+                BitmapManager.ActiveDocument.UndoManager.AddUndoChange(new Change(
+                    ApplyOffsets,
+                    new object[] { startingOffsets },
+                    ApplyOffsets,
+                    new object[] { GetOffsets(affectedLayers) },
                     "Move layers"));
                     "Move layers"));
             }
             }
         }
         }
 
 
-        public override void OnStart(Coordinates startPos)

-        {

+        public override void OnStart(Coordinates startPos)
+        {
             ResetSelectionValues(startPos);

             ResetSelectionValues(startPos);

-

-            // Move offset if no selection

-            Document doc = BitmapManager.ActiveDocument;

-            Selection selection = doc.ActiveSelection;

-            if (selection != null && selection.SelectedPoints.Count > 0)

-            {

-                currentSelection = selection.SelectedPoints.ToArray();

-            }

-            else

-            {

-                currentSelection = Array.Empty<Coordinates>();

-            }

-

-            if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)

-            {

-                affectedLayers = doc.Layers.Where(x => x.IsVisible)

-                    .ToArray();

+            // Move offset if no selection
+            Document doc = BitmapManager.ActiveDocument;
+            Selection selection = doc.ActiveSelection;
+            if (selection != null && selection.SelectedPoints.Count > 0)
+            {
+                currentSelection = selection.SelectedPoints.ToArray();
+            }
+            else
+            {
+                currentSelection = Array.Empty<Coordinates>();
             }

             }

-            else

-            {

-                affectedLayers = doc.Layers.Where(x => x.IsActive && doc.GetFinalLayerIsVisible(x)).ToArray();

+            if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)
+            {
+                affectedLayers = doc.Layers.Where(x => x.IsVisible).ToArray();
+            }
+            else
+            {
+                affectedLayers = doc.Layers.Where(x => x.IsActive && doc.GetFinalLayerIsVisible(x)).ToArray();
             }

             }

-

-            startSelection = currentSelection;

-            startPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, startSelection);

-            startingOffsets = GetOffsets(affectedLayers);

+            startSelection = currentSelection;
+            startPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, startSelection);
+            startingOffsets = GetOffsets(affectedLayers);
         }
         }
 
 
         public override void Use(Layer layer, List<Coordinates> mouseMove, SKColor color)
         public override void Use(Layer layer, List<Coordinates> mouseMove, SKColor color)
@@ -170,21 +161,18 @@ namespace PixiEditor.Models.Tools.Tools
 
 
             // return result;
             // return result;
         }

         }

-

         public BitmapPixelChanges MoveSelection(Layer layer, IEnumerable<Coordinates> mouseMove)
         public BitmapPixelChanges MoveSelection(Layer layer, IEnumerable<Coordinates> mouseMove)
         {
         {
             Coordinates end = mouseMove.First();
             Coordinates end = mouseMove.First();
 
 
             currentSelection = TranslateSelection(end);
             currentSelection = TranslateSelection(end);
-            if (updateViewModelSelection)

-            {

-                ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(currentSelection, SelectionType.New);

-            }
-

+            if (updateViewModelSelection)
+            {
+                ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
+            }

             lastMouseMove = end;
             lastMouseMove = end;
             return BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer.LayerGuid]);
             return BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer.LayerGuid]);
         }

         }

-

         private void ApplyOffsets(object[] parameters)
         private void ApplyOffsets(object[] parameters)
         {
         {
             Dictionary<Guid, Thickness> offsets = (Dictionary<Guid, Thickness>)parameters[0];
             Dictionary<Guid, Thickness> offsets = (Dictionary<Guid, Thickness>)parameters[0];
@@ -209,11 +197,10 @@ namespace PixiEditor.Models.Tools.Tools
 
 
         private BitmapPixelChanges RemoveTransparentPixels(BitmapPixelChanges pixels)
         private BitmapPixelChanges RemoveTransparentPixels(BitmapPixelChanges pixels)
         {
         {
-            foreach (var item in pixels.ChangedPixels.Where(x => x.Value.Alpha == 0).ToList())

-            {

-                pixels.ChangedPixels.Remove(item.Key);

-            }

-

+            foreach (var item in pixels.ChangedPixels.Where(x => x.Value.Alpha == 0).ToList())
+            {
+                pixels.ChangedPixels.Remove(item.Key);
+            }
             return pixels;
             return pixels;
         }
         }
 
 

+ 34 - 72
PixiEditor/Models/Tools/Tools/RectangleTool.cs

@@ -1,18 +1,11 @@
-using System;
-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.Helpers.Extensions;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
 using SkiaSharp;
 using SkiaSharp;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.Linq;
+using System.Windows;
 using System.Windows.Input;
 using System.Windows.Input;
 
 
 namespace PixiEditor.Models.Tools.Tools
 namespace PixiEditor.Models.Tools.Tools
@@ -47,85 +40,54 @@ namespace PixiEditor.Models.Tools.Tools
         public override void Use(Layer layer, List<Coordinates> coordinates, SKColor color)
         public override void Use(Layer layer, List<Coordinates> coordinates, SKColor color)
         {
         {
             int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
             int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
-            CreateRectangle(layer, color, coordinates, thickness);
+            SKColor? fillColor = null;
             if (Toolbar.GetSetting<BoolSetting>("Fill").Value)
             if (Toolbar.GetSetting<BoolSetting>("Fill").Value)
             {
             {
-                Color fillColor = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
-                DrawRectangleFill(layer, color, coordinates[^1], coordinates[0], thickness);
+                var temp = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
+                fillColor = new SKColor(temp.R, temp.G, temp.B, temp.A);
             }
             }
+            CreateRectangle(layer, color, fillColor, coordinates, thickness);
         }
         }
 
 
-        public void CreateRectangle(Layer layer, SKColor color, List<Coordinates> coordinates, int thickness)
+        public void CreateRectangle(Layer layer, SKColor color, SKColor? fillColor, List<Coordinates> coordinates, int thickness)
         {
         {
             DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
             DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
 
 
-            //using var ctx = layer.LayerBitmap.GetBitmapContext();
-
-            DrawRectangle(layer, color, fixedCoordinates);
-
-            for (int i = 1; i < (int)Math.Floor(thickness / 2f) + 1; i++)
-            {
-                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)));
-            }
-
-            for (int i = 1; i < (int)Math.Ceiling(thickness / 2f); i++)
+            int halfThickness = (int)Math.Ceiling(thickness / 2.0);
+            Int32Rect dirtyRect = new Int32Rect(
+                fixedCoordinates.Coords1.X - halfThickness,
+                fixedCoordinates.Coords1.Y - halfThickness,
+                fixedCoordinates.Coords2.X + halfThickness * 2 - fixedCoordinates.Coords1.X,
+                fixedCoordinates.Coords2.Y + halfThickness * 2 - fixedCoordinates.Coords1.Y);
+            Int32Rect curLayerRect = new(layer.OffsetX, layer.OffsetY, layer.Width, layer.Height);
+            Int32Rect expanded = dirtyRect.Expand(curLayerRect);
+            layer.DynamicResize(expanded.X + expanded.Width - 1, expanded.Y + expanded.Height - 1, expanded.X, expanded.Y);
+
+            using (SKPaint paint = new SKPaint())
             {
             {
-                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)));
-            }
-        }
-
-        public void CreateRectangle(Layer layer, SKColor color, Coordinates start, Coordinates end, int thickness)
-        {
-            CreateRectangle(layer, color, new() { end, start }, thickness);
-        }
-
-        public void DrawRectangleFill(Layer layer, SKColor color, Coordinates start, Coordinates end, int thickness)
-        {
-            int offset = (int)Math.Ceiling(thickness / 2f);
-            DoubleCords fixedCords = CalculateCoordinatesForShapeRotation(start, end);
+                int x = fixedCoordinates.Coords1.X - layer.OffsetX;
+                int y = fixedCoordinates.Coords1.Y - layer.OffsetY;
+                int w = fixedCoordinates.Coords2.X - fixedCoordinates.Coords1.X;
+                int h = fixedCoordinates.Coords2.Y - fixedCoordinates.Coords1.Y;
 
 
-            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;
-            }
-
-            int i = 0;
-            for (int y = 0; y < height; y++)
-            {
-                for (int x = 0; x < width; x++)
+                if (fillColor.HasValue)
                 {
                 {
-                    layer.SetPixel(new Coordinates(innerCords.Coords1.X + x, innerCords.Coords1.Y + y), color);
-                    i++;
+                    paint.Color = fillColor.Value;
+                    paint.Style = SKPaintStyle.StrokeAndFill;
+                    layer.LayerBitmap.SkiaSurface.Canvas.DrawRect(x, y, w, h, paint);
                 }
                 }
+
+                paint.StrokeWidth = thickness;
+                paint.Style = SKPaintStyle.Stroke;
+                paint.Color = color;
+                layer.LayerBitmap.SkiaSurface.Canvas.DrawRect(x, y, w, h, paint);
             }
             }
+            layer.InvokeLayerBitmapChange(dirtyRect);
         }
         }
 
 
-        private void DrawRectangle(Layer layer, SKColor color, DoubleCords coordinates)
+        public void CreateRectangle(Layer layer, SKColor color, SKColor? fillColor, Coordinates start, Coordinates end, int thickness)
         {
         {
-            for (int i = coordinates.Coords1.X; i < coordinates.Coords2.X + 1; i++)
-            {
-                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++)
-            {
-                layer.SetPixel(new Coordinates(coordinates.Coords1.X, i), color);
-                layer.SetPixel(new Coordinates(coordinates.Coords2.X, i), color);
-            }
+            CreateRectangle(layer, color, fillColor, new() { end, start }, thickness);
         }
         }
     }
     }
 }
 }