-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
WinConversions.shared.cs
183 lines (148 loc) · 4.01 KB
/
WinConversions.shared.cs
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using sdp = System.Drawing.Printing;
#if WPF
namespace Eto.Wpf
#else
namespace Eto.WinForms
#endif
{
public static partial class WinConversions
{
public const float WheelDelta = 120f;
public static MouseEventArgs ToEto(this swf.MouseEventArgs e, swf.Control control)
{
var point = control.PointToClient(swf.Control.MousePosition).ToEto();
var buttons = ToEto(e.Button);
var modifiers = swf.Control.ModifierKeys.ToEto();
return new MouseEventArgs(buttons, modifiers, point, new SizeF(0, (float)e.Delta / WheelDelta));
}
public static SizeF ToEtoDelta(this swf.MouseEventArgs e)
{
return new SizeF(0, (float)e.Delta / WheelDelta);
}
public static MouseButtons ToEto(this swf.MouseButtons button)
{
MouseButtons buttons = MouseButtons.None;
if ((button & swf.MouseButtons.Left) != 0)
buttons |= MouseButtons.Primary;
if ((button & swf.MouseButtons.Right) != 0)
buttons |= MouseButtons.Alternate;
if ((button & swf.MouseButtons.Middle) != 0)
buttons |= MouseButtons.Middle;
return buttons;
}
public static Padding ToEto(this swf.Padding padding)
{
return new Padding(padding.Left, padding.Top, padding.Right, padding.Bottom);
}
public static swf.Padding ToSWF(this Padding padding)
{
return new swf.Padding(padding.Left, padding.Top, padding.Right, padding.Bottom);
}
public static Color ToEto(this sd.Color color)
{
return new Color(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
}
public static sd.Color ToSD(this Color color)
{
return sd.Color.FromArgb((byte)(color.A * 255), (byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255));
}
public static Point ToEto(this sd.Point point)
{
return new Point(point.X, point.Y);
}
public static PointF ToEto(this sd.PointF point)
{
return new PointF(point.X, point.Y);
}
public static sd.PointF ToSD(this PointF point)
{
return new sd.PointF(point.X, point.Y);
}
public static sd.Point ToSDPoint(this PointF point)
{
return new sd.Point((int)point.X, (int)point.Y);
}
public static Size ToEto(this sd.Size size)
{
return new Size(size.Width, size.Height);
}
public static sd.Size ToSD(this Size size)
{
return new sd.Size(size.Width, size.Height);
}
public static Size ToEtoF(this sd.SizeF size)
{
return new Size((int)size.Width, (int)size.Height);
}
public static SizeF ToEto(this sd.SizeF size)
{
return new SizeF(size.Width, size.Height);
}
public static sd.SizeF ToSD(this SizeF size)
{
return new sd.SizeF(size.Width, size.Height);
}
public static Rectangle ToEto(this sd.Rectangle rect)
{
return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
public static RectangleF ToEto(this sd.RectangleF rect)
{
return new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
}
public static sd.Rectangle ToSD(this Rectangle rect)
{
return new sd.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
public static sd.RectangleF ToSD(this RectangleF rect)
{
return new sd.RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
}
public static sd.Rectangle ToSDRectangle(this RectangleF rect)
{
return new sd.Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
}
internal static sd.Point[] ToSD(this Point[] points)
{
var result =
new sd.Point[points.Length];
for (var i = 0;
i < points.Length;
++i)
{
var p = points[i];
result[i] =
new sd.Point(p.X, p.Y);
}
return result;
}
internal static sd.PointF[] ToSD(this PointF[] points)
{
var result =
new sd.PointF[points.Length];
for (var i = 0;
i < points.Length;
++i)
{
var p = points[i];
result[i] =
new sd.PointF(p.X, p.Y);
}
return result;
}
internal static PointF[] ToEto(this sd.PointF[] points)
{
var result =
new PointF[points.Length];
for (var i = 0;
i < points.Length;
++i)
{
var p = points[i];
result[i] =
new PointF(p.X, p.Y);
}
return result;
}
}
}