Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cairo.h>
- int main (int argc, char *argv[])
- {
- float alpha=0.65;
- float alpha_circle=0.8;
- cairo_surface_t *surface;
- cairo_t* cr;
- surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 480, 270);
- cr=cairo_create(surface);
- // Draw Circle
- cairo_save(cr);
- cairo_set_source_rgba(cr, 1.0, 0.5, 0.5, 1.0);
- cairo_move_to(cr, 140.0+70.0, 117.0);
- cairo_arc(cr, 140.0, 117.0, 70.0, 0.0, 2*3.14159);
- cairo_clip(cr);
- cairo_paint_with_alpha(cr, alpha_circle);
- cairo_restore(cr);
- //Prepare rectangle
- cairo_save(cr);
- cairo_set_source_rgba(cr, 0.26, 1.0, 1.0, 1.0);
- cairo_rectangle(cr, 164.0, 114.0, 186.0, 103.0);
- cairo_clip(cr);
- // this section of code performs the following operator:
- // aR = aA*alpha + (1-alpha)*aB
- // xR = (xaA*alpha + (1-alpha)*xaB)/xR
- // When alpha =0.0 aR = aB and xR = xB
- // When alpha =1.0 aR = aA and xR = xA
- {
- cairo_save(cr);
- cairo_surface_t* dest=cairo_get_target(cr);
- cairo_surface_flush(dest);
- cairo_surface_t* destimage=cairo_surface_map_to_image(dest, NULL);
- int w=cairo_image_surface_get_width(destimage);
- int h=cairo_image_surface_get_height(destimage);
- cairo_surface_t* newdest=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
- cairo_t* destcr=cairo_create(newdest);
- cairo_set_source_surface(destcr, destimage, 0, 0);
- cairo_paint_with_alpha(destcr, 1.0-alpha);
- cairo_destroy(destcr);
- destcr=cairo_create(destimage);
- cairo_set_source_surface(destcr, newdest, 0, 0);
- cairo_set_operator(destcr, CAIRO_OPERATOR_SOURCE);
- cairo_paint(destcr);
- cairo_destroy(destcr);
- cairo_surface_unmap_image(dest, destimage);
- cairo_surface_mark_dirty(dest);
- cairo_surface_destroy(newdest);
- cairo_restore(cr);
- }
- //
- // Effectively draw the retangle
- cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
- cairo_paint_with_alpha(cr, alpha);
- cairo_restore(cr);
- cairo_destroy(cr);
- cairo_surface_write_to_png(surface, "straight-cairo-full.png");
- cairo_surface_destroy(surface);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement