mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-15 12:26:35 +08:00
添加Avalonia项目的demo
This commit is contained in:
55
Serein.Workbench.Avalonia/Extension/LineExtension.cs
Normal file
55
Serein.Workbench.Avalonia/Extension/LineExtension.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Avalonia.Media;
|
||||
using Serein.Library;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Workbench.Avalonia.Extension
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 线条颜色
|
||||
/// </summary>
|
||||
public static class LineExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据连接类型指定颜色
|
||||
/// </summary>
|
||||
/// <param name="currentConnectionType"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static SolidColorBrush ToLineColor(this ConnectionInvokeType currentConnectionType)
|
||||
{
|
||||
return currentConnectionType switch
|
||||
{
|
||||
ConnectionInvokeType.IsSucceed => new SolidColorBrush(Color.Parse("#04FC10")), // 04FC10 & 027E08
|
||||
ConnectionInvokeType.IsFail => new SolidColorBrush(Color.Parse("#F18905")),
|
||||
ConnectionInvokeType.IsError => new SolidColorBrush(Color.Parse("#FE1343")),
|
||||
ConnectionInvokeType.Upstream => new SolidColorBrush(Color.Parse("#4A82E4")),
|
||||
ConnectionInvokeType.None => new SolidColorBrush(Color.Parse("#56CEF6")),
|
||||
_ => throw new Exception(),
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据连接类型指定颜色
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static SolidColorBrush ToLineColor(this ConnectionArgSourceType connection)
|
||||
{
|
||||
return connection switch
|
||||
{
|
||||
|
||||
ConnectionArgSourceType.GetPreviousNodeData => new SolidColorBrush(Color.Parse("#56CEF6")), // 04FC10 & 027E08
|
||||
ConnectionArgSourceType.GetOtherNodeData => new SolidColorBrush(Color.Parse("#56CEF6")),
|
||||
ConnectionArgSourceType.GetOtherNodeDataOfInvoke => new SolidColorBrush(Color.Parse("#56CEF6")),
|
||||
_ => throw new Exception(),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
Serein.Workbench.Avalonia/Extension/PointExtension.cs
Normal file
42
Serein.Workbench.Avalonia/Extension/PointExtension.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Avalonia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Workbench.Avalonia.Extension
|
||||
{
|
||||
public static class PointExtension
|
||||
{
|
||||
public static Point Add(this Point a, Point b)
|
||||
{
|
||||
return new Point(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
|
||||
public static Point Sub(this Point a, Point b)
|
||||
{
|
||||
return new Point(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
|
||||
public static Vector ToVector(this Point me)
|
||||
{
|
||||
return new Vector(me.X, me.Y);
|
||||
}
|
||||
}
|
||||
public static class VectorExtension
|
||||
{
|
||||
public static double DotProduct(this Vector a, Vector b)
|
||||
{
|
||||
return a.X * b.X + a.Y * b.Y;
|
||||
}
|
||||
|
||||
public static Vector NormalizeTo(this Vector v)
|
||||
{
|
||||
var temp = v;
|
||||
temp.Normalize();
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Serein.Workbench.Avalonia/Extension/PointerExtension.cs
Normal file
32
Serein.Workbench.Avalonia/Extension/PointerExtension.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Workbench.Avalonia.Extension
|
||||
{
|
||||
internal static class PointerExtension
|
||||
{
|
||||
public static bool JudgePointer(this
|
||||
PointerEventArgs eventArgs,
|
||||
object? sender,
|
||||
PointerType pointerType,
|
||||
Func<PointerPointProperties,bool> judgePointerFunc)
|
||||
{
|
||||
if(sender is not Visual visual)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (eventArgs.Pointer.Type == pointerType) // 是否是否是指定的设备类型
|
||||
{
|
||||
var point = eventArgs.GetCurrentPoint(visual); // 获取到点击点
|
||||
return judgePointerFunc.Invoke(point.Properties); // 判断是否属于某种类型的点击
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user