프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Etc / ImgControl.cs @ eb2b9248

이력 | 보기 | 이력해설 | 다운로드 (13 KB)

1 787a4489 KangIngu
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 OverViewPathDataProperty = DependencyProperty.Register(
67
        "OverViewPathData", typeof(Geometry), typeof(ImgControl), null);
68
69
        public static readonly DependencyProperty ImageDataProperty = DependencyProperty.Register(
70
            "ImageData", typeof(ImageSource), typeof(ImgControl), new PropertyMetadata(null));
71
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
72
            "UserID", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
73
        public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register(
74
            "FilePath", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
75
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
76
            "StartPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
77
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
78
            "EndPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
79
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
80
            "PointSet", typeof(List<Point>), typeof(ImgControl), new PropertyMetadata(new List<Point>()));
81
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
82
             "TopRightPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
83
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
84
              "LeftBottomPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
85
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(ImgControl),
86
                        new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
87
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(ImgControl),
88
                        new PropertyMetadata((double)0, OnCenterXYChanged));
89
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(ImgControl),
90
                        new PropertyMetadata((double)0, OnCenterXYChanged));
91
92
        #endregion
93
        #region PropertyChanged Method
94
95
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
96
        {
97
            //var instance = (ImgControl)sender;
98
99
            //if (e.OldValue != e.NewValue && instance.Base_Image != null)
100
            //{
101
102
            //    instance.SetValue(e.Property, e.NewValue);
103
104
            //    if (instance.IsSelected)
105
            //    {
106
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Blue);
107
            //    }
108
            //    else
109
            //    {
110
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Red);
111
            //    }
112
            //}
113
        }
114
115
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
116
        {
117
            var instance = (ImgControl)sender;
118
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
119
            {
120
                instance.SetValue(e.Property, e.NewValue);
121
                instance.SetImage();
122
            }
123
        }
124
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
125
        {
126
            var instance = (ImgControl)sender;
127
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
128
            {
129
                instance.SetValue(e.Property, e.NewValue);
130
                instance.SetImage();
131
            }
132
        }
133
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
134
        {
135
            var instance = (ImgControl)sender;
136
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
137
            {
138
                instance.SetValue(e.Property, e.NewValue);
139
                instance.SetImage();
140
            }
141
        }
142
        #endregion
143
        #region Properties
144
        public double CenterX
145
        {
146
            get { return (double)GetValue(CenterXProperty); }
147
            set { SetValue(CenterXProperty, value); }
148
        }
149
        public string UserID
150
        {
151
            get { return (string)GetValue(UserIDProperty); }
152
            set
153
            {
154
                if (this.UserID != value)
155
                {
156
                    SetValue(UserIDProperty, value);
157
                    OnPropertyChanged("UserID");
158
                }
159
            }
160
        }
161
       
162
        public double CenterY
163
        {
164
            get { return (double)GetValue(CenterYProperty); }
165
            set { SetValue(CenterYProperty, value); }
166
        }
167
        public string FilePath
168
        {
169
            get { return (string)GetValue(FilePathProperty); }
170
            set { SetValue(FilePathProperty, value); }
171
        }
172
        public Point EndPoint
173
        {
174
            get { return (Point)GetValue(EndPointProperty); }
175
            set
176
            {
177
                if (this.EndPoint != value)
178
                {
179
                    SetValue(EndPointProperty, value);
180
                    OnPropertyChanged("EndPoint");
181
                }
182
            }
183
        }
184
        public List<Point> PointSet
185
        {
186
            get { return (List<Point>)GetValue(PointSetProperty); }
187
            set { SetValue(PointSetProperty, value); }
188
        }
189
        public Point StartPoint
190
        {
191
            get { return (Point)GetValue(StartPointProperty); }
192
            set
193
            {
194
                if (this.StartPoint != value)
195
                {
196
                    SetValue(StartPointProperty, value);
197
                    OnPropertyChanged("StartPoint");
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 double Angle
220
        {
221
            get { return (double)GetValue(AngleProperty); }
222
            set
223
            {
224
                if (this.Angle != value)
225
                {
226
                    SetValue(AngleProperty, value);
227
                }
228
            }
229
        }
230
        public ImageSource ImageData
231
        {
232
            get { return (ImageSource)this.GetValue(ImageDataProperty); }
233
            set { this.SetValue(ImageDataProperty, value); }
234
        }
235
236
         public bool IsSelected
237
        {
238
            get
239
            {
240
                return (bool)GetValue(IsSelectedProperty);
241
            }
242
            set
243
            {
244
                SetValue(IsSelectedProperty, value);
245
                OnPropertyChanged("IsSelected");
246
            }
247
        }
248
249
        public ControlType ControlType
250
        {
251
            set
252
            {
253
                SetValue(ControlTypeProperty, value);
254
                OnPropertyChanged("ControlType");
255
            }
256
            get
257
            {
258
                return (ControlType)GetValue(ControlTypeProperty);
259
            }
260
        }
261
262
        public Geometry OverViewPathData
263
        {
264
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
265
            set
266
            {
267
                SetValue(OverViewPathDataProperty, value);
268
                OnPropertyChanged("OverViewPathData");
269
            }
270
        }
271
272
273
        #endregion
274
275
        public override void OnApplyTemplate()
276
        {
277
            base.OnApplyTemplate();
278
            Base_Image = GetTemplateChild(PART_Image) as Image;
279
            Base_Image.Width = 0;
280
            Base_Image.Height = 0;
281
            SetImage();
282
        }
283
        public void SetImage()
284
        {
285
            this.ApplyTemplate();
286
            Point mid = MathSet.FindCentroid(new List<Point>()
287
            {
288
                this.StartPoint,
289
                this.LeftBottomPoint,
290
                this.EndPoint,
291
                this.TopRightPoint,                
292
            });
293
            double AngleData = this.Angle * -1;
294
            PathFigure pathFigure = new PathFigure();
295
296
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
297
298
            LineSegment lineSegment0 = new LineSegment();
299
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
300
            pathFigure.Segments.Add(lineSegment0);
301
302
            LineSegment lineSegment1 = new LineSegment();
303
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
304
            pathFigure.Segments.Add(lineSegment1);
305
306
            LineSegment lineSegment2 = new LineSegment();
307
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
308
            pathFigure.Segments.Add(lineSegment2);
309
310
            LineSegment lineSegment3 = new LineSegment();
311
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
312
            pathFigure.Segments.Add(lineSegment3);
313
314
            PathGeometry pathGeometry = new PathGeometry();
315
            pathGeometry.Figures = new PathFigureCollection();
316
            pathFigure.IsClosed = true;
317
            pathGeometry.Figures.Add(pathFigure);
318
            this.Base_Image.Width = pathGeometry.Bounds.Width;
319
            this.Base_Image.Height = pathGeometry.Bounds.Height;
320
             this.Tag = pathGeometry;
321
322
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2);
323
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2);
324
325
        }
326
        public void updateControl()
327
        {
328
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
329
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
330
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
331
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
332
        }
333
334
        public double LineSize { get; set; }
335
336
        public Geometry PathData { get; set; }
337
338
        
339
    }
340
}
클립보드 이미지 추가 (최대 크기: 500 MB)