프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Etc / ImgControl.cs @ 53880c83

이력 | 보기 | 이력해설 | 다운로드 (13.3 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
            { 
51
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
52
            }
53
        }
54

    
55
        public void ApplyOverViewData()
56
        {
57
            this.OverViewPathData = this.PathData;
58
        }
59

    
60
        #region Dependency Properties
61

    
62
        public static readonly DependencyProperty IsSelectedProperty =
63
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(ImgControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
64

    
65
        public static readonly DependencyProperty ControlTypeProperty =
66
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ImgControl), new FrameworkPropertyMetadata(ControlType.ImgControl));
67

    
68
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
69
       "PathData", typeof(Geometry), typeof(ImgControl), null);
70
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
71
        "OverViewPathData", typeof(Geometry), typeof(ImgControl), null);
72

    
73
        public static readonly DependencyProperty ImageDataProperty = DependencyProperty.Register(
74
            "ImageData", typeof(ImageSource), typeof(ImgControl), new PropertyMetadata(null));
75
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
76
            "UserID", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
77
        public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register(
78
            "FilePath", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
79
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
80
            "StartPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
81
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
82
            "EndPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
83
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
84
            "PointSet", typeof(List<Point>), typeof(ImgControl), new PropertyMetadata(new List<Point>()));
85
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
86
             "TopRightPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
87
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
88
              "LeftBottomPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
89
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(ImgControl),
90
                        new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
91
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(ImgControl),
92
                        new PropertyMetadata((double)0, OnCenterXYChanged));
93
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(ImgControl),
94
                        new PropertyMetadata((double)0, OnCenterXYChanged));
95

    
96

    
97
        #endregion
98
        #region PropertyChanged Method
99

    
100
       
101
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
102
        {
103
            //var instance = (ImgControl)sender;
104

    
105
            //if (e.OldValue != e.NewValue && instance.Base_Image != null)
106
            //{
107

    
108
            //    instance.SetValue(e.Property, e.NewValue);
109

    
110
            //    if (instance.IsSelected)
111
            //    {
112
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Blue);
113
            //    }
114
            //    else
115
            //    {
116
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Red);
117
            //    }
118
            //}
119
        }
120

    
121
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
122
        {
123
            var instance = (ImgControl)sender;
124
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
125
            {
126
                instance.SetValue(e.Property, e.NewValue);
127
                instance.SetImage();
128
            }
129
        }
130
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
131
        {
132
            var instance = (ImgControl)sender;
133
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
134
            {
135
                instance.SetValue(e.Property, e.NewValue);
136
                instance.SetImage();
137
            }
138
        }
139
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
140
        {
141
            var instance = (ImgControl)sender;
142
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
143
            {
144
                instance.SetValue(e.Property, e.NewValue);
145
                instance.SetImage();
146
            }
147
        }
148
        #endregion
149
        #region Properties
150
        public double CenterX
151
        {
152
            get { return (double)GetValue(CenterXProperty); }
153
            set { SetValue(CenterXProperty, value); }
154
        }
155
        public string UserID
156
        {
157
            get { return (string)GetValue(UserIDProperty); }
158
            set
159
            {
160
                if (this.UserID != value)
161
                {
162
                    SetValue(UserIDProperty, value);
163
                    OnPropertyChanged("UserID");
164
                }
165
            }
166
        }
167
       
168
        public double CenterY
169
        {
170
            get { return (double)GetValue(CenterYProperty); }
171
            set { SetValue(CenterYProperty, value); }
172
        }
173
        public string FilePath
174
        {
175
            get { return (string)GetValue(FilePathProperty); }
176
            set { SetValue(FilePathProperty, value); }
177
        }
178
        public Point EndPoint
179
        {
180
            get { return (Point)GetValue(EndPointProperty); }
181
            set
182
            {
183
                if (this.EndPoint != value)
184
                {
185
                    SetValue(EndPointProperty, value);
186
                    OnPropertyChanged("EndPoint");
187
                }
188
            }
189
        }
190
        public List<Point> PointSet
191
        {
192
            get { return (List<Point>)GetValue(PointSetProperty); }
193
            set { SetValue(PointSetProperty, value); }
194
        }
195
        public Point StartPoint
196
        {
197
            get { return (Point)GetValue(StartPointProperty); }
198
            set
199
            {
200
                if (this.StartPoint != value)
201
                {
202
                    SetValue(StartPointProperty, value);
203
                    OnPropertyChanged("StartPoint");
204
                }
205
            }
206
        }
207
        public Point TopRightPoint
208
        {
209
            get { return (Point)GetValue(TopRightPointProperty); }
210
            set
211
            {
212
                SetValue(TopRightPointProperty, value);
213
                OnPropertyChanged("TopRightPoint");
214
            }
215
        }
216
        public Point LeftBottomPoint
217
        {
218
            get { return (Point)GetValue(LeftBottomPointProperty); }
219
            set
220
            {
221
                SetValue(LeftBottomPointProperty, value);
222
                OnPropertyChanged("LeftBottomPoint");
223
            }
224
        }
225
        public double Angle
226
        {
227
            get { return (double)GetValue(AngleProperty); }
228
            set
229
            {
230
                if (this.Angle != value)
231
                {
232
                    SetValue(AngleProperty, value);
233
                }
234
            }
235
        }
236
        public ImageSource ImageData
237
        {
238
            get { return (ImageSource)this.GetValue(ImageDataProperty); }
239
            set { this.SetValue(ImageDataProperty, value); }
240
        }
241

    
242
         public bool IsSelected
243
        {
244
            get
245
            {
246
                return (bool)GetValue(IsSelectedProperty);
247
            }
248
            set
249
            {
250
                SetValue(IsSelectedProperty, value);
251
                //OnPropertyChanged("IsSelected");
252
            }
253
        }
254

    
255
        public ControlType ControlType
256
        {
257
            set
258
            {
259
                SetValue(ControlTypeProperty, value);
260
                OnPropertyChanged("ControlType");
261
            }
262
            get
263
            {
264
                return (ControlType)GetValue(ControlTypeProperty);
265
            }
266
        }
267

    
268
        public Geometry OverViewPathData
269
        {
270
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
271
            set
272
            {
273
                SetValue(OverViewPathDataProperty, value);
274
                OnPropertyChanged("OverViewPathData");
275
            }
276
        }
277

    
278

    
279
        #endregion
280

    
281
        public override void OnApplyTemplate()
282
        {
283
            base.OnApplyTemplate();
284
            Base_Image = GetTemplateChild(PART_Image) as Image;
285
            Base_Image.Width = 0;
286
            Base_Image.Height = 0;
287
            SetImage();
288
        }
289
        public void SetImage()
290
        {
291
            this.ApplyTemplate();
292
            Point mid = MathSet.FindCentroid(new List<Point>()
293
            {
294
                this.StartPoint,
295
                this.LeftBottomPoint,
296
                this.EndPoint,
297
                this.TopRightPoint,                
298
            });
299
            double AngleData = this.Angle * -1;
300
            PathFigure pathFigure = new PathFigure();
301

    
302
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
303

    
304
            LineSegment lineSegment0 = new LineSegment();
305
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
306
            pathFigure.Segments.Add(lineSegment0);
307

    
308
            LineSegment lineSegment1 = new LineSegment();
309
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
310
            pathFigure.Segments.Add(lineSegment1);
311

    
312
            LineSegment lineSegment2 = new LineSegment();
313
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
314
            pathFigure.Segments.Add(lineSegment2);
315

    
316
            LineSegment lineSegment3 = new LineSegment();
317
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
318
            pathFigure.Segments.Add(lineSegment3);
319

    
320
            PathGeometry pathGeometry = new PathGeometry();
321
            pathGeometry.Figures = new PathFigureCollection();
322
            pathFigure.IsClosed = true;
323
            pathGeometry.Figures.Add(pathFigure);
324
            this.Base_Image.Width = pathGeometry.Bounds.Width;
325
            this.Base_Image.Height = pathGeometry.Bounds.Height;
326
             this.Tag = pathGeometry;
327

    
328
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2);
329
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2);
330

    
331
            this.PathData = pathGeometry;
332
            ApplyOverViewData();
333

    
334
        }
335
        public void updateControl()
336
        {
337
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
338
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
339
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
340
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
341
        }
342

    
343
        public double LineSize { get; set; }
344

    
345

    
346
        public Geometry PathData { get; set; }
347
    }
348
}
클립보드 이미지 추가 (최대 크기: 500 MB)