ur reworking; mum improvements

This commit is contained in:
2023-10-04 22:57:37 +00:00
parent e02054bd10
commit 5578b0f7e4
9 changed files with 392 additions and 330 deletions

View File

@@ -282,26 +282,12 @@ JSValue duk_ui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
float size = js2number(argv[2]);
struct rgba c = js2color(argv[3]);
int wrap = js2int(argv[4]);
struct boundingbox bb = js2bb(argv[5]);
JSValue ret = JS_NewInt64(js, renderText(s, pos, size, c, wrap, -1, 1.0, bb));
int cursor = js2int(argv[5]);
JSValue ret = JS_NewInt64(js, renderText(s, pos, size, c, wrap, cursor, 1.0));
JS_FreeCString(js, s);
return ret;
}
JSValue duk_cursor_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
const char *s = JS_ToCString(js, argv[0]);
HMM_Vec2 pos = js2hmmv2(argv[1]);
float size = js2number(argv[2]);
struct rgba c = js2color(argv[3]);
int wrap = js2int(argv[5]);
int cursor = js2int(argv[4]);
struct boundingbox bb = js2bb(argv[6]);
renderText(s, pos, size, c, wrap, cursor, 1.0,bb);
JS_FreeCString(js, s);
return JS_NULL;
}
JSValue duk_gui_img(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
const char *img = JS_ToCString(js, argv[0]);
gui_draw_img(img, js2hmmv2(argv[1]), js2hmmv2(argv[2]), js2number(argv[3]), js2bool(argv[4]), js2hmmv2(argv[5]), 1.0, js2color(argv[6]));
@@ -1636,8 +1622,7 @@ void ffi_load() {
DUK_FUNC(register, 3)
DUK_FUNC(register_collide, 6)
DUK_FUNC(ui_text, 5)
DUK_FUNC(cursor_text, 5)
DUK_FUNC(ui_text, 6)
DUK_FUNC(gui_img, 10)
DUK_FUNC(inflate_cpv, 3)

View File

@@ -191,6 +191,7 @@ void draw_char_box(struct Character c, HMM_Vec2 cursor, float scale, struct rgba
cpVect b;
b.x = cursor.X;
b.y = cursor.Y;
color.a = 30;
draw_box(b, wh, color);
}
@@ -210,10 +211,8 @@ void text_flush(HMM_Mat4 *proj) {
curchar = 0;
}
static int drawcaret = 0;
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color, struct boundingbox frame) {
if (curchar == max_chars)
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color) {
if (curchar+1 >= max_chars)
return;
struct text_vert vert;
@@ -278,14 +277,13 @@ struct boundingbox text_bb(const char *text, float scale, float lw, float tracki
}
}
}
return cwh2bb((HMM_Vec2){0,0}, (HMM_Vec2){cursor.X,-cursor.Y});
return cwh2bb((HMM_Vec2){0,0}, (HMM_Vec2){cursor.X,font->linegap-cursor.Y});
}
/* pos given in screen coordinates */
int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, float lw, int caret, float tracking, struct boundingbox frame) {
int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, float lw, int caret, float tracking) {
int len = strlen(text);
drawcaret = caret;
HMM_Vec2 cursor = pos;
@@ -295,15 +293,15 @@ int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, f
struct rgba usecolor = color;
while (*line != '\0') {
if (caret == curchar)
if (caret >= 0 && caret == curchar)
draw_char_box(font->Characters[69], cursor, scale, color);
if (isblank(*line)) {
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor, frame);
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor);
cursor.X += font->Characters[*line].Advance * tracking * scale;
line++;
} else if (isspace(*line)) {
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor, frame);
sdrawCharacter(font->Characters[*line], cursor, scale, usecolor);
cursor.Y -= scale * font->linegap;
cursor.X = pos.X;
line++;
@@ -322,7 +320,7 @@ int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, f
}
while (wordstart < line) {
sdrawCharacter(font->Characters[*wordstart], cursor, scale, usecolor, frame);
sdrawCharacter(font->Characters[*wordstart], cursor, scale, usecolor);
cursor.X += font->Characters[*wordstart].Advance * tracking * scale;
wordstart++;
}

View File

@@ -31,10 +31,10 @@ struct sFont {
void font_init();
struct sFont *MakeFont(const char *fontfile, int height);
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color, struct boundingbox frame);
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color);
void text_settype(struct sFont *font);
struct boundingbox text_bb(const char *text, float scale, float lw, float tracking);
int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, float lw, int caret, float tracking, struct boundingbox frame);
int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, float lw, int caret, float tracking);
// void text_frame();
void text_flush(HMM_Mat4 *proj);