-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from elachlan/626
Add drawing types templates
- Loading branch information
Showing
5 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
partial struct RECT | ||
{ | ||
internal RECT(global::System.Drawing.Rectangle value) : | ||
this(value.Left, value.Top, value.Right, value.Bottom) { } | ||
internal RECT(global::System.Drawing.Point location, global::System.Drawing.Size size) : | ||
this(location.X, location.Y, unchecked(location.X + size.Width), unchecked(location.Y + size.Height)) { } | ||
internal RECT(int left, int top, int right, int bottom) | ||
{ | ||
this.left = left; | ||
this.top = top; | ||
this.right = right; | ||
this.bottom = bottom; | ||
} | ||
|
||
internal static RECT FromXYWH(int x, int y, int width, int height) => | ||
new RECT(x, y, unchecked(x + width), unchecked(y + height)); | ||
internal readonly int Width => unchecked(this.right - this.left); | ||
internal readonly int Height => unchecked(this.bottom - this.top); | ||
internal readonly bool IsEmpty => this.left == 0 && this.top == 0 && this.right == 0 && this.bottom == 0; | ||
internal readonly int X => this.left; | ||
internal readonly int Y => this.top; | ||
internal readonly global::System.Drawing.Size Size => new global::System.Drawing.Size(this.Width, this.Height); | ||
public static implicit operator global::System.Drawing.Rectangle(RECT value) => new global::System.Drawing.Rectangle(value.left, value.top, value.Width, value.Height); | ||
public static implicit operator global::System.Drawing.RectangleF(RECT value) => new global::System.Drawing.RectangleF(value.left, value.top, value.Width, value.Height); | ||
public static implicit operator RECT(global::System.Drawing.Rectangle value) => new RECT(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
partial struct SIZE | ||
{ | ||
internal SIZE(global::System.Drawing.Size value) : this(value.Width, value.Height) { } | ||
internal SIZE(int width, int height) | ||
{ | ||
this.cx = width; | ||
this.cy = height; | ||
} | ||
|
||
internal readonly int Width => this.cx; | ||
internal readonly int Height => this.cy; | ||
internal readonly bool IsEmpty => this.cx == 0 && this.cy == 0; | ||
public static implicit operator global::System.Drawing.Size(SIZE value) => new global::System.Drawing.Size(value.cx, value.cy); | ||
public static implicit operator SIZE(global::System.Drawing.Size value) => new SIZE(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
BOOL | ||
BOOLEAN | ||
RECT | ||
SIZE | ||
CHAR | ||
CreateCursor | ||
CreateFile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Drawing; | ||
using Windows.Win32.Foundation; | ||
|
||
public class SystemDrawingStructTests | ||
{ | ||
[Fact] | ||
public void Size() | ||
{ | ||
SIZE s = new SIZE(1, 1); | ||
Size s2 = s; | ||
Assert.False(s.IsEmpty); | ||
Assert.False(s2.IsEmpty); | ||
|
||
Assert.True(default(SIZE).IsEmpty); | ||
} | ||
|
||
[Fact] | ||
public void NotLossyConversionBetweenSizeAndSIZE() | ||
{ | ||
SIZE nativeSize = new SIZE(1, 1); | ||
Size managedSize = nativeSize; | ||
SIZE roundtrippedNativeSize = managedSize; | ||
Assert.Equal(nativeSize, roundtrippedNativeSize); | ||
} | ||
|
||
[Fact] | ||
public void NotLossyConversionBetweenSizeAndSIZE_Ctors() | ||
{ | ||
SIZE nativeSize = new SIZE(1, 1); | ||
Size managedSize = nativeSize; | ||
SIZE roundtrippedNativeSize = new SIZE(managedSize); | ||
Assert.Equal(nativeSize, roundtrippedNativeSize); | ||
} | ||
|
||
[Fact] | ||
public void Rect() | ||
{ | ||
RECT r = new RECT(1, 1, 2, 2); | ||
Rectangle r2 = r; | ||
Assert.False(r.IsEmpty); | ||
Assert.False(r2.IsEmpty); | ||
|
||
Assert.True(default(RECT).IsEmpty); | ||
} | ||
|
||
[Fact] | ||
public void NotLossyConversionBetweenRectangleAndRECT() | ||
{ | ||
RECT nativeSize = new RECT(1, 1, 2, 2); | ||
Rectangle managedSize = nativeSize; | ||
RECT roundtrippedNativeSize = managedSize; | ||
Assert.Equal(nativeSize, roundtrippedNativeSize); | ||
} | ||
|
||
[Fact] | ||
public void NotLossyConversionBetweenRectangleAndRECT_Ctors() | ||
{ | ||
RECT nativeSize = new RECT(1, 1, 2, 2); | ||
Rectangle managedSize = nativeSize; | ||
RECT roundtrippedNativeSize = new RECT(managedSize); | ||
Assert.Equal(nativeSize, roundtrippedNativeSize); | ||
} | ||
|
||
[Fact] | ||
public void RectangleAndRECTFromXYWH_AreEqual() | ||
{ | ||
RECT nativeSize = RECT.FromXYWH(1, 1, 2, 2); | ||
Rectangle managedSize = new Rectangle(1, 1, 2, 2); | ||
Assert.Equal(nativeSize.left, managedSize.Left); | ||
Assert.Equal(nativeSize.right, managedSize.Right); | ||
Assert.Equal(nativeSize.top, managedSize.Top); | ||
Assert.Equal(nativeSize.bottom, managedSize.Bottom); | ||
} | ||
} |