绘制DropIcon矢量图

This commit is contained in:
zengwenjie
2025-09-25 19:22:01 +08:00
parent c901c9c096
commit 8b1ab264e6
4 changed files with 83 additions and 5 deletions

View File

@@ -5,6 +5,9 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;
using System.ComponentModel;
using System.Windows.Controls;
using Drawing = System.Drawing;
namespace Deedy.Activity.Helpers
{
@@ -30,12 +33,12 @@ namespace Deedy.Activity.Helpers
{
case DropPlacement.Rejected:
{
}
break;
case DropPlacement.Uncertain:
{
}
break;
case DropPlacement.BeforeMe:
@@ -93,7 +96,7 @@ namespace Deedy.Activity.Helpers
DropPlacement result = DropPlacement.UnDragged;
if (ui != null)
{
Size size = ui.RenderSize;
System.Windows.Size size = ui.RenderSize;
double horRuler = size.Width / 3;
if (horRuler > 20) horRuler = 20;
double verRuler = size.Height / 3;
@@ -149,5 +152,31 @@ namespace Deedy.Activity.Helpers
}
return result;
}
/// <summary>
/// 将一个字符串解析为一个矢量图形
/// </summary>
/// <param name="geometryString">矢量图形的字符串表示形式</param>
/// <returns>如果解析成功则返回「Geometry」对象</returns>
public static Geometry? Help_ParseAsGeometry(this string geometryString) => TypeDescriptor.GetConverter(typeof(Geometry)).ConvertFromString(geometryString) as Geometry;
/// <summary>
/// 对一个矢量图形进行连续的「缩放」、「平移」到一个「Rectangle」后再以图形中心点为中心沿顺时针旋转指定角度
/// </summary>
/// <param name="geometry">要进行映射的矢量图形</param>
/// <param name="rectangle">目标位置</param>
/// <param name="angle">旋转角度</param>
/// <returns>克隆平移后的新矢量图形</returns>
public static Geometry Help_MappingToBounds(this Geometry geometry, Rect rectangle, double angle)
{
Geometry newGeometry = geometry.Clone();
newGeometry.Transform = new TransformGroup
{
Children = {
new ScaleTransform(rectangle.Width/ newGeometry.Bounds.Width, rectangle.Height/newGeometry.Bounds.Height), // 宽度放大2倍高度放大1.5倍
new TranslateTransform(rectangle.Left-newGeometry.Bounds.Left, rectangle.Top-newGeometry.Bounds.Top), // X/Y方向位移
new RotateTransform(angle,rectangle.Width/2,rectangle.Height/2) // 顺时针旋转90度
}
};
return newGeometry;
}
}
}

View File

@@ -23,6 +23,13 @@ namespace Deedy.Activity
public const string ToolIcon_Close = "ToolIcon_Close";
public const string ToolIcon_Edit = "ToolIcon_Edit";
public const string ToolIcon_Save = "ToolIcon_Save";
public const string DropIcon_BringForward = "DropIcon_BringForward"; // 上移一层
public const string DropIcon_SendBackward = "DropIcon_SendBackward"; // 下移一层
public const string DropIcon_InsideOneself = "DropIcon_InsideOneself"; // 自身内部
public const string DropIcon_BeforeOrBehind = "DropIcon_BeforeOrBehind"; // 自身前后
public const string DropIcon_ReplaceOneself = "DropIcon_ReplaceOneself"; // 替换自身
public const string DropIcon_LinkWithOneself = "DropIcon_LinkWithOneself"; // 链接自身
}
public static ComponentResourceKey? LookupResourceKey(string themeKey)
@@ -43,5 +50,12 @@ namespace Deedy.Activity
public static ComponentResourceKey ToolIcon_Close = new ComponentResourceKey(typeof(ThemeKeys), Keys.ToolIcon_Close);
public static ComponentResourceKey ToolIcon_Edit = new ComponentResourceKey(typeof(ThemeKeys), Keys.ToolIcon_Edit);
public static ComponentResourceKey ToolIcon_Save = new ComponentResourceKey(typeof(ThemeKeys), Keys.ToolIcon_Save);
public static ComponentResourceKey DropIcon_BringForward = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_BringForward);
public static ComponentResourceKey DropIcon_SendBackward = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_SendBackward);
public static ComponentResourceKey DropIcon_InsideOneself = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_InsideOneself);
public static ComponentResourceKey DropIcon_BeforeOrBehind = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_BeforeOrBehind);
public static ComponentResourceKey DropIcon_ReplaceOneself = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_ReplaceOneself);
public static ComponentResourceKey DropIcon_LinkWithOneself = new ComponentResourceKey(typeof(ThemeKeys), Keys.DropIcon_LinkWithOneself);
}
}

View File

@@ -21,5 +21,12 @@ namespace Deedy.Activity
public ImageSource? ToolIcon_Close => this[ThemeKeys.ToolIcon_Close] as ImageSource;
public ImageSource? ToolIcon_Edit => this[ThemeKeys.ToolIcon_Edit] as ImageSource;
public ImageSource? ToolIcon_Save => this[ThemeKeys.ToolIcon_Save] as ImageSource;
public PathGeometry? DropIcon_BringForward => this[ThemeKeys.DropIcon_BringForward] as PathGeometry;
public PathGeometry? DropIcon_SendBackward => this[ThemeKeys.DropIcon_SendBackward] as PathGeometry;
public PathGeometry? DropIcon_InsideOneself => this[ThemeKeys.DropIcon_InsideOneself] as PathGeometry;
public PathGeometry? DropIcon_BeforeOrBehind => this[ThemeKeys.DropIcon_BeforeOrBehind] as PathGeometry;
public PathGeometry? DropIcon_ReplaceOneself => this[ThemeKeys.DropIcon_ReplaceOneself] as PathGeometry;
public PathGeometry? DropIcon_LinkWithOneself => this[ThemeKeys.DropIcon_LinkWithOneself] as PathGeometry;
}
}

View File

@@ -2,10 +2,13 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Deedy.Activity">
<!--#region ActivityIcon-->
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=Activity_DefaultIcon}">
<!--矢量图标定义-->
</DrawingImage>
<!--#endregion-->
<!--#region 消息回显图标-->
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=InfoIcon_None}">
<!--矢量图标定义-->
</DrawingImage>
@@ -18,7 +21,9 @@
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=InfoIcon_Error}">
<!--矢量图标定义-->
</DrawingImage>
<!--#endregion-->
<!--#region 工具按钮图标-->
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=ToolIcon_Delete}">
<!--矢量图标定义-->
</DrawingImage>
@@ -31,5 +36,28 @@
<DrawingImage x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=ToolIcon_Save}">
<!--矢量图标定义-->
</DrawingImage>
<!--#endregion-->
<!--#region 拖放操作图标-->
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_BringForward}">
M0,0H24V4H0Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_SendBackward}">
M0,0H24V4H0Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_InsideOneself}">
M0,0H8L16,16L0,8ZM16,16L24,0V24H0Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_BeforeOrBehind}">
M0,0H24V4H0ZM12,4L0,16L12,10L24,16ZM12,10L0,24L12,16L24,24Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_ReplaceOneself}">
M0,24V0H24L6,6ZM6,6L12,24V12H24Z
</PathGeometry>
<PathGeometry x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=DropIcon_LinkWithOneself}">
M0,0H24V4H0Z
</PathGeometry>
<!--#endregion-->
<!-- x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ThemeKeys},ResourceId=ResourceKey}" -->
</ResourceDictionary>