Browse Source

Tried fixing helloThere window

CPKreuz 3 years ago
parent
commit
45bdeeb339

+ 9 - 5
PixiEditor/Models/DataHolders/RecentlyOpenedDocument.cs

@@ -1,9 +1,11 @@
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
-using PixiEditor.Models.ImageManipulation;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.IO;
+using PixiEditor.Models.Position;
 using PixiEditor.Parser;
 using PixiEditor.Parser;
+using PixiEditor.Parser.Skia;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.IO;
 using System.IO;
+using System.Linq;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
 namespace PixiEditor.Models.DataHolders
 namespace PixiEditor.Models.DataHolders
@@ -49,14 +51,13 @@ namespace PixiEditor.Models.DataHolders
             }
             }
         }
         }
 
 
-        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
         public WriteableBitmap PreviewBitmap
         public WriteableBitmap PreviewBitmap
         {
         {
             get
             get
             {
             {
                 if (previewBitmap == null && !Corrupt)
                 if (previewBitmap == null && !Corrupt)
                 {
                 {
-                    PreviewBitmap = LoadPreviewBitmap();
+                    previewBitmap = LoadPreviewBitmap();
                 }
                 }
 
 
                 return previewBitmap;
                 return previewBitmap;
@@ -85,9 +86,12 @@ namespace PixiEditor.Models.DataHolders
                     return null;
                     return null;
                 }
                 }
 
 
-                return BitmapUtils.GeneratePreviewBitmap(serializableDocument.Layers, serializableDocument.Width, serializableDocument.Height, 80, 50);
+                // TODO: Make this work
+                Surface surface = Surface.Combine(serializableDocument.Width, serializableDocument.Height, serializableDocument.Layers.Select(x => (x.ToSKImage(), new Coordinates(x.OffsetX, x.OffsetY))));
+
+                return surface.ToWriteableBitmap();
             }
             }
-            else if (FileExtension == ".png" || FileExtension == ".jpg" || FileExtension == ".jpeg")
+            else if (FileExtension is ".png" or ".jpg" or ".jpeg")
             {
             {
                 WriteableBitmap bitmap = null;
                 WriteableBitmap bitmap = null;
 
 

+ 22 - 0
PixiEditor/Models/DataHolders/Surface.cs

@@ -1,6 +1,8 @@
 using PixiEditor.Helpers.Extensions;
 using PixiEditor.Helpers.Extensions;
+using PixiEditor.Models.Position;
 using SkiaSharp;
 using SkiaSharp;
 using System;
 using System;
+using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 using System.Windows;
 using System.Windows;
@@ -72,6 +74,26 @@ namespace PixiEditor.Models.DataHolders
             SkiaSurface.Canvas.DrawImage(image, 0, 0);
             SkiaSurface.Canvas.DrawImage(image, 0, 0);
         }
         }
 
 
+        /// <summary>
+        /// Combines the <paramref name="images"/> into a <see cref="Surface"/>
+        /// </summary>
+        /// <param name="width">The width of the <see cref="Surface"/></param>
+        /// <param name="height">The height of the <see cref="Surface"/></param>
+        /// <returns>A surface that has the <paramref name="images"/> drawn on it</returns>
+        public static Surface Combine(int width, int height, IEnumerable<(SKImage image, Coordinates offset)> images)
+        {
+            Surface surface = new Surface(width, height);
+
+            foreach (var image in images)
+            {
+                surface.SkiaSurface.Canvas.DrawImage(image.image, (SKPoint)image.offset);
+            }
+
+            surface.SkiaSurface.Canvas.DrawRect(0, 0, width, height, new SKPaint() { Color = SKColors.White, BlendMode = SKBlendMode.Plus });
+
+            return surface;
+        }
+
         public Surface ResizeNearestNeighbor(int newW, int newH)
         public Surface ResizeNearestNeighbor(int newW, int newH)
         {
         {
             SKImage image = SkiaSurface.Snapshot();
             SKImage image = SkiaSurface.Snapshot();

+ 22 - 7
PixiEditor/Models/Position/Coordinates.cs

@@ -1,9 +1,14 @@
-using System;
+using SkiaSharp;
+using System;
+using System.Diagnostics;
 
 
 namespace PixiEditor.Models.Position
 namespace PixiEditor.Models.Position
 {
 {
+    [DebuggerDisplay("({DebuggerDisplay,nq})")]
     public struct Coordinates
     public struct Coordinates
     {
     {
+        private string DebuggerDisplay => ToString();
+
         public Coordinates(int x, int y)
         public Coordinates(int x, int y)
         {
         {
             X = x;
             X = x;
@@ -39,14 +44,24 @@ namespace PixiEditor.Models.Position
             return $"{X}, {Y}";
             return $"{X}, {Y}";
         }
         }
 
 
-        public override bool Equals(object obj)
+        public string ToString(IFormatProvider provider)
+        {
+            return $"{X.ToString(provider)}, {Y.ToString(provider)}";
+        }
+
+        public static explicit operator SKPoint(Coordinates coordinates)
         {
         {
-            if (obj is Coordinates coords)
-            {
-                return this == coords;
-            }
+            return new SKPoint(coordinates.X, coordinates.Y);
+        }
 
 
-            return false;
+        public static explicit operator SKPointI(Coordinates coordinates)
+        {
+            return new SKPointI(coordinates.X, coordinates.Y);
+        }
+
+        public override bool Equals(object obj)
+        {
+            return obj is Coordinates coords && this == coords;
         }
         }
 
 
         public override int GetHashCode()
         public override int GetHashCode()

+ 2 - 0
PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -6,8 +6,10 @@
         xmlns:dataHolders="clr-namespace:PixiEditor.Models.DataHolders" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
         xmlns:dataHolders="clr-namespace:PixiEditor.Models.DataHolders" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
         xmlns:sys="clr-namespace:System;assembly=System.Runtime"
         xmlns:sys="clr-namespace:System;assembly=System.Runtime"
         xmlns:uc="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:uc="clr-namespace:PixiEditor.Views.UserControls"
+        xmlns:local="clr-namespace:PixiEditor.Views.Dialogs"
         mc:Ignorable="d" ShowInTaskbar="False"
         mc:Ignorable="d" ShowInTaskbar="False"
         Title="Hello there!" Height="662" Width="632"
         Title="Hello there!" Height="662" Width="632"
+        d:DataContext="{d:DesignInstance local:HelloTherePopup}"
         WindowStyle="None" WindowStartupLocation="CenterScreen">
         WindowStyle="None" WindowStartupLocation="CenterScreen">
 
 
     <Window.Resources>
     <Window.Resources>