markus / MarkupToPDF_Old / Controls / Shape / CircleControl.cs @ 5538eb5a
이력 | 보기 | 이력해설 | 다운로드 (15.9 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.ComponentModel; |
12 |
using System.Collections.Generic; |
13 |
using MarkupToPDF.Controls.Common; |
14 |
using MarkupToPDF.Controls.Shape; |
15 |
|
16 |
namespace MarkupToPDF.Controls.Shape |
17 |
{ |
18 |
[TemplatePart(Name = "PART_CirclePath", Type = typeof(Path))] |
19 |
public class CircleControl : Control, IDisposable, IPath, INotifyPropertyChanged, IMarkupCommonData, IShapeControl, ICircleControl |
20 |
{ |
21 |
private const string PART_CirclePath = "PART_CirclePath"; |
22 |
public Path Base_CirclePath = null; |
23 |
|
24 |
static CircleControl() |
25 |
{ |
26 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(CircleControl), new FrameworkPropertyMetadata(typeof(CircleControl))); |
27 |
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
28 |
ResourceDictionary dictionary = new ResourceDictionary(); |
29 |
dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
30 |
Application.Current.Resources.MergedDictionaries.Add(dictionary); |
31 |
} |
32 |
|
33 |
#region Dependency Properties |
34 |
|
35 |
public static readonly DependencyProperty IsSelectedProperty = |
36 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(CircleControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
37 |
|
38 |
public static readonly DependencyProperty ControlTypeProperty = |
39 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(CircleControl), new FrameworkPropertyMetadata(ControlType.Circle)); |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
45 |
"OverViewPathData", typeof(Geometry), typeof(CircleControl), new PropertyMetadata(null)); |
46 |
|
47 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
48 |
"LineSize", typeof(double), typeof(CircleControl), new PropertyMetadata((Double)1)); |
49 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
50 |
"UserID", typeof(string), typeof(CircleControl), new PropertyMetadata(null)); |
51 |
|
52 |
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
53 |
"FillColor", typeof(SolidColorBrush), typeof(CircleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
54 |
|
55 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
56 |
"StrokeColor", typeof(SolidColorBrush), typeof(CircleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
57 |
|
58 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
59 |
"PathData", typeof(Geometry), typeof(CircleControl), null); |
60 |
|
61 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
62 |
"Paint", typeof(PaintSet), typeof(CircleControl), new PropertyMetadata(PaintSet.None)); |
63 |
|
64 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
65 |
"EndPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
66 |
|
67 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
68 |
"DashSize", typeof(DoubleCollection), typeof(CircleControl), new PropertyMetadata(new DoubleCollection { 1, 1 })); |
69 |
|
70 |
public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
71 |
"TopRightPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
72 |
|
73 |
public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
74 |
"LeftBottomPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
75 |
|
76 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
77 |
"StartPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
78 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
79 |
"PointSet", typeof(List<Point>), typeof(CircleControl), new PropertyMetadata(new List<Point>())); |
80 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(CircleControl), |
81 |
new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
82 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(CircleControl), |
83 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
84 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(CircleControl), |
85 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
86 |
public static readonly DependencyProperty mousemodeProperty = |
87 |
DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(CircleControl), new PropertyMetadata(MouseMode.None, PointValueChanged)); |
88 |
#endregion |
89 |
#region PropertyChanged Method |
90 |
|
91 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
92 |
{ |
93 |
var instance = (CircleControl)sender; |
94 |
|
95 |
if (e.OldValue != e.NewValue && instance.Base_CirclePath != null) |
96 |
{ |
97 |
|
98 |
instance.SetValue(e.Property, e.NewValue); |
99 |
|
100 |
if (instance.IsSelected) |
101 |
{ |
102 |
instance.Base_CirclePath.Stroke = new SolidColorBrush(Colors.Blue); |
103 |
} |
104 |
else |
105 |
{ |
106 |
instance.Base_CirclePath.Stroke = new SolidColorBrush(Colors.Red); |
107 |
} |
108 |
} |
109 |
} |
110 |
|
111 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
112 |
{ |
113 |
var instance = (CircleControl)sender; |
114 |
if (e.OldValue != e.NewValue && instance.Base_CirclePath != null) |
115 |
{ |
116 |
instance.SetValue(e.Property, e.NewValue); |
117 |
instance.SetCircle(); |
118 |
} |
119 |
} |
120 |
|
121 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
122 |
{ |
123 |
var instance = (CircleControl)sender; |
124 |
if (e.OldValue != e.NewValue && instance.Base_CirclePath != null) |
125 |
{ |
126 |
instance.SetValue(e.Property, e.NewValue); |
127 |
instance.SetCircle(); |
128 |
} |
129 |
} |
130 |
|
131 |
|
132 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
133 |
{ |
134 |
var instance = (CircleControl)sender; |
135 |
if (e.OldValue != e.NewValue && instance.Base_CirclePath != null) |
136 |
{ |
137 |
instance.SetValue(e.Property, e.NewValue); |
138 |
instance.SetCircle(); |
139 |
} |
140 |
} |
141 |
#endregion |
142 |
#region Properties |
143 |
public string UserID |
144 |
{ |
145 |
get { return (string)GetValue(UserIDProperty); } |
146 |
set |
147 |
{ |
148 |
if (this.UserID != value) |
149 |
{ |
150 |
SetValue(UserIDProperty, value); |
151 |
OnPropertyChanged("UserID"); |
152 |
} |
153 |
} |
154 |
} |
155 |
public MouseMode mousemode |
156 |
{ |
157 |
get |
158 |
{ |
159 |
return (MouseMode)GetValue(mousemodeProperty); |
160 |
} |
161 |
set |
162 |
{ |
163 |
SetValue(mousemodeProperty, value); |
164 |
OnPropertyChanged("mousemode"); |
165 |
} |
166 |
} |
167 |
|
168 |
public Double LineSize |
169 |
{ |
170 |
get { return (Double)GetValue(LineSizeProperty); } |
171 |
set |
172 |
{ |
173 |
if (this.LineSize != value) |
174 |
{ |
175 |
SetValue(LineSizeProperty, value); |
176 |
} |
177 |
} |
178 |
} |
179 |
public DoubleCollection DashSize |
180 |
{ |
181 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
182 |
set |
183 |
{ |
184 |
if (this.DashSize != value) |
185 |
{ |
186 |
SetValue(DashSizeProperty, value); |
187 |
} |
188 |
} |
189 |
} |
190 |
public SolidColorBrush FillColor |
191 |
{ |
192 |
get { return (SolidColorBrush)GetValue(FillColorProperty); } |
193 |
set |
194 |
{ |
195 |
if (this.FillColor != value) |
196 |
{ |
197 |
SetValue(FillColorProperty, value); |
198 |
} |
199 |
} |
200 |
} |
201 |
public Point TopRightPoint |
202 |
{ |
203 |
get { return (Point)GetValue(TopRightPointProperty); } |
204 |
set |
205 |
{ |
206 |
SetValue(TopRightPointProperty, value); |
207 |
OnPropertyChanged("TopRightPoint"); |
208 |
} |
209 |
} |
210 |
public Point LeftBottomPoint |
211 |
{ |
212 |
get { return (Point)GetValue(LeftBottomPointProperty); } |
213 |
set |
214 |
{ |
215 |
SetValue(LeftBottomPointProperty, value); |
216 |
OnPropertyChanged("LeftBottomPoint"); |
217 |
} |
218 |
} |
219 |
public SolidColorBrush StrokeColor |
220 |
{ |
221 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
222 |
set |
223 |
{ |
224 |
if (this.StrokeColor != value) |
225 |
{ |
226 |
SetValue(StrokeColorProperty, value); |
227 |
} |
228 |
} |
229 |
} |
230 |
public Geometry PathData |
231 |
{ |
232 |
get { return (Geometry)GetValue(PathDataProperty); } |
233 |
set { SetValue(PathDataProperty, value); } |
234 |
} |
235 |
|
236 |
public Geometry OverViewPathData |
237 |
{ |
238 |
get |
239 |
{ |
240 |
return (Geometry)GetValue(OverViewPathDataProperty); |
241 |
} |
242 |
set |
243 |
{ |
244 |
SetValue(OverViewPathDataProperty, value); |
245 |
OnPropertyChanged("OverViewPathData"); |
246 |
} |
247 |
} |
248 |
public PaintSet Paint |
249 |
{ |
250 |
get { return (PaintSet)GetValue(PaintProperty); } |
251 |
set |
252 |
{ |
253 |
if (this.Paint != value) |
254 |
{ |
255 |
SetValue(PaintProperty, value); |
256 |
} |
257 |
} |
258 |
} |
259 |
public Point EndPoint |
260 |
{ |
261 |
get { return (Point)GetValue(EndPointProperty); } |
262 |
set { SetValue(EndPointProperty, value); } |
263 |
} |
264 |
public Point StartPoint |
265 |
{ |
266 |
get { return (Point)GetValue(StartPointProperty); } |
267 |
set { SetValue(StartPointProperty, value); } |
268 |
} |
269 |
//public double CenterX |
270 |
//{ |
271 |
// get { return (double)GetValue(CenterXProperty); } |
272 |
// set { SetValue(CenterXProperty, value); } |
273 |
//} |
274 |
//public double CenterY |
275 |
//{ |
276 |
// get { return (double)GetValue(CenterYProperty); } |
277 |
// set { SetValue(CenterYProperty, value); } |
278 |
//} |
279 |
public double AngleValue |
280 |
{ |
281 |
get { return (double)GetValue(AngleProperty); } |
282 |
set { SetValue(AngleProperty, value); } |
283 |
} |
284 |
public double Angle |
285 |
{ |
286 |
get { return (double)GetValue(AngleProperty); } |
287 |
set |
288 |
{ |
289 |
if (this.Angle != value) |
290 |
{ |
291 |
SetValue(AngleProperty, value); |
292 |
} |
293 |
} |
294 |
} |
295 |
public List<Point> PointSet |
296 |
{ |
297 |
get { return (List<Point>)GetValue(PointSetProperty); } |
298 |
set { SetValue(PointSetProperty, value); } |
299 |
} |
300 |
|
301 |
public bool IsSelected |
302 |
{ |
303 |
get |
304 |
{ |
305 |
return (bool)GetValue(IsSelectedProperty); |
306 |
} |
307 |
set |
308 |
{ |
309 |
SetValue(IsSelectedProperty, value); |
310 |
} |
311 |
} |
312 |
|
313 |
public ControlType ControlType |
314 |
{ |
315 |
get |
316 |
{ |
317 |
return (ControlType)GetValue(ControlTypeProperty); |
318 |
} |
319 |
set |
320 |
{ |
321 |
SetValue(ControlTypeProperty, value); |
322 |
} |
323 |
} |
324 |
|
325 |
public double CenterX |
326 |
{ |
327 |
get { return (double)GetValue(CenterXProperty); } |
328 |
set { SetValue(CenterXProperty, value); } |
329 |
} |
330 |
public double CenterY |
331 |
{ |
332 |
get { return (double)GetValue(CenterYProperty); } |
333 |
set { SetValue(CenterYProperty, value); } |
334 |
} |
335 |
#endregion |
336 |
#region Object & Variable |
337 |
EllipseGeometry instance = new EllipseGeometry(); |
338 |
GeometryGroup CircleGroup = new GeometryGroup(); |
339 |
|
340 |
#endregion |
341 |
public override void OnApplyTemplate() |
342 |
{ |
343 |
base.OnApplyTemplate(); |
344 |
Base_CirclePath = GetTemplateChild(PART_CirclePath) as Path; |
345 |
} |
346 |
public void Dispose() |
347 |
{ |
348 |
GC.Collect(); |
349 |
GC.SuppressFinalize(this); |
350 |
} |
351 |
|
352 |
public event PropertyChangedEventHandler PropertyChanged; |
353 |
protected void OnPropertyChanged(string propName) |
354 |
{ |
355 |
if (PropertyChanged != null) |
356 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
357 |
} |
358 |
public void SetCircle() |
359 |
{ |
360 |
|
361 |
Base_CirclePath.StrokeDashArray.Clear(); |
362 |
foreach (var item in this.DashSize) |
363 |
{ |
364 |
Base_CirclePath.StrokeDashArray.Add(item); |
365 |
} |
366 |
Base_CirclePath.StrokeDashCap = PenLineCap.Square; |
367 |
|
368 |
Point middle = MathSet.getMiddlePoint(this.EndPoint, this.StartPoint); |
369 |
|
370 |
instance.RadiusX = (MathSet.DistanceTo(this.LeftBottomPoint, this.EndPoint) / 2); |
371 |
instance.RadiusY = (MathSet.DistanceTo(this.EndPoint, this.TopRightPoint) / 2); |
372 |
instance.Center = middle; |
373 |
switch (this.Paint) |
374 |
{ |
375 |
case PaintSet.None: |
376 |
this.FillColor = null; |
377 |
Base_CirclePath.Fill = this.FillColor; |
378 |
break; |
379 |
case PaintSet.Rect: |
380 |
this.FillColor = this.StrokeColor; |
381 |
Base_CirclePath.Fill = this.FillColor; |
382 |
break; |
383 |
case PaintSet.Cloud: |
384 |
Base_CirclePath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor); |
385 |
break; |
386 |
default: |
387 |
break; |
388 |
} |
389 |
|
390 |
CircleGroup.Children.Clear(); |
391 |
CircleGroup.FillRule = FillRule.Nonzero; |
392 |
CircleGroup.Children.Add(instance); |
393 |
|
394 |
try |
395 |
{ |
396 |
this.Width = Math.Abs(this.CircleGroup.Bounds.Right + 2); |
397 |
this.Height = Math.Abs(this.CircleGroup.Bounds.Bottom + 2); |
398 |
} |
399 |
catch (Exception) |
400 |
{ |
401 |
|
402 |
} |
403 |
CenterX = Math.Abs(this.CircleGroup.Bounds.X / 2); |
404 |
CenterY = Math.Abs(this.CircleGroup.Bounds.Y / 2); |
405 |
this.PathData = CircleGroup; |
406 |
ApplyOverViewData(); |
407 |
} |
408 |
public void updateControl() |
409 |
{ |
410 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
411 |
this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
412 |
this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
413 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
414 |
} |
415 |
|
416 |
public void SetCenterXY() |
417 |
{ |
418 |
CenterX = MathSet.getMiddlePoint(this.StartPoint, this.EndPoint).X; |
419 |
CenterY = MathSet.getMiddlePoint(this.StartPoint, this.EndPoint).Y; |
420 |
} |
421 |
|
422 |
public void ApplyOverViewData() |
423 |
{ |
424 |
this.OverViewPathData = this.PathData; |
425 |
} |
426 |
|
427 |
public void ChangePaint(PaintSet state) |
428 |
{ |
429 |
this.Paint = state; |
430 |
this.SetCircle(); |
431 |
} |
432 |
} |
433 |
} |