gdkrectangle.c

Go to the documentation of this file.
00001 /* GDK - The GIMP Drawing Kit
00002  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
00022  * file for a list of people on the GTK+ Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #include <gdk/gdk.h>
00028 
00029 void
00030 gdk_rectangle_union(GdkRectangle * src1,
00031                     GdkRectangle * src2, GdkRectangle * dest)
00032 {
00033    g_return_if_fail(src1 != NULL);
00034    g_return_if_fail(src2 != NULL);
00035    g_return_if_fail(dest != NULL);
00036 
00037    dest->x = MIN(src1->x, src2->x);
00038    dest->y = MIN(src1->y, src2->y);
00039    dest->width =
00040        MAX(src1->x + src1->width, src2->x + src2->width) - dest->x;
00041    dest->height =
00042        MAX(src1->y + src1->height, src2->y + src2->height) - dest->y;
00043 }
00044 
00045 gboolean
00046 gdk_rectangle_intersect(GdkRectangle * src1,
00047                         GdkRectangle * src2, GdkRectangle * dest)
00048 {
00049    GdkRectangle *temp;
00050    gint src1_x2, src1_y2;
00051    gint src2_x2, src2_y2;
00052    gint return_val;
00053 
00054    g_return_val_if_fail(src1 != NULL, FALSE);
00055    g_return_val_if_fail(src2 != NULL, FALSE);
00056    g_return_val_if_fail(dest != NULL, FALSE);
00057 
00058    return_val = FALSE;
00059 
00060    if (src2->x < src1->x) {
00061       temp = src1;
00062       src1 = src2;
00063       src2 = temp;
00064    }
00065    dest->x = src2->x;
00066 
00067    src1_x2 = src1->x + src1->width;
00068    src2_x2 = src2->x + src2->width;
00069 
00070    if (src2->x < src1_x2) {
00071       if (src1_x2 < src2_x2)
00072          dest->width = src1_x2 - dest->x;
00073       else
00074          dest->width = src2_x2 - dest->x;
00075 
00076       if (src2->y < src1->y) {
00077          temp = src1;
00078          src1 = src2;
00079          src2 = temp;
00080       }
00081       dest->y = src2->y;
00082 
00083       src1_y2 = src1->y + src1->height;
00084       src2_y2 = src2->y + src2->height;
00085 
00086       if (src2->y < src1_y2) {
00087          return_val = TRUE;
00088 
00089          if (src1_y2 < src2_y2)
00090             dest->height = src1_y2 - dest->y;
00091          else
00092             dest->height = src2_y2 - dest->y;
00093 
00094          if (dest->height == 0)
00095             return_val = FALSE;
00096          if (dest->width == 0)
00097             return_val = FALSE;
00098       }
00099    }
00100 
00101    return return_val;
00102 }

Generated on Tue Jul 5 14:14:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1