From 15fd5e6d59cb0cc5c6e8083ace8f7cea8175ebfe Mon Sep 17 00:00:00 2001 From: Iris Lightshard Date: Thu, 1 Feb 2024 22:57:26 -0700 Subject: [PATCH] can draw some text --- 9port.mkfile | 3 +++ dat.h | 19 +++++++++++++------ fns.h | 6 +++++- node.c | 16 ++++++++++++---- opcodes.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ theme.c | 28 ++++++++++++++++++++++++++++ theme.h | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 opcodes.c create mode 100644 theme.c create mode 100644 theme.h diff --git a/9port.mkfile b/9port.mkfile index cf35d74..459301c 100644 --- a/9port.mkfile +++ b/9port.mkfile @@ -8,9 +8,12 @@ OFILES=\ client.$O\ util.$O\ node.$O\ + opcodes.$O\ + theme.$O\ HFILES=dat.h\ fns.h\ + theme.h\ UPDATE=\ mkfile\ diff --git a/dat.h b/dat.h index 5eb0a34..e5ba5b1 100644 --- a/dat.h +++ b/dat.h @@ -8,6 +8,7 @@ #include #include #include +#include typedef enum { CTL = 0, @@ -55,7 +56,7 @@ typedef enum { BODYF, SHELLF, TOTAL_SUBF -} SubFrame; +} FrameType; typedef struct Aux { FileType type; @@ -70,16 +71,19 @@ typedef struct { typedef void (*Handler)(void*, void*); +typedef struct { + Rune* text; + uint text_len; + Frame* frame; +} SubFrame; + typedef struct { uvlong id; WindowStatus status; Image* img; Screen* screen; char filepath[512]; - Rune* tag; - uint tag_len; - Rune* body; - uint body_len; + SubFrame* editorState[TOTAL_SUBF]; } KuroMemory; typedef struct { @@ -89,4 +93,7 @@ typedef struct { Handler* handlers; KuroMemory* memory; Channel* status; /* chan(WidowStatus) */ -} Node; \ No newline at end of file +} Node; + +Image* tagcols[NCOL]; +Image* textcols[NCOL]; \ No newline at end of file diff --git a/fns.h b/fns.h index d38a81f..7a62afd 100644 --- a/fns.h +++ b/fns.h @@ -15,4 +15,8 @@ void node_loop(void* data); Node* create_node(char* filename); void supervise_node(Node* self); void node_cleanup(Node* self); -void memory_cleanup(KuroMemory* self); \ No newline at end of file +void memory_cleanup(KuroMemory* self); + +void set_theme(Image** t, Image** b); + +Handler* get_handlers(void); \ No newline at end of file diff --git a/node.c b/node.c index 736ff2c..d0371f8 100644 --- a/node.c +++ b/node.c @@ -1,6 +1,7 @@ #include "dat.h" #include "fns.h" +static Instruction init_instr = { INIT, nil }; void node_setup(Node* self, Handler* handlers, KuroMemory* memory) { if (self) { @@ -15,17 +16,22 @@ void node_loop(void* data) { Instruction x; for (;;) { + print("waiting for instruction\n"); recv(self->cpu, &x); + print("got opcode: %d\n", x.opcode); + if (self->handlers[x.opcode]) { (*(self->handlers[x.opcode]))(self, x.data); + print("finished executing handler for opcode %d\n", x.opcode); switch(self->memory->status) { case KURO_QUITS: - nbsend(self->status, 0); + nbsend(self->status, 0); threadexits(0); default: break; } - flushimage(self->memory->screen->display, 1); + flushimage(display, 1); + print("refreshed screen\n"); } } } @@ -40,11 +46,11 @@ Node* create_node(char* filename) { KuroMemory* self = (KuroMemory*)malloc(sizeof(KuroMemory)); Node* node = (Node*)malloc(sizeof(Node)); - Handler* handlers = (Handler*)malloc(TOTAL_OPCODES * sizeof(Handler*)); + Handler* handlers = get_handlers(); node_setup(node, handlers, self); - self->img = screen; + self->img = allocimage(display, screen->r, screen->chan, 1, display->black); self->screen = _screen; if (filename) { strcpy(self->filepath, filename); @@ -52,6 +58,8 @@ Node* create_node(char* filename) { /* node_execute runs the node on a separate thread */ node_execute(node); + + send(node->cpu, (void*)&init_instr); return node; } diff --git a/opcodes.c b/opcodes.c new file mode 100644 index 0000000..7530f9a --- /dev/null +++ b/opcodes.c @@ -0,0 +1,52 @@ +#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; +} + +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); + + 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; +} \ No newline at end of file diff --git a/theme.c b/theme.c new file mode 100644 index 0000000..ab7b129 --- /dev/null +++ b/theme.c @@ -0,0 +1,28 @@ +#include "dat.h" +#include "fns.h" +#include "theme.h" + +void set_theme(Image** t, Image** b) { + t[BACK] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_BG); + t[HIGH] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_HI); + t[BORD] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_BD); + t[TEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_TX); + t[HTEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_HT); + + /* BODY */ + b[BACK] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_BG); + b[HIGH] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_HI); + b[BORD] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_BD); + b[TEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_TX); + b[HTEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_HT); +} \ No newline at end of file diff --git a/theme.h b/theme.h new file mode 100644 index 0000000..d8733a3 --- /dev/null +++ b/theme.h @@ -0,0 +1,32 @@ +/* tag & body colors: bg, hilight, border, text, hilighted text */ +#define COLOR_TAG_BG 0x000000FF +#define COLOR_TAG_HI 0x1F9B92FF +#define COLOR_TAG_BD 0x797979FF +#define COLOR_TAG_TX 0xC9C9C9FF +#define COLOR_TAG_HT 0x000000FF + +#define COLOR_BODY_BG 0x000F19FF +#define COLOR_BODY_HI 0x1F9B92FF +#define COLOR_BODY_BD 0x797979FF +#define COLOR_BODY_TX 0x93A1A1FF +#define COLOR_BODY_HT 0x000000FF + +/* button colors: dirty file (mod) indicator and column handles */ + +#define COLOR_BTN_MD 0x1F9B92FF +#define COLOR_BTN_CO 0x002B36FF + +/* button 2 and 3 selection colors */ + +#define COLOR_B2_HI 0x797979FF +#define COLOR_B3_HI 0x002B36FF + +/********* + * fonts * + *********/ + +/* can use either x fonts via fontsrv or p9p fonts */ + +#define PRIMARY_FONT "/mnt/font/SauceCodeProNF/9a/font" +#define SECONDARY_FONT "/lib/font/bit/lucm/unicode.9.font" +