[Gtk-sharp-list] [PATCH] Gdk.DotNet.GdkConvert

Ben Maurer bmaurer@ximian.com
Sun, 06 Feb 2005 20:06:50 -0500


--=-Oupc8GLy5KWiLbPU0NWq
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hey guys,

This is a patch that adds a new class to the gtk-dotnet assembly. The
class is Gdk.DotNet.GdkConvert. This class provides System.Drawing <->
Gdk conversions. Eg, from Gdk.Rectangle to and from
System.Drawing.Rectangle.

The patch comes with docs.

One thing I feel deserves explanation is my choice of class names. I did
not want to do Gdk.DotNet.Convert because someone who imported both
Gdk.DotNet and System could not use the class without fully qualifying
it. I realize that Gtk.DotNet.Graphics has the same situation (with
S.Drawing). However, I believe that Convert would be more likely to get
used in multiple places inside a file, so fully qualifying it is more of
a pain.

-- Ben

--=-Oupc8GLy5KWiLbPU0NWq
Content-Disposition: attachment; filename=gtk-gdk-convert.patch
Content-Type: text/x-patch; name=gtk-gdk-convert.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: doc/ChangeLog
===================================================================
--- doc/ChangeLog	(revision 40225)
+++ doc/ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2005-02-06  Ben Maurer  <bmaurer@ximian.com>
+
+	* en/Gdk.DotNet/GdkConvert.xml: Documentation for the new class.
+
 2005-01-28  Dan Winship  <danw@novell.com>
 
 	* en/GLib/NotifyArgs.xml:
Index: doc/en/Gdk.DotNet/GdkConvert.xml
===================================================================
--- doc/en/Gdk.DotNet/GdkConvert.xml	(revision 0)
+++ doc/en/Gdk.DotNet/GdkConvert.xml	(revision 0)
@@ -0,0 +1,143 @@
+<Type Name="GdkConvert" FullName="Gdk.DotNet.GdkConvert">
+  <TypeSignature Language="C#" Value="public class GdkConvert" Maintainer="auto" />
+  <AssemblyInfo>
+    <AssemblyName>gtk-dotnet</AssemblyName>
+    <AssemblyPublicKey>[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4]</AssemblyPublicKey>
+    <AssemblyVersion>2.0.0.0</AssemblyVersion>
+    <AssemblyCulture>neutral</AssemblyCulture>
+    <Attributes />
+  </AssemblyInfo>
+  <ThreadSafetyStatement>Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details.</ThreadSafetyStatement>
+  <Docs>
+    <summary>Converts between Gdk types and System.Drawing types</summary>
+  </Docs>
+  <Base>
+    <BaseTypeName>System.Object</BaseTypeName>
+  </Base>
+  <Interfaces />
+  <Attributes />
+  <Members>
+    <Member MemberName="Rectangle">
+      <MemberSignature Language="C#" Value="public static Gdk.Rectangle Rectangle (System.Drawing.Rectangle r);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>Gdk.Rectangle</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="r" Type="System.Drawing.Rectangle" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="r" /> to a <see cref="T:Gdk.Rectangle" /></summary>
+        <param name="r">a <see cref="T:System.Drawing.Rectangle" /></param>
+        <returns><paramref name="r" /> as a <see cref="T:Gdk.Rectangle" /></returns>
+      </Docs>
+    </Member>
+    <Member MemberName="Rectangle">
+      <MemberSignature Language="C#" Value="public static System.Drawing.Rectangle Rectangle (Gdk.Rectangle r);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Drawing.Rectangle</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="r" Type="Gdk.Rectangle" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="r" /> to a <see cref="T:System.Drawing.Rectangle" /></summary>
+        <param name="r">a <see cref="T:Gdk.Rectangle" /></param>
+        <returns><paramref name="r" /> as a <see cref="T:System.Drawing.Rectangle" /></returns>
+      </Docs>
+    </Member>
+    <Member MemberName="Point">
+      <MemberSignature Language="C#" Value="public static Gdk.Point Point (System.Drawing.Point p);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>Gdk.Point</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="p" Type="System.Drawing.Point" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="p" /> to a <see cref="T:Gdk.Point" /></summary>
+        <param name="p">a <see cref="T:System.Drawing.Point" /></param>
+        <returns><paramref name="p" /> as a <see cref="T:Gdk.Point" /></returns>
+        <remarks>To be added</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="Point">
+      <MemberSignature Language="C#" Value="public static System.Drawing.Point Point (Gdk.Point p);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Drawing.Point</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="p" Type="Gdk.Point" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="r" /> to a <see cref="T:System.Drawing.Point" /></summary>
+        <param name="p">a <see cref="T:Gdk.Point" /></param>
+        <returns><paramref name="p" /> as a <see cref="T:System.Drawing.Point" /></returns>
+      </Docs>
+    </Member>
+    <Member MemberName="Size">
+      <MemberSignature Language="C#" Value="public static Gdk.Size Size (System.Drawing.Size s);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>Gdk.Size</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="s" Type="System.Drawing.Size" />
+      </Parameters>
+      <Docs>
+        <summary>To be added</summary>
+        <param name="s">a <see cref="T:System.Drawing.Size" /></param>
+        <returns><paramref name="s" /> as a <see cref="T:Gdk.Size" /></returns>
+      </Docs>
+    </Member>
+    <Member MemberName="Size">
+      <MemberSignature Language="C#" Value="public static System.Drawing.Size Size (Gdk.Size s);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Drawing.Size</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="s" Type="Gdk.Size" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="s" /> to a <see cref="T:System.Drawing.Size" /></summary>
+        <param name="s">a <see cref="T:Gdk.Size" /></param>
+        <returns><paramref name="s" /> as a <see cref="T:System.Drawing.Size" /></returns>
+      </Docs>
+    </Member>
+    <Member MemberName="Color">
+      <MemberSignature Language="C#" Value="public static Gdk.Color Color (System.Drawing.Color c);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>Gdk.Color</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="c" Type="System.Drawing.Color" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="c" /> to a <see cref="T:Gdk.Color" /></summary>
+        <param name="c">a <see cref="T:System.Drawing.Color" /></param>
+        <returns><paramref name="c" /> as a <see cref="T:Gdk.Color" /></returns>
+        <remarks>Note that this method does not handle the alpha channel of the color. Gdk colors do not have alpha.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="Color">
+      <MemberSignature Language="C#" Value="public static System.Drawing.Color Color (Gdk.Color c);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Drawing.Color</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="c" Type="Gdk.Color" />
+      </Parameters>
+      <Docs>
+        <summary>Converts <paramref name="c" /> to a <see cref="T:System.Drawing.Color" /></summary>
+        <param name="c">a <see cref="T:Gdk.Color" /></param>
+        <returns><paramref name="c" /> as a <see cref="T:System.Drawing.Color" /></returns>
+      </Docs>
+    </Member>
+  </Members>
+</Type>
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40225)
+++ ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2005-02-06  Ben Maurer  <bmaurer@ximian.com>
+
+	* gtkdotnet/Makefile.am (sources): Add Convert.cs 
+
+	* gtkdotnet/Convert.cs: New file.
+
 2005-02-03  Mike Kestner  <mkestner@novell.com>
 
 	* gtk/NodeStore.cs : use CreateNativeObject to allow subclassing.
Index: gtkdotnet/Convert.cs
===================================================================
--- gtkdotnet/Convert.cs	(revision 0)
+++ gtkdotnet/Convert.cs	(revision 0)
@@ -0,0 +1,71 @@
+// Convert.cs - System.Drawing integration with Gtk#
+//
+// Author:  Ben Maurer  <bmaurer@novell.com>
+//
+// Copyright (c) 2005 Novell, Inc.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of version 2 of the Lesser GNU General 
+// Public License as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+using System;
+using SD = System.Drawing;
+using G = Gdk;
+
+namespace Gdk.DotNet {
+	public class GdkConvert {
+		
+		private GdkConvert () {}
+		
+		public static G.Rectangle Rectangle (SD.Rectangle r)
+		{
+			return new G.Rectangle (r.X, r.Y, r.Width, r.Height);
+		}
+		
+		public static SD.Rectangle Rectangle (G.Rectangle r)
+		{
+			return new SD.Rectangle (r.X, r.Y, r.Width, r.Height);
+		}
+		
+		public static G.Point Point (SD.Point p)
+		{
+			return new G.Point (p.X, p.Y);
+		}
+		
+		public static SD.Point Point (G.Point p)
+		{
+			return new SD.Point (p.X, p.Y);
+		}
+		
+		public static G.Size Size (SD.Size s)
+		{
+			return new G.Size (s.Width, s.Height);
+		}
+		
+		public static SD.Size Size (G.Size s)
+		{
+			return new SD.Size (s.Width, s.Height);
+		}
+		
+		// Note, this doesn't do Alpha
+		public static G.Color Color (SD.Color c)
+		{
+			return new G.Color (c.R, c.G, c.B);
+		}
+		
+		public static SD.Color Color (G.Color c)
+		{
+			return SD.Color.FromArgb (c.Red, c.Green, c.Blue);
+		}
+	}
+}
Index: gtkdotnet/Makefile.am
===================================================================
--- gtkdotnet/Makefile.am	(revision 40225)
+++ gtkdotnet/Makefile.am	(working copy)
@@ -16,7 +16,8 @@
 build_references = $(addprefix -r:, $(references)) -r:System.Drawing
 
 sources =		 			\
-	Graphics.cs
+	Graphics.cs				\
+	Convert.cs
 
 build_sources = $(addprefix $(srcdir)/, $(sources)) ../AssemblyInfo.cs
 

--=-Oupc8GLy5KWiLbPU0NWq--