Ver Fonte

Define casts and equality operators to enable mostly-seamless transition away from Rect

Brandon Thetford há 1 ano atrás
pai
commit
21fbb4c321

+ 11 - 0
Terminal.Gui/Types/Point.TemporaryOperators.cs

@@ -0,0 +1,11 @@
+namespace Terminal.Gui;
+
+public partial struct Point
+{
+    public static implicit operator System.Drawing.Point (Terminal.Gui.Point tgp) => new (tgp.X, tgp.Y);
+    public static implicit operator Point (System.Drawing.Point sdp) => new (sdp.X, sdp.Y);
+    public static bool operator != (Point left, System.Drawing.Point right) => new System.Drawing.Point (left.X,left.Y) != right;
+    public static bool operator == (Point left, System.Drawing.Point right) => new System.Drawing.Point (left.X,left.Y) == right;
+    public static bool operator != (System.Drawing.Point left, Point right) => left != new System.Drawing.Point(right.X,right.Y);
+    public static bool operator == (System.Drawing.Point left, Point right) => left == new System.Drawing.Point(right.X,right.Y);
+}

+ 1 - 1
Terminal.Gui/Types/Point.cs

@@ -14,7 +14,7 @@ using System.Text.Json.Serialization;
 namespace Terminal.Gui;
 
 /// <summary>Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.</summary>
-public struct Point
+public partial struct Point
 {
     /// <summary>Gets or sets the x-coordinate of this Point.</summary>
     [JsonInclude]

+ 11 - 0
Terminal.Gui/Types/Size.TemporaryOperators.cs

@@ -0,0 +1,11 @@
+namespace Terminal.Gui;
+
+public partial struct Size
+{
+    public static implicit operator Size (System.Drawing.Size sds) => new (sds.Width, sds.Height);
+    public static implicit operator System.Drawing.Size (Size tgs) => new (tgs.Width, tgs.Height);
+    public static bool operator != (Size left, System.Drawing.Size right) => new System.Drawing.Size (left.Width,left.Height) != right;
+    public static bool operator == (Size left, System.Drawing.Size right) => new System.Drawing.Size (left.Width,left.Height) == right;
+    public static bool operator != (System.Drawing.Size left, Size right) => left != new System.Drawing.Size(right.Width,right.Height);
+    public static bool operator == (System.Drawing.Size left, Size right) => left == new System.Drawing.Size(right.Width,right.Height);
+}

+ 1 - 1
Terminal.Gui/Types/Size.cs

@@ -11,7 +11,7 @@
 namespace Terminal.Gui;
 
 /// <summary>Stores an ordered pair of integers, which specify a Height and Width.</summary>
-public struct Size
+public partial struct Size
 {
     private int width, height;