diff --git a/ChangeLog b/ChangeLog index a849f0ac0..9511d5fee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-02-07 Ben Maurer + + * gdk/Point.custom, gdk/Rectangle.custom: misc. new apis to make + this more like the S.D structs. + 2005-02-03 Mike Kestner * gtk/NodeStore.cs : use CreateNativeObject to allow subclassing. diff --git a/doc/ChangeLog b/doc/ChangeLog index cdc25ec53..0bff51465 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2005-02-07 Ben Maurer + + * en/Gdk/Point.xml, en/Gdk/Rectangle.xml: Document new + members. + 2005-01-28 Dan Winship * en/GLib/NotifyArgs.xml: diff --git a/doc/en/Gdk/Point.xml b/doc/en/Gdk/Point.xml index e3f49ae66..8f108d750 100644 --- a/doc/en/Gdk/Point.xml +++ b/doc/en/Gdk/Point.xml @@ -103,5 +103,74 @@ + + + Property + + System.Boolean + + + + Checks if the point is (0,0) + true if this == (0,0 + + + + + Method + + System.Boolean + + + + + + Equality for points + a + true if == this + + + + + Method + + System.Int32 + + + + Hashing for points + a hash code + + + + + Method + + System.Void + + + + + + + Moves this point by quanities dx and dy + Quanity by which to change X + Quanity by which to change Y + + + + + Constructor + + + + + + Constructs a point from a + a + as a + The point will have an X of .Width and a Y of .Height + + \ No newline at end of file diff --git a/doc/en/Gdk/Rectangle.xml b/doc/en/Gdk/Rectangle.xml index 285284a9f..4924f10d8 100644 --- a/doc/en/Gdk/Rectangle.xml +++ b/doc/en/Gdk/Rectangle.xml @@ -179,5 +179,400 @@ The result is the rectangular region occupied by both source rectanlges. + + + Property + + System.Int32 + + + + The Y coordinate of the top of the rectangle. + a + + + + + Property + + System.Int32 + + + + The Y coordinate of the bottom of the rectangle. + a + + + + + Property + + System.Int32 + + + + The X coordinate of the right of the rectangle. + a + + + + + Property + + System.Int32 + + + + The X coordinate of the left of the rectangle. + a + + + + + Property + + System.Boolean + + + + Gets if the area of the rectangle is zero + a + This will return true if either the height or the width is zero. + + + + + Property + + Gdk.Size + + + + Gets the size represented by (Width, Height) + a + + + + + Property + + Gdk.Point + + + + Gets the point represented by (X, Y) + a + + + + + Method + + Gdk.Rectangle + + + + + + + + + Creates a rectangle given the left, right, top, and bottom. + a + a + a + a + a + + + + + Method + + Gdk.Rectangle + + + + + + + Gets the smallest rectangle that contains both parameters + a + a + a + + + + + Method + + Gdk.Rectangle + + + + + + + Gets the largest rectangle (if any) which is contained by both parameters. + a + a + a + + + + + Method + + Gdk.Rectangle + + + + + + + + Changes the size of each side of the rectangle by the specified amount. + a + Change in the X size + Change in the Y size + a + The rectangle's center is the same as the center of . + + + + + Method + + Gdk.Rectangle + + + + + + + Changes the size of each side of the rectangle by the specified amount. + a + A change in size. + a + The rectangle's center is the same as the center of . + + + + + Method + + Gdk.Rectangle + + + + + + + + Returns the rectangle shifted by (dx,dy) + a + a + a + a + + + + + Method + + Gdk.Rectangle + + + + + + + Returns a rectangle shifted by the vector dr + a + a + a + + + + + Method + + System.Boolean + + + + + + Equality for rectangles + a + a + + + + + Method + + System.Int32 + + + + Hashing for rectangles + a + + + + + Method + + System.Boolean + + + + + + Tests if a rectangle is contained in this rectangle. + a + a + The rectangle must be fully enclosed for this test to return true. That is, + the intersection of this and must equal . + + + + + Method + + System.Boolean + + + + + + Does hit testing for a point + a + a + + + + + Method + + System.Boolean + + + + + + + Does hit testing for a point + a + a + a + + + + + Method + + System.Boolean + + + + + + Tests if there is any overlap of this rectangle and another + a + a + + + + + Method + + System.Void + + + + + + Modifies this rectangle to be the intersection with another rectangle + a + + + + + Method + + System.Void + + + + + + Inflates this rectangle by a given size. + a + + + + + Method + + System.Void + + + + + + + Inflates this rectangle by a given size. + a + a + + + + + Method + + System.Void + + + + + + + Offsets this rectangle by (dx,dy) + a + a + + + + + Method + + System.Void + + + + + + Offsets this rectangle by the vector dr + a + To be added + + + + + Constructor + + + + + + + Creates a rectangle from a point and a size. + a + a + A rectangle with a location of and size of . + + \ No newline at end of file diff --git a/gdk/Point.custom b/gdk/Point.custom index bc091bdd7..29fbd28a6 100644 --- a/gdk/Point.custom +++ b/gdk/Point.custom @@ -1,10 +1,14 @@ // Gdk.Point.custom - Gdk Point class customizations // -// Author: Jasper van Putten -// Author: Martin Willemoes Hansen +// Authors: +// Jasper van Putten +// Martin Willemoes Hansen +// Ben Maurer +// Contains lots of c&p from System.Drawing // // Copyright (c) 2002 Jasper van Putten // Copyright (c) 2003 Martin Willemoes Hansen +// Copyright (c) 2005 Novell, Inc // // This code is inserted after the automatically generated code. // @@ -22,30 +26,69 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. -/// -/// ToString method -/// -/// -/// -/// returns a string representation of this point -/// - public override string ToString () { return String.Format ("({0},{1})", X, Y); } -/// -/// Point Constructor -/// -/// -/// -/// Constructs a new Point with the specified -/// coordinates. -/// - public Point (int x, int y) { - this.X = x; - this.Y = y; + this.X = x; + this.Y = y; +} + +public Point (Size sz) +{ + this.X = sz.Width; + this.Y = sz.Height; +} + +public override bool Equals (object o) +{ + if (!(o is Point)) + return false; + + return (this == (Point) o); +} + +public override int GetHashCode () +{ + return X ^ Y; +} + +public void Offset (int dx, int dy) +{ + X += dx; + Y += dy; +} + +public bool IsEmpty { + get { + return ((X == 0) && (Y == 0)); + } +} + +public static explicit operator Size (Point pt) +{ + return new Size (pt.X, pt.Y); +} + +public static Point operator + (Point pt, Size sz) +{ + return new Point (pt.X + sz.Width, pt.Y + sz.Height); +} + +public static Point operator - (Point pt, Size sz) +{ + return new Point (pt.X - sz.Width, pt.Y - sz.Height); +} + +public static bool operator == (Point pt_a, Point pt_b) +{ + return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y)); +} + +public static bool operator != (Point pt_a, Point pt_b) +{ + return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y)); } diff --git a/gdk/Rectangle.custom b/gdk/Rectangle.custom index 5376ee80a..955fdd23e 100644 --- a/gdk/Rectangle.custom +++ b/gdk/Rectangle.custom @@ -1,8 +1,12 @@ // Gdk.Point.Rectangle - Gdk Rectangle class customizations // -// Author: Jasper van Putten +// Authors: +// Jasper van Putten +// Ben Maurer +// Contains lots of c&p from System.Drawing // // Copyright (c) 2002 Jasper van Putten +// Copyright (c) 2005 Novell, Inc // // This code is inserted after the automatically generated code. // @@ -21,20 +25,12 @@ // Boston, MA 02111-1307, USA. -/// -/// ToString method -/// -/// -/// -/// returns a string representation of this Rectangle -/// -/// - public override string ToString () { return String.Format ("{0}x{1}+{2}+{3}", Width, Height, X, Y); } +// constructors public Rectangle (int x, int y, int width, int height) { this.X = x; @@ -43,3 +39,174 @@ public Rectangle (int x, int y, int width, int height) this.Height = height; } +public Rectangle (Point loc, Size sz) : this (loc.X, loc.Y, sz.Width, sz.Height) {} + +public static Rectangle FromLTRB (int left, int top, int right, int bottom) +{ + return new Rectangle (left, top, right - left, + bottom - top); +} + +// Equality +public override bool Equals (object o) +{ + if (!(o is Rectangle)) + return false; + + return (this == (Rectangle) o); +} + +public override int GetHashCode () +{ + return (Height + Width) ^ X + Y; +} + +public static bool operator == (Rectangle r1, Rectangle r2) +{ + return ((r1.Location == r2.Location) && (r1.Size == r2.Size)); +} + +public static bool operator != (Rectangle r1, Rectangle r2) +{ + return !(r1 == r2); +} + +// Hit Testing / Intersection / Union +public bool Contains (Rectangle rect) +{ + return (rect == Intersect (this, rect)); +} + +public bool Contains (Point pt) +{ + return Contains (pt.X, pt.Y); +} + +public bool Contains (int x, int y) +{ + return ((x >= Left) && (x <= Right) && + (y >= Top) && (y <= Bottom)); +} + +public bool IntersectsWith (Rectangle r) +{ + return !((Left > r.Right) || (Right < r.Left) || + (Top > r.Bottom) || (Bottom < r.Top)); +} + +public static Rectangle Union (Rectangle r1, Rectangle r2) +{ + return FromLTRB (Math.Min (r1.Left, r2.Left), + Math.Min (r1.Top, r2.Top), + Math.Max (r1.Right, r2.Right), + Math.Max (r1.Bottom, r2.Bottom)); +} + +public void Intersect (Rectangle r) +{ + if (!IntersectsWith (r)) { + X = 0; + Y = 0; + Width = 0; + Height = 0; + } + + X = Math.Max (Left, r.Left); + Y = Math.Max (Top, r.Top); + Width = Math.Min (Right, r.Right) - X; + Height = Math.Min (Bottom, r.Bottom) - Y; +} + +public static Rectangle Intersect (Rectangle r1, Rectangle r2) +{ + Rectangle r = r1; + r.Intersect (r2); + return r; +} + +// Position/Size +public int Top { + get { return Y; } +} +public int Bottom { + get { return Y + Height; } +} +public int Right { + get { return X + Width; } +} +public int Left { + get { return X; } +} + +public bool IsEmpty { + get { return (Width == 0) || (Height == 0); } +} + +public Size Size { + get { + return new Size (Width, Height); + } + set { + Width = value.Width; + Height = value.Height; + } +} + +public Point Location { + get { + return new Point (X, Y); + } + set { + X = value.X; + Y = value.Y; + } +} + +// Inflate and Offset +public void Inflate (Size sz) +{ + Inflate (sz.Width, sz.Height); +} + +public void Inflate (int width, int height) +{ + X -= width; + Y -= height; + Width += width * 2; + Height += height * 2; +} + +public static Rectangle Inflate (Rectangle rect, int x, int y) +{ + Rectangle r = rect; + r.Inflate (x, y); + return r; +} + +public static Rectangle Inflate (Rectangle rect, Size sz) +{ + return Inflate (rect, sz.Width, sz.Height); +} + +public void Offset (int dx, int dy) +{ + X += dx; + Y += dy; +} + +public void Offset (Point dr) +{ + Offset (dr.X, dr.Y); +} + +public static Rectangle Offset (Rectangle rect, int dx, int dy) +{ + Rectangle r = rect; + r.Offset (dx, dy); + return r; +} + +public static Rectangle Offset (Rectangle rect, Point dr) +{ + return Offset (rect, dr.X, dr.Y); +}