Browse Source

Fixed ReferenceLayer

Krzysztof Krysiński 1 year ago
parent
commit
7c9b379e44

+ 3 - 6
src/PixiEditor.AvaloniaUI/Helpers/DocumentViewModelBuilder.cs

@@ -327,7 +327,7 @@ internal class DocumentViewModelBuilder : ChildrenBuilder
         
         public ShapeCorners Shape { get; set; }
         
-        public byte[] ImagePbgra32Bytes { get; set; }
+        public byte[] ImageBgra8888Bytes { get; set; }
 
         public ReferenceLayerBuilder WithIsVisible(bool isVisible)
         {
@@ -343,10 +343,7 @@ internal class DocumentViewModelBuilder : ChildrenBuilder
 
         public ReferenceLayerBuilder WithSurface(Surface surface)
         {
-            // TODO: Make sure this works, there was WriteableBitmap previously
-            byte[] bytes = new byte[surface.Size.Y * surface.BytesPerPixel];
-            Marshal.Copy(surface.PixelBuffer, bytes, 0, bytes.Length);
-
+            byte[] bytes = surface.ToByteArray();
             WithImage(surface.Size, bytes);
             
             return this;
@@ -355,7 +352,7 @@ internal class DocumentViewModelBuilder : ChildrenBuilder
         public ReferenceLayerBuilder WithImage(VecI size, byte[] pbgraData)
         {
             ImageSize = size;
-            ImagePbgra32Bytes = pbgraData;
+            ImageBgra8888Bytes = pbgraData;
             return this;
         }
 

+ 2 - 0
src/PixiEditor.AvaloniaUI/Helpers/Extensions/PixiParserDocumentEx.cs

@@ -2,6 +2,7 @@
 using ChunkyImageLib;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.DrawingApi.Core.Numerics;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Extensions.Palettes;
 using PixiEditor.Parser;
 using PixiEditor.Parser.Deprecated;
@@ -25,6 +26,7 @@ internal static class PixiParserDocumentEx
                 .WithReferenceLayer(document.ReferenceLayer, (r, builder) => builder
                     .WithIsVisible(r.Enabled)
                     .WithShape(r.Corners)
+                    .WithIsTopmost(r.Topmost)
                     .WithSurface(Surface.Load(r.ImageBytes)));
 
             BuildChildren(b, document.RootFolder.Children);

+ 1 - 1
src/PixiEditor.AvaloniaUI/Helpers/SupportedFilesHelper.cs

@@ -107,7 +107,7 @@ internal class SupportedFilesHelper
         if (file is null)
             return FileType.Unset;
 
-        string extension = Path.GetExtension(file.Path.AbsolutePath);
+        string extension = Path.GetExtension(file.Path.LocalPath);
         return allSupportedExtensions.Single(i => i.Extensions.Contains(extension)).FileType;
     }
 

+ 1 - 1
src/PixiEditor.AvaloniaUI/Helpers/SurfaceHelpers.cs

@@ -34,7 +34,7 @@ public static class SurfaceHelpers
         return result;
     }
 
-    private static unsafe byte[] ToByteArray(Surface surface, ColorType colorType = ColorType.Bgra8888, AlphaType alphaType = AlphaType.Premul)
+    public static unsafe byte[] ToByteArray(this Surface surface, ColorType colorType = ColorType.Bgra8888, AlphaType alphaType = AlphaType.Premul)
     {
         int width = surface.Size.X;
         int height = surface.Size.Y;

+ 2 - 2
src/PixiEditor.AvaloniaUI/Models/Controllers/ClipboardController.cs

@@ -184,7 +184,7 @@ internal static class ClipboardController
             return surfaces;
         }
 
-        var paths = data.GetFileDropList().Select(x => x.Path.AbsolutePath).ToList();
+        var paths = data.GetFileDropList().Select(x => x.Path.LocalPath).ToList();
         if(paths != null && data.TryGetRawTextPath(out string? textPath))
         {
             paths.Add(textPath);
@@ -290,7 +290,7 @@ internal static class ClipboardController
             var files = dataObject.GetFileDropList();
             if (files != null)
             {
-                if (IsImageFormat(files.Select(x => x.Path.AbsolutePath).ToArray()))
+                if (IsImageFormat(files.Select(x => x.Path.LocalPath).ToArray()))
                 {
                     return true;
                 }

+ 1 - 1
src/PixiEditor.AvaloniaUI/Models/ExtensionServices/FileSystemProvider.cs

@@ -16,7 +16,7 @@ public class FileSystemProvider : IFileSystemProvider
             return false;
         }
 
-        path = task.Result[0].Path.AbsolutePath;
+        path = task.Result[0].Path.LocalPath;
         return true;
     }
 }

+ 1 - 1
src/PixiEditor.AvaloniaUI/Models/IO/Exporter.cs

@@ -76,7 +76,7 @@ internal class Exporter
 
             var fileType = SupportedFilesHelper.GetSaveFileType(true, file);
 
-            var saveResult = TrySaveUsingDataFromDialog(document, file.Path.AbsolutePath, fileType, out string fixedPath, exportSize);
+            var saveResult = TrySaveUsingDataFromDialog(document, file.Path.LocalPath, fileType, out string fixedPath, exportSize);
             if (saveResult == SaveResult.Success)
             {
                 result.Path = fixedPath;

+ 1 - 1
src/PixiEditor.AvaloniaUI/ViewModels/Document/DocumentViewModel.cs

@@ -231,7 +231,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         if (builderInstance.ReferenceLayer is { } refLayer)
         {
             acc
-                .AddActions(new SetReferenceLayer_Action(refLayer.Shape, refLayer.ImagePbgra32Bytes.ToImmutableArray(), refLayer.ImageSize));
+                .AddActions(new SetReferenceLayer_Action(refLayer.Shape, refLayer.ImageBgra8888Bytes.ToImmutableArray(), refLayer.ImageSize));
         }
 
         viewModel.Swatches = new ObservableCollection<PaletteColor>(builderInstance.Swatches);

+ 4 - 4
src/PixiEditor.AvaloniaUI/ViewModels/SettingsWindowViewModel.cs

@@ -127,7 +127,7 @@ internal partial class SettingsWindowViewModel : ViewModelBase
         
         if (file is not null)
         {
-            File.Copy(CommandController.ShortcutsPath, file.Path.AbsolutePath, true);
+            File.Copy(CommandController.ShortcutsPath, file.Path.LocalPath, true);
         }
         
         // Sometimes, focus was brought back to the last edited shortcut
@@ -186,7 +186,7 @@ internal partial class SettingsWindowViewModel : ViewModelBase
             
             CommandController.Current.ResetShortcuts();
             CommandController.Current.Import(shortcuts, false);
-            File.Copy(files[0].Path.AbsolutePath, CommandController.ShortcutsPath, true);
+            File.Copy(files[0].Path.LocalPath, CommandController.ShortcutsPath, true);
             NoticeDialog.Show("SHORTCUTS_IMPORTED_SUCCESS", "SUCCESS");
         }
         
@@ -200,7 +200,7 @@ internal partial class SettingsWindowViewModel : ViewModelBase
         {
             try
             {
-                shortcuts = ShortcutFile.LoadTemplate(file.Path.AbsolutePath)?.Shortcuts.ToList();
+                shortcuts = ShortcutFile.LoadTemplate(file.Path.LocalPath)?.Shortcuts.ToList();
             }
             catch (Exception)
             {
@@ -226,7 +226,7 @@ internal partial class SettingsWindowViewModel : ViewModelBase
 
             try
             {
-                shortcuts = provider.KeysParser.Parse(file.Path.AbsolutePath, false)?.Shortcuts.ToList();
+                shortcuts = provider.KeysParser.Parse(file.Path.LocalPath, false)?.Shortcuts.ToList();
             }
             catch (RecoverableException e)
             {

+ 7 - 7
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/DebugViewModel.cs

@@ -127,7 +127,7 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
             {
                 var commands = Owner.CommandController.Commands;
 
-                using StreamWriter writer = new StreamWriter(pickedFile.Path.AbsolutePath);
+                using StreamWriter writer = new StreamWriter(pickedFile.Path.LocalPath);
                 foreach (var command in commands)
                 {
                     writer.WriteLine($"InternalName: {command.InternalName}");
@@ -153,7 +153,7 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
             {
                 var commands = Owner.CommandController.Commands;
 
-                using StreamWriter writer = new StreamWriter(pickedFile.Path.AbsolutePath);
+                using StreamWriter writer = new StreamWriter(pickedFile.Path.LocalPath);
                 Dictionary<string, KeyDefinition> keyDefinitions = new Dictionary<string, KeyDefinition>();
                 foreach (var command in commands)
                 {
@@ -164,7 +164,7 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
 
                 writer.Write(JsonConvert.SerializeObject(keyDefinitions, Formatting.Indented));
                 writer.Close();
-                string file = await File.ReadAllTextAsync(pickedFile.Path.AbsolutePath);
+                string file = await File.ReadAllTextAsync(pickedFile.Path.LocalPath);
                 foreach (var command in commands)
                 {
                     if(command.IsDebug)
@@ -172,8 +172,8 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
                     file = file.Replace($"(provider).{command.InternalName}", "");
                 }
 
-                await File.WriteAllTextAsync(pickedFile.Path.AbsolutePath, file);
-                IOperatingSystem.Current.OpenFolder(Path.GetDirectoryName(pickedFile.Path.AbsolutePath));
+                await File.WriteAllTextAsync(pickedFile.Path.LocalPath, file);
+                IOperatingSystem.Current.OpenFolder(Path.GetDirectoryName(pickedFile.Path.LocalPath));
             }
         });
     }
@@ -195,7 +195,7 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
 
             if (pickedFile != null)
             {
-                string file = await File.ReadAllTextAsync(pickedFile.Path.AbsolutePath);
+                string file = await File.ReadAllTextAsync(pickedFile.Path.LocalPath);
                 var keyDefinitions = JsonConvert.DeserializeObject<Dictionary<string, KeyDefinition>>(file);
                 int emptyKeys = file.Split("\"\":").Length - 1;
                 int unknownCommands = 0;
@@ -267,7 +267,7 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
             {
                 Owner.LocalizationProvider.LoadDebugKeys(
                     JsonConvert.DeserializeObject<Dictionary<string, string>>(
-                        await File.ReadAllTextAsync(pickedFile.Path.AbsolutePath)),
+                        await File.ReadAllTextAsync(pickedFile.Path.LocalPath)),
                     false);
             }
         });

+ 2 - 2
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/FileViewModel.cs

@@ -140,10 +140,10 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
             var dialog = await desktop.MainWindow.StorageProvider.OpenFilePickerAsync(
                 new FilePickerOpenOptions { FileTypeFilter = filter });
 
-            if (dialog.Count == 0 || !Importer.IsSupportedFile(dialog[0].Path.AbsolutePath))
+            if (dialog.Count == 0 || !Importer.IsSupportedFile(dialog[0].Path.LocalPath))
                 return;
 
-            OpenFromPath(dialog[0].Path.AbsolutePath);
+            OpenFromPath(dialog[0].Path.LocalPath);
         }
     }
 

+ 1 - 1
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/LayersViewModel.cs

@@ -382,7 +382,7 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
             if (filePicker is null || filePicker.Count == 0)
                 return null;
 
-            return filePicker[0].Path.AbsolutePath;
+            return filePicker[0].Path.LocalPath;
         }
 
         return null;

+ 1 - 1
src/PixiEditor.AvaloniaUI/Views/Dialogs/ExportFilePopup.axaml.cs

@@ -127,7 +127,7 @@ public partial class ExportFilePopup : PixiEditorPopup
                     return null;
                 }
 
-                string fileName = SupportedFilesHelper.FixFileExtension(file.Path.AbsolutePath, SaveFormat);
+                string fileName = SupportedFilesHelper.FixFileExtension(file.Path.LocalPath, SaveFormat);
 
                 return fileName;
             }

+ 4 - 4
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml.cs

@@ -145,7 +145,7 @@ internal partial class PaletteViewer : UserControl
 
             if (file is null || file.Count == 0) return;
 
-            await ImportPalette(file[0].Path.AbsolutePath);
+            await ImportPalette(file[0].Path.LocalPath);
         });
     }
 
@@ -182,7 +182,7 @@ internal partial class PaletteViewer : UserControl
 
             try
             {
-                bool saved = await foundParser.Save(file.Path.AbsolutePath, new PaletteFileData(Colors.ToArray()));
+                bool saved = await foundParser.Save(file.Path.LocalPath, new PaletteFileData(Colors.ToArray()));
                 if (!saved)
                 {
                     NoticeDialog.Show("COULD_NOT_SAVE_PALETTE", "ERROR");
@@ -256,10 +256,10 @@ internal partial class PaletteViewer : UserControl
             {
                 IStorageItem file = files[0];
                 var foundParser = PaletteProvider.AvailableParsers.FirstOrDefault(x =>
-                    x.SupportedFileExtensions.Contains(Path.GetExtension(file.Path.AbsolutePath)));
+                    x.SupportedFileExtensions.Contains(Path.GetExtension(file.Path.LocalPath)));
                 if (foundParser != null)
                 {
-                    filePath = file.Path.AbsolutePath;
+                    filePath = file.Path.LocalPath;
                     return true;
                 }
             }

+ 1 - 1
src/PixiEditor.AvaloniaUI/Views/Windows/PalettesBrowser.axaml.cs

@@ -663,7 +663,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
 
         if (file is { Count: > 0 })
         {
-            var fileName = file[0].Path.AbsolutePath;
+            var fileName = file[0].Path.LocalPath;
             await ImportPalette(fileName, parsers);
         }
     }

+ 1 - 2
src/PixiEditor.UI.Common/Controls/CheckBox.axaml

@@ -1,6 +1,5 @@
 <ResourceDictionary xmlns="https://github.com/avaloniaui"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:animators="clr-namespace:PixiEditor.UI.Common.Animators">
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <Design.PreviewWith>
         <StackPanel HorizontalAlignment="Center">
             <CheckBox IsChecked="True" Content="Label"/>