You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.6 KiB
149 lines
4.6 KiB
using Avalonia.Data.Converters;
|
|
using Avalonia.Media;
|
|
using Avalonia;
|
|
using AuroraDesk.Core.Entities;
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
|
|
namespace AuroraDesk.Presentation.Converters;
|
|
|
|
/// <summary>
|
|
/// 节点画布相关转换器
|
|
/// </summary>
|
|
public static class NodeCanvasConverters
|
|
{
|
|
public static readonly IValueConverter BooleanToBorderBrushConverter = new BooleanToBorderBrushConverter();
|
|
public static readonly IValueConverter BooleanToBorderThicknessConverter = new BooleanToBorderThicknessConverter();
|
|
public static readonly IValueConverter FilterInputPointsConverter = new FilterInputPointsConverter();
|
|
public static readonly IValueConverter FilterOutputPointsConverter = new FilterOutputPointsConverter();
|
|
public static readonly IValueConverter NodeToSelectionTextConverter = new NodeToSelectionTextConverter();
|
|
public static readonly IValueConverter IsNotNullConverter = new IsNotNullConverter();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 布尔值到边框颜色转换器(选中时显示蓝色边框)
|
|
/// </summary>
|
|
public class BooleanToBorderBrushConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool isSelected && isSelected)
|
|
{
|
|
// 使用 StaticResource 的颜色,如果无法获取则使用默认蓝色
|
|
try
|
|
{
|
|
var color = Color.Parse("#3498DB"); // PrimaryBlue
|
|
return new SolidColorBrush(color);
|
|
}
|
|
catch
|
|
{
|
|
return new SolidColorBrush(Color.FromRgb(52, 152, 219)); // #3498DB
|
|
}
|
|
}
|
|
return new SolidColorBrush(Colors.Transparent);
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 布尔值到边框厚度转换器(选中时显示边框)
|
|
/// </summary>
|
|
public class BooleanToBorderThicknessConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool isSelected && isSelected)
|
|
{
|
|
return new Thickness(2);
|
|
}
|
|
return new Thickness(0);
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 过滤输入连接点转换器
|
|
/// </summary>
|
|
public class FilterInputPointsConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is ObservableCollection<ConnectionPoint> points)
|
|
{
|
|
return points.Where(p => p.Type == ConnectionPointType.Input).ToList();
|
|
}
|
|
return Enumerable.Empty<ConnectionPoint>();
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 过滤输出连接点转换器
|
|
/// </summary>
|
|
public class FilterOutputPointsConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is ObservableCollection<ConnectionPoint> points)
|
|
{
|
|
return points.Where(p => p.Type == ConnectionPointType.Output).ToList();
|
|
}
|
|
return Enumerable.Empty<ConnectionPoint>();
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 节点到选择文本转换器
|
|
/// </summary>
|
|
public class NodeToSelectionTextConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is Node node)
|
|
{
|
|
return $"已选中1个对象 (节点)";
|
|
}
|
|
return "未选中对象";
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 非空转换器(用于控制可见性)
|
|
/// </summary>
|
|
public class IsNotNullConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value != null;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
|