cairo graphics 0.9 intersection II



/* Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */
// module do_draw

//do_draw will be executed in a separate thread whenever we would like to update
//our animation
void *do_draw(void *ptr){

currently_drawing = 1;

int width, height;
gdk_threads_enter();
gdk_drawable_get_size(pixmap, &width, &height);
gdk_threads_leave();

//create a gtk-independant surface to draw on
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);

//Vertical Line
cairo_move_to(cr, 200,30);
cairo_line_to(cr,200,200);

//Horizontal Line
cairo_move_to(cr, 50,120);
cairo_line_to(cr,350,120);

//do some time-consuming drawing
static int i = 0;
++i; i = i % 300; //give a little movement to our animation
cairo_set_source_rgb (cr, .9, .9, .9);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 50,50);
int j,k;
/* for(k=0; k<100; ++k){*/ //lets just redraw lots of times to use a lot of proc power
for(j=0; j < 100; j++){
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 100,76);
/* cairo_line_to(cr,200+i,100);*/
/* cairo_arc(cr,300+i,100,4,0, 2*M_PI);*/
/* cairo_arc(cr,70+i,100,40,0,2*M_PI);*/
if ( i < 100)
cairo_arc(cr, 100+i,76,0,0,0);
/* cairo_rectangle(cr,50+i,50+i,50,50); */

cairo_stroke(cr);
}
/* }*/
cairo_destroy(cr);
//When dealing with gdkPixmap's, we need to make sure not to
//access them from outside gtk_main().
gdk_threads_enter();

cairo_t *cr_pixmap = gdk_cairo_create(pixmap);
cairo_set_source_surface (cr_pixmap, cst, 0, 0);
cairo_paint(cr_pixmap);
cairo_destroy(cr_pixmap);

gdk_threads_leave();

cairo_surface_destroy(cst);

currently_drawing = 0;

return NULL;
}