Forráskód Böngészése

Fixed not attaching preview controls

Krzysztof Krysiński 1 hónapja
szülő
commit
509699f717
1 módosított fájl, 28 hozzáadás és 4 törlés
  1. 28 4
      src/PixiEditor/Views/Visuals/PreviewPainterControl.cs

+ 28 - 4
src/PixiEditor/Views/Visuals/PreviewPainterControl.cs

@@ -1,4 +1,6 @@
 using Avalonia;
+using Avalonia.Interactivity;
+using Avalonia.LogicalTree;
 using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
@@ -17,8 +19,9 @@ public class PreviewPainterControl : DrawieControl
         AvaloniaProperty.Register<PreviewPainterControl, PreviewPainter>(
             nameof(PreviewPainter));
 
-    public static readonly StyledProperty<VecI> CustomRenderSizeProperty = AvaloniaProperty.Register<PreviewPainterControl, VecI>(
-        nameof(CustomRenderSize));
+    public static readonly StyledProperty<VecI> CustomRenderSizeProperty =
+        AvaloniaProperty.Register<PreviewPainterControl, VecI>(
+            nameof(CustomRenderSize));
 
     public VecI CustomRenderSize
     {
@@ -69,6 +72,25 @@ public class PreviewPainterControl : DrawieControl
         }
     }
 
+    protected override void OnLoaded(RoutedEventArgs e)
+    {
+        base.OnLoaded(e);
+        if (PreviewPainter != null && painterInstance == null)
+        {
+            painterInstance = PreviewPainter.AttachPainterInstance();
+            VecI finalSize = GetFinalSize();
+            if (finalSize is { X: > 0, Y: > 0 })
+            {
+                PreviewPainter.ChangeRenderTextureSize(painterInstance.RequestId, finalSize);
+            }
+
+            painterInstance.RequestMatrix = OnPainterRequestMatrix;
+            painterInstance.RequestRepaint = OnPainterRenderRequest;
+
+            PreviewPainter.RepaintFor(painterInstance.RequestId);
+        }
+    }
+
     private static void PainterChanged(AvaloniaPropertyChangedEventArgs<PreviewPainter> args)
     {
         var sender = args.Sender as PreviewPainterControl;
@@ -148,8 +170,10 @@ public class PreviewPainterControl : DrawieControl
 
     private VecI GetFinalSize()
     {
-        VecI finalSize = CustomRenderSize.ShortestAxis > 0 ? CustomRenderSize : new VecI((int)Bounds.Width, (int)Bounds.Height);
-        if(Bounds.Width < finalSize.X && Bounds.Height < finalSize.Y)
+        VecI finalSize = CustomRenderSize.ShortestAxis > 0
+            ? CustomRenderSize
+            : new VecI((int)Bounds.Width, (int)Bounds.Height);
+        if (Bounds.Width < finalSize.X && Bounds.Height < finalSize.Y)
         {
             finalSize = new VecI((int)Bounds.Width, (int)Bounds.Height);
         }