From 38d4552bd9ceabab4e4005c7b1938fcb0defe76c Mon Sep 17 00:00:00 2001 From: Raphael Boucherie <raphael.boucherie@inria.fr> Date: Mon, 10 Apr 2017 10:22:58 +0200 Subject: [PATCH] added global array for color, corrected spelling mistake, removed useless library --- include/libdraw.h | 9 ++++++-- src/treedraw.c | 44 ++++++++++--------------------------- testings/testing_treedraw.c | 2 +- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/include/libdraw.h b/include/libdraw.h index 3425381..e245f75 100644 --- a/include/libdraw.h +++ b/include/libdraw.h @@ -9,12 +9,11 @@ * * @version 1.0.0 * @author Raphael Boucherie - * @author Matthieu Faverge + * @author Mathieu Faverge * @date 2017-04-04 * **/ -#include <stdio.h> #ifndef _LIBDRAW_H_ #define _LIBDRAW_H_ @@ -22,6 +21,12 @@ BEGIN_C_DECLS +/* + * Clobal array for color + */ + +extern char *color[4]; + /* * function for treedraw */ diff --git a/src/treedraw.c b/src/treedraw.c index 5ffa182..b714078 100644 --- a/src/treedraw.c +++ b/src/treedraw.c @@ -18,14 +18,20 @@ #include <stdio.h> #include "libdraw.h" +/* + * Global array for color + */ + +char *color[4] = {"red", "blue", "green", "purple"}; + /* * functions writing in the svg file */ void libhqr_writeheader(FILE *tree){ - if(fprintf(tree, "<?xml version=\"1.0\" standalone=\"no\"?>\n") < 0) return; - if(fprintf(tree, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n ") < 0) return; - if(fprintf(tree, "<svg width=\"2000\" height=\"2000\" version=\"1.1\" \n xmlns=\"http://www.w3.org/2000/svg\">\n") <0) return; + if(fprintf(tree, "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + "<svg width=\"2000\" height=\"2000\" version=\"1.1\" \n xmlns=\"http://www.w3.org/2000/svg\">\n") <0) return; } /* @@ -38,41 +44,13 @@ void libhqr_writeheader(FILE *tree){ */ void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *tree){ - switch (k % 4){ - case 0 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"red\" /> \n", x, y, w, h) < 0 ) return; - break; - case 1 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"blue\" /> \n", x, y, w, h) < 0 ) return; - break; - case 2 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"green\" /> \n", x, y, w, h) < 0 ) return; - break; - case 3 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"black\" /> \n", x, y, w, h) < 0 ) return; - break; - default: + if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, color[k%4]) < 0 ) return; - } } void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *tree){ - switch (k % 4){ - case 0 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"red\" /> \n", x, y, w, h) < 0 ) return; - break; - case 1 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"blue\" /> \n", x, y, w, h) < 0 ) return; - break; - case 2 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"green\" /> \n", x, y, w, h) < 0 ) return; - break; - case 3 : - if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"black\" /> \n", x, y, w, h) < 0 ) return; - break; - default: + if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, color[k%4]) < 0 ) return; - } int x2 = x + (w / 4); int y2 = y + (h / 4); int w2 = (w / 2); diff --git a/testings/testing_treedraw.c b/testings/testing_treedraw.c index f2fdd7b..773d23a 100644 --- a/testings/testing_treedraw.c +++ b/testings/testing_treedraw.c @@ -33,7 +33,7 @@ main(int argc, char ** argv) for (j = 1; j < 9; j++){ x = 100*i; y = 100*j; - libhqr_drawTS(x,y,WIDTH,HEIGHT,1,tree); + libhqr_drawTS(x,y,WIDTH,HEIGHT,3,tree); } } libhqr_writeend(tree); -- GitLab