aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Converters
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-05-27 19:33:15 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-05-27 19:33:15 +0300
commite571f20e27c4fca6bb6efe03d6427a1f332f9830 (patch)
treeb16041b76ea3b4e8368039c9396f9bbf9624dcc2 /Software/Visual_Studio/Tango.Touch/Converters
parent157e0685abb2e7b22b6584cdc7d6f5838ed0a808 (diff)
downloadTango-e571f20e27c4fca6bb6efe03d6427a1f332f9830.tar.gz
Tango-e571f20e27c4fca6bb6efe03d6427a1f332f9830.zip
Working on panel pc.
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch/Converters')
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/ArcEndPointConverter.cs47
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/ArcSizeConverter.cs25
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/LargeArcConverter.cs37
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/LocalEx.cs22
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/NotZeroConverter.cs23
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/RotateTransformCentreConverter.cs20
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/RotateTransformConverter.cs28
-rw-r--r--Software/Visual_Studio/Tango.Touch/Converters/StartPointConverter.cs28
8 files changed, 230 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/ArcEndPointConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/ArcEndPointConverter.cs
new file mode 100644
index 000000000..b5bbfa7de
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/ArcEndPointConverter.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class ArcEndPointConverter : IMultiValueConverter
+ {
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ var actualWidth = values[0].ExtractDouble();
+ var value = values[1].ExtractDouble();
+ var minimum = values[2].ExtractDouble();
+ var maximum = values[3].ExtractDouble();
+
+ if (new[] {actualWidth, value, minimum, maximum}.AnyNan())
+ return Binding.DoNothing;
+
+ if (values.Length == 5)
+ {
+ var fullIndeterminateScaling = values[4].ExtractDouble();
+ if (!double.IsNaN(fullIndeterminateScaling) && fullIndeterminateScaling > 0.0)
+ {
+ value = (maximum - minimum)*fullIndeterminateScaling;
+ }
+ }
+
+ var percent = maximum <= minimum ? 1.0 : (value - minimum)/(maximum - minimum);
+ var degrees = 360*percent;
+ var radians = degrees*(Math.PI/180);
+
+ var centre = new Point(actualWidth/2, actualWidth/2);
+ var hypotenuseRadius = (actualWidth/2);
+
+ var adjacent = Math.Cos(radians)*hypotenuseRadius;
+ var opposite = Math.Sin(radians)*hypotenuseRadius;
+
+ return new Point(centre.X + opposite, centre.Y - adjacent);
+ }
+
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/ArcSizeConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/ArcSizeConverter.cs
new file mode 100644
index 000000000..8bc90b03a
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/ArcSizeConverter.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class ArcSizeConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is double && ((double)value > 0.0))
+ {
+ return new Size((double)value / 2, (double)value / 2);
+ }
+
+ return new Point();
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return Binding.DoNothing;
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/LargeArcConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/LargeArcConverter.cs
new file mode 100644
index 000000000..6ce52afb2
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/LargeArcConverter.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class LargeArcConverter : IMultiValueConverter
+ {
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ var value = values[0].ExtractDouble();
+ var minimum = values[1].ExtractDouble();
+ var maximum = values[2].ExtractDouble();
+
+ if (new[] { value, minimum, maximum }.AnyNan())
+ return Binding.DoNothing;
+
+ if (values.Length == 4)
+ {
+ var fullIndeterminateScaling = values[3].ExtractDouble();
+ if (!double.IsNaN(fullIndeterminateScaling) && fullIndeterminateScaling > 0.0)
+ {
+ value = (maximum - minimum) * fullIndeterminateScaling;
+ }
+ }
+
+ var percent = maximum <= minimum ? 1.0 : (value - minimum) / (maximum - minimum);
+
+ return percent > 0.5;
+ }
+
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/LocalEx.cs b/Software/Visual_Studio/Tango.Touch/Converters/LocalEx.cs
new file mode 100644
index 000000000..d559ae296
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/LocalEx.cs
@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Touch.Converters
+{
+ internal static class LocalEx
+ {
+ public static double ExtractDouble(this object val)
+ {
+ var d = val as double? ?? double.NaN;
+ return double.IsInfinity(d) ? double.NaN : d;
+ }
+
+
+ public static bool AnyNan(this IEnumerable<double> vals)
+ {
+ return vals.Any(double.IsNaN);
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/NotZeroConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/NotZeroConverter.cs
new file mode 100644
index 000000000..2c206fd9a
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/NotZeroConverter.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class NotZeroConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (double.TryParse((value ?? "").ToString(), out double val))
+ {
+ return Math.Abs(val) > 0.0;
+ }
+ return null;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return Binding.DoNothing;
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/RotateTransformCentreConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/RotateTransformCentreConverter.cs
new file mode 100644
index 000000000..63348117e
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/RotateTransformCentreConverter.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class RotateTransformCentreConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ //value == actual width
+ return (double) value/2;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return Binding.DoNothing;
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/RotateTransformConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/RotateTransformConverter.cs
new file mode 100644
index 000000000..ad1155f99
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/RotateTransformConverter.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class RotateTransformConverter : IMultiValueConverter
+ {
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ var value = values[0].ExtractDouble();
+ var minimum = values[1].ExtractDouble();
+ var maximum = values[2].ExtractDouble();
+
+ if (new[] { value, minimum, maximum }.AnyNan())
+ return Binding.DoNothing;
+
+ var percent = maximum <= minimum ? 1.0 : (value - minimum) / (maximum - minimum);
+
+ return 360*percent;
+ }
+
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Touch/Converters/StartPointConverter.cs b/Software/Visual_Studio/Tango.Touch/Converters/StartPointConverter.cs
new file mode 100644
index 000000000..5b51065a3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Touch/Converters/StartPointConverter.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace Tango.Touch.Converters
+{
+ public class StartPointConverter : IValueConverter
+ {
+ [Obsolete]
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is double && ((double) value > 0.0))
+ {
+ return new Point((double)value / 2, 0);
+ }
+
+ return new Point();
+ }
+
+ [Obsolete]
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return Binding.DoNothing;
+ }
+
+ }
+} \ No newline at end of file