can draw some text

This commit is contained in:
Iris Lightshard 2024-02-01 22:57:26 -07:00
parent 4ed8a026bb
commit 15fd5e6d59
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3
7 changed files with 145 additions and 11 deletions

View file

@ -8,9 +8,12 @@ OFILES=\
client.$O\ client.$O\
util.$O\ util.$O\
node.$O\ node.$O\
opcodes.$O\
theme.$O\
HFILES=dat.h\ HFILES=dat.h\
fns.h\ fns.h\
theme.h\
UPDATE=\ UPDATE=\
mkfile\ mkfile\

17
dat.h
View file

@ -8,6 +8,7 @@
#include <cursor.h> #include <cursor.h>
#include <mouse.h> #include <mouse.h>
#include <keyboard.h> #include <keyboard.h>
#include <frame.h>
typedef enum { typedef enum {
CTL = 0, CTL = 0,
@ -55,7 +56,7 @@ typedef enum {
BODYF, BODYF,
SHELLF, SHELLF,
TOTAL_SUBF TOTAL_SUBF
} SubFrame; } FrameType;
typedef struct Aux { typedef struct Aux {
FileType type; FileType type;
@ -70,16 +71,19 @@ typedef struct {
typedef void (*Handler)(void*, void*); typedef void (*Handler)(void*, void*);
typedef struct {
Rune* text;
uint text_len;
Frame* frame;
} SubFrame;
typedef struct { typedef struct {
uvlong id; uvlong id;
WindowStatus status; WindowStatus status;
Image* img; Image* img;
Screen* screen; Screen* screen;
char filepath[512]; char filepath[512];
Rune* tag; SubFrame* editorState[TOTAL_SUBF];
uint tag_len;
Rune* body;
uint body_len;
} KuroMemory; } KuroMemory;
typedef struct { typedef struct {
@ -90,3 +94,6 @@ typedef struct {
KuroMemory* memory; KuroMemory* memory;
Channel* status; /* chan(WidowStatus) */ Channel* status; /* chan(WidowStatus) */
} Node; } Node;
Image* tagcols[NCOL];
Image* textcols[NCOL];

4
fns.h
View file

@ -16,3 +16,7 @@ Node* create_node(char* filename);
void supervise_node(Node* self); void supervise_node(Node* self);
void node_cleanup(Node* self); void node_cleanup(Node* self);
void memory_cleanup(KuroMemory* self); void memory_cleanup(KuroMemory* self);
void set_theme(Image** t, Image** b);
Handler* get_handlers(void);

16
node.c
View file

@ -1,6 +1,7 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
static Instruction init_instr = { INIT, nil };
void node_setup(Node* self, Handler* handlers, KuroMemory* memory) { void node_setup(Node* self, Handler* handlers, KuroMemory* memory) {
if (self) { if (self) {
@ -15,17 +16,22 @@ void node_loop(void* data) {
Instruction x; Instruction x;
for (;;) { for (;;) {
print("waiting for instruction\n");
recv(self->cpu, &x); recv(self->cpu, &x);
print("got opcode: %d\n", x.opcode);
if (self->handlers[x.opcode]) { if (self->handlers[x.opcode]) {
(*(self->handlers[x.opcode]))(self, x.data); (*(self->handlers[x.opcode]))(self, x.data);
print("finished executing handler for opcode %d\n", x.opcode);
switch(self->memory->status) { switch(self->memory->status) {
case KURO_QUITS: case KURO_QUITS:
nbsend(self->status, 0); nbsend(self->status, 0);
threadexits(0); threadexits(0);
default: default:
break; 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)); KuroMemory* self = (KuroMemory*)malloc(sizeof(KuroMemory));
Node* node = (Node*)malloc(sizeof(Node)); Node* node = (Node*)malloc(sizeof(Node));
Handler* handlers = (Handler*)malloc(TOTAL_OPCODES * sizeof(Handler*)); Handler* handlers = get_handlers();
node_setup(node, handlers, self); node_setup(node, handlers, self);
self->img = screen; self->img = allocimage(display, screen->r, screen->chan, 1, display->black);
self->screen = _screen; self->screen = _screen;
if (filename) { if (filename) {
strcpy(self->filepath, filename); strcpy(self->filepath, filename);
@ -53,6 +59,8 @@ Node* create_node(char* filename) {
/* node_execute runs the node on a separate thread */ /* node_execute runs the node on a separate thread */
node_execute(node); node_execute(node);
send(node->cpu, (void*)&init_instr);
return node; return node;
} }

52
opcodes.c Normal file
View file

@ -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;
}

28
theme.c Normal file
View file

@ -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);
}

32
theme.h Normal file
View file

@ -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"