#include "gdkpixbuf.h"
-static GdkImage* gdk_drawable_real_get_image (GdkDrawable *drawable,
- gint x,
- gint y,
- gint width,
- gint height);
static GdkDrawable* gdk_drawable_real_get_composite_drawable (GdkDrawable *drawable,
gint x,
gint y,
static void
gdk_drawable_class_init (GdkDrawableClass *klass)
{
- klass->get_image = gdk_drawable_real_get_image;
klass->get_composite_drawable = gdk_drawable_real_get_composite_drawable;
/* Default implementation for clip and visible region is the same */
klass->get_clip_region = gdk_drawable_real_get_visible_region;
/* Drawing
*/
-/**
- * gdk_draw_point:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @x: the x coordinate of the point.
- * @y: the y coordinate of the point.
- *
- * Draws a point, using the foreground color and other attributes of
- * the #GdkGC.
- **/
-void
-gdk_draw_point (GdkDrawable *drawable,
- GdkGC *gc,
- gint x,
- gint y)
-{
- GdkPoint point;
-
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- point.x = x;
- point.y = y;
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc, &point, 1);
-}
-
-/**
- * gdk_draw_line:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @x1_: the x coordinate of the start point.
- * @y1_: the y coordinate of the start point.
- * @x2_: the x coordinate of the end point.
- * @y2_: the y coordinate of the end point.
- *
- * Draws a line, using the foreground color and other attributes of
- * the #GdkGC.
- **/
-void
-gdk_draw_line (GdkDrawable *drawable,
- GdkGC *gc,
- gint x1,
- gint y1,
- gint x2,
- gint y2)
-{
- GdkSegment segment;
-
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- segment.x1 = x1;
- segment.y1 = y1;
- segment.x2 = x2;
- segment.y2 = y2;
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc, &segment, 1);
-}
-
-/**
- * gdk_draw_rectangle:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @filled: %TRUE if the rectangle should be filled.
- * @x: the x coordinate of the left edge of the rectangle.
- * @y: the y coordinate of the top edge of the rectangle.
- * @width: the width of the rectangle.
- * @height: the height of the rectangle.
- *
- * Draws a rectangular outline or filled rectangle, using the foreground color
- * and other attributes of the #GdkGC.
- *
- * A rectangle drawn filled is 1 pixel smaller in both dimensions than a
- * rectangle outlined. Calling
- * <literal>gdk_draw_rectangle (window, gc, TRUE, 0, 0, 20, 20)</literal>
- * results in a filled rectangle 20 pixels wide and 20 pixels high. Calling
- * <literal>gdk_draw_rectangle (window, gc, FALSE, 0, 0, 20, 20)</literal>
- * results in an outlined rectangle with corners at (0, 0), (0, 20), (20, 20),
- * and (20, 0), which makes it 21 pixels wide and 21 pixels high.
- **/
-void
-gdk_draw_rectangle (GdkDrawable *drawable,
- GdkGC *gc,
- gboolean filled,
- gint x,
- gint y,
- gint width,
- gint height)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- if (width < 0 || height < 0)
- {
- gint real_width;
- gint real_height;
-
- gdk_drawable_get_size (drawable, &real_width, &real_height);
-
- if (width < 0)
- width = real_width;
- if (height < 0)
- height = real_height;
- }
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_rectangle (drawable, gc, filled, x, y,
- width, height);
-}
-
-/**
- * gdk_draw_arc:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @filled: %TRUE if the arc should be filled, producing a 'pie slice'.
- * @x: the x coordinate of the left edge of the bounding rectangle.
- * @y: the y coordinate of the top edge of the bounding rectangle.
- * @width: the width of the bounding rectangle.
- * @height: the height of the bounding rectangle.
- * @angle1: the start angle of the arc, relative to the 3 o'clock position,
- * counter-clockwise, in 1/64ths of a degree.
- * @angle2: the end angle of the arc, relative to @angle1, in 1/64ths
- * of a degree.
- *
- * Draws an arc or a filled 'pie slice'. The arc is defined by the bounding
- * rectangle of the entire ellipse, and the start and end angles of the part
- * of the ellipse to be drawn.
- **/
-void
-gdk_draw_arc (GdkDrawable *drawable,
- GdkGC *gc,
- gboolean filled,
- gint x,
- gint y,
- gint width,
- gint height,
- gint angle1,
- gint angle2)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- if (width < 0 || height < 0)
- {
- gint real_width;
- gint real_height;
-
- gdk_drawable_get_size (drawable, &real_width, &real_height);
-
- if (width < 0)
- width = real_width;
- if (height < 0)
- height = real_height;
- }
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_arc (drawable, gc, filled,
- x, y, width, height, angle1, angle2);
-}
-
-/**
- * gdk_draw_polygon:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @filled: %TRUE if the polygon should be filled. The polygon is closed
- * automatically, connecting the last point to the first point if
- * necessary.
- * @points: an array of #GdkPoint structures specifying the points making
- * up the polygon.
- * @n_points: the number of points.
- *
- * Draws an outlined or filled polygon.
- **/
-void
-gdk_draw_polygon (GdkDrawable *drawable,
- GdkGC *gc,
- gboolean filled,
- const GdkPoint *points,
- gint n_points)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_polygon (drawable, gc, filled,
- (GdkPoint *) points,
- n_points);
-}
-
/**
* gdk_draw_drawable:
* @drawable: a #GdkDrawable
g_object_unref (composite);
}
-/**
- * gdk_draw_points:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @points: an array of #GdkPoint structures.
- * @n_points: the number of points to be drawn.
- *
- * Draws a number of points, using the foreground color and other
- * attributes of the #GdkGC.
- **/
-void
-gdk_draw_points (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkPoint *points,
- gint n_points)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail ((points != NULL) && (n_points > 0));
- g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (n_points >= 0);
-
- if (n_points == 0)
- return;
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_points (drawable, gc,
- (GdkPoint *) points, n_points);
-}
-
-/**
- * gdk_draw_segments:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @segs: an array of #GdkSegment structures specifying the start and
- * end points of the lines to be drawn.
- * @n_segs: the number of line segments to draw, i.e. the size of the
- * @segs array.
- *
- * Draws a number of unconnected lines.
- **/
-void
-gdk_draw_segments (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkSegment *segs,
- gint n_segs)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
-
- if (n_segs == 0)
- return;
-
- g_return_if_fail (segs != NULL);
- g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (n_segs >= 0);
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_segments (drawable, gc,
- (GdkSegment *) segs, n_segs);
-}
-
-/**
- * gdk_draw_lines:
- * @drawable: a #GdkDrawable (a #GdkWindow or a #GdkPixmap).
- * @gc: a #GdkGC.
- * @points: an array of #GdkPoint structures specifying the endpoints of the
- * @n_points: the size of the @points array.
- *
- * Draws a series of lines connecting the given points.
- * The way in which joins between lines are draw is determined by the
- * #GdkCapStyle value in the #GdkGC. This can be set with
- * gdk_gc_set_line_attributes().
- **/
-void
-gdk_draw_lines (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkPoint *points,
- gint n_points)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (points != NULL);
- g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (n_points >= 0);
-
- if (n_points == 0)
- return;
-
- GDK_DRAWABLE_GET_CLASS (drawable)->draw_lines (drawable, gc,
- (GdkPoint *) points, n_points);
-}
-
-static void
-real_draw_glyphs (GdkDrawable *drawable,
- GdkGC *gc,
- const PangoMatrix *matrix,
- PangoFont *font,
- gdouble x,
- gdouble y,
- PangoGlyphString *glyphs)
-{
- cairo_t *cr;
-
- cr = gdk_cairo_create (drawable);
- _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable);
-
- if (matrix)
- {
- cairo_matrix_t cairo_matrix;
-
- cairo_matrix.xx = matrix->xx;
- cairo_matrix.yx = matrix->yx;
- cairo_matrix.xy = matrix->xy;
- cairo_matrix.yy = matrix->yy;
- cairo_matrix.x0 = matrix->x0;
- cairo_matrix.y0 = matrix->y0;
-
- cairo_set_matrix (cr, &cairo_matrix);
- }
-
- cairo_move_to (cr, x, y);
- pango_cairo_show_glyph_string (cr, font, glyphs);
-
- cairo_destroy (cr);
-}
-
-/**
- * gdk_draw_glyphs:
- * @drawable: a #GdkDrawable
- * @gc: a #GdkGC
- * @font: font to be used
- * @x: X coordinate of baseline origin
- * @y: Y coordinate of baseline origin
- * @glyphs: the glyph string to draw
- *
- * This is a low-level function; 99% of text rendering should be done
- * using gdk_draw_layout() instead.
- *
- * A glyph is a single image in a font. This function draws a sequence of
- * glyphs. To obtain a sequence of glyphs you have to understand a
- * lot about internationalized text handling, which you don't want to
- * understand; thus, use gdk_draw_layout() instead of this function,
- * gdk_draw_layout() handles the details.
- *
- **/
-void
-gdk_draw_glyphs (GdkDrawable *drawable,
- GdkGC *gc,
- PangoFont *font,
- gint x,
- gint y,
- PangoGlyphString *glyphs)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- real_draw_glyphs (drawable, gc, NULL, font,
- x, y, glyphs);
-}
-
-/**
- * gdk_draw_glyphs_transformed:
- * @drawable: a #GdkDrawable
- * @gc: a #GdkGC
- * @matrix: (allow-none): a #PangoMatrix, or %NULL to use an identity transformation
- * @font: the font in which to draw the string
- * @x: the x position of the start of the string (in Pango
- * units in user space coordinates)
- * @y: the y position of the baseline (in Pango units
- * in user space coordinates)
- * @glyphs: the glyph string to draw
- *
- * Renders a #PangoGlyphString onto a drawable, possibly
- * transforming the layed-out coordinates through a transformation
- * matrix. Note that the transformation matrix for @font is not
- * changed, so to produce correct rendering results, the @font
- * must have been loaded using a #PangoContext with an identical
- * transformation matrix to that passed in to this function.
- *
- * See also gdk_draw_glyphs(), gdk_draw_layout().
- *
- * Since: 2.6
- **/
-void
-gdk_draw_glyphs_transformed (GdkDrawable *drawable,
- GdkGC *gc,
- const PangoMatrix *matrix,
- PangoFont *font,
- gint x,
- gint y,
- PangoGlyphString *glyphs)
-{
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
-
- real_draw_glyphs (drawable, gc, matrix, font,
- x / PANGO_SCALE, y / PANGO_SCALE, glyphs);
-}
-
-/**
- * gdk_draw_trapezoids:
- * @drawable: a #GdkDrawable
- * @gc: a #GdkGC
- * @trapezoids: an array of #GdkTrapezoid structures
- * @n_trapezoids: the number of trapezoids to draw
- *
- * Draws a set of anti-aliased trapezoids. The trapezoids are
- * combined using saturation addition, then drawn over the background
- * as a set. This is low level functionality used internally to implement
- * rotated underlines and backgrouds when rendering a PangoLayout and is
- * likely not useful for applications.
- *
- * Since: 2.6
- **/
-void
-gdk_draw_trapezoids (GdkDrawable *drawable,
- GdkGC *gc,
- const GdkTrapezoid *trapezoids,
- gint n_trapezoids)
-{
- cairo_t *cr;
- int i;
-
- g_return_if_fail (GDK_IS_DRAWABLE (drawable));
- g_return_if_fail (GDK_IS_GC (gc));
- g_return_if_fail (n_trapezoids == 0 || trapezoids != NULL);
-
- cr = gdk_cairo_create (drawable);
- _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable);
-
- for (i = 0; i < n_trapezoids; i++)
- {
- cairo_move_to (cr, trapezoids[i].x11, trapezoids[i].y1);
- cairo_line_to (cr, trapezoids[i].x21, trapezoids[i].y1);
- cairo_line_to (cr, trapezoids[i].x22, trapezoids[i].y2);
- cairo_line_to (cr, trapezoids[i].x12, trapezoids[i].y2);
- cairo_close_path (cr);
- }
-
- cairo_fill (cr);
-
- cairo_destroy (cr);
-}
-
-/**
- * gdk_drawable_copy_to_image:
- * @drawable: a #GdkDrawable
- * @image: (allow-none): a #GdkDrawable, or %NULL if a new @image should be created.
- * @src_x: x coordinate on @drawable
- * @src_y: y coordinate on @drawable
- * @dest_x: x coordinate within @image. Must be 0 if @image is %NULL
- * @dest_y: y coordinate within @image. Must be 0 if @image is %NULL
- * @width: width of region to get
- * @height: height or region to get
- *
- * Copies a portion of @drawable into the client side image structure
- * @image. If @image is %NULL, creates a new image of size @width x @height
- * and copies into that. See gdk_drawable_get_image() for further details.
- *
- * Return value: @image, or a new a #GdkImage containing the contents
- * of @drawable
- *
- * Since: 2.4
- **/
-GdkImage*
-gdk_drawable_copy_to_image (GdkDrawable *drawable,
- GdkImage *image,
- gint src_x,
- gint src_y,
- gint dest_x,
- gint dest_y,
- gint width,
- gint height)
-{
- GdkDrawable *composite;
- gint composite_x_offset = 0;
- gint composite_y_offset = 0;
- GdkImage *retval;
- GdkColormap *cmap;
-
- g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
- g_return_val_if_fail (src_x >= 0, NULL);
- g_return_val_if_fail (src_y >= 0, NULL);
-
- /* FIXME? Note race condition since we get the size then
- * get the image, and the size may have changed.
- */
-
- if (width < 0 || height < 0)
- gdk_drawable_get_size (drawable,
- width < 0 ? &width : NULL,
- height < 0 ? &height : NULL);
-
- composite =
- GDK_DRAWABLE_GET_CLASS (drawable)->get_composite_drawable (drawable,
- src_x, src_y,
- width, height,
- &composite_x_offset,
- &composite_y_offset);
-
- retval = GDK_DRAWABLE_GET_CLASS (composite)->_copy_to_image (composite,
- image,
- src_x - composite_x_offset,
- src_y - composite_y_offset,
- dest_x, dest_y,
- width, height);
-
- g_object_unref (composite);
-
- if (!image && retval)
- {
- cmap = gdk_drawable_get_colormap (drawable);
-
- if (cmap)
- gdk_image_set_colormap (retval, cmap);
- }
-
- return retval;
-}
-
-/**
- * gdk_drawable_get_image:
- * @drawable: a #GdkDrawable
- * @x: x coordinate on @drawable
- * @y: y coordinate on @drawable
- * @width: width of region to get
- * @height: height or region to get
- *
- * A #GdkImage stores client-side image data (pixels). In contrast,
- * #GdkPixmap and #GdkWindow are server-side
- * objects. gdk_drawable_get_image() obtains the pixels from a
- * server-side drawable as a client-side #GdkImage. The format of a
- * #GdkImage depends on the #GdkVisual of the current display, which
- * makes manipulating #GdkImage extremely difficult; therefore, in
- * most cases you should use gdk_pixbuf_get_from_drawable() instead of
- * this lower-level function. A #GdkPixbuf contains image data in a
- * canonicalized RGB format, rather than a display-dependent format.
- * Of course, there's a convenience vs. speed tradeoff here, so you'll
- * want to think about what makes sense for your application.
- *
- * @x, @y, @width, and @height define the region of @drawable to
- * obtain as an image.
- *
- * You would usually copy image data to the client side if you intend
- * to examine the values of individual pixels, for example to darken
- * an image or add a red tint. It would be prohibitively slow to
- * make a round-trip request to the windowing system for each pixel,
- * so instead you get all of them at once, modify them, then copy
- * them all back at once.
- *
- * If the X server or other windowing system backend is on the local
- * machine, this function may use shared memory to avoid copying
- * the image data.
- *
- * If the source drawable is a #GdkWindow and partially offscreen
- * or obscured, then the obscured portions of the returned image
- * will contain undefined data.
- *
- * Return value: a #GdkImage containing the contents of @drawable
- **/
-GdkImage*
-gdk_drawable_get_image (GdkDrawable *drawable,
- gint x,
- gint y,
- gint width,
- gint height)
-{
- GdkDrawable *composite;
- gint composite_x_offset = 0;
- gint composite_y_offset = 0;
- GdkImage *retval;
- GdkColormap *cmap;
-
- g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
- g_return_val_if_fail (x >= 0, NULL);
- g_return_val_if_fail (y >= 0, NULL);
-
- /* FIXME? Note race condition since we get the size then
- * get the image, and the size may have changed.
- */
-
- if (width < 0 || height < 0)
- gdk_drawable_get_size (drawable,
- width < 0 ? &width : NULL,
- height < 0 ? &height : NULL);
-
- composite =
- GDK_DRAWABLE_GET_CLASS (drawable)->get_composite_drawable (drawable,
- x, y,
- width, height,
- &composite_x_offset,
- &composite_y_offset);
-
- retval = GDK_DRAWABLE_GET_CLASS (composite)->get_image (composite,
- x - composite_x_offset,
- y - composite_y_offset,
- width, height);
-
- g_object_unref (composite);
-
- cmap = gdk_drawable_get_colormap (drawable);
-
- if (retval && cmap)
- gdk_image_set_colormap (retval, cmap);
-
- return retval;
-}
-
-static GdkImage*
-gdk_drawable_real_get_image (GdkDrawable *drawable,
- gint x,
- gint y,
- gint width,
- gint height)
-{
- return gdk_drawable_copy_to_image (drawable, NULL, x, y, 0, 0, width, height);
-}
-
static GdkDrawable *
gdk_drawable_real_get_composite_drawable (GdkDrawable *drawable,
gint x,