0,0 → 1,321 |
///============================================================================ |
/// MKLiveView |
/// Copyright © 2016 Steph |
/// |
///This file is part of MKLiveView. |
/// |
///MKLiveView is free software: you can redistribute it and/or modify |
///it under the terms of the GNU General Public License as published by |
///the Free Software Foundation, either version 3 of the License, or |
///(at your option) any later version. |
/// |
///MKLiveView is distributed in the hope that it will be useful, |
///but WITHOUT ANY WARRANTY; without even the implied warranty of |
///MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
///GNU General Public License for more details. |
/// |
///You should have received a copy of the GNU General Public License |
///along with cssRcon. If not, see <http://www.gnu.org/licenses/>. |
/// |
///============================================================================ |
///Credits: |
|
/// radioman (http://www.codeplex.com/site/users/view/radioman) |
/// for his really GreatMaps! (http://greatmaps.codeplex.com/) |
/// |
/// I made some changes to the source, so You need all files from this project here in order to compile and run |
/// |
/// JOHN C. MACDONALD at Ira A. Fulton College of Engineering and Technology |
/// for his MIKROKOPTER SERIAL CONTROL TUTORIAL (http://hdl.lib.byu.edu/1877/2747) |
/// and the sourcecode (http://hdl.lib.byu.edu/1877/2748) |
/// By his work I finally managed to get the communication with the Mikrokopter controllers to run |
/// Some of his code was used in this programm like the SimpelSerialPort class (with lots of changes) |
/// and the FilghtControllerMessage class |
/// |
///============================================================================ |
/// DISCLAIMER |
/// =========== |
/// |
/// I created this software with my best knowledge and belief. |
/// |
/// IN NO EVENT, UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, |
/// SHALL I, OR ANY PERSON BE LIABLE FOR ANY LOSS, EXPENSE OR DAMAGE, |
/// OF ANY TYPE OR NATURE ARISING OUT OF THE USE OF, |
/// OR INABILITY TO USE THIS SOFTWARE OR PROGRAM, |
/// INCLUDING, BUT NOT LIMITED TO, CLAIMS, SUITS OR CAUSES OF ACTION |
/// INVOLVING ALLEGED INFRINGEMENT OF COPYRIGHTS, |
/// PATENTS, TRADEMARKS, TRADE SECRETS, OR UNFAIR COMPETITION. |
/// |
/// This means: use it & have fun (but @ Your own risk...) |
/// =========================================================================== |
|
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Controls.Primitives; |
using System.Windows.Input; |
using System.Windows.Media; |
using GMap.NET.WindowsPresentation; |
using System.Diagnostics; |
|
namespace MKLiveView.GMapCustomMarkers |
{ |
public partial class CustomMarkerWP |
{ |
//Popup Popup; |
//Label Label; |
GMapMarker Marker; |
MainWindow MainWindow; |
int _type = 0; |
public event positionChangedEventHandler positionChanged; |
public delegate void positionChangedEventHandler(CustomMarkerWP wp); |
public event newPositionEventHandler newPosition; |
public delegate void newPositionEventHandler(CustomMarkerWP wp); |
public event mouseCapturedEventHandler mouseCaptured; |
public delegate void mouseCapturedEventHandler(bool isCaptured); |
|
public CustomMarkerWP(MainWindow window, GMapMarker marker, string title, int type) |
{ |
this.InitializeComponent(); |
|
this.MainWindow = window; |
this.Marker = marker; |
_type = type; |
|
//Popup = new Popup(); |
//Label = new Label(); |
|
//this.Unloaded += new RoutedEventHandler(CustomMarkerWP_Unloaded); |
this.Loaded += new RoutedEventHandler(CustomMarkerWP_Loaded); |
this.SizeChanged += new SizeChangedEventHandler(CustomMarkerWP_SizeChanged); |
this.MouseEnter += new MouseEventHandler(MarkerControl_MouseEnter); |
this.MouseLeave += new MouseEventHandler(MarkerControl_MouseLeave); |
this.MouseMove += new MouseEventHandler(CustomMarkerWP_MouseMove); |
this.MouseLeftButtonUp += new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonUp); |
this.MouseLeftButtonDown += new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonDown); |
StylusEnter += CustomMarkerWP_StylusEnter; |
StylusLeave += CustomMarkerWP_StylusLeave; |
StylusDown += CustomMarkerWP_StylusDown; |
StylusMove += CustomMarkerWP_StylusMove; |
StylusUp += CustomMarkerWP_StylusUp; |
|
//Popup.Placement = PlacementMode.Mouse; |
//{ |
// Label.Background = Brushes.Blue; |
// Label.Foreground = Brushes.White; |
// Label.BorderBrush = Brushes.WhiteSmoke; |
// Label.BorderThickness = new Thickness(2); |
// Label.Padding = new Thickness(5); |
// Label.FontSize = 22; |
// Label.Content = title; |
//} |
//Popup.Child = Label; |
text.Text = title; |
setType(); |
} |
|
private void CustomMarkerWP_StylusUp(object sender, StylusEventArgs e) |
{ |
if (IsStylusCaptured) |
{ |
Stylus.Capture(null); |
newPosition(this); |
mouseCaptured(false); |
} |
} |
|
private void CustomMarkerWP_StylusMove(object sender, StylusEventArgs e) |
{ |
if (IsStylusCaptured) |
{ |
Point p = e.GetPosition(MainWindow.MainMap); |
Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y)); |
if (positionChanged != null) |
positionChanged(this); |
} |
} |
|
private void CustomMarkerWP_StylusDown(object sender, StylusDownEventArgs e) |
{ |
if (!IsStylusCaptured) |
{ |
Stylus.Capture(this); |
mouseCaptured(true); |
} |
} |
|
private void CustomMarkerWP_StylusLeave(object sender, StylusEventArgs e) |
{ |
Marker.ZIndex -= 10000; |
} |
|
private void CustomMarkerWP_StylusEnter(object sender, StylusEventArgs e) |
{ |
Marker.ZIndex += 10000; |
} |
|
void setType() |
{ |
if (_type == 0) |
{ |
gLanding.Visibility = Visibility.Hidden; |
rect.Visibility = Visibility.Hidden; |
ellipse.Visibility = Visibility.Visible; |
} |
if (_type == 1 | _type == 2) |
{ |
gLanding.Visibility = Visibility.Hidden; |
ellipse.Visibility = Visibility.Hidden; |
rect.Visibility = Visibility.Visible; |
} |
if (_type == 3) |
{ |
gLanding.Visibility = Visibility.Visible; |
ellipse.Visibility = Visibility.Hidden; |
rect.Visibility = Visibility.Hidden; |
} |
|
} |
void CustomMarkerWP_Loaded(object sender, RoutedEventArgs e) |
{ |
//if (icon.Source.CanFreeze) |
//{ |
// icon.Source.Freeze(); |
//} |
} |
|
void CustomMarkerWP_Unloaded(object sender, RoutedEventArgs e) |
{ |
//this.Unloaded -= new RoutedEventHandler(CustomMarkerWP_Unloaded); |
//this.Loaded -= new RoutedEventHandler(CustomMarkerWP_Loaded); |
this.SizeChanged -= new SizeChangedEventHandler(CustomMarkerWP_SizeChanged); |
this.MouseEnter -= new MouseEventHandler(MarkerControl_MouseEnter); |
this.MouseLeave -= new MouseEventHandler(MarkerControl_MouseLeave); |
this.MouseMove -= new MouseEventHandler(CustomMarkerWP_MouseMove); |
this.MouseLeftButtonUp -= new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonUp); |
this.MouseLeftButtonDown -= new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonDown); |
StylusEnter -= CustomMarkerWP_StylusEnter; |
StylusLeave -= CustomMarkerWP_StylusLeave; |
StylusDown -= CustomMarkerWP_StylusDown; |
StylusMove -= CustomMarkerWP_StylusMove; |
StylusUp -= CustomMarkerWP_StylusUp; |
|
Marker.Shape = null; |
//icon.Source = null; |
//icon = null; |
//Popup = null; |
//Label = null; |
} |
public string WPText |
{ |
get { return text.Text; } |
set { text.Text = value; } |
} |
public int WPType |
{ |
get { return _type; } |
set |
{ |
_type = value; |
setType(); |
} |
} |
|
public void setColor(string sColor) |
{ |
RadialGradientBrush rgb = new RadialGradientBrush(); |
GradientStop gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0x00),0), gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x1B, 0x1B),1); |
switch (sColor) |
{ |
case "red": |
ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00)); |
rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00)); |
landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00)); |
gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0x00),0); |
gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x1B, 0x1B),1); |
break; |
case "green": |
ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); |
rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); |
landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); |
gs0 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0xFD, 0x50),0); |
gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x2F, 0x1B),1); |
break; |
case "yellow": |
ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00)); |
rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00)); |
landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00)); |
gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0xFD, 0x00),0); |
gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x5F, 0x1B),1); |
break; |
case "blue": |
ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)); |
rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)); |
landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)); |
gs0 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0xDB, 0xFD),0); |
gs1 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0x66, 0x5C),1); |
break; |
case "pink": |
ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)); |
rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)); |
landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)); |
gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0xCF),0); |
gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x00, 0x66),1); |
break; |
} |
rgb.GradientStops.Add(gs0); |
rgb.GradientStops.Add(gs1); |
ellipse.Fill = rgb; |
rect.Fill = rgb; |
landing.Fill = rgb; |
|
} |
|
void CustomMarkerWP_SizeChanged(object sender, SizeChangedEventArgs e) |
{ |
// Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2); |
} |
|
void CustomMarkerWP_MouseMove(object sender, MouseEventArgs e) |
{ |
if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured) |
{ |
Point p = e.GetPosition(MainWindow.MainMap); |
Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y)); |
if(positionChanged != null) |
positionChanged(this); |
} |
} |
|
void CustomMarkerWP_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
{ |
if (!IsMouseCaptured) |
{ |
Mouse.Capture(this); |
mouseCaptured(true); |
} |
} |
|
void CustomMarkerWP_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) |
{ |
if (IsMouseCaptured) |
{ |
Mouse.Capture(null); |
newPosition(this); |
mouseCaptured(false); |
} |
} |
|
void MarkerControl_MouseLeave(object sender, MouseEventArgs e) |
{ |
Marker.ZIndex -= 10000; |
//Popup.IsOpen = false; |
} |
|
void MarkerControl_MouseEnter(object sender, MouseEventArgs e) |
{ |
Marker.ZIndex += 10000; |
//Popup.IsOpen = true; |
} |
|
} |
} |