draw functions

This commit is contained in:
KikooDX 2021-11-18 01:07:06 +01:00
parent 3a2609f8e4
commit 738830d453
2 changed files with 73 additions and 2 deletions

View File

@ -1,5 +1,17 @@
#include "fe.h"
#include "raygint/display.h"
#include <stdio.h>
#include <stdlib.h>
static fe_Object *f_dbegin(fe_Context *ctx, fe_Object *arg);
static fe_Object *f_dend(fe_Context *ctx, fe_Object *arg);
static fe_Object *f_dcolor(fe_Context *ctx, fe_Object *arg);
static fe_Object *f_dclear(fe_Context *ctx, fe_Object *arg);
static fe_Object *f_drect(fe_Context *ctx, fe_Object *arg);
static int r = 0;
static int g = 0;
static int b = 0;
int
main(void)
@ -10,6 +22,14 @@ main(void)
#ifdef RAYLIB
FILE *fp = fopen("test.fe", "rb");
int gc = fe_savegc(ctx);
rDisplayInit();
SetTargetFPS(30);
fe_set(ctx, fe_symbol(ctx, "dbegin"), fe_cfunc(ctx, f_dbegin));
fe_set(ctx, fe_symbol(ctx, "dend"), fe_cfunc(ctx, f_dend));
fe_set(ctx, fe_symbol(ctx, "dcolor"), fe_cfunc(ctx, f_dcolor));
fe_set(ctx, fe_symbol(ctx, "dclear"), fe_cfunc(ctx, f_dclear));
fe_set(ctx, fe_symbol(ctx, "drect"), fe_cfunc(ctx, f_drect));
for (;;) {
fe_Object *obj = fe_readfp(ctx, fp);
@ -26,9 +46,51 @@ main(void)
fe_restoregc(ctx, gc);
}
rDisplayDeinit();
fclose(fp);
#endif
fe_close(ctx);
free(data);
return 0;
}
static fe_Object *
f_dbegin(fe_Context *ctx, fe_Object *arg)
{
rDrawBegin();
return NULL;
}
static fe_Object *
f_dend(fe_Context *ctx, fe_Object *arg)
{
rDrawEnd();
return NULL;
}
static fe_Object *
f_dcolor(fe_Context *ctx, fe_Object *arg)
{
r = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
g = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
b = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
return NULL;
}
static fe_Object *
f_dclear(fe_Context *ctx, fe_Object *arg)
{
dclear(C_RGB(r, g, b));
return NULL;
}
static fe_Object *
f_drect(fe_Context *ctx, fe_Object *arg)
{
const int x = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
const int y = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
const int w = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
const int h = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
drect(x, y, x + w - 1, y + h - 1, C_RGB(r, g, b));
return NULL;
}

13
test.fe
View File

@ -1,2 +1,11 @@
(= x 2) (= y 3)
(print "hello world" (+ y (* x x)))
(= x 0) (= y 0)
(while (< y 224)
(= x (+ x 1))
(= y (+ y 1))
(dbegin)
(dcolor 0 0 0)
(dclear)
(dcolor 31 31 31)
(drect x y 16 16)
(dend)
)