|
@@ -1,6 +1,7 @@
|
|
using PixiEditor.Models.Controllers;
|
|
using PixiEditor.Models.Controllers;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Position;
|
|
using PixiEditor.Models.Position;
|
|
|
|
+using PixiEditor.Models.Tools.Brushes;
|
|
using PixiEditor.Models.Tools.ToolSettings.Settings;
|
|
using PixiEditor.Models.Tools.ToolSettings.Settings;
|
|
using PixiEditor.Models.Tools.ToolSettings.Toolbars;
|
|
using PixiEditor.Models.Tools.ToolSettings.Toolbars;
|
|
using SkiaSharp;
|
|
using SkiaSharp;
|
|
@@ -25,6 +26,10 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
private BitmapManager BitmapManager { get; }
|
|
private BitmapManager BitmapManager { get; }
|
|
|
|
|
|
|
|
+ private Dictionary<int, CustomBrush> _customBrushes = new Dictionary<int, CustomBrush>();
|
|
|
|
+
|
|
|
|
+ private bool _drawCustomBrush = false;
|
|
|
|
+
|
|
public PenTool(BitmapManager bitmapManager)
|
|
public PenTool(BitmapManager bitmapManager)
|
|
{
|
|
{
|
|
Cursor = Cursors.Pen;
|
|
Cursor = Cursors.Pen;
|
|
@@ -36,11 +41,16 @@ namespace PixiEditor.Models.Tools.Tools
|
|
BitmapManager = bitmapManager;
|
|
BitmapManager = bitmapManager;
|
|
paint.BlendMode = SKBlendMode.Src;
|
|
paint.BlendMode = SKBlendMode.Src;
|
|
lineTool = new LineTool();
|
|
lineTool = new LineTool();
|
|
|
|
+ lineTool.AutomaticallyResizeCanvas = AutomaticallyResizeCanvas;
|
|
|
|
+ _customBrushes.Add(1, new PointBrush());
|
|
|
|
+ _customBrushes.Add(3, new CrossBrush());
|
|
}
|
|
}
|
|
|
|
|
|
public override string Tooltip => "Standard brush. (B)";
|
|
public override string Tooltip => "Standard brush. (B)";
|
|
public override bool UsesShift => false;
|
|
public override bool UsesShift => false;
|
|
|
|
|
|
|
|
+ public bool AutomaticallyResizeCanvas { get; set; } = true;
|
|
|
|
+
|
|
public override void OnRecordingLeftMouseDown(MouseEventArgs e)
|
|
public override void OnRecordingLeftMouseDown(MouseEventArgs e)
|
|
{
|
|
{
|
|
base.OnRecordingLeftMouseDown(e);
|
|
base.OnRecordingLeftMouseDown(e);
|
|
@@ -52,7 +62,10 @@ 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)
|
|
{
|
|
{
|
|
Coordinates startingCords = coordinates.Count > 1 ? coordinates[1] : coordinates[0];
|
|
Coordinates startingCords = coordinates.Count > 1 ? coordinates[1] : coordinates[0];
|
|
- layer.DynamicResizeAbsolute(coordinates.Max(x => x.X), coordinates.Max(x => x.Y), coordinates.Min(x => x.X), coordinates.Min(x => x.Y));
|
|
|
|
|
|
+ if (AutomaticallyResizeCanvas)
|
|
|
|
+ {
|
|
|
|
+ layer.DynamicResizeAbsolute(coordinates.Max(x => x.X), coordinates.Max(x => x.Y), coordinates.Min(x => x.X), coordinates.Min(x => x.Y));
|
|
|
|
+ }
|
|
Draw(
|
|
Draw(
|
|
layer,
|
|
layer,
|
|
startingCords,
|
|
startingCords,
|
|
@@ -70,9 +83,24 @@ namespace PixiEditor.Models.Tools.Tools
|
|
SKBlendMode blendMode = SKBlendMode.Src)
|
|
SKBlendMode blendMode = SKBlendMode.Src)
|
|
{
|
|
{
|
|
|
|
|
|
- SKStrokeCap cap = toolSize == 1 || toolSize == 3 ? SKStrokeCap.Square : SKStrokeCap.Round;
|
|
|
|
|
|
+ SKStrokeCap cap = SKStrokeCap.Round;
|
|
|
|
+ _drawCustomBrush = _customBrushes.ContainsKey(toolSize);
|
|
|
|
+ CustomBrush customBrush = null;
|
|
|
|
+ paint.Color = color;
|
|
|
|
+
|
|
|
|
+ if (_drawCustomBrush)
|
|
|
|
+ {
|
|
|
|
+ cap = SKStrokeCap.Butt;
|
|
|
|
+ customBrush = _customBrushes[toolSize];
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!pixelPerfect)
|
|
if (!pixelPerfect)
|
|
{
|
|
{
|
|
|
|
+ if(_drawCustomBrush)
|
|
|
|
+ {
|
|
|
|
+ DrawCustomBrush(layer, latestCords, customBrush);
|
|
|
|
+ }
|
|
|
|
+
|
|
lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, cap);
|
|
lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, cap);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -84,6 +112,11 @@ namespace PixiEditor.Models.Tools.Tools
|
|
confirmedPixels.Add(latestCords);
|
|
confirmedPixels.Add(latestCords);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (_drawCustomBrush)
|
|
|
|
+ {
|
|
|
|
+ DrawCustomBrush(layer, latestCords, customBrush);
|
|
|
|
+ }
|
|
|
|
+
|
|
lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, cap);
|
|
lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, cap);
|
|
SetPixelToCheck(LineTool.GetBresenhamLine(startingCoords, latestCords));
|
|
SetPixelToCheck(LineTool.GetBresenhamLine(startingCoords, latestCords));
|
|
|
|
|
|
@@ -108,8 +141,16 @@ namespace PixiEditor.Models.Tools.Tools
|
|
}
|
|
}
|
|
|
|
|
|
lastChangedPixel = latestCords;
|
|
lastChangedPixel = latestCords;
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void DrawCustomBrush(Layer layer, Coordinates latestCords, CustomBrush customBrush)
|
|
|
|
+ {
|
|
|
|
+ layer.LayerBitmap.SkiaSurface.Canvas.DrawPoints(
|
|
|
|
+ SKPointMode.Points,
|
|
|
|
+ customBrush.GetAtPoint(latestCords, layer.OffsetX, layer.OffsetY),
|
|
|
|
+ paint);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void MovePixelsToCheck(byte alpha)
|
|
private void MovePixelsToCheck(byte alpha)
|
|
{
|
|
{
|
|
if (alpha != 0)
|
|
if (alpha != 0)
|
|
@@ -170,5 +211,10 @@ namespace PixiEditor.Models.Tools.Tools
|
|
layer.InvokeLayerBitmapChange(dirtyRect);
|
|
layer.InvokeLayerBitmapChange(dirtyRect);
|
|
return alpha;
|
|
return alpha;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ internal void Draw(Layer previewLayer, object zero1, object zero2, SKColor highlightColor, int toolSize)
|
|
|
|
+ {
|
|
|
|
+ throw new NotImplementedException();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|