evolution-3.6.4/libgnomecanvas/gnome-canvas-util.c

No issues found

  1 /*
  2  * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
  3  * All rights reserved.
  4  *
  5  * This file is part of the Gnome Library.
  6  *
  7  * The Gnome Library is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU Library General Public License as
  9  * published by the Free Software Foundation; either version 2 of the
 10  * License, or (at your option) any later version.
 11  *
 12  * The Gnome Library is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15  * Library General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Library General Public
 18  * License along with the Gnome Library; see the file COPYING.LIB.  If not,
 19  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 20  * Boston, MA 02111-1307, USA.
 21  */
 22 /*
 23   @NOTATION@
 24  */
 25 /* Miscellaneous utility functions for the GnomeCanvas widget
 26  *
 27  * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
 28  * widget.  Tk is copyrighted by the Regents of the University of California,
 29  * Sun Microsystems, and other parties.
 30  *
 31  *
 32  * Author: Federico Mena <federico@nuclecu.unam.mx>
 33  */
 34 
 35 #ifdef HAVE_CONFIG_H
 36 #include <config.h>
 37 #endif
 38 
 39 /* needed for M_PI_2 under 'gcc -ansi -predantic' on GNU/Linux */
 40 #ifndef _BSD_SOURCE
 41 #  define _BSD_SOURCE 1
 42 #endif
 43 #include <sys/types.h>
 44 
 45 #include <math.h>
 46 #include "gnome-canvas.h"
 47 #include "gnome-canvas-util.h"
 48 
 49 /* Here are some helper functions for aa rendering: */
 50 
 51 /**
 52  * gnome_canvas_item_reset_bounds:
 53  * @item: A canvas item
 54  *
 55  * Resets the bounding box of a canvas item to an empty rectangle.
 56  **/
 57 void
 58 gnome_canvas_item_reset_bounds (GnomeCanvasItem *item)
 59 {
 60 	item->x1 = 0.0;
 61 	item->y1 = 0.0;
 62 	item->x2 = 0.0;
 63 	item->y2 = 0.0;
 64 }
 65 
 66 /**
 67  * gnome_canvas_update_bbox:
 68  * @item: the canvas item needing update
 69  * @x1: Left coordinate of the new bounding box
 70  * @y1: Top coordinate of the new bounding box
 71  * @x2: Right coordinate of the new bounding box
 72  * @y2: Bottom coordinate of the new bounding box
 73  *
 74  * Sets the bbox to the new value, requesting full repaint.
 75  **/
 76 void
 77 gnome_canvas_update_bbox (GnomeCanvasItem *item,
 78                           gint x1,
 79                           gint y1,
 80                           gint x2,
 81                           gint y2)
 82 {
 83 	gnome_canvas_request_redraw (
 84 		item->canvas, item->x1, item->y1, item->x2, item->y2);
 85 
 86 	item->x1 = x1;
 87 	item->y1 = y1;
 88 	item->x2 = x2;
 89 	item->y2 = y2;
 90 
 91 	gnome_canvas_request_redraw (
 92 		item->canvas, item->x1, item->y1, item->x2, item->y2);
 93 }
 94 
 95 /**
 96  * gnome_canvas_cairo_create_scratch:
 97  *
 98  * Create a scratch #cairo_t. This is useful for measuring purposes or
 99  * calling functions like cairo_in_fill().
100  *
101  * Returns: A new cairo_t. Destroy with cairo_destroy() after use.
102  **/
103 cairo_t *
104 gnome_canvas_cairo_create_scratch (void)
105 {
106 	cairo_surface_t *surface;
107 	cairo_t *cr;
108 
109 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
110 	cr = cairo_create (surface);
111 	cairo_surface_destroy (surface);
112 
113 	return cr;
114 }
115 
116 /**
117  * gnome_canvas_matrix_transform_rect:
118  * @matrix: a cairo matrix
119  * @x1: x coordinate of top left position of rectangle (in-out)
120  * @y1: y coordinate of top left position of rectangle (in-out)
121  * @x2: x coordinate of bottom right position of rectangle (in-out)
122  * @y2: y coordinate of bottom right position of rectangle (in-out)
123  *
124  * Computes the smallest rectangle containing the whole area of the given
125  * rectangle after applying the transformation given in @matrix.
126  **/
127 void
128 gnome_canvas_matrix_transform_rect (const cairo_matrix_t *matrix,
129                                     gdouble *x1,
130                                     gdouble *y1,
131                                     gdouble *x2,
132                                     gdouble *y2)
133 {
134 	gdouble maxx, maxy, minx, miny;
135 	gdouble tmpx, tmpy;
136 
137 	tmpx = *x1;
138 	tmpy = *y1;
139 	cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
140 	minx = maxx = tmpx;
141 	miny = maxy = tmpy;
142 
143 	tmpx = *x2;
144 	tmpy = *y1;
145 	cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
146 	minx = MIN (minx, tmpx);
147 	maxx = MAX (maxx, tmpx);
148 	miny = MIN (miny, tmpy);
149 	maxy = MAX (maxy, tmpy);
150 
151 	tmpx = *x2;
152 	tmpy = *y2;
153 	cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
154 	minx = MIN (minx, tmpx);
155 	maxx = MAX (maxx, tmpx);
156 	miny = MIN (miny, tmpy);
157 	maxy = MAX (maxy, tmpy);
158 
159 	tmpx = *x1;
160 	tmpy = *y2;
161 	cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
162 	minx = MIN (minx, tmpx);
163 	maxx = MAX (maxx, tmpx);
164 	miny = MIN (miny, tmpy);
165 	maxy = MAX (maxy, tmpy);
166 
167         *x1 = minx;
168         *x2 = maxx;
169         *y1 = miny;
170         *y2 = maxy;
171 }