Add a function for drawing a cairo surface

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-08-20 12:02:31 +02:00
parent c3e0f72c56
commit 7b53a73b0f
2 changed files with 20 additions and 0 deletions

19
draw.c
View File

@ -283,6 +283,25 @@ draw_image(draw_context_t *ctx, int x, int y, double ratio, image_t *image)
draw_image_from_argb_data(ctx, x, y, image_getwidth(image), image_getheight(image), ratio, image_getdata(image)); draw_image_from_argb_data(ctx, x, y, image_getwidth(image), image_getheight(image), ratio, image_getdata(image));
} }
/** Draw an image to a draw context.
* \param ctx Draw context to draw to.
* \param x X coordinate.
* \param y Y coordinate.
* \param ratio The ratio to apply to the image.
* \param source The image to draw.
*/
void
draw_surface(draw_context_t *ctx, int x, int y,
double ratio, cairo_surface_t *source)
{
cairo_t *cr = cairo_create(ctx->surface);
cairo_scale(cr, ratio, ratio);
cairo_set_source_surface(cr, source, x / ratio, y / ratio);
cairo_paint(cr);
cairo_destroy(cr);
}
/** Rotate a pixmap. /** Rotate a pixmap.
* \param ctx Draw context to draw with. * \param ctx Draw context to draw with.
* \param src Drawable to draw from. * \param src Drawable to draw from.

1
draw.h
View File

@ -130,6 +130,7 @@ bool draw_text_context_init(draw_text_context_t *, const char *, ssize_t);
void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, alignment_t, area_t); void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, alignment_t, area_t);
void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *); void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *);
void draw_image(draw_context_t *, int, int, double, image_t *); void draw_image(draw_context_t *, int, int, double, image_t *);
void draw_surface(draw_context_t *, int, int, double, cairo_surface_t *);
void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int); void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
area_t draw_text_extents(draw_text_context_t *); area_t draw_text_extents(draw_text_context_t *);
alignment_t draw_align_fromstr(const char *); alignment_t draw_align_fromstr(const char *);