Skip to content

Commit

Permalink
Theoretically, pixel-perfect should work, but it doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Nov 20, 2021
1 parent b4bca30 commit 73e51a5
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions PixiEditor/Models/Tools/Tools/PenTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PenTool : ShapeTool
private SKPaint paint = new SKPaint() { Style = SKPaintStyle.Stroke };
private Coordinates[] lastChangedPixels = new Coordinates[3];
private byte changedPixelsindex;
private Coordinates lastChangedPixel = new Coordinates(-1, -1);

private BitmapManager BitmapManager { get; }

Expand Down Expand Up @@ -76,31 +77,36 @@ public override void Use(Layer layer, List<Coordinates> coordinates, SKColor col
return;
}

if (previewLayer != null && previewLayer.GetPixelWithOffset(latestCords.X, latestCords.Y).Alpha > 0)
if (latestCords != lastChangedPixel)
{
confirmedPixels.Add(latestCords);
}

lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, cap);
SetPixelToCheck(LineTool.GetBresenhamLine(startingCoords, latestCords));
if (previewLayer != null && previewLayer.GetPixelWithOffset(latestCords.X, latestCords.Y).Alpha > 0)
{
confirmedPixels.Add(latestCords);
}

if (changedPixelsindex == 2)
{
byte alpha = ApplyPixelPerfectToPixels(
layer,
lastChangedPixels[0],
lastChangedPixels[1],
lastChangedPixels[2],
color,
toolSize,
paint);
lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, cap);
SetPixelToCheck(LineTool.GetBresenhamLine(startingCoords, latestCords));

MovePixelsToCheck(alpha);
if (changedPixelsindex == 2)
{
byte alpha = ApplyPixelPerfectToPixels(
layer,
lastChangedPixels[0],
lastChangedPixels[1],
lastChangedPixels[2],
color,
toolSize,
paint);

MovePixelsToCheck(alpha);

return;
}

return;
changedPixelsindex += changedPixelsindex >= 2 ? (byte)0 : (byte)1;
}

changedPixelsindex += changedPixelsindex >= 2 ? (byte)0 : (byte)1;
lastChangedPixel = latestCords;
}

private void MovePixelsToCheck(byte alpha)
Expand Down

0 comments on commit 73e51a5

Please sign in to comment.