From c9b119217829f976a7830a0555650401cf9df2cb Mon Sep 17 00:00:00 2001 From: axtloss Date: Tue, 27 Feb 2024 01:44:26 +0100 Subject: add functionality to read from bvg file --- fbwarn/src/parseBVG.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) (limited to 'fbwarn/src/parseBVG.c') diff --git a/fbwarn/src/parseBVG.c b/fbwarn/src/parseBVG.c index b71b55f..4209383 100644 --- a/fbwarn/src/parseBVG.c +++ b/fbwarn/src/parseBVG.c @@ -29,8 +29,6 @@ void BVGDrawCircle(BVGCircle *circle) { if (circle->drawSector) { DrawCircleSector(center, circle->radius, circle->startAngle, circle->endAngle, circle->segments, circle->color); } else { - printf("center: %f, %f\n", center.x, center.y); - printf("radius: %f, color: %d\n", circle->radius, circle->color.a); DrawCircle(circle->centerX, circle->centerY, circle->radius, circle->color); } } @@ -40,6 +38,14 @@ void BVGDrawRing(BVGRing *ring) { DrawRing(center, ring->inRadius, ring->outRadius, ring->startAngle, ring->endAngle, ring->segmets, ring->color); } +void BVGDrawTriangle(BVGTriangle *triangle) { + if (triangle->fill) { + DrawTriangle(triangle->corner1, triangle->corner2, triangle->corner3, triangle->color); + } else { + DrawTriangleLines(triangle->corner1, triangle->corner2, triangle->corner3, triangle->color); + } +} + void BVGDrawText(BVGText *text) { DrawText(text->text, text->x, text->y, text->fontSize, text->color); } @@ -61,9 +67,11 @@ FILE *readFile(char *path) { char *multiToSingle(char *s) { // allocating the size of lines is safe since characters arent added char *midresult = malloc (strlen(s)+1); + char *notab = malloc(strlen(s)+1); char *line; midresult = replaceStr(s, "\n", ""); - return replaceStr(midresult, ", ", ","); + notab = replaceStr(midresult, "\t", ""); + return replaceStr(notab, ", ", ","); } /* @@ -85,7 +93,11 @@ void collectArgs(char *res[], char *call, int n) { the res array contains only the values of each argument */ void orderArgs(char *res[], char *argv[], int n, char *knownArgs[]) { + if (argv == NULL || knownArgs == NULL) + exit(1); for(int i=0; iwidth=width; result->height=height; + return result; +} + /* Creates a BVGRectangle based on a BVG function call */ @@ -137,7 +161,6 @@ BVGRectangle *BVGParseRectangle(char *argv[7]) { size_t argN = 7; char *args[argN]; char *knownArgs[7] = {"x", "y", "width", "height", "color", "fill", "thickness"}; - //printf("118 Parsing...%s \n", args[0]); orderArgs(args, argv, argN, knownArgs); printf("119 Parsing...%s \n", args[0]); int x, y, width, height, r, g, b, a; @@ -275,6 +298,34 @@ BVGRing *BVGParseRing(char *argv[8]) { return result; } +BVGTriangle *BVGParseTriangle(char *argv[8]) { + BVGTriangle *result = malloc(sizeof(BVGTriangle)); + size_t argN = 8; + char *args[argN]; + char *knownArgs[8] = {"x1", "y1", "x2", "y2", "x3", "y3", "fill", "color"}; + orderArgs(args, argv, argN, knownArgs); + int x1, x2, x3; + int y1, y2, y3; + bool fill; + Color *clr; + sscanf(args[0], "%d", &x1); + sscanf(args[1], "%d", &y1); + sscanf(args[2], "%d", &x2); + sscanf(args[3], "%d", &y2); + sscanf(args[4], "%d", &x3); + sscanf(args[5], "%d", &y3); + fill = parseBoolValue(args[6]); + args[7] = args[7]+2; + args[7][strlen(args[7])-1] = '\0'; + clr = parseColorFromHex(args[7]); + result->corner1 = (Vector2){x1, y1}; + result->corner2 = (Vector2){x2, y2}; + result->corner3 = (Vector2){x3, y3}; + result->fill = fill; + result->color = *clr; + return result; +} + BVGText *BVGParseText(char *argv[5]) { BVGText *result = malloc(sizeof(BVGText)); size_t argN = 5; @@ -347,6 +398,13 @@ void matchFunctionCall(char *call) { BVGRing *ring = malloc(sizeof(BVGRing)); ring = BVGParseRing(argv); BVGDrawRing(ring); + } else if (strcmp(function, "triangle") == 0) { + char *argv[8]; + call = call+strlen("triangle ("); + collectArgs(argv, call, 8); + BVGTriangle *triangle = malloc(sizeof(BVGTriangle)); + triangle = BVGParseTriangle(argv); + BVGDrawTriangle(triangle); } else if (strcmp(function, "text") == 0) { char *argv[5]; call = call+strlen("text ("); -- cgit v1.2.3