|
0
|
1 |
using System; |
|
|
2 |
using System.Collections.Generic; |
|
|
3 |
using System.Linq; |
|
|
4 |
using System.Net; |
|
|
5 |
using System.Windows; |
|
|
6 |
using System.Windows.Controls; |
|
|
7 |
using System.Windows.Documents; |
|
|
8 |
using System.Windows.Input; |
|
|
9 |
using System.Windows.Media; |
|
|
10 |
using System.Windows.Media.Animation; |
|
|
11 |
using System.Windows.Shapes; |
|
|
12 |
using System.Threading; |
|
|
13 |
using Iri.Modernisation.BaseMVVM.Commands; |
|
|
14 |
using Iri.Modernisation.Controls.Converter; |
|
|
15 |
using Iri.Modernisation.Data.Models; |
|
|
16 |
namespace Iri.Modernisation.Controls.View |
|
|
17 |
{ |
|
|
18 |
public partial class ContextualBinderLayer : UserControl |
|
|
19 |
{ |
|
|
20 |
private ContextualLinkBinder _movingBinder; |
|
|
21 |
private Line _linkLine; |
|
|
22 |
private bool _active = false; |
|
|
23 |
private System.Windows.Threading.DispatcherTimer myDispatcherTimer; |
|
13
|
24 |
private Point _menuAnnotationPoint; |
|
0
|
25 |
public ContextualBinderLayer() |
|
|
26 |
{ |
|
|
27 |
InitializeComponent(); |
|
13
|
28 |
Commands.PolemicElement.ElementSelected.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(ElementSelected_Executed); |
|
0
|
29 |
Commands.ContextualBinderLayer.EndBind.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EndBind_Executed); |
|
35
|
30 |
Commands.EscapeKeyPressed.Executed += Commands.ContextualBinderLayer.EndBind.Execute; |
|
|
31 |
|
|
0
|
32 |
MouseLeftButtonUp += new MouseButtonEventHandler(ContextualBinderLayer_MouseLeftButtonUp); |
|
|
33 |
MouseMove += new MouseEventHandler(ContextualBinderLayer_MouseMove); |
|
|
34 |
Commands.ContextualBinderLayer.BeginBind.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(BeginBind_Executed); |
|
|
35 |
myDispatcherTimer = new System.Windows.Threading.DispatcherTimer(); |
|
|
36 |
myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 0); |
|
|
37 |
myDispatcherTimer.Tick +=new EventHandler(myDispatcherTimer_Tick); |
|
|
38 |
} |
|
|
39 |
|
|
13
|
40 |
void ElementSelected_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
41 |
{ |
|
|
42 |
_menuAnnotationPoint = ((MouseButtonEventArgs)e.Parameter).GetPosition(Application.Current.RootVisual); |
|
|
43 |
} |
|
|
44 |
|
|
0
|
45 |
void myDispatcherTimer_Tick(object sender, EventArgs e) |
|
|
46 |
{ |
|
28
|
47 |
LayoutRoot.Background = new SolidColorBrush(_movingBinder.PolemicType.Color); |
|
0
|
48 |
LayoutRoot.Background.Opacity = 0.0; |
|
|
49 |
_movingBinder.Visibility = Visibility.Visible; |
|
|
50 |
_linkLine.Visibility = Visibility.Visible; |
|
|
51 |
} |
|
|
52 |
void EndBind_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
53 |
{ |
|
|
54 |
if (_active) |
|
|
55 |
{ |
|
|
56 |
FlushDisplay(); |
|
|
57 |
} |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
void ContextualBinderLayer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) |
|
|
61 |
{ |
|
|
62 |
FlushDisplay(); |
|
|
63 |
} |
|
|
64 |
private void FlushDisplay() |
|
|
65 |
{ |
|
|
66 |
LayoutRoot.Children.Clear(); |
|
|
67 |
_movingBinder.ReleaseMouseCapture(); |
|
|
68 |
LayoutRoot.Background = null; |
|
|
69 |
_active = false; |
|
|
70 |
myDispatcherTimer.Stop(); |
|
|
71 |
Commands.ContextualBinderLayer.DesactiveBind.Execute(); |
|
|
72 |
} |
|
|
73 |
|
|
|
74 |
void ContextualBinderLayer_MouseMove(object sender, MouseEventArgs e) |
|
|
75 |
{ |
|
|
76 |
LayoutRoot.Background = null; |
|
|
77 |
_movingBinder.Visibility = Visibility.Collapsed; |
|
|
78 |
_linkLine.Visibility = Visibility.Collapsed; |
|
|
79 |
LayoutRoot.UpdateLayout(); |
|
|
80 |
_movingBinder.Margin = new Thickness( |
|
|
81 |
e.GetPosition(this).X - _movingBinder.Width/2, |
|
|
82 |
e.GetPosition(this).Y - _movingBinder.Height / 2, |
|
|
83 |
0, |
|
|
84 |
0); |
|
|
85 |
_linkLine.X2 = e.GetPosition(this).X ; |
|
|
86 |
_linkLine.Y2 = e.GetPosition(this).Y; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
void BeginBind_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
90 |
{ |
|
13
|
91 |
Point temp; |
|
|
92 |
if(e.Source ==null) |
|
|
93 |
{ |
|
|
94 |
temp = _menuAnnotationPoint; |
|
|
95 |
} |
|
|
96 |
else |
|
|
97 |
{ |
|
|
98 |
temp = ((MouseButtonEventArgs)e.Source).GetPosition(Application.Current.RootVisual); |
|
|
99 |
} |
|
0
|
100 |
LayoutRoot.Children.Clear(); |
|
|
101 |
_movingBinder =new ContextualLinkBinder( ((ContextualLinkBinder)e.Parameter)); |
|
|
102 |
_movingBinder.Margin = new Thickness( |
|
13
|
103 |
temp.X - _movingBinder.Width/ 2, |
|
|
104 |
temp.Y - _movingBinder.Height / 2, |
|
0
|
105 |
_movingBinder.Margin.Right, |
|
|
106 |
_movingBinder.Margin.Bottom); |
|
|
107 |
_linkLine = new Line() |
|
|
108 |
{ |
|
13
|
109 |
X1 = temp.X, |
|
|
110 |
Y1 = temp.Y, |
|
|
111 |
X2 = temp.X, |
|
|
112 |
Y2 = temp.Y, |
|
28
|
113 |
Stroke = new SolidColorBrush(_movingBinder.PolemicType.Color), |
|
0
|
114 |
StrokeThickness = 2 |
|
|
115 |
}; |
|
28
|
116 |
LayoutRoot.Background = new SolidColorBrush(_movingBinder.PolemicType.Color); |
|
0
|
117 |
LayoutRoot.Background.Opacity = 0.0; |
|
|
118 |
LayoutRoot.Children.Add(_movingBinder); |
|
|
119 |
LayoutRoot.Children.Add(_linkLine); |
|
|
120 |
_active = true; |
|
|
121 |
Commands.ContextualBinderLayer.ActiveBind.Execute(); |
|
|
122 |
myDispatcherTimer.Start(); |
|
|
123 |
} |
|
|
124 |
} |
|
|
125 |
} |