Graphics/GraphicsUtility.cs
(开头部分) 56KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
namespace DrawingPad.Graphics
{
public static class GraphicsUtility
{
/// <summary>
/// 获取矩形的中心点
/// </summary>
/// <param name="rect"></param>
/// <returns></returns>
public static Point GetCenter(this Rect rect)
{
return new Point(rect.Location.X + rect.Width / 2, rect.Location.Y + rect.Height / 2);
}
/// <summary>
/// 获取点P相对于图形的位置
/// 点P可以是任意一点
/// </summary>
/// <param name="graphics"></param>
/// <param name="p"></param>
/// <returns></returns>
public static RelativeLocation GetRelativeLocation(GraphicsBase graphics, Point p)
{
Rect bounds = graphics.GetBounds();
if (p.X >= bounds.TopLeft.X && p.X <= bounds.TopRight.X && p.Y <= bounds.TopLeft.Y)
{
// 点在图形的上方
return RelativeLocation.Top;
}
if (p.X <= bounds.TopLeft.X && p.Y >= bounds.TopLeft.Y && p.Y <= bounds.BottomLeft.Y)
{
// 点在图形的左边
return RelativeLocation.Left;
}
if (p.Y >= bounds.BottomLeft.Y && p.X >= bounds.TopLeft.X && p.X <= bounds.TopRight.X)
{
// 点在图形的下面
return RelativeLocation.Bottom;
}
if (p.X >= bounds.TopRight.X && p.Y >= bounds.TopRight.Y && p.Y <= bounds.BottomRight.Y)
{
// 点在图形的右边
return RelativeLocation.Right;
}
if (p.X < bounds.TopLeft.X && p.Y < bounds.TopLeft.Y)
{
// 点在图形的左上方
后面还有 1214 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。