Browse Source

Core finished :D

flabbet 2 years ago
parent
commit
fbd9b5309a

+ 1 - 1
src/ChunkyImageLib/Operations/ClearPathOperation.cs

@@ -14,7 +14,7 @@ internal class ClearPathOperation : IDrawOperation
     public ClearPathOperation(VectorPath path, RectI? pathTightBounds = null)
     {
         this.path = new VectorPath(path);
-        this.pathTightBounds = (RectI)(pathTightBounds ?? path.TightBounds);
+        this.pathTightBounds = (pathTightBounds ?? (RectI)path.TightBounds);
     }
 
     public void DrawOnChunk(Chunk chunk, VecI chunkPos)

+ 2 - 2
src/ChunkyImageLib/Operations/EllipseOperation.cs

@@ -36,11 +36,11 @@ internal class EllipseOperation : IDrawOperation
         if (strokeWidth == 1)
         {
             var ellipseList = EllipseHelper.GenerateEllipseFromRect(location);
-            ellipse = ellipseList.Select(a => (Point)a).ToArray();
+            ellipse = ellipseList.Select(a => new Point(a)).ToArray();
             if (fillColor.A > 0 || paint.BlendMode != BlendMode.SrcOver)
             {
                 (var fill, ellipseFillRect) = EllipseHelper.SplitEllipseIntoRegions(ellipseList, location);
-                ellipseFill = fill.Select(a => (Point)a).ToArray();
+                ellipseFill = fill.Select(a => new Point(a)).ToArray();
             }
         }
         else

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changes/Drawing/ClearSelectedArea_Change.cs

@@ -32,7 +32,7 @@ internal class ClearSelectedArea_Change : Change
         var image = DrawingChangeHelper.GetTargetImageOrThrow(target, memberGuid, drawOnMask);
 
         RectD bounds = target.Selection.SelectionPath.Bounds;
-        RectI intBounds = (RectI)bounds.Intersect(SKRect.Create(0, 0, target.Size.X, target.Size.Y)).RoundOutwards();
+        RectI intBounds = (RectI)bounds.Intersect(new RectD(0, 0, target.Size.X, target.Size.Y)).RoundOutwards();
 
         image.EnqueueClearPath(target.Selection.SelectionPath, intBounds);
         var affChunks = image.FindAffectedChunks();

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Drawing/PixelPerfectPen_UpdateableChange.cs

@@ -72,11 +72,11 @@ internal class PixelPerfectPen_UpdateableChange : UpdateableChange
         pixelsToConfirm.Clear();
 
         Point[] line = BresenhamLineHelper.GetBresenhamLine(incomingPoints[pointsCount - 2], incomingPoints[pointsCount - 1]);
-        foreach (VecI pixel in line)
+        foreach (Point pixel in line)
         {
             pixelsToConfirm.Add(pixel);
         }
-        image.EnqueueDrawPixels(line.Select(point => (VecI)point), color, BlendMode.Src);
+        image.EnqueueDrawPixels(line.Select(point => new VecI((int)point.X, (int)point.Y)), color, BlendMode.Src);
 
         if (pointsCount >= 3 && IsLShape(pointsCount - 1) && !confirmedPixels.Contains(incomingPoints[pointsCount - 2]))
         {

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Selection/SelectLasso_UpdateableChange.cs

@@ -13,14 +13,14 @@ internal class SelectLasso_UpdateableChange : UpdateableChange
     [GenerateUpdateableChangeActions]
     public SelectLasso_UpdateableChange(VecI point, SelectionMode mode)
     {
-        path.MoveTo((Point)point);
+        path.MoveTo(point);
         this.mode = mode;
     }
 
     [UpdateChangeMethod]
     public void Update(VecI point)
     {
-        path.LineTo((Point)point);
+        path.LineTo(point);
     }
 
     public override OneOf<Success, Error> InitializeAndValidate(Document target)

+ 4 - 4
src/PixiEditor.ChangeableDocument/Changes/Selection/SelectRectangle_UpdateableChange.cs

@@ -35,10 +35,10 @@ internal class SelectRectangle_UpdateableChange : UpdateableChange
         using var rectPath = new VectorPath() { FillType = PathFillType.EvenOdd };
         if (!rect.IsZeroArea)
         {
-            rectPath.MoveTo((Point)rect.TopLeft);
-            rectPath.LineTo((Point)rect.TopRight);
-            rectPath.LineTo((Point)rect.BottomRight);
-            rectPath.LineTo((Point)rect.BottomLeft);
+            rectPath.MoveTo(rect.TopLeft);
+            rectPath.LineTo(rect.TopRight);
+            rectPath.LineTo(rect.BottomRight);
+            rectPath.LineTo(rect.BottomLeft);
             rectPath.Close();
         }
 

+ 11 - 0
src/PixiEditor.DrawingApi.Core/Numerics/RectI.cs

@@ -314,4 +314,15 @@ public struct RectI : IEquatable<RectI>
             Bottom = height
         };
     }
+    
+    public static RectI Create(int x, int y, int width, int height)
+    {
+        return new RectI()
+        {
+            Left = x,
+            Right = width,
+            Top = y,
+            Bottom = height
+        };
+    }
 }

+ 1 - 1
src/PixiEditor.DrawingApi.Core/Surface/DrawingSurface.cs

@@ -16,7 +16,7 @@ namespace PixiEditor.DrawingApi.Core.Surface
         {
         }
         
-        public DrawingSurface Create(Pixmap imageInfo)
+        public static DrawingSurface Create(Pixmap imageInfo)
         {
             return DrawingBackendApi.Current.SurfaceOperations.Create(imageInfo);
         }

+ 6 - 0
src/PixiEditor.DrawingApi.Skia/Class1.cs

@@ -0,0 +1,6 @@
+using System;
+
+namespace PixiEditor.DrawingApi.Skia
+{
+    
+}

+ 8 - 0
src/PixiEditor.DrawingApi.Skia/PixiEditor.DrawingApi.Skia.csproj

@@ -0,0 +1,8 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <TargetFramework>netstandard2.1</TargetFramework>
+        <Nullable>enable</Nullable>
+    </PropertyGroup>
+
+</Project>

+ 32 - 0
src/PixiEditor.sln

@@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PixiEditor.Zoombox", "PixiE
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiEditor.DrawingApi.Core", "PixiEditor.DrawingApi.Core\PixiEditor.DrawingApi.Core.csproj", "{5FC5E9C5-F439-43AA-92AF-9B7554D6FA13}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiEditor.DrawingApi.Skia", "PixiEditor.DrawingApi.Skia\PixiEditor.DrawingApi.Skia.csproj", "{98040E8A-F08E-45F8-956F-6480C8272049}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -424,6 +426,36 @@ Global
 		{5FC5E9C5-F439-43AA-92AF-9B7554D6FA13}.Release|x64.Build.0 = Release|Any CPU
 		{5FC5E9C5-F439-43AA-92AF-9B7554D6FA13}.Release|x86.ActiveCfg = Release|Any CPU
 		{5FC5E9C5-F439-43AA-92AF-9B7554D6FA13}.Release|x86.Build.0 = Release|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Debug|x64.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Debug|x86.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Dev Release|Any CPU.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Dev Release|Any CPU.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Dev Release|x64.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Dev Release|x64.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Dev Release|x86.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Dev Release|x86.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX Debug|Any CPU.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX Debug|x64.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX Debug|x64.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX Debug|x86.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX Debug|x86.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX|Any CPU.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX|Any CPU.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX|x64.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX|x64.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX|x86.ActiveCfg = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.MSIX|x86.Build.0 = Debug|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Release|Any CPU.Build.0 = Release|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Release|x64.ActiveCfg = Release|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Release|x64.Build.0 = Release|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Release|x86.ActiveCfg = Release|Any CPU
+		{98040E8A-F08E-45F8-956F-6480C8272049}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 10 - 8
src/PixiEditor/Models/Colors/ExColor.cs

@@ -1,4 +1,6 @@
-namespace PixiEditor.Models.Colors;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+
+namespace PixiEditor.Models.Colors;
 
 internal static class ExColor
 {
@@ -11,19 +13,19 @@ internal static class ExColor
     ///     Negative values produce darker colors.
     /// </param>
     /// <returns>
-    ///     Corrected <see cref="SKColor" /> structure.
+    ///     Corrected <see cref="Color" /> structure.
     /// </returns>
-    public static SKColor ChangeColorBrightness(SKColor color, float correctionFactor)
+    public static Color ChangeColorBrightness(Color color, float correctionFactor)
     {
-        Tuple<int, float, float> hsl = RgbToHsl(color.Red, color.Green, color.Blue);
+        Tuple<int, float, float> hsl = RgbToHsl(color.R, color.G, color.B);
         int h = hsl.Item1;
         float s = hsl.Item2;
         float l = hsl.Item3;
 
         l = Math.Clamp(l + correctionFactor, 0, 100);
-        SKColor rgb = HslToRgb(h, s, l);
+        Color rgb = HslToRgb(h, s, l);
 
-        return new SKColor(rgb.Red, rgb.Green, rgb.Blue, color.Alpha);
+        return new Color(rgb.R, rgb.G, rgb.B, color.A);
     }
 
     /// <summary>
@@ -91,7 +93,7 @@ internal static class ExColor
     ///     Converts HSL color format to RGB.
     /// </summary>
     /// <returns>RGB Color.</returns>
-    public static SKColor HslToRgb(int h, float s, float l)
+    public static Color HslToRgb(int h, float s, float l)
     {
         s /= 100;
         l /= 100;
@@ -116,7 +118,7 @@ internal static class ExColor
             b = (byte)(255 * HueToRgb(v1, v2, hue - (1.0f / 3)));
         }
 
-        return new SKColor(r, g, b);
+        return new Color(r, g, b);
     }
 
     private static float HueToRgb(float v1, float v2, float hue)

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/ShapeToolExecutor.cs

@@ -105,7 +105,7 @@ internal abstract class ShapeToolExecutor<T> : UpdateableChangeExecutor where T
             return;
         }
         transforming = true;
-        document!.TransformViewModel.ShowTransform(TransformMode, false, new ShapeCorners(lastRect));
+        document!.TransformViewModel.ShowTransform(TransformMode, false, new ShapeCorners((RectD)lastRect));
     }
 
     public override void ForceStop()

+ 1 - 1
src/PixiEditor/Models/IO/ClsFile/ClsFileParser.cs

@@ -21,7 +21,7 @@ internal class ClsFileParser : PaletteFileParser
             }
             catch
             {
-                return new PaletteFileData("Corrupted", Array.Empty<SKColor>()) { IsCorrupted = true };
+                return new PaletteFileData("Corrupted", Array.Empty<Color>()) { IsCorrupted = true };
             }
 
             PaletteFileData data = new(

+ 6 - 4
src/PixiEditor/Models/IO/Importer.cs

@@ -5,6 +5,8 @@ using System.Windows.Media.Imaging;
 using ChunkyImageLib;
 using ChunkyImageLib.DataHolders;
 using PixiEditor.DrawingApi.Core.Numerics;
+using PixiEditor.DrawingApi.Core.Surface;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Exceptions;
 using PixiEditor.Helpers;
 using PixiEditor.Models.DataHolders;
@@ -87,15 +89,15 @@ internal class Importer : NotifyableObject
         int width = BitConverter.ToInt32(bytes, 0);
         int height = BitConverter.ToInt32(bytes, 4);
 
-        SKImageInfo info = new SKImageInfo(width, height, SKColorType.RgbaF16);
+        ImageInfo info = new ImageInfo(width, height, ColorType.RgbaF16);
         IntPtr ptr = Marshal.AllocHGlobal(bytes.Length - 8);
         try
         {
             Marshal.Copy(bytes, 8, ptr, bytes.Length - 8);
-            SKPixmap map = new(info, ptr);
-            SKSurface surface = SKSurface.Create(map);
+            Pixmap map = new(info, ptr);
+            DrawingSurface surface = DrawingSurface.Create(map);
             Surface finalSurface = new Surface(new VecI(width, height));
-            using SKPaint paint = new() { BlendMode = SKBlendMode.Src };
+            using Paint paint = new() { BlendMode = BlendMode.Src };
             surface.Draw(finalSurface.DrawingSurface.Canvas, 0, 0, paint);
             return finalSurface;
         }

+ 10 - 9
src/PixiEditor/Views/UserControls/CommandSearch/CommandSearchControl.xaml.cs

@@ -5,6 +5,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Threading;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Commands;
 using PixiEditor.Models.DataHolders;
@@ -131,7 +132,7 @@ internal partial class CommandSearchControl : UserControl, INotifyPropertyChange
     {
         e.Handled = true;
 
-        OneOf<SKColor, Error, None> result;
+        OneOf<Color, Error, None> result;
 
         if (e.Key == Key.Enter && SelectedResult is not null)
         {
@@ -179,28 +180,28 @@ internal partial class CommandSearchControl : UserControl, INotifyPropertyChange
         }
     }
 
-    private void SwitchColor(SKColor color)
+    private void SwitchColor(Color color)
     {
         if (SearchTerm.StartsWith('#'))
         {
-            if (color.Alpha == 255)
+            if (color.A == 255)
             {
-                SearchTerm = $"rgb({color.Red},{color.Green},{color.Blue})";
+                SearchTerm = $"rgb({color.R},{color.G},{color.B})";
             }
             else
             {
-                SearchTerm = $"rgba({color.Red},{color.Green},{color.Blue},{color.Alpha})";
+                SearchTerm = $"rgba({color.R},{color.G},{color.B},{color.A})";
             }
         }
         else
         {
-            if (color.Alpha == 255)
+            if (color.A == 255)
             {
-                SearchTerm = $"#{color.Red:X2}{color.Green:X2}{color.Blue:X2}";
+                SearchTerm = $"#{color.R:X2}{color.G:X2}{color.B:X2}";
             }
             else
             {
-                SearchTerm = $"#{color.Red:X2}{color.Green:X2}{color.Blue:X2}{color.Alpha:X2}";
+                SearchTerm = $"#{color.R:X2}{color.G:X2}{color.B:X2}{color.A:X2}";
             }
         }
     }
@@ -211,7 +212,7 @@ internal partial class CommandSearchControl : UserControl, INotifyPropertyChange
             return;
         if (SelectedResult is null)
         {
-            SelectedResult = Results.Where(x => x.CanExecute).First();
+            SelectedResult = Results.First(x => x.CanExecute);
             return;
         }