|
@@ -1,20 +1,14 @@
|
|
using ChunkyImageLib;
|
|
using ChunkyImageLib;
|
|
-using ChunkyImageLib.DataHolders;
|
|
|
|
-using ChunkyImageLib.Operations;
|
|
|
|
-using PixiEditor.ChangeableDocument.Changeables.Interfaces;
|
|
|
|
-using PixiEditor.ChangeableDocument.Rendering;
|
|
|
|
using PixiEditor.DrawingApi.Core.ColorsImpl;
|
|
using PixiEditor.DrawingApi.Core.ColorsImpl;
|
|
using PixiEditor.DrawingApi.Core.Numerics;
|
|
using PixiEditor.DrawingApi.Core.Numerics;
|
|
using PixiEditor.DrawingApi.Core.Surface.ImageData;
|
|
using PixiEditor.DrawingApi.Core.Surface.ImageData;
|
|
-using PixiEditor.Parser;
|
|
|
|
using PixiEditor.Parser.Collections.Deprecated;
|
|
using PixiEditor.Parser.Collections.Deprecated;
|
|
using PixiEditor.Parser.Deprecated;
|
|
using PixiEditor.Parser.Deprecated;
|
|
-using PixiEditor.Parser.Skia;
|
|
|
|
using PixiEditor.ViewModels.SubViewModels.Document;
|
|
using PixiEditor.ViewModels.SubViewModels.Document;
|
|
|
|
|
|
namespace PixiEditor.Helpers.Extensions;
|
|
namespace PixiEditor.Helpers.Extensions;
|
|
|
|
|
|
-internal static class ParserHelpers
|
|
|
|
|
|
+internal static class SerializableDocumentEx
|
|
{
|
|
{
|
|
public static Image ToImage(this SerializableLayer serializableLayer)
|
|
public static Image ToImage(this SerializableLayer serializableLayer)
|
|
{
|
|
{
|
|
@@ -58,55 +52,6 @@ internal static class ParserHelpers
|
|
return vm;
|
|
return vm;
|
|
}
|
|
}
|
|
|
|
|
|
- public static DocumentViewModel ToDocument(this Document document)
|
|
|
|
- {
|
|
|
|
- return DocumentViewModel.Build(b =>
|
|
|
|
- {
|
|
|
|
- b
|
|
|
|
- .WithSize(document.Width, document.Height)
|
|
|
|
- .WithPalette(document.Palette, x => new Color(x.R, x.G, x.B, x.A))
|
|
|
|
- .WithSwatches(document.Swatches, x => new(x.R, x.G, x.B, x.A));
|
|
|
|
-
|
|
|
|
- BuildChildren(b, document.RootFolder.Children);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- void BuildChildren(ChildrenBuilder builder, IEnumerable<IStructureMember> members)
|
|
|
|
- {
|
|
|
|
- foreach (var member in members)
|
|
|
|
- {
|
|
|
|
- if (member is Folder folder)
|
|
|
|
- {
|
|
|
|
- builder.WithFolder(x => BuildFolder(x, folder));
|
|
|
|
- }
|
|
|
|
- else if (member is ImageLayer layer)
|
|
|
|
- {
|
|
|
|
- builder.WithLayer(x => BuildLayer(x, layer));
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- throw new NotImplementedException($"StructureMember of type '{member.GetType().FullName}' has not been implemented");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void BuildFolder(DocumentViewModelBuilder.FolderBuilder builder, Folder folder) => builder
|
|
|
|
- .WithName(folder.Name)
|
|
|
|
- .WithVisibility(folder.Enabled)
|
|
|
|
- .WithOpacity(folder.Opacity)
|
|
|
|
- .WithBlendMode((PixiEditor.ChangeableDocument.Enums.BlendMode)(int)folder.BlendMode)
|
|
|
|
- .WithChildren(x => BuildChildren(x, folder.Children))
|
|
|
|
- .WithMask(folder.Mask, (x, m) => x.WithVisibility(m.Enabled).WithSurface(m.Width, m.Height, x => x.WithImage(m.ImageBytes, m.OffsetX, m.OffsetY)));
|
|
|
|
-
|
|
|
|
- void BuildLayer(DocumentViewModelBuilder.LayerBuilder builder, ImageLayer layer) => builder
|
|
|
|
- .WithName(layer.Name)
|
|
|
|
- .WithVisibility(layer.Enabled)
|
|
|
|
- .WithOpacity(layer.Opacity)
|
|
|
|
- .WithBlendMode((PixiEditor.ChangeableDocument.Enums.BlendMode)(int)layer.BlendMode)
|
|
|
|
- .WithSize(layer.Width, layer.Height)
|
|
|
|
- .WithSurface(x => x.WithImage(layer.ImageBytes, layer.OffsetX, layer.OffsetY))
|
|
|
|
- .WithMask(layer.Mask, (x, m) => x.WithVisibility(m.Enabled).WithSurface(m.Width, m.Height, x => x.WithImage(m.ImageBytes, m.OffsetX, m.OffsetY)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Builds folder and its children.
|
|
/// Builds folder and its children.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -193,7 +138,7 @@ internal static class ParserHelpers
|
|
layers.Add(serializableDocumentLayers[i]);
|
|
layers.Add(serializableDocumentLayers[i]);
|
|
}
|
|
}
|
|
|
|
|
|
- if(group.Subgroups is { Count: > 0 })
|
|
|
|
|
|
+ if (group.Subgroups is { Count: > 0 })
|
|
{
|
|
{
|
|
foreach (var subGroup in group.Subgroups)
|
|
foreach (var subGroup in group.Subgroups)
|
|
{
|
|
{
|
|
@@ -220,16 +165,4 @@ internal static class ParserHelpers
|
|
SortMembersRecursively(folderBuilder.Children);
|
|
SortMembersRecursively(folderBuilder.Children);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public static SerializableDocument AddSwatches(this SerializableDocument document, IEnumerable<Color> colors)
|
|
|
|
- {
|
|
|
|
- document.Swatches.AddRange(colors.Select(x => System.Drawing.Color.FromArgb(x.A, x.R, x.G, x.B)));
|
|
|
|
- return document;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static SerializableDocument AddPalette(this SerializableDocument document, IEnumerable<Color> palette)
|
|
|
|
- {
|
|
|
|
- document.Palette.AddRange(palette.Select(x => System.Drawing.Color.FromArgb(x.A, x.R, x.G, x.B)));
|
|
|
|
- return document;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|