int main() { /********************************** * 1 - Criar papel e caneta cairo * **********************************/ Drawer * cairo = DrawerInit(800, 600, 0, "result.pdf"); /**************** * 2 - Desenhar * ****************/ Rectangle base = {0, //x 0, //y 800, //width 600, //height 0.0, // borderWidth {1.0, 1.0, 1.0, 1.0},// Color Bg {0.0, 0.0, 0.0, 0.0}// Color border (borderless) }; DrawerDrawRectangle(cairo, base); /*cairo_rectangle (cairo->context, 0, 0, 800, 600); cairo_set_source_rgb(cairo->context, 1.0, 1.0, 1.0); cairo_fill(cairo->context);*/ Rectangle rect = {400-100, //x - altura/2 300-100, //y - largura/2 200, //width 200, //height 10.0, // borderWidth {1.0, 1.0, 1.0, 1.0}, // Color Bg {0.0, 0.0, 1.0, 1.0} // Color border }; DrawerDrawRectangle(cairo, rect); /*cairo_rectangle (cairo->context, 400 - 50, 300 - 50, 100, 100); cairo_set_source_rgb(cairo->context, 1.0, 0.0, 0.0); cairo_fill_preserve(cairo->context); cairo_set_source_rgba(cairo->context, 1.0, 1.0, 0.0, 1.0); cairo_stroke(cairo->context);*/ /*cairo_set_source_rgb(cairo->context, 0.0, 0.0, 0.0); cairo_arc (cairo->context, 400, 300, 2, 0, 2* M_PI); cairo_fill(cairo->context);*/ Arc arc = {400, //x 300, //y 0, //initAngle 1*2*M_PI, //endAngle 50, //radius 5.0, // borderWidth {1.0, 0.0, 1.0, 1.0}, // Color Bg {0.5, 1.0, 1.0, 1.0} // Color border }; DrawerDrawArc(cairo, arc); /************************* * 3 - Salvar em arquivo * *************************/ cairo_surface_write_to_png(cairo->surface, "test.png"); /****************************** * 4 - Deletar caneta e papel * ******************************/ DrawerDestroy(cairo); cairo = 0; return 0; }
void pizza(Drawer * drawer, Chart * chart, Rectangle base) { Color rcolor; float initAngle = 0.0; int i; char str[20] = ""; for(i = 0; chart->content[i] != 0; ++i) { float perc = chart->content[i]->percentage; randColor(&rcolor);//Função que randomiza os números responsáveis pelas cores percToText(perc*100,str);//Função que transforma a porcentagem em string Arc arc = { base.width/3, //x base.height/2, //y initAngle, //initAngle perc*2*M_PI+initAngle, //endAngle 200, //radius 0.5, // borderWidth {rcolor.r, rcolor.g, rcolor.b, 1.0}, // Color Bg {1.0,1.0,1.0, 1.0} // Color border }; Rectangle rectPerc = { 2*base.width/3, //x 4*base.height/10 + 35*i, //y 60,//width 30, //height 1.0, // borderWidth {rcolor.r, rcolor.g, rcolor.b, 1.0}, // Color Bg {1.0,1.0,1.0, 1.0}// Color border }; Text text = { 2*rectPerc.height/3,//Font Size 3*base.width/4 ,//X 4*base.height/10 + rectPerc.height/2,//Y chart->content[i]->label ,//Label str,//Percentage(String Form) 1.4,//BorderWidth rectPerc.y - 4*base.height/10,//Space Legend -5,//Space Percentage 2*base.width/3 + rectPerc.width/4,//Coordenada X da porcentagem 4*base.height/10 + rectPerc.height/2,//Coordenada Y da porcentagem 0,//Se 1 = Retangulo 1,//Se 1 = Arco {0.0,0.0,0.0,1.0},//Color Bg {rcolor.r, rcolor.g, rcolor.b, 1.0},//Color Border {1.0,1.0,1.0,1.0}//Color of Percentage }; DrawerDrawRectangle(drawer, rectPerc); if(perc == 1.0) {//Se o gráfico de pizza tiver somente um parâmetro (100%), excluir a borda arc.border.a = 0.0; } DrawerDrawArc(drawer, arc); DrawerDrawText(drawer, text, base); initAngle += chart->content[i]->percentage*2*M_PI; } }