ソースを参照

Added string property view

flabbet 9 ヶ月 前
コミット
867a6366da

+ 66 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CustomOutputNode.cs

@@ -0,0 +1,66 @@
+using PixiEditor.ChangeableDocument.Changeables.Animations;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.ChangeableDocument.Rendering;
+using Drawie.Backend.Core;
+using Drawie.Backend.Core.Surfaces;
+using Drawie.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+
+[NodeInfo("CustomOutput")]
+public class CustomOutputNode : Node, IRenderInput, IPreviewRenderable
+{
+    public RenderInputProperty Input { get; } 
+    public InputProperty<string> OutputName { get; }
+    
+    private VecI? lastDocumentSize;
+    public CustomOutputNode()
+    {
+        Input = new RenderInputProperty(this, OutputNode.InputPropertyName, "BACKGROUND", null);
+        AddInputProperty(Input);
+        
+        OutputName = CreateInput("OutputName", "OUTPUT_NAME", "");
+    }
+
+    public override Node CreateCopy()
+    {
+        return new CustomOutputNode();
+    }
+
+    protected override void OnExecute(RenderContext context)
+    {
+        lastDocumentSize = context.DocumentSize;
+        
+        int saved = context.RenderSurface.Canvas.Save();
+        context.RenderSurface.Canvas.ClipRect(new RectD(0, 0, context.DocumentSize.X, context.DocumentSize.Y));
+        Input.Value?.Paint(context, context.RenderSurface);
+        
+        context.RenderSurface.Canvas.RestoreToCount(saved);
+    }
+
+    RenderInputProperty IRenderInput.Background => Input;
+    public RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
+    {
+        if (lastDocumentSize == null)
+        {
+            return null;
+        }
+        
+        return new RectD(0, 0, lastDocumentSize.Value.X, lastDocumentSize.Value.Y); 
+    }
+
+    public bool RenderPreview(DrawingSurface renderOn, RenderContext context, string elementToRenderName)
+    {
+        if (Input.Value == null)
+        {
+            return false;
+        }
+        
+        int saved = renderOn.Canvas.Save();
+        Input.Value.Paint(context, renderOn);
+        
+        renderOn.Canvas.RestoreToCount(saved);
+        
+        return true;
+    }
+}

+ 8 - 0
src/PixiEditor/ViewModels/Document/Nodes/CustomOutputNodeViewModel.cs

@@ -0,0 +1,8 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+using PixiEditor.Extensions.Common.Localization;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes;
+
+[NodeViewModel("CUSTOM_OUTPUT_NODE", "MISC", null)]
+internal class CustomOutputNodeViewModel : NodeViewModel<CustomOutputNode>;

+ 25 - 0
src/PixiEditor/ViewModels/Nodes/Properties/StringPropertyViewModel.cs

@@ -0,0 +1,25 @@
+using System.ComponentModel;
+
+namespace PixiEditor.ViewModels.Nodes.Properties;
+
+internal class StringPropertyViewModel : NodePropertyViewModel<string>
+{
+    public string StringValue
+    {
+        get => Value;
+        set => Value = value;
+    }
+    
+    public StringPropertyViewModel(NodeViewModel node, Type valueType) : base(node, valueType)
+    {
+        PropertyChanged += StringPropertyViewModel_PropertyChanged;
+    }
+    
+    private void StringPropertyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
+    {
+        if (e.PropertyName == nameof(Value))
+        {
+            OnPropertyChanged(nameof(StringValue));
+        }
+    }
+}

+ 23 - 0
src/PixiEditor/Views/Nodes/Properties/StringPropertyView.axaml

@@ -0,0 +1,23 @@
+<properties:NodePropertyView xmlns="https://github.com/avaloniaui"
+                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+                             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+                             xmlns:properties="clr-namespace:PixiEditor.Views.Nodes.Properties"
+                             xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
+                             xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+                             xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours"
+                             xmlns:system="clr-namespace:System;assembly=System.Runtime"
+                             xmlns:properties1="clr-namespace:PixiEditor.ViewModels.Nodes.Properties"
+                             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+                             x:DataType="properties1:StringPropertyViewModel"
+                             x:Class="PixiEditor.Views.Nodes.Properties.StringPropertyView">
+    <DockPanel LastChildFill="True"
+        HorizontalAlignment="{Binding IsInput, Converter={converters:BoolToValueConverter FalseValue='Right', TrueValue='Stretch'}}">
+        <TextBlock VerticalAlignment="Center" ui:Translator.Key="{Binding DisplayName}" />
+        <TextBox Text="{CompiledBinding StringValue, Mode=TwoWay}" IsVisible="{Binding ShowInputField}">
+            <Interaction.Behaviors>
+                <behaviours:GlobalShortcutFocusBehavior />
+            </Interaction.Behaviors>
+        </TextBox>
+    </DockPanel>
+</properties:NodePropertyView>

+ 14 - 0
src/PixiEditor/Views/Nodes/Properties/StringPropertyView.axaml.cs

@@ -0,0 +1,14 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace PixiEditor.Views.Nodes.Properties;
+
+public partial class StringPropertyView : NodePropertyView
+{
+    public StringPropertyView()
+    {
+        InitializeComponent();
+    }
+}
+