Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2500 - 1
///============================================================================
2
/// MKLiveView 
3
/// Copyright © 2016 Steph
4
/// 
5
///This file is part of MKLiveView.
6
///
7
///MKLiveView is free software: you can redistribute it and/or modify
8
///it under the terms of the GNU General Public License as published by
9
///the Free Software Foundation, either version 3 of the License, or
10
///(at your option) any later version.
11
///
12
///MKLiveView is distributed in the hope that it will be useful,
13
///but WITHOUT ANY WARRANTY; without even the implied warranty of
14
///MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
///GNU General Public License for more details.
16
///
17
///You should have received a copy of the GNU General Public License
18
///along with cssRcon.  If not, see <http://www.gnu.org/licenses/>.
19
///
20
///============================================================================
21
///Credits:
22
 
23
/// radioman (http://www.codeplex.com/site/users/view/radioman)
24
/// for his really GreatMaps! (http://greatmaps.codeplex.com/)
25
///
26
/// I made some changes to the source, so You need all files from this project here in order to compile and run
27
///
28
/// JOHN C. MACDONALD at Ira A. Fulton College of Engineering and Technology
29
/// for his MIKROKOPTER SERIAL CONTROL TUTORIAL (http://hdl.lib.byu.edu/1877/2747)
30
/// and the sourcecode (http://hdl.lib.byu.edu/1877/2748)
31
/// By his work I finally managed to get the communication with the Mikrokopter controllers to run
32
/// Some of his code was used in this programm like the SimpelSerialPort class (with lots of changes)
33
/// and the FilghtControllerMessage class
34
/// 
35
///============================================================================
36
/// DISCLAIMER
37
/// ===========
38
/// 
39
/// I created this software with my best knowledge and belief.
40
/// 
41
/// IN NO EVENT, UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, 
42
/// SHALL I, OR ANY PERSON BE LIABLE FOR ANY LOSS, EXPENSE OR DAMAGE, 
43
/// OF ANY TYPE OR NATURE ARISING OUT OF THE USE OF, 
44
/// OR INABILITY TO USE THIS SOFTWARE OR PROGRAM, 
45
/// INCLUDING, BUT NOT LIMITED TO, CLAIMS, SUITS OR CAUSES OF ACTION 
46
/// INVOLVING ALLEGED INFRINGEMENT OF COPYRIGHTS, 
47
/// PATENTS, TRADEMARKS, TRADE SECRETS, OR UNFAIR COMPETITION.
48
/// 
49
/// This means: use it & have fun (but @ Your own risk...)
50
/// ===========================================================================
51
 
52
using System.Windows;
53
using System.Windows.Controls;
54
using System.Windows.Controls.Primitives;
55
using System.Windows.Input;
56
using System.Windows.Media;
57
using GMap.NET.WindowsPresentation;
58
using System.Diagnostics;
59
 
60
namespace MKLiveView.GMapCustomMarkers
61
{
62
    public partial class CustomMarkerWP
63
    {
64
        //Popup Popup;
65
        //Label Label;
66
        GMapMarker Marker;
67
        MainWindow MainWindow;
68
        int _type = 0;
69
        public event positionChangedEventHandler positionChanged;
70
        public delegate void positionChangedEventHandler(CustomMarkerWP wp);
71
        public event newPositionEventHandler newPosition;
72
        public delegate void newPositionEventHandler(CustomMarkerWP wp);
73
        public event mouseCapturedEventHandler mouseCaptured;
74
        public delegate void mouseCapturedEventHandler(bool isCaptured);
75
 
76
        public CustomMarkerWP(MainWindow window, GMapMarker marker, string title, int type)
77
        {
78
            this.InitializeComponent();
79
 
80
            this.MainWindow = window;
81
            this.Marker = marker;
82
            _type = type;
83
 
84
            //Popup = new Popup();
85
            //Label = new Label();
86
 
87
            //this.Unloaded += new RoutedEventHandler(CustomMarkerWP_Unloaded);
88
            this.Loaded += new RoutedEventHandler(CustomMarkerWP_Loaded);
89
            this.SizeChanged += new SizeChangedEventHandler(CustomMarkerWP_SizeChanged);
90
            this.MouseEnter += new MouseEventHandler(MarkerControl_MouseEnter);
91
            this.MouseLeave += new MouseEventHandler(MarkerControl_MouseLeave);
92
            this.MouseMove += new MouseEventHandler(CustomMarkerWP_MouseMove);
93
            this.MouseLeftButtonUp += new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonUp);
94
            this.MouseLeftButtonDown += new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonDown);
95
            StylusEnter += CustomMarkerWP_StylusEnter;
96
            StylusLeave += CustomMarkerWP_StylusLeave;
97
            StylusDown += CustomMarkerWP_StylusDown;
98
            StylusMove += CustomMarkerWP_StylusMove;
99
            StylusUp += CustomMarkerWP_StylusUp;
100
 
101
            //Popup.Placement = PlacementMode.Mouse;
102
            //{
103
            //   Label.Background = Brushes.Blue;
104
            //   Label.Foreground = Brushes.White;
105
            //   Label.BorderBrush = Brushes.WhiteSmoke;
106
            //   Label.BorderThickness = new Thickness(2);
107
            //   Label.Padding = new Thickness(5);
108
            //   Label.FontSize = 22;
109
            //   Label.Content = title;
110
            //}
111
            //Popup.Child = Label;
112
            text.Text = title;
113
            setType();
114
        }
115
 
116
        private void CustomMarkerWP_StylusUp(object sender, StylusEventArgs e)
117
        {
118
            if (IsStylusCaptured)
119
            {
120
                Stylus.Capture(null);
121
                newPosition(this);
122
                mouseCaptured(false);
123
            }
124
        }
125
 
126
        private void CustomMarkerWP_StylusMove(object sender, StylusEventArgs e)
127
        {
128
            if (IsStylusCaptured)
129
            {
130
                Point p = e.GetPosition(MainWindow.MainMap);
131
                Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y));
132
                if (positionChanged != null)
133
                    positionChanged(this);
134
            }
135
        }
136
 
137
        private void CustomMarkerWP_StylusDown(object sender, StylusDownEventArgs e)
138
        {
139
            if (!IsStylusCaptured)
140
            {
141
                Stylus.Capture(this);
142
                mouseCaptured(true);
143
            }
144
        }
145
 
146
        private void CustomMarkerWP_StylusLeave(object sender, StylusEventArgs e)
147
        {
148
            Marker.ZIndex -= 10000;
149
        }
150
 
151
        private void CustomMarkerWP_StylusEnter(object sender, StylusEventArgs e)
152
        {
153
            Marker.ZIndex += 10000;
154
        }
155
 
156
        void setType()
157
        {
158
            if (_type == 0)
159
            {
160
                gLanding.Visibility = Visibility.Hidden;
161
                rect.Visibility = Visibility.Hidden;
162
                ellipse.Visibility = Visibility.Visible;
163
            }
164
            if (_type == 1 | _type == 2)
165
            {
166
                gLanding.Visibility = Visibility.Hidden;
167
                ellipse.Visibility = Visibility.Hidden;
168
                rect.Visibility = Visibility.Visible;
169
            }
170
            if (_type == 3)
171
            {
172
                gLanding.Visibility = Visibility.Visible;
173
                ellipse.Visibility = Visibility.Hidden;
174
                rect.Visibility = Visibility.Hidden;
175
            }
176
 
177
        }
178
        void CustomMarkerWP_Loaded(object sender, RoutedEventArgs e)
179
        {
180
            //if (icon.Source.CanFreeze)
181
            //{
182
            //    icon.Source.Freeze();
183
            //}
184
        }
185
 
186
        void CustomMarkerWP_Unloaded(object sender, RoutedEventArgs e)
187
        {
188
            //this.Unloaded -= new RoutedEventHandler(CustomMarkerWP_Unloaded);
189
            //this.Loaded -= new RoutedEventHandler(CustomMarkerWP_Loaded);
190
            this.SizeChanged -= new SizeChangedEventHandler(CustomMarkerWP_SizeChanged);
191
            this.MouseEnter -= new MouseEventHandler(MarkerControl_MouseEnter);
192
            this.MouseLeave -= new MouseEventHandler(MarkerControl_MouseLeave);
193
            this.MouseMove -= new MouseEventHandler(CustomMarkerWP_MouseMove);
194
            this.MouseLeftButtonUp -= new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonUp);
195
            this.MouseLeftButtonDown -= new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonDown);
196
            StylusEnter -= CustomMarkerWP_StylusEnter;
197
            StylusLeave -= CustomMarkerWP_StylusLeave;
198
            StylusDown -= CustomMarkerWP_StylusDown;
199
            StylusMove -= CustomMarkerWP_StylusMove;
200
            StylusUp -= CustomMarkerWP_StylusUp;
201
 
202
            Marker.Shape = null;
203
            //icon.Source = null;
204
            //icon = null;
205
            //Popup = null;
206
            //Label = null;         
207
        }
208
        public string WPText
209
        {
210
            get { return text.Text; }
211
            set { text.Text = value; }
212
        }
213
        public int WPType
214
        {
215
            get { return _type; }
216
            set
217
            {
218
                _type = value;
219
                setType();
220
            }
221
        }
222
 
223
        public void setColor(string sColor)
224
        {
225
            RadialGradientBrush rgb = new RadialGradientBrush();
226
            GradientStop gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0x00),0), gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x1B, 0x1B),1);
227
            switch (sColor)
228
            {
229
                case "red":
230
                    ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00));
231
                    rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00));
232
                    landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00));
233
                    gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0x00),0);
234
                    gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x1B, 0x1B),1);
235
                break;
236
                case "green":
237
                    ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00));
238
                    rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00));
239
                    landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00));
240
                    gs0 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0xFD, 0x50),0);
241
                    gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x2F, 0x1B),1);
242
                break;
243
                case "yellow":
244
                    ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00));
245
                    rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00));
246
                    landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00));
247
                    gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0xFD, 0x00),0);
248
                    gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x5F, 0x1B),1);
249
                break;
250
                case "blue":
251
                    ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF));
252
                    rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF));
253
                    landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF));
254
                    gs0 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0xDB, 0xFD),0);
255
                    gs1 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0x66, 0x5C),1);
256
                break;
257
                case "pink":
258
                    ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF));
259
                    rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF));
260
                    landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF));
261
                    gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0xCF),0);
262
                    gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x00, 0x66),1);
263
                break;
264
            }
265
            rgb.GradientStops.Add(gs0);
266
            rgb.GradientStops.Add(gs1);
267
            ellipse.Fill = rgb;
268
            rect.Fill = rgb;
269
            landing.Fill = rgb;
270
 
271
        }
272
 
273
        void CustomMarkerWP_SizeChanged(object sender, SizeChangedEventArgs e)
274
        {
275
          //  Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2);
276
        }
277
 
278
        void CustomMarkerWP_MouseMove(object sender, MouseEventArgs e)
279
        {
280
            if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured)
281
            {
282
                Point p = e.GetPosition(MainWindow.MainMap);
283
                Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y));
284
                if(positionChanged != null)
285
                    positionChanged(this);
286
            }
287
        }
288
 
289
        void CustomMarkerWP_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
290
        {
291
            if (!IsMouseCaptured)
292
            {
293
                Mouse.Capture(this);
294
                mouseCaptured(true);
295
            }
296
        }
297
 
298
        void CustomMarkerWP_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
299
        {
300
            if (IsMouseCaptured)
301
            {
302
                Mouse.Capture(null);
303
                newPosition(this);
304
                mouseCaptured(false);
305
            }
306
        }
307
 
308
        void MarkerControl_MouseLeave(object sender, MouseEventArgs e)
309
        {
310
            Marker.ZIndex -= 10000;
311
            //Popup.IsOpen = false;
312
        }
313
 
314
        void MarkerControl_MouseEnter(object sender, MouseEventArgs e)
315
        {
316
            Marker.ZIndex += 10000;
317
            //Popup.IsOpen = true;
318
        }
319
 
320
    }
321
}