aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--fbwarn/.gitignore30
-rw-r--r--fbwarn/rectangle.bvg47
-rw-r--r--fbwarn/src/BVGTypes.h8
-rw-r--r--fbwarn/src/Makefile.am2
-rw-r--r--fbwarn/src/extString.c15
-rw-r--r--fbwarn/src/extString.h1
-rw-r--r--fbwarn/src/parseBVG.c78
-rw-r--r--fbwarn/src/parseBVG.h10
-rw-r--r--fbwarn/src/warn.c16
9 files changed, 179 insertions, 28 deletions
diff --git a/fbwarn/.gitignore b/fbwarn/.gitignore
new file mode 100644
index 0000000..be38d20
--- /dev/null
+++ b/fbwarn/.gitignore
@@ -0,0 +1,30 @@
+autom4te.cache
+configure
+ltmain.sh
+m4/
+missing
+stamp-h1
+configure~
+config.h
+config.h.in
+config.h.in~
+config.log
+Makefile
+Makefile.in
+aclocal.m4
+ar-lib
+compile
+config.guess
+config.status
+config.sub
+configure.scan
+depcomp
+install-sh
+libtool
+src/Makefile
+src/Makefile.in
+src/fbwarn
+src/.deps
+*~
+*/*~
+*.o
diff --git a/fbwarn/rectangle.bvg b/fbwarn/rectangle.bvg
new file mode 100644
index 0000000..a1effbd
--- /dev/null
+++ b/fbwarn/rectangle.bvg
@@ -0,0 +1,47 @@
+// Single line comments are started with //
+
+/*
+A multiline comment can be
+done in this fashion
+basically like C
+*/
+
+
+// The IMG function is always required
+// it initializes the image with its size
+IMG (size=100, width=100)
+
+// A function call can be split across multiple lines
+
+// The viewport function defines the view of an image
+// it functions like the svg viewport function
+viewport (x=0,
+ y=0,
+ height=100,
+ width=100)
+
+// A rectangle
+rectangle (x=0, y=0,
+ height=100,
+ width=100,
+ color="#5BCEFA",
+ fill=true,
+ thickness=0)
+
+rectangle (x=20, y=0,
+ height=60,
+ width=100,
+ color="#F5A9B8",
+ fill=true,
+ thickness=0)
+
+rectangle (x=40, y=0,
+ height=20
+ width=100,
+ color="#FFFFFF",
+ fill=true,
+ thickness=0)
+/*
+ A bvg file is parsed from top to bottom
+ This means that the lowest element gets drawn over existing elements
+*/ \ No newline at end of file
diff --git a/fbwarn/src/BVGTypes.h b/fbwarn/src/BVGTypes.h
new file mode 100644
index 0000000..1ed1919
--- /dev/null
+++ b/fbwarn/src/BVGTypes.h
@@ -0,0 +1,8 @@
+#include <raylib.h>
+#include <stdbool.h>
+typedef struct BVGRectangle {
+ Rectangle rayrectangle;
+ Color color;
+ bool fill;
+ float lineThickness;
+} BVGRectangle;
diff --git a/fbwarn/src/Makefile.am b/fbwarn/src/Makefile.am
index 15711b4..aed12bd 100644
--- a/fbwarn/src/Makefile.am
+++ b/fbwarn/src/Makefile.am
@@ -1,3 +1,3 @@
bin_PROGRAMS = fbwarn
-fbwarn_SOURCES = warn.c parseBVG.c
+fbwarn_SOURCES = warn.c parseBVG.c extString.c parseBVG.h extString.h BVGTypes.h
AM_LDFLAGS = -lraylib
diff --git a/fbwarn/src/extString.c b/fbwarn/src/extString.c
new file mode 100644
index 0000000..c93cffd
--- /dev/null
+++ b/fbwarn/src/extString.c
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+char *strlwr(char *str)
+{
+ unsigned char *p = (unsigned char *)str;
+
+ while (*p) {
+ *p = tolower((unsigned char)*p);
+ p++;
+ }
+
+ return str;
+}
diff --git a/fbwarn/src/extString.h b/fbwarn/src/extString.h
new file mode 100644
index 0000000..06d2b49
--- /dev/null
+++ b/fbwarn/src/extString.h
@@ -0,0 +1 @@
+char *strlwr(char*);
diff --git a/fbwarn/src/parseBVG.c b/fbwarn/src/parseBVG.c
index ff8b248..ead9c83 100644
--- a/fbwarn/src/parseBVG.c
+++ b/fbwarn/src/parseBVG.c
@@ -1,7 +1,19 @@
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include "BVGTypes.h"
#include "raylib.h"
+#include "extString.h"
+
+void BVGDrawRectangle(BVGRectangle *rectangle) {
+ if (rectangle->fill) {
+ DrawRectangleRec(rectangle->rayrectangle, rectangle->color);
+ } else {
+ DrawRectangleLinesEx(rectangle->rayrectangle, rectangle->lineThickness, rectangle->color);
+ }
+ return;
+}
// reads a given file
FILE *readFile(char *path) {
@@ -28,41 +40,73 @@ char *multiToSingle(char *lines) {
return result;
}
-void BVGRectangle(char *argv[5]) {
- printf("Drawing rectangle\n");
- argv[4][strlen(argv[4])-2] = '\0';
- printf("%s, %s\n %s, %s,\n %s\n", argv[0], argv[1], argv[2], argv[3], argv[4]);
- int x, y, width, height, r, g, b;
+/*
+ Converts a given char pointer to a corresponding boolean value
+ expects the char to only contain true/false without any whitespace or similiar
+ case is ignored
+ If no match is found, true is returned by default
+*/
+bool parseBoolValue(char *value) {
+ char *valueLower = strdup(strlwr(value));
+ printf("Matching bool %s --- %s", valueLower, value);
+ if (strcmp(valueLower, "false") == 0) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+BVGRectangle *BVGParseRectangle(char *argv[7]) {
+ BVGRectangle *result = malloc(sizeof(BVGRectangle));
+ Rectangle *rectangle = malloc(sizeof(Rectangle));
+ argv[4][strlen(argv[4])-1] = '\0';
+ argv[4] = argv[4]+strlen("color=#'");
+ int x, y, width, height, r, g, b, a;
+ float thickness = 1.0;
+ Color *clr = malloc(sizeof(Color));
sscanf(argv[0]+strlen("x="), "%d", &x);
sscanf(argv[1]+strlen("y="), "%d", &y);
sscanf(argv[2]+strlen("width="), "%d", &width);
sscanf(argv[3]+strlen("height="), "%d", &height);
- sscanf(argv[4]+strlen("color='#"), "%02x%02x%02x", &r, &g, &b);
+ if (strlen(argv[4]) == 6) {
+ sscanf(argv[4], "%02x%02x%02x", &r, &g, &b);
+ clr->r=r; clr->g=g; clr->b=b; clr->a=255;
+ } else {
+ sscanf(argv[4], "%02x%02x%02x%02x", &r, &g, &b, &a);
+ clr->r=r; clr->g=g; clr->b=b; clr->a=a;
+ }
+ sscanf(argv[6]+strlen("thickness="), "%fd", &thickness);
printf("X: %d, Y: %d\n", x, y);
printf("Width: %d, Height: %d\n", width, height);
printf("Color: %d, %d, %d\n", r, g, b);
- Color *clr = malloc(sizeof(Color));
- clr->r=r;
- clr->g=g;
- clr->b=b;
- clr->a=255;
- DrawRectangle(x, y, width, height, *clr);
- return;
+ printf("Fill: %d, Thickness: %f\n", parseBoolValue(argv[5]+strlen("fill=")), thickness);
+
+ rectangle->x=x; rectangle->y=y;
+ rectangle->height=height; rectangle->width=width;
+ result->rayrectangle=*rectangle;
+
+ result->color=*clr;
+ result->fill=parseBoolValue(argv[5]+strlen("fill="));
+ result->lineThickness=thickness;
+
+ return result;
}
-void matchFunctionCall(char *call) {
+void matchFunctionCall(char *call, void *ret) {
printf("Matching %s\n", call);
char *funcCall = strdup(call);
char *funcName = strsep(&funcCall, "(");
printf("Got function %s\n", funcName);
if (strcmp(funcName, "rectangle ") == 0) {
- char **arg, *argv[5];
+ char **arg, *argv[7];
call = call+strlen("rectangle (");
for (arg = argv; (*arg = strsep(&call, ",")) != NULL;)
if (**arg != '\0')
- if (++arg >= &argv[5])
+ if (++arg >= &argv[7])
break;
- BVGRectangle(argv);
+ BVGRectangle *rect = malloc(sizeof(BVGRectangle));
+ rect = BVGParseRectangle(argv);
+ BVGDrawRectangle(rect);
}
return;
}
diff --git a/fbwarn/src/parseBVG.h b/fbwarn/src/parseBVG.h
index 87cf4a4..ed9b874 100644
--- a/fbwarn/src/parseBVG.h
+++ b/fbwarn/src/parseBVG.h
@@ -1,4 +1,10 @@
#include <stdio.h>
-FILE readFile(char*);
+#include <stdlib.h>
+#include "raylib.h"
+#include "BVGTypes.h"
+
+void BVGDrawRectangle(BVGRectangle*);
+FILE *readFile(char*);
char *multiToSingle(char*);
-void matchFunctionCall(char*);
+void matchFunctionCall(char *);
+BVGRectangle *BVGParseRectangle(char*[7]);
diff --git a/fbwarn/src/warn.c b/fbwarn/src/warn.c
index 1f946cc..1589e48 100644
--- a/fbwarn/src/warn.c
+++ b/fbwarn/src/warn.c
@@ -6,39 +6,39 @@
int main(void) {
char *rectA, *rectB, *rectC, *rectAFree, *rectBFree, *rectCFree, *singleA, *singleB, *singleC;
- rectAFree = rectA = strdup("rectangle (x=0,y=0,\nwidth=100,\nheight=100,\ncolor='#5BCEFA')\n");
+ rectAFree = rectA = strdup("rectangle (x=0,y=0,\nwidth=100,\nheight=100,\ncolor='#9787CFFF',\nfill=true,\nthickness=1.0)\n");
if (rectA == NULL)
return 1;
singleA = multiToSingle(rectA);
free(rectAFree);
- rectBFree = rectB = strdup("rectangle (x=0,y=20,\nwidth=100,\nheight=60,\ncolor='#F5A9B8')\n");
+ rectBFree = rectB = strdup("rectangle (x=0,y=20,\nwidth=100,\nheight=60,\ncolor='#88C2B1FF',\nfill=false,\nthickness=5.0)\n");
if (rectB == NULL)
return 1;
singleB = multiToSingle(rectB);
free(rectBFree);
- rectCFree = rectC = strdup("rectangle (x=0,y=40,\nwidth=100,\nheight=20,\ncolor='#FFFFFF')\n");
+ rectCFree = rectC = strdup("rectangle (x=0,y=40,\nwidth=100,\nheight=20,\ncolor='#BE79A7FF',\nfill=true,\nthickness=3.0)\n");
if (rectC == NULL)
return 1;
singleC = multiToSingle(rectC);
free(rectCFree);
-
+
InitWindow (100, 100, ":3");
while (!WindowShouldClose ()) {
+
BeginDrawing ();
ClearBackground (RAYWHITE);
-
char *parseA = strdup(singleA);
matchFunctionCall(parseA);
-
+
char *parseB = strdup(singleB);
matchFunctionCall(parseB);
-
+
char *parseC = strdup(singleC);
matchFunctionCall(parseC);
- DrawText ("tranmsgenmer", 15, 50, 10, MAROON);
+
EndDrawing ();
}