-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCanvasItemGuideCircle.cs
47 lines (41 loc) · 1.32 KB
/
CanvasItemGuideCircle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Linq;
using System.Net.Mime;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace GCEd
{
class CanvasItemGuideCircle : CanvasItem
{
public CanvasItemGuideCircle(GOperation operation)
: base(operation)
{
}
public override void OperationChanged()
{
base.OperationChanged();
var axes = Operation.AbsEnd - Operation.AbsStart;
AbsBoundingBox = new RectangleF(Operation.AbsXStart - axes.X, Operation.AbsYStart - axes.Y, axes.X * 2, axes.Y * 2);
}
public override void Draw(Graphics g, CanvasStyle style)
{
var pen = Selected ? style.SelectedGuidePen
: Hovered ? style.HoveredGuidePen
: style.GuidePen;
var axes = Operation.AbsEnd - Operation.AbsStart;
g.DrawEllipse(pen, Operation.AbsXStart - axes.X, Operation.AbsYStart - axes.Y, axes.X * 2, axes.Y * 2);
}
public override float Distance(Vector2 p)
{
if (AbsBoundingBox == default) return base.Distance(p);
var distance = Geometry.LineLength(new Vector2((float)Operation.Line.X.GetValueOrDefault(), (float)Operation.Line.Y.GetValueOrDefault()), p);
var radius = (float)Operation.Line.I.GetValueOrDefault();
return (float)Math.Abs(distance - radius);
}
}
}