Skip to content

Commit

Permalink
LineTool WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Oct 9, 2021
1 parent c612fc7 commit 7d2c0e4
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions PixiEditor/Models/Tools/Tools/LineTool.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PixiEditor.Helpers.Extensions;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Enums;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using PixiEditor.Models.Tools.ToolSettings.Settings;
using PixiEditor.Models.Tools.ToolSettings.Toolbars;
using SkiaSharp;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;

namespace PixiEditor.Models.Tools.Tools
{
Expand Down Expand Up @@ -48,14 +48,35 @@ public override void OnKeyUp(KeyEventArgs e)

public override void Use(Layer layer, List<Coordinates> coordinates, SKColor color)
{
layer.DynamicResize(coordinates.Max(x => x.X), coordinates.Max(x => x.Y), coordinates.Min(x => x.X), coordinates.Min(x => x.Y));

CreateLine(
layer, color,
coordinates,
Toolbar.GetSetting<SizeSetting>("ToolSize").Value,
CapType.Square,
CapType.Square);
int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;

DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);

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())
{
int x = fixedCoordinates.Coords1.X;
int y = fixedCoordinates.Coords1.Y;
int x1 = fixedCoordinates.Coords2.X;
int y1 = fixedCoordinates.Coords2.Y;


paint.StrokeWidth = thickness;
paint.Style = SKPaintStyle.Stroke;
paint.Color = color;
layer.LayerBitmap.SkiaSurface.Canvas.DrawLine(x, y, x1, y1, paint);
}
layer.InvokeLayerBitmapChange(dirtyRect);
}

public List<Coordinates> CreateLine(Layer layer, SKColor color, Coordinates start, Coordinates end, int thickness)
Expand Down

0 comments on commit 7d2c0e4

Please sign in to comment.