]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkrectangle.c
Change FSF Address
[~andy/gtk] / gdk / gdkrectangle.c
index 427dbfd4911e008ebf8199b02bf5ee0233e3637a..2224413a51c2af72d47a56ad336fc67e8d3d49f8 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
-#include <gdk/gdk.h>
-#include "gdkalias.h"
+#include "config.h"
+
+#include "gdkrectangle.h"
+
+
+/**
+ * SECTION:regions
+ * @Short_description: Simple graphical data types
+ * @Title: Points and Rectangles
+ *
+ * GDK provides the #GdkPoint and #GdkRectangle data types for representing pixels
+ * and sets of pixels on the screen. Together with Cairo's #cairo_region_t data
+ * type, they make up the central types for representing graphical data.
+ *
+ * #GdkPoint is a simple structure containing an x and y coordinate of a point.
+ *
+ * #GdkRectangle is a structure holding the position and size of a rectangle.
+ * The intersection of two rectangles can be computed with
+ * gdk_rectangle_intersect(). To find the union of two rectangles use
+ * gdk_rectangle_union().
+ *
+ * #cairo_region_t is usually used for managing clipping of graphical operations.
+ */
+
 
 /**
  * gdk_rectangle_union:
  * @src1: a #GdkRectangle
  * @src2: a #GdkRectangle
- * @dest: return location for the union of @src1 and @src2
+ * @dest: (out): return location for the union of @src1 and @src2
  *
  * Calculates the union of two rectangles.
  * The union of rectangles @src1 and @src2 is the smallest rectangle which
  * includes both @src1 and @src2 within it.
+ * It is allowed for @dest to be the same as either @src1 or @src2.
  */
 void
-gdk_rectangle_union (GdkRectangle *src1,
-                    GdkRectangle *src2,
-                    GdkRectangle *dest)
+gdk_rectangle_union (const GdkRectangle *src1,
+                    const GdkRectangle *src2,
+                    GdkRectangle       *dest)
 {
   gint dest_x, dest_y;
   
@@ -61,41 +81,49 @@ gdk_rectangle_union (GdkRectangle *src1,
  * gdk_rectangle_intersect:
  * @src1: a #GdkRectangle
  * @src2: a #GdkRectangle
- * @dest: return location for the intersection of @src1 and @src2
+ * @dest: (out caller-allocates) (allow-none): return location for the
+ * intersection of @src1 and @src2, or %NULL
  *
- * Calculates the intersection of two rectangles.
+ * Calculates the intersection of two rectangles. It is allowed for
+ * @dest to be the same as either @src1 or @src2. If the rectangles 
+ * do not intersect, @dest's width and height is set to 0 and its x 
+ * and y values are undefined. If you are only interested in whether
+ * the rectangles intersect, but not in the intersecting area itself,
+ * pass %NULL for @dest.
  *
  * Returns: %TRUE if the rectangles intersect.
  */
 gboolean
-gdk_rectangle_intersect (GdkRectangle *src1,
-                        GdkRectangle *src2,
-                        GdkRectangle *dest)
+gdk_rectangle_intersect (const GdkRectangle *src1,
+                        const GdkRectangle *src2,
+                        GdkRectangle       *dest)
 {
   gint dest_x, dest_y;
-  gint dest_w, dest_h;
+  gint dest_x2, dest_y2;
   gint return_val;
 
   g_return_val_if_fail (src1 != NULL, FALSE);
   g_return_val_if_fail (src2 != NULL, FALSE);
-  g_return_val_if_fail (dest != NULL, FALSE);
 
   return_val = FALSE;
 
   dest_x = MAX (src1->x, src2->x);
   dest_y = MAX (src1->y, src2->y);
-  dest_w = MIN (src1->x + src1->width, src2->x + src2->width) - dest_x;
-  dest_h = MIN (src1->y + src1->height, src2->y + src2->height) - dest_y;
+  dest_x2 = MIN (src1->x + src1->width, src2->x + src2->width);
+  dest_y2 = MIN (src1->y + src1->height, src2->y + src2->height);
 
-  if (dest_w > 0 && dest_h > 0)
+  if (dest_x2 > dest_x && dest_y2 > dest_y)
     {
-      dest->x = dest_x;
-      dest->y = dest_y;
-      dest->width = dest_w;
-      dest->height = dest_h;
+      if (dest)
+        {
+          dest->x = dest_x;
+          dest->y = dest_y;
+          dest->width = dest_x2 - dest_x;
+          dest->height = dest_y2 - dest_y;
+        }
       return_val = TRUE;
     }
-  else
+  else if (dest)
     {
       dest->width = 0;
       dest->height = 0;
@@ -113,18 +141,6 @@ gdk_rectangle_copy (const GdkRectangle *rectangle)
   return result;
 }
 
-GType
-gdk_rectangle_get_type (void)
-{
-  static GType our_type = 0;
-  
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static (g_intern_static_string ("GdkRectangle"),
-                                            (GBoxedCopyFunc)gdk_rectangle_copy,
-                                            (GBoxedFreeFunc)g_free);
-  return our_type;
-}
-
-
-#define __GDK_RECTANGLE_C__
-#include "gdkaliasdef.c"
+G_DEFINE_BOXED_TYPE (GdkRectangle, gdk_rectangle,
+                     gdk_rectangle_copy,
+                     g_free)