瀏覽代碼

Fixed missing node previews

flabbet 11 月之前
父節點
當前提交
067c3313f5

+ 6 - 6
src/PixiEditor/Models/Rendering/MemberPreviewUpdater.cs

@@ -560,7 +560,7 @@ internal class MemberPreviewUpdater
         AffectedArea area,
         VecI position, float scaling)
     {
-        PostRender(() =>
+        QueueRender(() =>
         {
             memberVM.PreviewSurface.Surface.Canvas.Save();
             memberVM.PreviewSurface.Surface.Canvas.Scale(scaling);
@@ -608,7 +608,7 @@ internal class MemberPreviewUpdater
     private void RenderLayerMainPreview(IReadOnlyLayerNode layer, Texture surface, AffectedArea area,
         VecI position, float scaling, int frame)
     {
-        PostRender(() =>
+        QueueRender(() =>
         {
             surface.Surface.Canvas.Save();
             surface.Surface.Canvas.Scale(scaling);
@@ -643,7 +643,7 @@ internal class MemberPreviewUpdater
                 new Texture(StructureHelpers.CalculatePreviewSize(internals.Tracker.Document.Size));
         }
 
-        PostRender(() =>
+        QueueRender(() =>
         {
             keyFrameVM.PreviewSurface!.Surface.Canvas.Save();
             float scaling = (float)keyFrameVM.PreviewSurface.Size.X / internals.Tracker.Document.Size.X;
@@ -706,7 +706,7 @@ internal class MemberPreviewUpdater
 
             var member = internals.Tracker.Document.FindMemberOrThrow(guid);
 
-            PostRender(() =>
+            QueueRender(() =>
             {
                 memberVM.MaskPreviewSurface!.Surface.Canvas.Save();
                 memberVM.MaskPreviewSurface.Surface.Canvas.Scale(scaling);
@@ -754,7 +754,7 @@ internal class MemberPreviewUpdater
             float scalingX = (float)nodeVm.ResultPreview.Size.X / node.CachedResult.Size.X;
             float scalingY = (float)nodeVm.ResultPreview.Size.Y / node.CachedResult.Size.Y;
 
-            PostRender(() =>
+            QueueRender(() =>
             {
                 nodeVm.ResultPreview.Surface.Canvas.Save();
                 nodeVm.ResultPreview.Surface.Canvas.Scale(scalingX, scalingY);
@@ -771,7 +771,7 @@ internal class MemberPreviewUpdater
         }
     }
 
-    private void PostRender(Action action)
+    private void QueueRender(Action action)
     {
         if (!DrawingBackendApi.Current.IsHardwareAccelerated)
         {

+ 5 - 5
src/PixiEditor/Styles/Templates/NodeView.axaml

@@ -55,14 +55,14 @@
                             </Border>
                             <Border IsVisible="{Binding !!ResultPreview, RelativeSource={RelativeSource TemplatedParent}}"
                                 CornerRadius="0, 0, 4.5, 4.5" Grid.Row="2" ClipToBounds="True">
-                                <visuals:SurfaceControl Width="200" Height="200"
-                                                        Surface="{TemplateBinding ResultPreview}"
+                                <visuals:TextureControl Width="200" Height="200"
+                                                        Texture="{TemplateBinding ResultPreview}"
                                                         RenderOptions.BitmapInterpolationMode="None">
-                                    <visuals:SurfaceControl.Background>
+                                    <visuals:TextureControl.Background>
                                         <ImageBrush Source="/Images/CheckerTile.png"
                                                     TileMode="Tile" DestinationRect="0, 0, 25, 25" />
-                                    </visuals:SurfaceControl.Background>
-                                </visuals:SurfaceControl>
+                                    </visuals:TextureControl.Background>
+                                </visuals:TextureControl>
                             </Border>
                         </Grid>
                     </Border>

+ 2 - 2
src/PixiEditor/Views/Nodes/NodeView.cs

@@ -34,7 +34,7 @@ public class NodeView : TemplatedControl
         AvaloniaProperty.Register<NodeView, ObservableRangeCollection<INodePropertyHandler>>(
             nameof(Outputs));
 
-    public static readonly StyledProperty<Surface> ResultPreviewProperty = AvaloniaProperty.Register<NodeView, Surface>(
+    public static readonly StyledProperty<Texture> ResultPreviewProperty = AvaloniaProperty.Register<NodeView, Texture>(
         nameof(ResultPreview));
 
     public static readonly StyledProperty<bool> IsSelectedProperty = AvaloniaProperty.Register<NodeView, bool>(
@@ -64,7 +64,7 @@ public class NodeView : TemplatedControl
         set => SetValue(IsSelectedProperty, value);
     }
 
-    public Surface ResultPreview
+    public Texture ResultPreview
     {
         get => GetValue(ResultPreviewProperty);
         set => SetValue(ResultPreviewProperty, value);

+ 15 - 1
src/PixiEditor/Views/Visuals/TextureControl.cs

@@ -21,6 +21,9 @@ public class TextureControl : Control
     public static readonly StyledProperty<Stretch> StretchProperty = AvaloniaProperty.Register<TextureControl, Stretch>(
         nameof(Stretch), Stretch.Uniform);
 
+    public static readonly StyledProperty<IBrush> BackgroundProperty = AvaloniaProperty.Register<TextureControl, IBrush>
+    (nameof(Background));
+
     public Stretch Stretch
     {
         get => GetValue(StretchProperty);
@@ -33,6 +36,12 @@ public class TextureControl : Control
         set => SetValue(TextureProperty, value);
     }
 
+    public IBrush Background
+    {
+        get { return (IBrush)GetValue(BackgroundProperty); }
+        set { SetValue(BackgroundProperty, value); }
+    }
+
     static TextureControl()
     {
         AffectsRender<TextureControl>(TextureProperty, StretchProperty);
@@ -87,7 +96,12 @@ public class TextureControl : Control
 
     public override void Render(DrawingContext context)
     {
-        if (Texture == null)
+        if (Background != null)
+        {
+            context.FillRectangle(Background, new Rect(Bounds.Size));
+        }
+        
+        if (Texture == null || Texture.IsDisposed)
         {
             return;
         }