From c1878dd859c5939fa0516ef0d764b8939d4a8851 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 16 Mar 2004 20:43:14 +0000 Subject: [PATCH] 2004-03-16 Mike Kestner * gdk/Makefile.am : add new file. * gdk/Size.cs : implementation of a Size value type. svn path=/trunk/gtk-sharp/; revision=24164 --- ChangeLog | 5 +++ gdk/Makefile.am | 3 +- gdk/Size.cs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 gdk/Size.cs diff --git a/ChangeLog b/ChangeLog index bb8af72fc..92435ac62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-03-16 Mike Kestner + + * gdk/Makefile.am : add new file. + * gdk/Size.cs : implementation of a Size value type. + 2004-03-16 Mike Kestner * generator/Signal.cs : remove a C.WL. diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 33532b89e..a03aff494 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -33,7 +33,8 @@ sources = \ EventSetting.cs \ EventVisibility.cs \ EventWindowState.cs \ - Key.cs + Key.cs \ + Size.cs build_sources = $(addprefix $(srcdir)/, $(sources)) diff --git a/gdk/Size.cs b/gdk/Size.cs new file mode 100644 index 000000000..a724964fd --- /dev/null +++ b/gdk/Size.cs @@ -0,0 +1,100 @@ +// Size.cs +// +// Author: Mike Kestner (mkestner@speakeasy.net) +// +// (C) 2001 Mike Kestner + +using System; + +namespace Gdk { + + public struct Size { + + int width, height; + + public static readonly Size Empty; + + public static Size operator + (Size sz1, Size sz2) + { + return new Size (sz1.Width + sz2.Width, + sz1.Height + sz2.Height); + } + + public static bool operator == (Size sz_a, Size sz_b) + { + return ((sz_a.Width == sz_b.Width) && + (sz_a.Height == sz_b.Height)); + } + + public static bool operator != (Size sz_a, Size sz_b) + { + return ((sz_a.Width != sz_b.Width) || + (sz_a.Height != sz_b.Height)); + } + + public static Size operator - (Size sz1, Size sz2) + { + return new Size (sz1.Width - sz2.Width, + sz1.Height - sz2.Height); + } + + public static explicit operator Point (Size sz) + { + return new Point (sz.Width, sz.Height); + } + + public Size (Point pt) + { + width = pt.X; + height = pt.Y; + } + + public Size (int width, int height) + { + this.width = width; + this.height = height; + } + + public bool IsEmpty { + get { + return ((width == 0) && (height == 0)); + } + } + + public int Width { + get { + return width; + } + set { + width = value; + } + } + + public int Height { + get { + return height; + } + set { + height = value; + } + } + + public override bool Equals (object o) + { + if (!(o is Size)) + return false; + + return (this == (Size) o); + } + + public override int GetHashCode () + { + return width^height; + } + + public override string ToString () + { + return String.Format ("{{Width={0}, Height={1}}}", width, height); + } + } +}