From 7b53a73b0fb4d98a08a340df3f7e5cff95b4c0c5 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 20 Aug 2010 12:02:31 +0200 Subject: [PATCH] Add a function for drawing a cairo surface Signed-off-by: Uli Schlachter --- draw.c | 19 +++++++++++++++++++ draw.h | 1 + 2 files changed, 20 insertions(+) diff --git a/draw.c b/draw.c index 565aeafcb..46a268c49 100644 --- a/draw.c +++ b/draw.c @@ -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 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. * \param ctx Draw context to draw with. * \param src Drawable to draw from. diff --git a/draw.h b/draw.h index 3993f8b67..c90e47024 100644 --- a/draw.h +++ b/draw.h @@ -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_rectangle(draw_context_t *, area_t, float, bool, const color_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); area_t draw_text_extents(draw_text_context_t *); alignment_t draw_align_fromstr(const char *);