kuro/opcodes.c

66 lines
2.1 KiB
C
Raw Permalink Normal View History

2024-02-02 05:57:26 +00:00
#include "dat.h"
#include "fns.h"
#include "theme.h"
static Handler handlers[TOTAL_OPCODES];
static Font* f;
static char testbytes[256] = "test data ya heard";
static Rune testdata[256];
void set_handler(Opcode o, Handler h) {
handlers[o] = h;
}
2024-02-13 05:24:15 +00:00
static void window_redraw(Node* self) {
short fheight = self->memory->editorState[0]->frame->font->height;
/* TODO: tagrect's height should be multiplied by the numer of lines in the tag */
Rectangle tagrect = Rect(0,0,self->memory->img->r.max.x,fheight);
Rectangle bodyrect = Rect(0,fheight,self->memory->img->r.max.x,self->memory->img->r.max.y);
draw(self->memory->img, tagrect, tagcols[BACK], nil, tagrect.min);
draw(self->memory->img, bodyrect, textcols[BACK], nil, bodyrect.min);
}
2024-02-02 05:57:26 +00:00
static void handle_init(void* node, void* data) {
Node* self = (Node*)node;
SubFrame* tag = (SubFrame*)malloc(sizeof(SubFrame));
SubFrame* body = (SubFrame*)malloc(sizeof(SubFrame));
SubFrame* shell = (SubFrame*)malloc(sizeof(SubFrame));
tag->frame = (Frame*)malloc(sizeof(Frame));
body->frame = (Frame*)malloc(sizeof(Frame));
shell->frame = (Frame*)malloc(sizeof(Frame));
self->memory->editorState[TAGF] = tag;
self->memory->editorState[BODYF] = body;
self->memory->editorState[SHELLF] = shell;
Rectangle r = Rect(self->memory->img->r.min.x,self->memory->img->r.min.y,self->memory->img->r.max.x, self->memory->img->r.min.y + 20);
Rectangle r2 = Rect(self->memory->img->r.min.x, self->memory->img->r.min.y + 20, self->memory->img->r.max.x, self->memory->img->r.max.y);
set_theme(tagcols, textcols);
f = openfont(display, PRIMARY_FONT);
frinit(tag->frame, r, f, self->memory->img, tagcols);
frinit(body->frame, r2, f, self->memory->img, textcols);
2024-02-13 05:24:15 +00:00
window_redraw(self);
2024-02-02 05:57:26 +00:00
Rune* rr = testdata;
for (char* c = testbytes; *c; c++, rr++) {
chartorune(rr, c);
}
frinsert(tag->frame, testdata, testdata + 8*sizeof(Rune), 0);
draw(screen, self->memory->img->r, self->memory->img, nil, r.min);
}
Handler* get_handlers(void) {
set_handler(INIT, handle_init);
return handlers;
}