添加Avalonia项目的demo

This commit is contained in:
fengjiayi
2025-01-01 17:49:48 +08:00
parent 6c6d493f93
commit 28df2d8fce
61 changed files with 4404 additions and 0 deletions

View 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(),
};
}
}
}

View 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;
}
}
}

View 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;
}
}
}