Add project files.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Nodify.Playground
|
||||
{
|
||||
public class FlowToConnectorPositionConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is ConnectionViewModel connection)
|
||||
{
|
||||
var connector = parameter is "Input" ? connection.Input : connection.Output;
|
||||
|
||||
if (connector.Node is KnotNodeViewModel)
|
||||
{
|
||||
var otherConnector = connection.Input == connector ? connection.Output : connection.Input;
|
||||
|
||||
if (otherConnector.Node is KnotNodeViewModel)
|
||||
{
|
||||
return ToPosition(connector == connection.Input ? ConnectorFlow.Input : ConnectorFlow.Output, connector.Node.Orientation);
|
||||
}
|
||||
|
||||
return ToPosition(otherConnector.Flow == ConnectorFlow.Output ? ConnectorFlow.Input : ConnectorFlow.Output, connector.Node.Orientation);
|
||||
}
|
||||
|
||||
return ToPosition(connector.Flow, connector.Node.Orientation);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private ConnectorPosition ToPosition(ConnectorFlow flow, Orientation orientation)
|
||||
{
|
||||
if (orientation == Orientation.Horizontal)
|
||||
{
|
||||
return flow == ConnectorFlow.Output
|
||||
? ConnectorPosition.Right
|
||||
: ConnectorPosition.Left;
|
||||
}
|
||||
|
||||
return flow == ConnectorFlow.Output
|
||||
? ConnectorPosition.Bottom
|
||||
: ConnectorPosition.Top;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Nodify.Playground
|
||||
{
|
||||
public class FlowToDirectionConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is ConnectorFlow flow)
|
||||
{
|
||||
return flow == ConnectorFlow.Output ? ConnectionDirection.Forward : ConnectionDirection.Backward;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is ConnectionDirection dir)
|
||||
{
|
||||
return dir == ConnectionDirection.Forward ? ConnectorFlow.Output : ConnectorFlow.Input;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Examples/Nodify.Playground/Converters/UIntToRectConverter.cs
Normal file
27
Examples/Nodify.Playground/Converters/UIntToRectConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Nodify.Playground
|
||||
{
|
||||
public class UIntToRectConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public uint Multiplier { get; set; } = 1;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
uint size = System.Convert.ToUInt32(value) * Multiplier;
|
||||
return new Rect(0d, 0d, size, size);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
=> this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user