forked from opensourceautomation/Open-Source-Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DragAdorner.cs
122 lines (101 loc) · 3.29 KB
/
DragAdorner.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace GUI2
{
class DragAdorner : Adorner
{
protected UIElement _child;
protected VisualBrush _brush;
protected UIElement _owner;
protected double XCenter;
protected double YCenter;
public DragAdorner(UIElement owner) : base(owner) { }
public DragAdorner(UIElement owner, UIElement adornElement, bool useVisualBrush, double opacity)
: base(owner)
{
System.Diagnostics.Debug.Assert(owner != null);
System.Diagnostics.Debug.Assert(adornElement != null);
_owner = owner;
if (useVisualBrush)
{
VisualBrush _brush = new VisualBrush(adornElement);
_brush.Opacity = opacity;
Rectangle r = new Rectangle();
r.RadiusX = 3;
r.RadiusY = 3;
//TODO: questioning DesiredSize vs. Actual
r.Width = adornElement.DesiredSize.Width;
r.Height = adornElement.DesiredSize.Height;
XCenter = adornElement.DesiredSize.Width / 2;
YCenter = adornElement.DesiredSize.Height / 2;
r.Fill = _brush;
_child = r;
}
else
_child = adornElement;
}
private double _leftOffset;
public double LeftOffset
{
get { return _leftOffset; }
set
{
_leftOffset = value - XCenter;
UpdatePosition();
}
}
private double _topOffset;
public double TopOffset
{
get { return _topOffset; }
set
{
_topOffset = value - YCenter;
UpdatePosition();
}
}
private void UpdatePosition()
{
AdornerLayer adorner = (AdornerLayer)this.Parent;
if (adorner != null)
{
adorner.Update(this.AdornedElement);
}
}
protected override Visual GetVisualChild(int index)
{
return _child;
}
protected override int VisualChildrenCount
{
get
{
return 1;
}
}
protected override Size MeasureOverride(Size finalSize)
{
_child.Measure(finalSize);
return _child.DesiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
_child.Arrange(new Rect(_child.DesiredSize));
return finalSize;
}
public double scale = 1.0;
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
GeneralTransformGroup result = new GeneralTransformGroup();
result.Children.Add(base.GetDesiredTransform(transform));
result.Children.Add(new TranslateTransform(_leftOffset, _topOffset));
return result;
}
}
}