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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
using System;
using CoreGraphics;
using PointF = CoreGraphics.CGPoint;
using RectangleF = CoreGraphics.CGRect;
using SizeF = CoreGraphics.CGSize;
#if __MOBILE__
using UIKit;
namespace Xamarin.Forms.Platform.iOS
#else
using AppKit;
using UIColor = AppKit.NSColor;
namespace Xamarin.Forms.Platform.MacOS
#endif
{
public static class ColorExtensions
{
#if __MOBILE__
internal static readonly UIColor Black = UIColor.Black;
internal static readonly UIColor SeventyPercentGrey = new UIColor(0.7f, 0.7f, 0.7f, 1);
#else
internal static readonly NSColor Black = NSColor.Black;
internal static readonly NSColor SeventyPercentGrey = NSColor.FromRgba(0.7f, 0.7f, 0.7f, 1);
#endif
public static CGColor ToCGColor(this Color color)
{
return new CGColor((float)color.R, (float)color.G, (float)color.B, (float)color.A);
}
public static Color ToColor(this UIColor color)
{
nfloat red;
nfloat green;
nfloat blue;
nfloat alpha;
#if __MOBILE__
color.GetRGBA(out red, out green, out blue, out alpha);
#else
color.GetRgba(out red, out green, out blue, out alpha);
#endif
return new Color(red, green, blue, alpha);
}
#if __MOBILE__
public static UIColor ToUIColor(this Color color)
{
return new UIColor((float)color.R, (float)color.G, (float)color.B, (float)color.A);
}
public static UIColor ToUIColor(this Color color, Color defaultColor)
{
if (color.IsDefault)
return defaultColor.ToUIColor();
return color.ToUIColor();
}
public static UIColor ToUIColor(this Color color, UIColor defaultColor)
{
if (color.IsDefault)
return defaultColor;
return color.ToUIColor();
}
#else
public static NSColor ToNSColor(this Color color)
{
return NSColor.FromRgba((float)color.R, (float)color.G, (float)color.B, (float)color.A);
}
public static NSColor ToNSColor(this Color color, Color defaultColor)
{
if (color.IsDefault)
return defaultColor.ToNSColor();
return color.ToNSColor();
}
public static NSColor ToNSColor(this Color color, NSColor defaultColor)
{
if (color.IsDefault)
return defaultColor;
return color.ToNSColor();
}
#endif
}
public static class PointExtensions
{
public static Point ToPoint(this PointF point)
{
return new Point(point.X, point.Y);
}
public static PointF ToPointF(this Point point)
{
return new PointF(point.X, point.Y);
}
}
public static class SizeExtensions
{
public static SizeF ToSizeF(this Size size)
{
return new SizeF((float)size.Width, (float)size.Height);
}
}
public static class RectangleExtensions
{
public static Rectangle ToRectangle(this RectangleF rect)
{
return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
public static RectangleF ToRectangleF(this Rectangle rect)
{
return new RectangleF((nfloat)rect.X, (nfloat)rect.Y, (nfloat)rect.Width, (nfloat)rect.Height);
}
}
}
|