编写VisualHelper
This commit is contained in:
@@ -11,25 +11,30 @@ namespace Deedy.Activity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DropPlacement : int
|
public enum DropPlacement : int
|
||||||
{
|
{
|
||||||
|
UnDragged = 0,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 不确定的
|
/// 不确定的
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Uncertain=0,
|
Uncertain = 1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拒绝放置
|
/// 拒绝放置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Rejected = 0,
|
Rejected = 2,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在节点前
|
/// 在节点前
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BeforeMe = 1,
|
BeforeMe = 3,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在节点内
|
/// 在节点内
|
||||||
/// </summary>
|
/// </summary>
|
||||||
WithinMe = 2,
|
WithinMe = 4,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在节点后
|
/// 在节点后
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BehindMe = 3,
|
BehindMe = 5,
|
||||||
|
/// <summary>
|
||||||
|
/// 替换自身
|
||||||
|
/// </summary>
|
||||||
|
ReplaceMe = 6,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Deedy.Activity
|
||||||
|
{
|
||||||
|
public enum LayoutDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 不可布局
|
||||||
|
/// </summary>
|
||||||
|
Cannot,
|
||||||
|
/// <summary>
|
||||||
|
/// 只有唯一子节点
|
||||||
|
/// </summary>
|
||||||
|
Decorator,
|
||||||
|
/// <summary>
|
||||||
|
/// 上下叠放
|
||||||
|
/// </summary>
|
||||||
|
Stacked,
|
||||||
|
/// <summary>
|
||||||
|
/// 从左向右
|
||||||
|
/// </summary>
|
||||||
|
Horizontal,
|
||||||
|
/// <summary>
|
||||||
|
/// 从上到下
|
||||||
|
/// </summary>
|
||||||
|
Vertical,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Deedy.Activity
|
namespace Deedy.Activity
|
||||||
{
|
{
|
||||||
public interface IDeedyInput
|
public interface IVisualInput
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Deedy.Activity
|
namespace Deedy.Activity
|
||||||
{
|
{
|
||||||
public interface IDeedyLayout : IContainerElement
|
public interface IVisualLayout : IContainerElement
|
||||||
{
|
{
|
||||||
|
LayoutDirection LayoutDirection { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Deedy.Activity
|
namespace Deedy.Activity
|
||||||
{
|
{
|
||||||
public class IDeedyViewer
|
public class IVisualViewer
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,10 @@ using System.Windows;
|
|||||||
|
|
||||||
namespace Deedy.Activity
|
namespace Deedy.Activity
|
||||||
{
|
{
|
||||||
public class DeedyLayout : IDeedyLayout
|
public class VisualLayout : IVisualLayout
|
||||||
{
|
{
|
||||||
public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping();
|
public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping();
|
||||||
public DeedyLayout() { }
|
public VisualLayout() { }
|
||||||
public string Class { get; protected internal set; } = "";
|
public string Class { get; protected internal set; } = "";
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
public string Remark { get; set; } = "";
|
public string Remark { get; set; } = "";
|
||||||
@@ -29,6 +29,8 @@ namespace Deedy.Activity
|
|||||||
|
|
||||||
public ParamDefineCollection ParamsMapping { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public ParamDefineCollection ParamsMapping { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
|
public LayoutDirection LayoutDirection => throw new NotImplementedException();
|
||||||
|
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -3,10 +3,151 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace Deedy.Activity.Helpers
|
namespace Deedy.Activity.Helpers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 辅助可视化单元进行相关操作
|
||||||
|
/// </summary>
|
||||||
public static partial class Helper
|
public static partial class Helper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 辅助可视化单元进行拖放装饰器绘制操作
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ui">要绘制的「UIElement」元素</param>
|
||||||
|
/// <param name="dc">「UIElement」元素的绘图上下文</param>
|
||||||
|
/// <param name="dropPlacement">拖放操作的放置位置</param>
|
||||||
|
/// <param name="parentLayout">父级布局的布局方向</param>
|
||||||
|
public static void Help_DrawDropAdorner(this UIElement ui, DrawingContext dc, DropPlacement dropPlacement, LayoutDirection parentLayout)
|
||||||
|
{
|
||||||
|
if (ui == null || dc == null || dropPlacement == DropPlacement.UnDragged) return;
|
||||||
|
Pen pen = new Pen(Brushes.Red, 3);
|
||||||
|
pen.Freeze();
|
||||||
|
|
||||||
|
switch (dropPlacement)
|
||||||
|
{
|
||||||
|
case DropPlacement.Rejected:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DropPlacement.Uncertain:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DropPlacement.BeforeMe:
|
||||||
|
{
|
||||||
|
if (parentLayout == LayoutDirection.Horizontal)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (parentLayout == LayoutDirection.Vertical)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (parentLayout == LayoutDirection.Stacked)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else { }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DropPlacement.BehindMe:
|
||||||
|
{
|
||||||
|
if (parentLayout == LayoutDirection.Horizontal)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (parentLayout == LayoutDirection.Vertical)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (parentLayout == LayoutDirection.Stacked)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else { }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DropPlacement.WithinMe:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DropPlacement.ReplaceMe:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: break; //DropPlacement.UnDragged;不需要绘制任何图样
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 检查拖放操作的模式
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ui">要检查的「UIElement」元素</param>
|
||||||
|
/// <param name="point">检查点位置</param>
|
||||||
|
/// <returns>检查后的拖放位置;其中不包括「DropPlacement.UnDragged」与「DropPlacement.Uncertain」</returns>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>「DropPlacement.UnDragged」= 未在拖放状态</para>
|
||||||
|
/// <para>「DropPlacement.Uncertain」= 拖放内容不是可视化元素</para>
|
||||||
|
/// <para>··以上两种情况需要在调用此方法前进行判定</para>
|
||||||
|
/// </remarks>
|
||||||
|
public static DropPlacement Help_CheckDropPlacement(this UIElement ui, Point point)
|
||||||
|
{
|
||||||
|
DropPlacement result = DropPlacement.UnDragged;
|
||||||
|
if (ui != null)
|
||||||
|
{
|
||||||
|
Size size = ui.RenderSize;
|
||||||
|
double horRuler = size.Width / 3;
|
||||||
|
if (horRuler > 20) horRuler = 20;
|
||||||
|
double verRuler = size.Height / 3;
|
||||||
|
if (verRuler > 20) verRuler = 20;
|
||||||
|
LayoutDirection direction = LayoutDirection.Cannot;
|
||||||
|
if (ui is IVisualLayout layout)
|
||||||
|
{
|
||||||
|
if (ui is FrameworkElement fe && fe.Parent is IVisualLayout parentLayout)
|
||||||
|
{
|
||||||
|
direction = parentLayout.LayoutDirection;
|
||||||
|
if (direction == LayoutDirection.Decorator)
|
||||||
|
{
|
||||||
|
if (point.X < horRuler
|
||||||
|
|| point.Y < verRuler
|
||||||
|
|| size.Width - point.X < horRuler
|
||||||
|
|| size.Height - point.Y < verRuler)
|
||||||
|
result = DropPlacement.ReplaceMe;
|
||||||
|
else result = DropPlacement.WithinMe;
|
||||||
|
}
|
||||||
|
else if (direction == LayoutDirection.Cannot)
|
||||||
|
result = DropPlacement.WithinMe;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (point.X < horRuler || point.Y < verRuler)
|
||||||
|
result = DropPlacement.BeforeMe;
|
||||||
|
else if (size.Width - point.X < horRuler || size.Height - point.Y < verRuler)
|
||||||
|
result = DropPlacement.BehindMe;
|
||||||
|
else result = DropPlacement.WithinMe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else result = DropPlacement.WithinMe;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ui is FrameworkElement fe && fe.Parent is IVisualLayout parentLayout)
|
||||||
|
{
|
||||||
|
direction = parentLayout.LayoutDirection;
|
||||||
|
if (direction == LayoutDirection.Decorator)
|
||||||
|
result = DropPlacement.ReplaceMe;
|
||||||
|
else if (direction == LayoutDirection.Cannot)
|
||||||
|
result = DropPlacement.Rejected;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (point.X < horRuler || point.Y < verRuler)
|
||||||
|
result = DropPlacement.BeforeMe;
|
||||||
|
else if (size.Width - point.X < horRuler || size.Height - point.Y < verRuler)
|
||||||
|
result = DropPlacement.BehindMe;
|
||||||
|
else result = DropPlacement.Rejected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else result = DropPlacement.Rejected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ namespace Deedy.Activity
|
|||||||
{
|
{
|
||||||
public interface IVisualElement : IElement
|
public interface IVisualElement : IElement
|
||||||
{
|
{
|
||||||
|
DropPlacement DropPlacement { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user