using Avalonia.Controls.Shapes;
using Avalonia.Controls;
using Avalonia.Media;
using Serein.Workbench.Avalonia.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.VisualTree;
using Serein.Library;
namespace Serein.Workbench.Avalonia.Custom.Junction
{
public abstract class JunctionControlBase : Control
{
protected JunctionControlBase()
{
this.Width = 25;
this.Height = 20;
this.PointerPressed += JunctionControlBase_PointerPressed;
this.PointerMoved += JunctionControlBase_PointerMoved;
this.PointerExited += JunctionControlBase_PointerExited;
}
/*
#region 控件属性,所在的节点
public static readonly DependencyProperty NodeProperty =
DependencyProperty.Register(nameof(MyNode), typeof(NodeModelBase), typeof(JunctionControlBase), new PropertyMetadata(default(NodeModelBase)));
//public NodeModelBase NodeModel;
///
/// 所在的节点
///
public NodeModelBase MyNode
{
get { return (NodeModelBase)GetValue(NodeProperty); }
set { SetValue(NodeProperty, value); }
}
#endregion
#region 控件属性,连接器类型
public static readonly DependencyProperty JunctionTypeProperty =
DependencyProperty.Register(nameof(JunctionType), typeof(string), typeof(JunctionControlBase), new PropertyMetadata(default(string)));
///
/// 控制点类型
///
public JunctionType JunctionType
{
get { return EnumHelper.ConvertEnum(GetValue(JunctionTypeProperty).ToString()); }
set { SetValue(JunctionTypeProperty, value.ToString()); }
}
#endregion
protected override Geometry DefiningGeometry => StreamGeometry;
*/
protected readonly StreamGeometry StreamGeometry = new StreamGeometry();
///
/// 重绘方法
///
///
public abstract void OnRender(DrawingContext drawingContext);
///
/// 中心点
///
public abstract Point MyCenterPoint { get; }
///
/// 禁止连接
///
private bool IsConnectionDisable;
///
/// 处理鼠标悬停状态
///
private bool _isMouseOver;
public bool IsMouseOver
{
get => _isMouseOver;
set
{
if (_isMouseOver != value)
{
//GlobalJunctionData.MyGlobalConnectingData.CurrentJunction = this;
_isMouseOver = value;
InvalidateVisual();
}
}
}
///
/// 控件重绘事件
///
///
public override void Render(DrawingContext drawingContext)
{
OnRender(drawingContext);
}
///
/// 获取背景颜色
///
///
protected Brush GetBackgrounp()
{
return (Brush)Brushes.Transparent;
//var myData = GlobalJunctionData.MyGlobalConnectingData;
//if (!myData.IsCreateing)
//{
// return Brushes.Transparent;
//}
//if (IsMouseOver)
//{
// if (myData.IsCanConnected)
// {
// if (myData.Type == JunctionOfConnectionType.Invoke)
// {
// return myData.ConnectionInvokeType.ToLineColor();
// }
// else
// {
// return myData.ConnectionArgSourceType.ToLineColor();
// }
// }
// else
// {
// return Brushes.Red;
// }
//}
//else
//{
// return Brushes.Transparent;
//}
}
private object lockObj = new object();
///
/// 控件获得鼠标焦点事件
///
///
///
private void JunctionControlBase_PointerMoved(object? sender, global::Avalonia.Input.PointerEventArgs e)
{
//if (!GlobalJunctionData.MyGlobalConnectingData.IsCreateing) return;
//if (IsMouseOver) return;
IsMouseOver = true;
this.InvalidateVisual();
}
///
/// 控件失去鼠标焦点事件
///
///
///
private void JunctionControlBase_PointerExited(object? sender, global::Avalonia.Input.PointerEventArgs e)
{
IsMouseOver = false;
e.Handled = true;
}
///
/// 在碰撞点上按下鼠标控件开始进行移动
///
///
///
private void JunctionControlBase_PointerPressed(object? sender, global::Avalonia.Input.PointerPressedEventArgs e)
{
throw new NotImplementedException();
//if (e.LeftButton == MouseButtonState.Pressed)
//{
// var canvas = MainWindow.GetParentOfType