프로젝트

일반

사용자정보

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

markus / MarkupToPDF_Old / Controls / Etc / ImgControl.cs @ 40b3ce25

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