68 lines
2.8 KiB
C#
68 lines
2.8 KiB
C#
using System;
|
|
using System.Reactive.Disposables;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using Intromat.ViewModels;
|
|
using ReactiveUI;
|
|
|
|
namespace Intromat.Views
|
|
{
|
|
public partial class CodeGenPortView : IViewFor<CodeGenPortViewModel>
|
|
{
|
|
public const string ExecutionPortTemplateKey = "ExecutionPortTemplate";
|
|
public const string IntegerPortTemplateKey = "IntegerPortTemplate";
|
|
public const string StringPortTemplateKey = "StringPortTemplate";
|
|
public const string BooleanPortTemplateKey = "BooleanPortTemplate";
|
|
public const string FloatPortTemplateKey = "FloatPortTemplate";
|
|
public const string TexturePortTemplateKey = "TexturePortTemplate";
|
|
public const string MeshPortTemplateKey = "MeshPortTemplate";
|
|
|
|
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(CodeGenPortViewModel), typeof(CodeGenPortView), new PropertyMetadata(null));
|
|
|
|
public CodeGenPortView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.WhenActivated(d =>
|
|
{
|
|
this.WhenAnyValue(v => v.ViewModel)
|
|
.BindTo(this, v => v.PortView.ViewModel)
|
|
.DisposeWith(d);
|
|
|
|
this.OneWayBind(ViewModel, vm => vm.PortType, v => v.PortView.Template, GetTemplateFromPortType)
|
|
.DisposeWith(d);
|
|
|
|
this.OneWayBind(ViewModel, vm => vm.IsMirrored, v => v.PortView.RenderTransform, isMirrored => new ScaleTransform(isMirrored ? -1.0 : 1.0, 1.0))
|
|
.DisposeWith(d);
|
|
});
|
|
}
|
|
|
|
public CodeGenPortViewModel? ViewModel
|
|
{
|
|
get => (CodeGenPortViewModel?)GetValue(ViewModelProperty);
|
|
set => SetValue(ViewModelProperty, value);
|
|
}
|
|
|
|
object? IViewFor.ViewModel
|
|
{
|
|
get => ViewModel;
|
|
set => ViewModel = (CodeGenPortViewModel?)value;
|
|
}
|
|
|
|
public ControlTemplate GetTemplateFromPortType(EPortType type)
|
|
{
|
|
return type switch
|
|
{
|
|
EPortType.Execution => (ControlTemplate)Resources[ExecutionPortTemplateKey],
|
|
EPortType.Integer => (ControlTemplate)Resources[IntegerPortTemplateKey],
|
|
EPortType.String => (ControlTemplate)Resources[StringPortTemplateKey],
|
|
EPortType.Boolean => (ControlTemplate)Resources[BooleanPortTemplateKey],
|
|
EPortType.Float => (ControlTemplate)Resources[FloatPortTemplateKey],
|
|
EPortType.Texture => (ControlTemplate)Resources[TexturePortTemplateKey],
|
|
EPortType.Mesh => (ControlTemplate)Resources[MeshPortTemplateKey],
|
|
_ => throw new Exception("Unsupported port type")
|
|
};
|
|
}
|
|
}
|
|
} |