Skip to content

Commit

Permalink
Selection wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Oct 22, 2021
1 parent 0d16ec8 commit 4b174a6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions PixiEditor/Models/DataHolders/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;

namespace PixiEditor.Models.DataHolders
{
Expand Down Expand Up @@ -56,6 +57,37 @@ public void SetSelection(IEnumerable<Coordinates> selection, SelectionType mode)
SelectionLayer.SetPixels(BitmapPixelChanges.FromSingleColoredArray(selection, selectionColor));
}

public void SetSelection(Int32Rect rect, bool isCirclular, SelectionType mode)
{
using SKPaint paint = new()
{
Color = selectionBlue,
BlendMode = SKBlendMode.Src,
Style = SKPaintStyle.StrokeAndFill,
};
switch (mode)
{
case SelectionType.New:
SelectionLayer.Reset();
break;
case SelectionType.Subtract:
paint.Color = SKColors.Transparent;
break;
}

SelectionLayer.DynamicResizeAbsolute(rect.X + rect.Width - 1, rect.Y + rect.Height - 1, rect.X, rect.Y);
if (isCirclular)
{
float cx = rect.X + rect.Width / 2f;
float cy = rect.Y + rect.Height / 2f;
SelectionLayer.LayerBitmap.SkiaSurface.Canvas.DrawOval(cx, cy, rect.Width / 2f, rect.Height / 2f, paint);
}
else
{
SelectionLayer.LayerBitmap.SkiaSurface.Canvas.DrawRect(rect.X, rect.Y, rect.Width, rect.Height, paint);
}
}

public void Clear()
{
SelectionLayer.Reset();
Expand Down

0 comments on commit 4b174a6

Please sign in to comment.