1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gdkdrawable.h"
31 #include "gdkinternals.h"
32 #include "gdkwindow.h"
33 #include "gdkscreen.h"
34 #include "gdk-pixbuf-private.h"
35 #include "gdkpixbuf.h"
37 static GdkImage* gdk_drawable_real_get_image (GdkDrawable *drawable,
42 static GdkDrawable* gdk_drawable_real_get_composite_drawable (GdkDrawable *drawable,
47 gint *composite_x_offset,
48 gint *composite_y_offset);
49 static GdkRegion * gdk_drawable_real_get_visible_region (GdkDrawable *drawable);
50 static void gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable,
62 static void gdk_drawable_real_draw_trapezoids (GdkDrawable *drawable,
64 GdkTrapezoid *trapezoids,
67 static void gdk_drawable_class_init (GdkDrawableClass *klass);
70 gdk_drawable_get_type (void)
72 static GType object_type = 0;
76 static const GTypeInfo object_info =
78 sizeof (GdkDrawableClass),
80 (GBaseFinalizeFunc) NULL,
81 (GClassInitFunc) gdk_drawable_class_init,
82 NULL, /* class_finalize */
83 NULL, /* class_data */
86 (GInstanceInitFunc) NULL,
89 object_type = g_type_register_static (G_TYPE_OBJECT,
92 G_TYPE_FLAG_ABSTRACT);
99 gdk_drawable_class_init (GdkDrawableClass *klass)
101 klass->get_image = gdk_drawable_real_get_image;
102 klass->get_composite_drawable = gdk_drawable_real_get_composite_drawable;
103 /* Default implementation for clip and visible region is the same */
104 klass->get_clip_region = gdk_drawable_real_get_visible_region;
105 klass->get_visible_region = gdk_drawable_real_get_visible_region;
106 klass->draw_pixbuf = gdk_drawable_real_draw_pixbuf;
107 klass->draw_trapezoids = gdk_drawable_real_draw_trapezoids;
110 /* Manipulation of drawables
114 * gdk_drawable_set_data:
115 * @drawable: a #GdkDrawable
116 * @key: name to store the data under
117 * @data: arbitrary data
118 * @destroy_func: function to free @data, or %NULL
120 * This function is equivalent to g_object_set_data(),
121 * the #GObject variant should be used instead.
125 gdk_drawable_set_data (GdkDrawable *drawable,
128 GDestroyNotify destroy_func)
130 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
132 g_object_set_qdata_full (G_OBJECT (drawable),
133 g_quark_from_string (key),
139 * gdk_drawable_get_data:
140 * @drawable: a #GdkDrawable
141 * @key: name the data was stored under
143 * Equivalent to g_object_get_data(); the #GObject variant should be
146 * Return value: the data stored at @key
149 gdk_drawable_get_data (GdkDrawable *drawable,
152 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
154 return g_object_get_qdata (G_OBJECT (drawable),
155 g_quark_try_string (key));
159 * gdk_drawable_get_size:
160 * @drawable: a #GdkDrawable
161 * @width: location to store drawable's width, or %NULL
162 * @height: location to store drawable's height, or %NULL
164 * Fills *@width and *@height with the size of @drawable.
165 * @width or @height can be %NULL if you only want the other one.
167 * On the X11 platform, if @drawable is a #GdkWindow, the returned
168 * size is the size reported in the most-recently-processed configure
169 * event, rather than the current size on the X server.
173 gdk_drawable_get_size (GdkDrawable *drawable,
177 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
179 GDK_DRAWABLE_GET_CLASS (drawable)->get_size (drawable, width, height);
183 * gdk_drawable_get_visual:
184 * @drawable: a #GdkDrawable
186 * Gets the #GdkVisual describing the pixel format of @drawable.
188 * Return value: a #GdkVisual
191 gdk_drawable_get_visual (GdkDrawable *drawable)
193 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
195 return GDK_DRAWABLE_GET_CLASS (drawable)->get_visual (drawable);
199 * gdk_drawable_get_depth:
200 * @drawable: a #GdkDrawable
202 * Obtains the bit depth of the drawable, that is, the number of bits
203 * that make up a pixel in the drawable's visual. Examples are 8 bits
204 * per pixel, 24 bits per pixel, etc.
206 * Return value: number of bits per pixel
209 gdk_drawable_get_depth (GdkDrawable *drawable)
211 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), 0);
213 return GDK_DRAWABLE_GET_CLASS (drawable)->get_depth (drawable);
216 * gdk_drawable_get_screen:
217 * @drawable: a #GdkDrawable
219 * Gets the #GdkScreen associated with a #GdkDrawable.
221 * Return value: the #GdkScreen associated with @drawable
226 gdk_drawable_get_screen(GdkDrawable *drawable)
228 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
230 return GDK_DRAWABLE_GET_CLASS (drawable)->get_screen (drawable);
234 * gdk_drawable_get_display:
235 * @drawable: a #GdkDrawable
237 * Gets the #GdkDisplay associated with a #GdkDrawable.
239 * Return value: the #GdkDisplay associated with @drawable
244 gdk_drawable_get_display (GdkDrawable *drawable)
246 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
248 return gdk_screen_get_display (gdk_drawable_get_screen (drawable));
252 * gdk_drawable_set_colormap:
253 * @drawable: a #GdkDrawable
254 * @colormap: a #GdkColormap
256 * Sets the colormap associated with @drawable. Normally this will
257 * happen automatically when the drawable is created; you only need to
258 * use this function if the drawable-creating function did not have a
259 * way to determine the colormap, and you then use drawable operations
260 * that require a colormap. The colormap for all drawables and
261 * graphics contexts you intend to use together should match. i.e.
262 * when using a #GdkGC to draw to a drawable, or copying one drawable
263 * to another, the colormaps should match.
267 gdk_drawable_set_colormap (GdkDrawable *drawable,
270 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
271 g_return_if_fail (cmap == NULL || gdk_drawable_get_depth (drawable)
272 == cmap->visual->depth);
274 GDK_DRAWABLE_GET_CLASS (drawable)->set_colormap (drawable, cmap);
278 * gdk_drawable_get_colormap:
279 * @drawable: a #GdkDrawable
281 * Gets the colormap for @drawable, if one is set; returns
284 * Return value: the colormap, or %NULL
287 gdk_drawable_get_colormap (GdkDrawable *drawable)
289 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
291 return GDK_DRAWABLE_GET_CLASS (drawable)->get_colormap (drawable);
296 * @drawable: a #GdkDrawable
298 * Deprecated equivalent of calling g_object_ref() on @drawable.
299 * (Drawables were not objects in previous versions of GDK.)
301 * Return value: the same @drawable passed in
304 gdk_drawable_ref (GdkDrawable *drawable)
306 return (GdkDrawable *) g_object_ref (drawable);
310 * gdk_drawable_unref:
311 * @drawable: a #GdkDrawable
313 * Deprecated equivalent of calling g_object_unref() on @drawable.
317 gdk_drawable_unref (GdkDrawable *drawable)
319 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
321 g_object_unref (drawable);
329 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
331 * @x: the x coordinate of the point.
332 * @y: the y coordinate of the point.
334 * Draws a point, using the foreground color and other attributes of
338 gdk_draw_point (GdkDrawable *drawable,
345 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
346 g_return_if_fail (GDK_IS_GC (gc));
351 GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, &point, 1);
356 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
358 * @x1_: the x coordinate of the start point.
359 * @y1_: the y coordinate of the start point.
360 * @x2_: the x coordinate of the end point.
361 * @y2_: the y coordinate of the end point.
363 * Draws a line, using the foreground color and other attributes of
367 gdk_draw_line (GdkDrawable *drawable,
376 g_return_if_fail (drawable != NULL);
377 g_return_if_fail (gc != NULL);
378 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
379 g_return_if_fail (GDK_IS_GC (gc));
385 GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, &segment, 1);
389 * gdk_draw_rectangle:
390 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
392 * @filled: %TRUE if the rectangle should be filled.
393 * @x: the x coordinate of the left edge of the rectangle.
394 * @y: the y coordinate of the top edge of the rectangle.
395 * @width: the width of the rectangle.
396 * @height: the height of the rectangle.
398 * Draws a rectangular outline or filled rectangle, using the foreground color
399 * and other attributes of the #GdkGC.
401 * A rectangle drawn filled is 1 pixel smaller in both dimensions than a
402 * rectangle outlined. Calling
403 * <literal>gdk_draw_rectangle (window, gc, TRUE, 0, 0, 20, 20)</literal>
404 * results in a filled rectangle 20 pixels wide and 20 pixels high. Calling
405 * <literal>gdk_draw_rectangle (window, gc, FALSE, 0, 0, 20, 20)</literal>
406 * results in an outlined rectangle with corners at (0, 0), (0, 20), (20, 20),
407 * and (20, 0), which makes it 21 pixels wide and 21 pixels high.
410 gdk_draw_rectangle (GdkDrawable *drawable,
418 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
419 g_return_if_fail (GDK_IS_GC (gc));
421 if (width < 0 || height < 0)
426 gdk_drawable_get_size (drawable, &real_width, &real_height);
431 height = real_height;
434 GDK_DRAWABLE_GET_CLASS (drawable)->draw_rectangle (drawable, gc, filled, x, y,
440 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
442 * @filled: %TRUE if the arc should be filled, producing a 'pie slice'.
443 * @x: the x coordinate of the left edge of the bounding rectangle.
444 * @y: the y coordinate of the top edge of the bounding rectangle.
445 * @width: the width of the bounding rectangle.
446 * @height: the height of the bounding rectangle.
447 * @angle1: the start angle of the arc, relative to the 3 o'clock position,
448 * counter-clockwise, in 1/64ths of a degree.
449 * @angle2: the end angle of the arc, relative to @angle1, in 1/64ths
452 * Draws an arc or a filled 'pie slice'. The arc is defined by the bounding
453 * rectangle of the entire ellipse, and the start and end angles of the part
454 * of the ellipse to be drawn.
457 gdk_draw_arc (GdkDrawable *drawable,
467 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
468 g_return_if_fail (GDK_IS_GC (gc));
470 if (width < 0 || height < 0)
475 gdk_drawable_get_size (drawable, &real_width, &real_height);
480 height = real_height;
483 GDK_DRAWABLE_GET_CLASS (drawable)->draw_arc (drawable, gc, filled,
484 x, y, width, height, angle1, angle2);
489 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
491 * @filled: %TRUE if the polygon should be filled. The polygon is closed
492 * automatically, connecting the last point to the first point if
494 * @points: an array of #GdkPoint structures specifying the points making
496 * @npoints: the number of points.
498 * Draws an outlined or filled polygon.
501 gdk_draw_polygon (GdkDrawable *drawable,
507 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
508 g_return_if_fail (GDK_IS_GC (gc));
510 GDK_DRAWABLE_GET_CLASS (drawable)->draw_polygon (drawable, gc, filled,
516 * Modified by Li-Da Lho to draw 16 bits and Multibyte strings
518 * Interface changed: add "GdkFont *font" to specify font or fontset explicitely
522 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
525 * @x: the x coordinate of the left edge of the text.
526 * @y: the y coordinate of the baseline of the text.
527 * @string: the string of characters to draw.
529 * Draws a string of characters in the given font or fontset.
531 * Deprecated: Use gdk_draw_layout() instead.
534 gdk_draw_string (GdkDrawable *drawable,
541 gdk_draw_text (drawable, font, gc, x, y, string, _gdk_font_strlen (font, string));
546 * Modified by Li-Da Lho to draw 16 bits and Multibyte strings
548 * Interface changed: add "GdkFont *font" to specify font or fontset explicitely
552 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
555 * @x: the x coordinate of the left edge of the text.
556 * @y: the y coordinate of the baseline of the text.
557 * @text: the characters to draw.
558 * @text_length: the number of characters of @text to draw.
560 * Draws a number of characters in the given font or fontset.
562 * Deprecated: Use gdk_draw_layout() instead.
565 gdk_draw_text (GdkDrawable *drawable,
573 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
574 g_return_if_fail (font != NULL);
575 g_return_if_fail (GDK_IS_GC (gc));
576 g_return_if_fail (text != NULL);
578 GDK_DRAWABLE_GET_CLASS (drawable)->draw_text (drawable, font, gc, x, y, text, text_length);
583 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
586 * @x: the x coordinate of the left edge of the text.
587 * @y: the y coordinate of the baseline of the text.
588 * @text: the wide characters to draw.
589 * @text_length: the number of characters to draw.
591 * Draws a number of wide characters using the given font of fontset.
592 * If the font is a 1-byte font, the string is converted into 1-byte
593 * characters (discarding the high bytes) before output.
595 * Deprecated: Use gdk_draw_layout() instead.
598 gdk_draw_text_wc (GdkDrawable *drawable,
603 const GdkWChar *text,
606 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
607 g_return_if_fail (font != NULL);
608 g_return_if_fail (GDK_IS_GC (gc));
609 g_return_if_fail (text != NULL);
611 GDK_DRAWABLE_GET_CLASS (drawable)->draw_text_wc (drawable, font, gc, x, y, text, text_length);
616 * @drawable: a #GdkDrawable
617 * @gc: a #GdkGC sharing the drawable's visual and colormap
618 * @src: the source #GdkDrawable, which may be the same as @drawable
619 * @xsrc: X position in @src of rectangle to draw
620 * @ysrc: Y position in @src of rectangle to draw
621 * @xdest: X position in @drawable where the rectangle should be drawn
622 * @ydest: Y position in @drawable where the rectangle should be drawn
623 * @width: width of rectangle to draw, or -1 for entire @src width
624 * @height: height of rectangle to draw, or -1 for entire @src height
626 * Copies the @width x @height region of @src at coordinates (@xsrc,
627 * @ysrc) to coordinates (@xdest, @ydest) in @drawable.
628 * @width and/or @height may be given as -1, in which case the entire
629 * @src drawable will be copied.
631 * Most fields in @gc are not used for this operation, but notably the
632 * clip mask or clip region will be honored.
634 * The source and destination drawables must have the same visual and
635 * colormap, or errors will result. (On X11, failure to match
636 * visual/colormap results in a BadMatch error from the X server.)
637 * A common cause of this problem is an attempt to draw a bitmap to
638 * a color drawable. The way to draw a bitmap is to set the
639 * bitmap as a clip mask on your #GdkGC, then use gdk_draw_rectangle()
640 * to draw a rectangle clipped to the bitmap.
643 gdk_draw_drawable (GdkDrawable *drawable,
653 GdkDrawable *composite;
654 gint composite_x_offset = 0;
655 gint composite_y_offset = 0;
657 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
658 g_return_if_fail (src != NULL);
659 g_return_if_fail (GDK_IS_GC (gc));
661 if (width < 0 || height < 0)
666 gdk_drawable_get_size (src, &real_width, &real_height);
671 height = real_height;
676 GDK_DRAWABLE_GET_CLASS (src)->get_composite_drawable (src,
680 &composite_y_offset);
683 GDK_DRAWABLE_GET_CLASS (drawable)->draw_drawable (drawable, gc, composite,
684 xsrc - composite_x_offset,
685 ysrc - composite_y_offset,
689 g_object_unref (composite);
694 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
696 * @image: the #GdkImage to draw.
697 * @xsrc: the left edge of the source rectangle within @image.
698 * @ysrc: the top of the source rectangle within @image.
699 * @xdest: the x coordinate of the destination within @drawable.
700 * @ydest: the y coordinate of the destination within @drawable.
701 * @width: the width of the area to be copied, or -1 to make the area
702 * extend to the right edge of @image.
703 * @height: the height of the area to be copied, or -1 to make the area
704 * extend to the bottom edge of @image.
706 * Draws a #GdkImage onto a drawable.
707 * The depth of the #GdkImage must match the depth of the #GdkDrawable.
710 gdk_draw_image (GdkDrawable *drawable,
720 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
721 g_return_if_fail (image != NULL);
722 g_return_if_fail (GDK_IS_GC (gc));
725 width = image->width;
727 height = image->height;
729 GDK_DRAWABLE_GET_CLASS (drawable)->draw_image (drawable, gc, image, xsrc, ysrc,
730 xdest, ydest, width, height);
735 * @drawable: Destination drawable.
736 * @gc: a #GdkGC, used for clipping, or %NULL
737 * @pixbuf: a #GdkPixbuf
738 * @src_x: Source X coordinate within pixbuf.
739 * @src_y: Source Y coordinates within pixbuf.
740 * @dest_x: Destination X coordinate within drawable.
741 * @dest_y: Destination Y coordinate within drawable.
742 * @width: Width of region to render, in pixels, or -1 to use pixbuf width.
743 * @height: Height of region to render, in pixels, or -1 to use pixbuf height.
744 * @dither: Dithering mode for #GdkRGB.
745 * @x_dither: X offset for dither.
746 * @y_dither: Y offset for dither.
748 * Renders a rectangular portion of a pixbuf to a drawable. The destination
749 * drawable must have a colormap. All windows have a colormap, however, pixmaps
750 * only have colormap by default if they were created with a non-%NULL window
751 * argument. Otherwise a colormap must be set on them with
752 * gdk_drawable_set_colormap().
754 * On older X servers, rendering pixbufs with an alpha channel involves round
755 * trips to the X server, and may be somewhat slow.
757 * The clip mask of @gc is ignored, but clip rectangles and clip regions work
763 gdk_draw_pixbuf (GdkDrawable *drawable,
776 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
777 g_return_if_fail (gc == NULL || GDK_IS_GC (gc));
778 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
781 width = gdk_pixbuf_get_width (pixbuf);
783 height = gdk_pixbuf_get_height (pixbuf);
785 GDK_DRAWABLE_GET_CLASS (drawable)->draw_pixbuf (drawable, gc, pixbuf,
786 src_x, src_y, dest_x, dest_y, width, height,
787 dither, x_dither, y_dither);
792 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
794 * @points: an array of #GdkPoint structures.
795 * @npoints: the number of points to be drawn.
797 * Draws a number of points, using the foreground color and other
798 * attributes of the #GdkGC.
801 gdk_draw_points (GdkDrawable *drawable,
806 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
807 g_return_if_fail ((points != NULL) && (npoints > 0));
808 g_return_if_fail (GDK_IS_GC (gc));
809 g_return_if_fail (npoints >= 0);
814 GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, points, npoints);
819 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
821 * @segs: an array of #GdkSegment structures specifying the start and
822 * end points of the lines to be drawn.
823 * @nsegs: the number of line segments to draw, i.e. the size of the
826 * Draws a number of unconnected lines.
829 gdk_draw_segments (GdkDrawable *drawable,
834 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
839 g_return_if_fail (segs != NULL);
840 g_return_if_fail (GDK_IS_GC (gc));
841 g_return_if_fail (nsegs >= 0);
843 GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, segs, nsegs);
848 * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
850 * @points: an array of #GdkPoint structures specifying the endpoints of the
851 * @npoints: the size of the @points array.
853 * Draws a series of lines connecting the given points.
854 * The way in which joins between lines are draw is determined by the
855 * #GdkCapStyle value in the #GdkGC. This can be set with
856 * gdk_gc_set_line_attributes().
859 gdk_draw_lines (GdkDrawable *drawable,
864 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
865 g_return_if_fail (points != NULL);
866 g_return_if_fail (GDK_IS_GC (gc));
867 g_return_if_fail (npoints >= 0);
872 GDK_DRAWABLE_GET_CLASS (drawable)->draw_lines (drawable, gc, points, npoints);
877 * @drawable: a #GdkDrawable
879 * @font: font to be used
880 * @x: X coordinate of baseline origin
881 * @y: Y coordinate of baseline origin
882 * @glyphs: the glyph string to draw
884 * This is a low-level function; 99% of text rendering should be done
885 * using gdk_draw_layout() instead.
887 * A glyph is a single image in a font. This function draws a sequence of
888 * glyphs. To obtain a sequence of glyphs you have to understand a
889 * lot about internationalized text handling, which you don't want to
890 * understand; thus, use gdk_draw_layout() instead of this function,
891 * gdk_draw_layout() handles the details.
895 gdk_draw_glyphs (GdkDrawable *drawable,
900 PangoGlyphString *glyphs)
902 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
903 g_return_if_fail (GDK_IS_GC (gc));
906 GDK_DRAWABLE_GET_CLASS (drawable)->draw_glyphs (drawable, gc, font, x, y, glyphs);
910 * gdk_draw_glyphs_transformed:
911 * @drawable: a #GdkDrawable
913 * @matrix: a #PangoMatrix, or %NULL to use an identity transformation
914 * @font: the font in which to draw the string
915 * @x: the x position of the start of the string (in Pango
916 * units in user space coordinates)
917 * @y: the y position of the baseline (in Pango units
918 * in user space coordinates)
919 * @glyphs: the glyph string to draw
921 * Renders a #PangoGlyphString onto a drawable, possibly
922 * transforming the layed-out coordinates through a transformation
923 * matrix. Note that the transformation matrix for @font is not
924 * changed, so to produce correct rendering results, the @font
925 * must have been loaded using a #PangoContext with an identical
926 * transformation matrix to that passed in to this function.
928 * See also gdk_draw_glyphs(), gdk_draw_layout().
933 gdk_draw_glyphs_transformed (GdkDrawable *drawable,
939 PangoGlyphString *glyphs)
941 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
942 g_return_if_fail (GDK_IS_GC (gc));
944 if (GDK_DRAWABLE_GET_CLASS (drawable)->draw_glyphs_transformed)
945 GDK_DRAWABLE_GET_CLASS (drawable)->draw_glyphs_transformed (drawable, gc, matrix,
950 * gdk_draw_trapezoids:
951 * @drawable: a #GdkDrawable
953 * @trapezoids: an array of #GdkTrapezoid structures
954 * @n_trapezoids: the number of trapezoids to draw
956 * Draws a set of anti-aliased trapezoids. The trapezoids are
957 * combined using saturation addition, then drawn over the background
958 * as a set. This is low level functionality used internally to implement
959 * rotated underlines and backgrouds when rendering a PangoLayout and is
960 * likely not useful for applications.
965 gdk_draw_trapezoids (GdkDrawable *drawable,
967 GdkTrapezoid *trapezoids,
970 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
971 g_return_if_fail (GDK_IS_GC (gc));
972 g_return_if_fail (n_trapezoids == 0 || trapezoids != NULL);
974 GDK_DRAWABLE_GET_CLASS (drawable)->draw_trapezoids (drawable, gc,
975 trapezoids, n_trapezoids);
979 * gdk_drawable_copy_to_image:
980 * @drawable: a #GdkDrawable
981 * @image: a #GdkDrawable, or %NULL if a new @image should be created.
982 * @src_x: x coordinate on @drawable
983 * @src_y: y coordinate on @drawable
984 * @dest_x: x coordinate within @image. Must be 0 if @image is %NULL
985 * @dest_y: y coordinate within @image. Must be 0 if @image is %NULL
986 * @width: width of region to get
987 * @height: height or region to get
989 * Copies a portion of @drawable into the client side image structure
990 * @image. If @image is %NULL, creates a new image of size @width x @height
991 * and copies into that. See gdk_drawable_get_image() for further details.
993 * Return value: @image, or a new a #GdkImage containing the contents
999 gdk_drawable_copy_to_image (GdkDrawable *drawable,
1008 GdkDrawable *composite;
1009 gint composite_x_offset = 0;
1010 gint composite_y_offset = 0;
1014 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
1015 g_return_val_if_fail (src_x >= 0, NULL);
1016 g_return_val_if_fail (src_y >= 0, NULL);
1018 /* FIXME? Note race condition since we get the size then
1019 * get the image, and the size may have changed.
1022 if (width < 0 || height < 0)
1023 gdk_drawable_get_size (drawable,
1024 width < 0 ? &width : NULL,
1025 height < 0 ? &height : NULL);
1028 GDK_DRAWABLE_GET_CLASS (drawable)->get_composite_drawable (drawable,
1031 &composite_x_offset,
1032 &composite_y_offset);
1034 retval = GDK_DRAWABLE_GET_CLASS (composite)->_copy_to_image (composite,
1036 src_x - composite_x_offset,
1037 src_y - composite_y_offset,
1041 g_object_unref (composite);
1043 if (!image && retval)
1045 cmap = gdk_drawable_get_colormap (drawable);
1048 gdk_image_set_colormap (retval, cmap);
1055 * gdk_drawable_get_image:
1056 * @drawable: a #GdkDrawable
1057 * @x: x coordinate on @drawable
1058 * @y: y coordinate on @drawable
1059 * @width: width of region to get
1060 * @height: height or region to get
1062 * A #GdkImage stores client-side image data (pixels). In contrast,
1063 * #GdkPixmap and #GdkWindow are server-side
1064 * objects. gdk_drawable_get_image() obtains the pixels from a
1065 * server-side drawable as a client-side #GdkImage. The format of a
1066 * #GdkImage depends on the #GdkVisual of the current display, which
1067 * makes manipulating #GdkImage extremely difficult; therefore, in
1068 * most cases you should use gdk_pixbuf_get_from_drawable() instead of
1069 * this lower-level function. A #GdkPixbuf contains image data in a
1070 * canonicalized RGB format, rather than a display-dependent format.
1071 * Of course, there's a convenience vs. speed tradeoff here, so you'll
1072 * want to think about what makes sense for your application.
1074 * @x, @y, @width, and @height define the region of @drawable to
1075 * obtain as an image.
1077 * You would usually copy image data to the client side if you intend
1078 * to examine the values of individual pixels, for example to darken
1079 * an image or add a red tint. It would be prohibitively slow to
1080 * make a round-trip request to the windowing system for each pixel,
1081 * so instead you get all of them at once, modify them, then copy
1082 * them all back at once.
1084 * If the X server or other windowing system backend is on the local
1085 * machine, this function may use shared memory to avoid copying
1088 * If the source drawable is a #GdkWindow and partially offscreen
1089 * or obscured, then the obscured portions of the returned image
1090 * will contain undefined data.
1092 * Return value: a #GdkImage containing the contents of @drawable
1095 gdk_drawable_get_image (GdkDrawable *drawable,
1101 GdkDrawable *composite;
1102 gint composite_x_offset = 0;
1103 gint composite_y_offset = 0;
1107 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
1108 g_return_val_if_fail (x >= 0, NULL);
1109 g_return_val_if_fail (y >= 0, NULL);
1111 /* FIXME? Note race condition since we get the size then
1112 * get the image, and the size may have changed.
1115 if (width < 0 || height < 0)
1116 gdk_drawable_get_size (drawable,
1117 width < 0 ? &width : NULL,
1118 height < 0 ? &height : NULL);
1121 GDK_DRAWABLE_GET_CLASS (drawable)->get_composite_drawable (drawable,
1124 &composite_x_offset,
1125 &composite_y_offset);
1127 retval = GDK_DRAWABLE_GET_CLASS (composite)->get_image (composite,
1128 x - composite_x_offset,
1129 y - composite_y_offset,
1132 g_object_unref (composite);
1134 cmap = gdk_drawable_get_colormap (drawable);
1137 gdk_image_set_colormap (retval, cmap);
1143 gdk_drawable_real_get_image (GdkDrawable *drawable,
1149 return gdk_drawable_copy_to_image (drawable, NULL, x, y, 0, 0, width, height);
1153 gdk_drawable_real_get_composite_drawable (GdkDrawable *drawable,
1158 gint *composite_x_offset,
1159 gint *composite_y_offset)
1161 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
1163 *composite_x_offset = 0;
1164 *composite_y_offset = 0;
1166 return g_object_ref (drawable);
1170 * gdk_drawable_get_clip_region:
1171 * @drawable: a #GdkDrawable
1173 * Computes the region of a drawable that potentially can be written
1174 * to by drawing primitives. This region will not take into account
1175 * the clip region for the GC, and may also not take into account
1176 * other factors such as if the window is obscured by other windows,
1177 * but no area outside of this region will be affected by drawing
1180 * Return value: a #GdkRegion. This must be freed with gdk_region_destroy()
1181 * when you are done.
1184 gdk_drawable_get_clip_region (GdkDrawable *drawable)
1186 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
1188 return GDK_DRAWABLE_GET_CLASS (drawable)->get_clip_region (drawable);
1192 * gdk_drawable_get_visible_region:
1195 * Computes the region of a drawable that is potentially visible.
1196 * This does not necessarily take into account if the window is
1197 * obscured by other windows, but no area outside of this region
1200 * Return value: a #GdkRegion. This must be freed with gdk_region_destroy()
1201 * when you are done.
1204 gdk_drawable_get_visible_region (GdkDrawable *drawable)
1206 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
1208 return GDK_DRAWABLE_GET_CLASS (drawable)->get_visible_region (drawable);
1212 gdk_drawable_real_get_visible_region (GdkDrawable *drawable)
1219 gdk_drawable_get_size (drawable, &rect.width, &rect.height);
1221 return gdk_region_rectangle (&rect);
1225 * gdk_drawable_set_cairo_target:
1226 * @drawable: a #GdkDrawable
1227 * @cr: a cairo context
1229 * Sets the given drawable as the target surface for a Cairo context.
1230 * Note that when @drawable is a window and gdk_window_begin_paint()
1231 * has been called, the target surface will be set to the temporary
1232 * backing pixmap, so you can only use the Cairo context until
1233 * the matching call to gdk_window_end_paint().
1238 gdk_drawable_set_cairo_target (GdkDrawable *drawable,
1241 g_return_if_fail (GDK_IS_DRAWABLE (drawable));
1242 g_return_if_fail (cr != NULL);
1244 return GDK_DRAWABLE_GET_CLASS (drawable)->set_cairo_target (drawable, cr);
1248 composite (guchar *src_buf,
1251 gint dest_rowstride,
1255 guchar *src = src_buf;
1256 guchar *dest = dest_buf;
1260 gint twidth = width;
1269 t = a * p[0] + (255 - a) * q[0] + 0x80;
1270 q[0] = (t + (t >> 8)) >> 8;
1271 t = a * p[1] + (255 - a) * q[1] + 0x80;
1272 q[1] = (t + (t >> 8)) >> 8;
1273 t = a * p[2] + (255 - a) * q[2] + 0x80;
1274 q[2] = (t + (t >> 8)) >> 8;
1280 src += src_rowstride;
1281 dest += dest_rowstride;
1286 composite_0888 (guchar *src_buf,
1289 gint dest_rowstride,
1290 GdkByteOrder dest_byte_order,
1294 guchar *src = src_buf;
1295 guchar *dest = dest_buf;
1299 gint twidth = width;
1303 if (dest_byte_order == GDK_LSB_FIRST)
1309 t = p[3] * p[2] + (255 - p[3]) * q[0] + 0x80;
1310 q[0] = (t + (t >> 8)) >> 8;
1311 t = p[3] * p[1] + (255 - p[3]) * q[1] + 0x80;
1312 q[1] = (t + (t >> 8)) >> 8;
1313 t = p[3] * p[0] + (255 - p[3]) * q[2] + 0x80;
1314 q[2] = (t + (t >> 8)) >> 8;
1325 t = p[3] * p[0] + (255 - p[3]) * q[1] + 0x80;
1326 q[1] = (t + (t >> 8)) >> 8;
1327 t = p[3] * p[1] + (255 - p[3]) * q[2] + 0x80;
1328 q[2] = (t + (t >> 8)) >> 8;
1329 t = p[3] * p[2] + (255 - p[3]) * q[3] + 0x80;
1330 q[3] = (t + (t >> 8)) >> 8;
1336 src += src_rowstride;
1337 dest += dest_rowstride;
1342 composite_565 (guchar *src_buf,
1345 gint dest_rowstride,
1346 GdkByteOrder dest_byte_order,
1350 guchar *src = src_buf;
1351 guchar *dest = dest_buf;
1355 gint twidth = width;
1357 gushort *q = (gushort *)dest;
1363 guint tr1, tg1, tb1;
1367 /* This is fast, and corresponds to what composite() above does
1368 * if we converted to 8-bit first.
1370 tr = (tmp & 0xf800);
1371 tr1 = a * p[0] + (255 - a) * ((tr >> 8) + (tr >> 13)) + 0x80;
1372 tg = (tmp & 0x07e0);
1373 tg1 = a * p[1] + (255 - a) * ((tg >> 3) + (tg >> 9)) + 0x80;
1374 tb = (tmp & 0x001f);
1375 tb1 = a * p[2] + (255 - a) * ((tb << 3) + (tb >> 2)) + 0x80;
1377 *q = (((tr1 + (tr1 >> 8)) & 0xf800) |
1378 (((tg1 + (tg1 >> 8)) & 0xfc00) >> 5) |
1379 ((tb1 + (tb1 >> 8)) >> 11));
1381 /* This version correspond to the result we get with XRENDER -
1382 * a bit of precision is lost since we convert to 8 bit after premultiplying
1383 * instead of at the end
1385 guint tr2, tg2, tb2;
1386 guint tr3, tg3, tb3;
1388 tr = (tmp & 0xf800);
1389 tr1 = (255 - a) * ((tr >> 8) + (tr >> 13)) + 0x80;
1390 tr2 = a * p[0] + 0x80;
1391 tr3 = ((tr1 + (tr1 >> 8)) >> 8) + ((tr2 + (tr2 >> 8)) >> 8);
1393 tg = (tmp & 0x07e0);
1394 tg1 = (255 - a) * ((tg >> 3) + (tg >> 9)) + 0x80;
1395 tg2 = a * p[0] + 0x80;
1396 tg3 = ((tg1 + (tg1 >> 8)) >> 8) + ((tg2 + (tg2 >> 8)) >> 8);
1398 tb = (tmp & 0x001f);
1399 tb1 = (255 - a) * ((tb << 3) + (tb >> 2)) + 0x80;
1400 tb2 = a * p[0] + 0x80;
1401 tb3 = ((tb1 + (tb1 >> 8)) >> 8) + ((tb2 + (tb2 >> 8)) >> 8);
1403 *q = (((tr3 & 0xf8) << 8) |
1404 ((tg3 & 0xfc) << 3) |
1412 src += src_rowstride;
1413 dest += dest_rowstride;
1418 gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable,
1427 GdkRgbDither dither,
1431 GdkPixbuf *composited = NULL;
1432 gint dwidth, dheight;
1435 GdkRectangle tmp_rect;
1437 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
1438 g_return_if_fail (pixbuf->colorspace == GDK_COLORSPACE_RGB);
1439 g_return_if_fail (pixbuf->n_channels == 3 || pixbuf->n_channels == 4);
1440 g_return_if_fail (pixbuf->bits_per_sample == 8);
1442 g_return_if_fail (drawable != NULL);
1445 width = pixbuf->width;
1447 height = pixbuf->height;
1449 g_return_if_fail (width >= 0 && height >= 0);
1450 g_return_if_fail (src_x >= 0 && src_x + width <= pixbuf->width);
1451 g_return_if_fail (src_y >= 0 && src_y + height <= pixbuf->height);
1453 /* Clip to the drawable; this is required for get_from_drawable() so
1454 * can't be done implicitly
1471 gdk_drawable_get_size (drawable, &dwidth, &dheight);
1473 if ((dest_x + width) > dwidth)
1474 width = dwidth - dest_x;
1476 if ((dest_y + height) > dheight)
1477 height = dheight - dest_y;
1479 if (width <= 0 || height <= 0)
1482 /* Clip to the clip region; this avoids getting more
1483 * image data from the server than we need to.
1486 tmp_rect.x = dest_x;
1487 tmp_rect.y = dest_y;
1488 tmp_rect.width = width;
1489 tmp_rect.height = height;
1491 drect = gdk_region_rectangle (&tmp_rect);
1492 clip = gdk_drawable_get_clip_region (drawable);
1494 gdk_region_intersect (drect, clip);
1496 gdk_region_get_clipbox (drect, &tmp_rect);
1498 gdk_region_destroy (drect);
1499 gdk_region_destroy (clip);
1501 if (tmp_rect.width == 0 ||
1502 tmp_rect.height == 0)
1507 gc = _gdk_drawable_get_scratch_gc (drawable, FALSE);
1509 if (pixbuf->has_alpha)
1511 GdkVisual *visual = gdk_drawable_get_visual (drawable);
1512 void (*composite_func) (guchar *src_buf,
1515 gint dest_rowstride,
1516 GdkByteOrder dest_byte_order,
1518 gint height) = NULL;
1520 /* First we see if we have a visual-specific composition function that can composite
1521 * the pixbuf data directly onto the image
1525 gint bits_per_pixel = _gdk_windowing_get_bits_for_depth (gdk_drawable_get_display (drawable),
1528 if (visual->byte_order == (G_BYTE_ORDER == G_BIG_ENDIAN ? GDK_MSB_FIRST : GDK_LSB_FIRST) &&
1529 visual->depth == 16 &&
1530 visual->red_mask == 0xf800 &&
1531 visual->green_mask == 0x07e0 &&
1532 visual->blue_mask == 0x001f)
1533 composite_func = composite_565;
1534 else if (visual->depth == 24 && bits_per_pixel == 32 &&
1535 visual->red_mask == 0xff0000 &&
1536 visual->green_mask == 0x00ff00 &&
1537 visual->blue_mask == 0x0000ff)
1538 composite_func = composite_0888;
1541 /* We can't use our composite func if we are required to dither
1543 if (composite_func && !(dither == GDK_RGB_DITHER_MAX && visual->depth != 24))
1546 for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
1548 gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT);
1549 for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH)
1553 gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH);
1555 GdkImage *image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable),
1557 gdk_drawable_get_depth (drawable), &xs0, &ys0);
1559 gdk_drawable_copy_to_image (drawable, image,
1560 dest_x + x0, dest_y + y0,
1563 (*composite_func) (pixbuf->pixels + (src_y + y0) * pixbuf->rowstride + (src_x + x0) * 4,
1565 (guchar*)image->mem + ys0 * image->bpl + xs0 * image->bpp,
1569 gdk_draw_image (drawable, gc, image,
1571 dest_x + x0, dest_y + y0,
1580 /* No special composition func, convert dest to 24 bit RGB data, composite against
1581 * that, and convert back.
1583 composited = gdk_pixbuf_get_from_drawable (NULL,
1591 composite (pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4,
1594 composited->rowstride,
1603 pixbuf = composited;
1606 if (pixbuf->n_channels == 4)
1608 guchar *buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4;
1610 gdk_draw_rgb_32_image_dithalign (drawable, gc,
1614 buf, pixbuf->rowstride,
1615 x_dither, y_dither);
1617 else /* n_channels == 3 */
1619 guchar *buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 3;
1621 gdk_draw_rgb_image_dithalign (drawable, gc,
1625 buf, pixbuf->rowstride,
1626 x_dither, y_dither);
1631 g_object_unref (composited);
1634 /************************************************************************/
1636 /* Fallback rendering code for anti-aliased trapezoids. Note that this code
1637 * is cut-and-pasted (with the substitution of GdkPixbuf for FT_Bitmap) between
1638 * here and pangoft2-render.c.
1647 draw_simple_trap (GdkPixbuf *pixbuf,
1653 guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
1654 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
1655 int pixbuf_width = gdk_pixbuf_get_width (pixbuf);
1656 int pixbuf_height = gdk_pixbuf_get_height (pixbuf);
1657 int iy = floor (t->y);
1659 double dy = b->y - t->y;
1662 if (iy < pixbuf_y || iy >= pixbuf_y + pixbuf_height)
1675 x1 = CLAMP (x1, pixbuf_x, pixbuf_x + pixbuf_width);
1676 x2 = CLAMP (x2, pixbuf_x, pixbuf_x + pixbuf_width);
1678 dest = pixels + (iy - pixbuf_y) * rowstride + (x1 - pixbuf_x) * 4;
1680 for (x = x1; x < x2; x++, dest += 4)
1682 double top_left = MAX (t->x1, x);
1683 double top_right = MIN (t->x2, x + 1);
1684 double bottom_left = MAX (b->x1, x);
1685 double bottom_right = MIN (b->x2, x + 1);
1686 double c = 0.5 * dy * ((top_right - top_left) + (bottom_right - bottom_left));
1688 /* When converting to [0,255], we round up. This is intended
1689 * to prevent the problem of pixels that get divided into
1690 * multiple slices not being fully black.
1694 /* We already set the entire buffer to the destination color */
1695 dest[3] = MIN (dest[3] + ic, 255);
1700 interpolate_position (Position *result,
1707 result->y = (top->y * (val2 - val) + bottom->y * (val - val1)) / (val2 - val1);
1708 result->x1 = (top->x1 * (val2 - val) + bottom->x1 * (val - val1)) / (val2 - val1);
1709 result->x2 = (top->x2 * (val2 - val) + bottom->x2 * (val - val1)) / (val2 - val1);
1712 /* This draws a trapezoid with the parallel sides aligned with
1713 * the X axis. We do this by subdividing the trapezoid vertically
1714 * into thin slices (themselves trapezoids) where two edge sides are each
1715 * contained within a single pixel and then rasterizing each
1716 * slice. There are frequently multiple slices within a single
1717 * line so we have to accumulate to get the final result.
1720 draw_trapezoid (GdkPixbuf *pixbuf,
1723 GdkTrapezoid *trapezoid)
1728 gboolean done = FALSE;
1730 if (trapezoid->y1 == trapezoid->y2)
1733 pos.y = t.y = trapezoid->y1;
1734 pos.x1 = t.x1 = trapezoid->x11;
1735 pos.x2 = t.x2 = trapezoid->x21;
1736 b.y = trapezoid->y2;
1737 b.x1 = trapezoid->x12;
1738 b.x2 = trapezoid->x22;
1743 double y_next, x1_next, x2_next;
1746 /* The algorithm here is written to emphasize simplicity and
1747 * numerical stability as opposed to speed.
1749 * While the end result is slicing up the polygon vertically,
1750 * conceptually we aren't walking in the X direction, rather we
1751 * are walking along the edges. When we compute crossing of
1752 * horizontal pixel boundaries, we use the X coordinate as the
1753 * interpolating variable, when we compute crossing for vertical
1754 * pixel boundaries, we use the Y coordinate.
1756 * This allows us to handle almost exactly horizontal edges without
1757 * running into difficulties. (Almost exactly horizontal edges
1758 * come up frequently due to inexactness in computing, say,
1759 * a 90 degree rotation transformation)
1765 /* Check for crossing vertical pixel boundaries */
1766 y_next = floor (pos.y) + 1;
1767 if (y_next < pos_next.y)
1769 interpolate_position (&pos_next, &t, &b,
1771 pos_next.y = y_next;
1775 /* Check left side for crossing horizontal pixel boundaries */
1776 ix1 = floor (pos.x1);
1785 if (x1_next > pos_next.x1)
1787 interpolate_position (&pos_next, &t, &b,
1788 x1_next, t.x1, b.x1);
1789 pos_next.x1 = x1_next;
1793 else if (b.x1 > t.x1)
1797 if (x1_next < pos_next.x1)
1799 interpolate_position (&pos_next, &t, &b,
1800 x1_next, t.x1, b.x1);
1801 pos_next.x1 = x1_next;
1806 /* Check right side for crossing horizontal pixel boundaries */
1807 ix2 = floor (pos.x2);
1816 if (x2_next > pos_next.x2)
1818 interpolate_position (&pos_next, &t, &b,
1819 x2_next, t.x2, b.x2);
1820 pos_next.x2 = x2_next;
1824 else if (trapezoid->x22 > trapezoid->x21)
1828 if (x2_next < pos_next.x2)
1830 interpolate_position (&pos_next, &t, &b,
1831 x2_next, t.x2, b.x2);
1832 pos_next.x2 = x2_next;
1837 draw_simple_trap (pixbuf, pixbuf_x, pixbuf_y, &pos, &pos_next);
1843 gdk_drawable_real_draw_trapezoids (GdkDrawable *drawable,
1845 GdkTrapezoid *trapezoids,
1849 double min_x, max_x, min_y, max_y;
1850 int x, y, width, height;
1854 if (n_trapezoids == 0)
1857 /* compute bounding box */
1859 min_x = max_x = trapezoids[0].x11;
1860 min_y = max_y = trapezoids[0].y1;
1862 for (i = 0; i < n_trapezoids; i++)
1864 if (trapezoids[i].x11 < min_x) min_x = trapezoids[i].x11;
1865 if (trapezoids[i].x21 > max_x) max_x = trapezoids[i].x21;
1866 if (trapezoids[i].x12 < min_x) min_x = trapezoids[i].x12;
1867 if (trapezoids[i].x22 > max_x) max_x = trapezoids[i].x22;
1868 if (trapezoids[i].y1 < min_y) min_y = trapezoids[i].y1;
1869 if (trapezoids[i].y2 > max_y) max_y = trapezoids[i].y2;
1872 /* allocate temporary pixbuf */
1875 width = ceil (max_x) - x;
1877 height = ceil (max_y) - y;
1879 if (width == 0 || height == 0)
1882 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1886 /* Fill the pixbuf with the foreground color and alpha 0 */
1888 _gdk_windowing_gc_get_foreground (gc, &color);
1889 gdk_pixbuf_fill (pixbuf,
1890 (((color.red & 0xff00) << 16) |
1891 ((color.green & 0xff00) << 8) |
1892 ((color.blue & 0xff00))));
1894 /* draw the trapezoids into the alpha channel */
1896 for (i = 0; i < n_trapezoids; i++)
1897 draw_trapezoid (pixbuf, x, y, &trapezoids[i]);
1899 /* composite that onto the drawable */
1901 gdk_draw_pixbuf (drawable, gc, pixbuf,
1902 0, 0, x, y, width, height,
1903 GDK_RGB_DITHER_NORMAL, 0, 0);
1905 g_object_unref (pixbuf);
1908 /************************************************************************/
1911 * _gdk_drawable_get_scratch_gc:
1912 * @drawable: A #GdkDrawable
1913 * @graphics_exposures: Whether the returned #GdkGC should generate graphics exposures
1915 * Returns a #GdkGC suitable for drawing on @drawable. The #GdkGC has
1916 * the standard values for @drawable, except for the graphics_exposures
1917 * field which is determined by the @graphics_exposures parameter.
1919 * The foreground color of the returned #GdkGC is undefined. The #GdkGC
1920 * must not be altered in any way, except to change its foreground color.
1922 * Return value: A #GdkGC suitable for drawing on @drawable
1927 _gdk_drawable_get_scratch_gc (GdkDrawable *drawable,
1928 gboolean graphics_exposures)
1933 g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
1935 screen = gdk_drawable_get_screen (drawable);
1937 g_return_val_if_fail (!screen->closed, NULL);
1939 depth = gdk_drawable_get_depth (drawable) - 1;
1941 if (graphics_exposures)
1943 if (!screen->exposure_gcs[depth])
1946 GdkGCValuesMask mask;
1948 values.graphics_exposures = TRUE;
1949 mask = GDK_GC_EXPOSURES;
1951 screen->exposure_gcs[depth] =
1952 gdk_gc_new_with_values (drawable, &values, mask);
1955 return screen->exposure_gcs[depth];
1959 if (!screen->normal_gcs[depth])
1961 screen->normal_gcs[depth] =
1962 gdk_gc_new (drawable);
1965 return screen->normal_gcs[depth];