markus / MarkupToPDF / Controls / Etc / ImgControl.cs @ 90e7968d
이력 | 보기 | 이력해설 | 다운로드 (13.2 KB)
1 |
using System; |
---|---|
2 |
using System.Net; |
3 |
using System.Windows; |
4 |
using System.Windows.Controls; |
5 |
using System.Windows.Documents; |
6 |
using System.Windows.Ink; |
7 |
using System.Windows.Input; |
8 |
using System.Windows.Media; |
9 |
using System.Windows.Media.Animation; |
10 |
using System.Windows.Shapes; |
11 |
using System.Collections.Generic; |
12 |
using System.ComponentModel; |
13 |
using System.Linq; |
14 |
using MarkupToPDF.Controls.Common; |
15 |
using MarkupToPDF.Common; |
16 |
|
17 |
namespace MarkupToPDF.Controls.Etc |
18 |
{ |
19 |
public class ImgControl : CommentUserInfo, IDisposable, INormal, INotifyPropertyChanged, IViewBox, IMarkupCommonData |
20 |
{ |
21 |
#region 초기선언 |
22 |
private const string PART_Image = "PART_Image"; |
23 |
public Image Base_Image = null; |
24 |
#endregion |
25 |
|
26 |
static ImgControl() |
27 |
{ |
28 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(ImgControl), new FrameworkPropertyMetadata(typeof(ImgControl))); |
29 |
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
30 |
ResourceDictionary dictionary = new ResourceDictionary(); |
31 |
dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
32 |
Application.Current.Resources.MergedDictionaries.Add(dictionary); |
33 |
//System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
34 |
} |
35 |
|
36 |
public ImgControl() |
37 |
{ |
38 |
this.DefaultStyleKey = typeof(ImgControl); |
39 |
} |
40 |
|
41 |
public void Dispose() |
42 |
{ |
43 |
GC.Collect(); |
44 |
GC.SuppressFinalize(this); |
45 |
} |
46 |
public event PropertyChangedEventHandler PropertyChanged; |
47 |
protected void OnPropertyChanged(string propName) |
48 |
{ |
49 |
if (PropertyChanged != null) |
50 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
51 |
} |
52 |
|
53 |
public void ApplyOverViewData() |
54 |
{ |
55 |
this.OverViewPathData = this.PathData; |
56 |
} |
57 |
|
58 |
#region Dependency Properties |
59 |
|
60 |
public static readonly DependencyProperty IsSelectedProperty = |
61 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(ImgControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
62 |
|
63 |
public static readonly DependencyProperty ControlTypeProperty = |
64 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ImgControl), new FrameworkPropertyMetadata(ControlType.ImgControl)); |
65 |
|
66 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
67 |
"PathData", typeof(Geometry), typeof(ImgControl), null); |
68 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
69 |
"OverViewPathData", typeof(Geometry), typeof(ImgControl), null); |
70 |
|
71 |
public static readonly DependencyProperty ImageDataProperty = DependencyProperty.Register( |
72 |
"ImageData", typeof(ImageSource), typeof(ImgControl), new PropertyMetadata(null)); |
73 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
74 |
"UserID", typeof(string), typeof(ImgControl), new PropertyMetadata(null)); |
75 |
public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register( |
76 |
"FilePath", typeof(string), typeof(ImgControl), new PropertyMetadata(null)); |
77 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
78 |
"StartPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
79 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
80 |
"EndPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
81 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
82 |
"PointSet", typeof(List<Point>), typeof(ImgControl), new PropertyMetadata(new List<Point>())); |
83 |
public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
84 |
"TopRightPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
85 |
public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
86 |
"LeftBottomPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
87 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(ImgControl), |
88 |
new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
89 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(ImgControl), |
90 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
91 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(ImgControl), |
92 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
93 |
|
94 |
#endregion |
95 |
#region PropertyChanged Method |
96 |
|
97 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
98 |
{ |
99 |
//var instance = (ImgControl)sender; |
100 |
|
101 |
//if (e.OldValue != e.NewValue && instance.Base_Image != null) |
102 |
//{ |
103 |
|
104 |
// instance.SetValue(e.Property, e.NewValue); |
105 |
|
106 |
// if (instance.IsSelected) |
107 |
// { |
108 |
// //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Blue); |
109 |
// } |
110 |
// else |
111 |
// { |
112 |
// //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Red); |
113 |
// } |
114 |
//} |
115 |
} |
116 |
|
117 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
118 |
{ |
119 |
var instance = (ImgControl)sender; |
120 |
if (e.OldValue != e.NewValue && instance.Base_Image != null) |
121 |
{ |
122 |
instance.SetValue(e.Property, e.NewValue); |
123 |
instance.SetImage(); |
124 |
} |
125 |
} |
126 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
127 |
{ |
128 |
var instance = (ImgControl)sender; |
129 |
if (e.OldValue != e.NewValue && instance.Base_Image != null) |
130 |
{ |
131 |
instance.SetValue(e.Property, e.NewValue); |
132 |
instance.SetImage(); |
133 |
} |
134 |
} |
135 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
136 |
{ |
137 |
var instance = (ImgControl)sender; |
138 |
if (e.OldValue != e.NewValue && instance.Base_Image != null) |
139 |
{ |
140 |
instance.SetValue(e.Property, e.NewValue); |
141 |
instance.SetImage(); |
142 |
} |
143 |
} |
144 |
#endregion |
145 |
#region Properties |
146 |
public double CenterX |
147 |
{ |
148 |
get { return (double)GetValue(CenterXProperty); } |
149 |
set { SetValue(CenterXProperty, value); } |
150 |
} |
151 |
public string UserID |
152 |
{ |
153 |
get { return (string)GetValue(UserIDProperty); } |
154 |
set |
155 |
{ |
156 |
if (this.UserID != value) |
157 |
{ |
158 |
SetValue(UserIDProperty, value); |
159 |
OnPropertyChanged("UserID"); |
160 |
} |
161 |
} |
162 |
} |
163 |
|
164 |
public double CenterY |
165 |
{ |
166 |
get { return (double)GetValue(CenterYProperty); } |
167 |
set { SetValue(CenterYProperty, value); } |
168 |
} |
169 |
public string FilePath |
170 |
{ |
171 |
get { return (string)GetValue(FilePathProperty); } |
172 |
set { SetValue(FilePathProperty, value); } |
173 |
} |
174 |
public Point EndPoint |
175 |
{ |
176 |
get { return (Point)GetValue(EndPointProperty); } |
177 |
set |
178 |
{ |
179 |
if (this.EndPoint != value) |
180 |
{ |
181 |
SetValue(EndPointProperty, value); |
182 |
OnPropertyChanged("EndPoint"); |
183 |
} |
184 |
} |
185 |
} |
186 |
public List<Point> PointSet |
187 |
{ |
188 |
get { return (List<Point>)GetValue(PointSetProperty); } |
189 |
set { SetValue(PointSetProperty, value); } |
190 |
} |
191 |
public Point StartPoint |
192 |
{ |
193 |
get { return (Point)GetValue(StartPointProperty); } |
194 |
set |
195 |
{ |
196 |
if (this.StartPoint != value) |
197 |
{ |
198 |
SetValue(StartPointProperty, value); |
199 |
OnPropertyChanged("StartPoint"); |
200 |
} |
201 |
} |
202 |
} |
203 |
public Point TopRightPoint |
204 |
{ |
205 |
get { return (Point)GetValue(TopRightPointProperty); } |
206 |
set |
207 |
{ |
208 |
SetValue(TopRightPointProperty, value); |
209 |
OnPropertyChanged("TopRightPoint"); |
210 |
} |
211 |
} |
212 |
public Point LeftBottomPoint |
213 |
{ |
214 |
get { return (Point)GetValue(LeftBottomPointProperty); } |
215 |
set |
216 |
{ |
217 |
SetValue(LeftBottomPointProperty, value); |
218 |
OnPropertyChanged("LeftBottomPoint"); |
219 |
} |
220 |
} |
221 |
public double Angle |
222 |
{ |
223 |
get { return (double)GetValue(AngleProperty); } |
224 |
set |
225 |
{ |
226 |
if (this.Angle != value) |
227 |
{ |
228 |
SetValue(AngleProperty, value); |
229 |
} |
230 |
} |
231 |
} |
232 |
public ImageSource ImageData |
233 |
{ |
234 |
get { return (ImageSource)this.GetValue(ImageDataProperty); } |
235 |
set { this.SetValue(ImageDataProperty, value); } |
236 |
} |
237 |
|
238 |
public bool IsSelected |
239 |
{ |
240 |
get |
241 |
{ |
242 |
return (bool)GetValue(IsSelectedProperty); |
243 |
} |
244 |
set |
245 |
{ |
246 |
SetValue(IsSelectedProperty, value); |
247 |
//OnPropertyChanged("IsSelected"); |
248 |
} |
249 |
} |
250 |
|
251 |
public ControlType ControlType |
252 |
{ |
253 |
set |
254 |
{ |
255 |
SetValue(ControlTypeProperty, value); |
256 |
OnPropertyChanged("ControlType"); |
257 |
} |
258 |
get |
259 |
{ |
260 |
return (ControlType)GetValue(ControlTypeProperty); |
261 |
} |
262 |
} |
263 |
|
264 |
public Geometry OverViewPathData |
265 |
{ |
266 |
get { return (Geometry)GetValue(OverViewPathDataProperty); } |
267 |
set |
268 |
{ |
269 |
SetValue(OverViewPathDataProperty, value); |
270 |
OnPropertyChanged("OverViewPathData"); |
271 |
} |
272 |
} |
273 |
|
274 |
|
275 |
#endregion |
276 |
|
277 |
public override void OnApplyTemplate() |
278 |
{ |
279 |
base.OnApplyTemplate(); |
280 |
Base_Image = GetTemplateChild(PART_Image) as Image; |
281 |
Base_Image.Width = 0; |
282 |
Base_Image.Height = 0; |
283 |
SetImage(); |
284 |
} |
285 |
public void SetImage() |
286 |
{ |
287 |
this.ApplyTemplate(); |
288 |
Point mid = MathSet.FindCentroid(new List<Point>() |
289 |
{ |
290 |
this.StartPoint, |
291 |
this.LeftBottomPoint, |
292 |
this.EndPoint, |
293 |
this.TopRightPoint, |
294 |
}); |
295 |
double AngleData = this.Angle * -1; |
296 |
PathFigure pathFigure = new PathFigure(); |
297 |
|
298 |
pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
299 |
|
300 |
LineSegment lineSegment0 = new LineSegment(); |
301 |
lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
302 |
pathFigure.Segments.Add(lineSegment0); |
303 |
|
304 |
LineSegment lineSegment1 = new LineSegment(); |
305 |
lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData); |
306 |
pathFigure.Segments.Add(lineSegment1); |
307 |
|
308 |
LineSegment lineSegment2 = new LineSegment(); |
309 |
lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData); |
310 |
pathFigure.Segments.Add(lineSegment2); |
311 |
|
312 |
LineSegment lineSegment3 = new LineSegment(); |
313 |
lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData); |
314 |
pathFigure.Segments.Add(lineSegment3); |
315 |
|
316 |
PathGeometry pathGeometry = new PathGeometry(); |
317 |
pathGeometry.Figures = new PathFigureCollection(); |
318 |
pathFigure.IsClosed = true; |
319 |
pathGeometry.Figures.Add(pathFigure); |
320 |
this.Base_Image.Width = pathGeometry.Bounds.Width; |
321 |
this.Base_Image.Height = pathGeometry.Bounds.Height; |
322 |
this.Tag = pathGeometry; |
323 |
|
324 |
Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2); |
325 |
Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2); |
326 |
|
327 |
this.PathData = pathGeometry; |
328 |
ApplyOverViewData(); |
329 |
|
330 |
} |
331 |
public void updateControl() |
332 |
{ |
333 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
334 |
this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
335 |
this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
336 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
337 |
} |
338 |
|
339 |
public double LineSize { get; set; } |
340 |
|
341 |
public Geometry PathData { get; set; } |
342 |
|
343 |
|
344 |
} |
345 |
} |