Skip to content

Commit

Permalink
Added implicit conversion from RECT -> System.Drawing.Rectangle.
Browse files Browse the repository at this point in the history
Fixes terrafx#387.

Signed-off-by: AraHaan <seandhunt_7@yahoo.com>
  • Loading branch information
AraHaan committed Mar 2, 2024
1 parent 39a0cf1 commit ca11061
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sources/Interop/Windows/Windows/shared/windef/RECT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace TerraFX.Interop.Windows;

using System.Drawing;

/// <include file='RECT.xml' path='doc/member[@name="RECT"]/*' />
public partial struct RECT
{
Expand All @@ -23,4 +25,19 @@ public partial struct RECT
/// <include file='RECT.xml' path='doc/member[@name="RECT.bottom"]/*' />
[NativeTypeName("LONG")]
public int bottom;

// type 'Rectangle' is from System.Drawing.Primitives which is from the base shared framework.
// as such these operators *should* be safe to include here.
public static implicit operator Rectangle(RECT rectangle)
=> Rectangle.FromLTRB(rectangle.left, rectangle.top, rectangle.right, rectangle.bottom);

public static explicit operator RECT(Rectangle rectangle)
=> new
{
// Obtained from inspecting 'Rectangle.FromLTRB(int, int, int, int)'.
left = rectangle.X,
top = rectangle.Y,
right = rectangle.Width + rectangle.X,
bottom = rectangle.Height + rectangle.Y,
};
}

0 comments on commit ca11061

Please sign in to comment.