blob: b5bbfa7deb6262dfcd5b77cd90abeebd3f000910 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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();
}
}
}
|