ui changes

isolation_bkp/dynres
Dominik Madarász 2021-05-17 21:10:12 +02:00
parent 4431597590
commit 5c063fb0b7
10 changed files with 58 additions and 13 deletions

BIN
art/ash.ecotex 100644

Binary file not shown.

BIN
art/asphalt.ecotex 100644

Binary file not shown.

Binary file not shown.

BIN
art/demo2.ecotex 100644

Binary file not shown.

BIN
art/road.ecotex 100644

Binary file not shown.

View File

@ -86,6 +86,7 @@ typedef enum {
TOP_COLOR_REPLACE, TOP_COLOR_REPLACE,
TOP_IMAGE_ALPHA_MASK, TOP_IMAGE_ALPHA_MASK,
TOP_IMAGE_ALPHA_MASK_CLEAR,
TOP_FORCE_UINT8 = UINT8_MAX TOP_FORCE_UINT8 = UINT8_MAX
} td_op_kind; } td_op_kind;
@ -246,7 +247,15 @@ void texed_run(int argc, char **argv) {
texed_new(TD_DEFAULT_IMG_WIDTH, TD_DEFAULT_IMG_HEIGHT); texed_new(TD_DEFAULT_IMG_WIDTH, TD_DEFAULT_IMG_HEIGHT);
GuiSetStyle(TEXTBOX, TEXT_COLOR_NORMAL, ColorToInt(RAYWHITE)); {
GuiSetStyle(TEXTBOX, TEXT_COLOR_NORMAL, ColorToInt(RAYWHITE));
GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0x012e33ff);
GuiSetStyle(BUTTON, BASE, 0x202020ff);
GuiSetStyle(BUTTON, BASE + GUI_STATE_DISABLED*3, 0x303030ff);
GuiSetStyle(BUTTON, TEXT + GUI_STATE_FOCUSED*3, 0x303030ff);
GuiSetStyle(DEFAULT, TEXT_COLOR_NORMAL, 0xffffffff);
GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, SCROLLBAR_LEFT_SIDE);
}
while (1) { while (1) {
zpl_aabb2 screen = { zpl_aabb2 screen = {
@ -362,12 +371,12 @@ void texed_destroy(void) {
} }
void texed_export_cc(char const *path) { void texed_export_cc(char const *path) {
zpl_printf("Building texture %s.h ...\n", path); zpl_printf("Building texture %s ...\n", zpl_bprintf("art/gen/%s.h", GetFileNameWithoutExt(path)));
ExportImageAsCode(ctx.img[ctx.img_pos], zpl_bprintf("art/gen/%s.h", GetFileNameWithoutExt(path))); ExportImageAsCode(ctx.img[ctx.img_pos], zpl_bprintf("art/gen/%s.h", GetFileNameWithoutExt(path)));
} }
void texed_export_png(char const *path) { void texed_export_png(char const *path) {
zpl_printf("Exporting texture %s.png ...\n", path); zpl_printf("Exporting texture %s ...\n", zpl_bprintf("art/gen/%s.png", GetFileNameWithoutExt(path)));
ExportImage(ctx.img[ctx.img_pos], zpl_bprintf("art/gen/%s.png", GetFileNameWithoutExt(path))); ExportImage(ctx.img[ctx.img_pos], zpl_bprintf("art/gen/%s.png", GetFileNameWithoutExt(path)));
} }

View File

@ -15,7 +15,7 @@ void texed_process_ops(void) {
for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) { for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) {
td_op *op = &ctx.ops[i]; td_op *op = &ctx.ops[i];
if (op->is_hidden) continue; if (op->is_hidden) continue;
zpl_printf("processing op: %s ... \n", op->name); //zpl_printf("processing op: %s ... \n", op->name);
switch (op->kind) { switch (op->kind) {
case TOP_PUSH_IMAGE: case TOP_PUSH_IMAGE:
@ -37,6 +37,9 @@ void texed_process_ops(void) {
ImageAlphaMask(di, *oi); ImageAlphaMask(di, *oi);
ctx.img_pos--; ctx.img_pos--;
}break; }break;
case TOP_IMAGE_ALPHA_MASK_CLEAR: {
ImageAlphaClear(&ctx.img[ctx.img_pos], op->params[0].color, op->params[1].flt);
}break;
case TOP_DRAW_RECT: { case TOP_DRAW_RECT: {
ImageDrawRectangle(&ctx.img[ctx.img_pos], ImageDrawRectangle(&ctx.img[ctx.img_pos],
op->params[0].i32, op->params[0].i32,
@ -209,7 +212,7 @@ void texed_process_ops(void) {
UnloadImage(img); UnloadImage(img);
}break; }break;
default: { default: {
zpl_printf("%s\n", "unsupported op!"); zpl_printf("%s\n", "unsupported op: %s!", op->name);
}break; }break;
} }
} }
@ -225,7 +228,7 @@ void texed_process_params(void) {
switch (p->kind) { switch (p->kind) {
case TPARAM_SLIDER: case TPARAM_SLIDER:
case TPARAM_FLOAT: { case TPARAM_FLOAT: {
p->flt = (float)zpl_str_to_f64(p->str, NULL); p->old_flt = p->flt = (float)zpl_str_to_f64(p->str, NULL);
}break; }break;
case TPARAM_INT: case TPARAM_INT:
case TPARAM_COORD: { case TPARAM_COORD: {

View File

@ -30,6 +30,12 @@ static td_op default_ops[] = {
} }
},{ },{
OP(TOP_IMAGE_ALPHA_MASK), OP(TOP_IMAGE_ALPHA_MASK),
},{
OP(TOP_IMAGE_ALPHA_MASK_CLEAR),
PARAMS(2) {
PARAM(TPARAM_COLOR, "color", "ffffffff"),
PARAM(TPARAM_FLOAT, "threshold", "1.0"),
}
},{ },{
OP(TOP_DRAW_RECT), OP(TOP_DRAW_RECT),
PARAMS(5) { PARAMS(5) {

View File

@ -11,7 +11,7 @@ void texed_load(void) {
is_repaint_locked = true; is_repaint_locked = true;
texed_clear(); texed_clear();
uint32_t size = 0; uint32_t size = 0;
uint8_t *databuf = LoadFileData(zpl_bprintf("art/%s", ctx.filepath), &size); uint8_t *databuf = LoadFileData(zpl_bprintf("art/%s.ecotex", ctx.filepath), &size);
cw_unpack_context uc; cw_unpack_context uc;
cw_unpack_context_init(&uc, databuf, (size_t)size, NULL); cw_unpack_context_init(&uc, databuf, (size_t)size, NULL);
@ -98,6 +98,6 @@ void texed_save(void) {
} }
} }
SaveFileData(zpl_bprintf("art/%s", ctx.filepath), databuf, pc.current - pc.start); SaveFileData(zpl_bprintf("art/%s.ecotex", ctx.filepath), databuf, pc.current - pc.start);
ctx.is_saved = true; ctx.is_saved = true;
} }

View File

@ -56,7 +56,7 @@ void texed_draw_topbar(zpl_aabb2 r) {
if (ctx.fileDialog.SelectFilePressed && load_pending) { if (ctx.fileDialog.SelectFilePressed && load_pending) {
ctx.fileDialog.SelectFilePressed = false; ctx.fileDialog.SelectFilePressed = false;
if (IsFileExtension(ctx.fileDialog.fileNameText, ".ecotex")) { if (IsFileExtension(ctx.fileDialog.fileNameText, ".ecotex")) {
zpl_strcpy(filename, ctx.fileDialog.fileNameText); strcpy(filename, GetFileNameWithoutExt(ctx.fileDialog.fileNameText));
ctx.filepath = filename; ctx.filepath = filename;
load_pending = false; load_pending = false;
texed_load(); texed_load();
@ -95,10 +95,7 @@ void texed_draw_topbar(zpl_aabb2 r) {
if (ctx.fileDialog.SelectFilePressed && save_as_pending) { if (ctx.fileDialog.SelectFilePressed && save_as_pending) {
ctx.fileDialog.SelectFilePressed = false; ctx.fileDialog.SelectFilePressed = false;
if (TextLength(ctx.fileDialog.fileNameText)) { if (TextLength(ctx.fileDialog.fileNameText)) {
if (!IsFileExtension(ctx.fileDialog.fileNameText, ".ecotex")) { strcpy(filename, GetFileNameWithoutExt(ctx.fileDialog.fileNameText));
zpl_strcpy(ctx.fileDialog.fileNameText, zpl_bprintf("%s.ecotex", ctx.fileDialog.fileNameText));
}
zpl_strcpy(filename, ctx.fileDialog.fileNameText);
ctx.filepath = filename; ctx.filepath = filename;
save_as_pending = false; save_as_pending = false;
texed_save(); texed_save();
@ -140,21 +137,49 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 add_op_r = zpl_aabb2_cut_right(&r, 180.0f); zpl_aabb2 add_op_r = zpl_aabb2_cut_right(&r, 180.0f);
DrawAABB(add_op_r, GetColor(0x122025)); DrawAABB(add_op_r, GetColor(0x122025));
add_op_r = zpl_aabb2_contract(&add_op_r, 3.0f); add_op_r = zpl_aabb2_contract(&add_op_r, 3.0f);
Rectangle panel_rec = aabb2_ray(add_op_r);
static Vector2 panel_scroll = {99, -20};
float list_y = (DEF_OPS_LEN) * 22.5f;
if (list_y >= (add_op_r.max.y-add_op_r.min.y)) add_op_r.min.x += 12.0f;
else add_op_r.min.x += 2.0f;
add_op_r.max.y = add_op_r.min.y + list_y;
Rectangle view = GuiScrollPanel(panel_rec, aabb2_ray(add_op_r), &panel_scroll);
BeginScissorMode(view.x, view.y, view.width, view.height);
for (int i = 0; i < DEF_OPS_LEN; i += 1) { for (int i = 0; i < DEF_OPS_LEN; i += 1) {
if (default_ops[i].is_locked) continue; if (default_ops[i].is_locked) continue;
zpl_aabb2 add_op_btn_r = zpl_aabb2_cut_top(&add_op_r, 22.5f); zpl_aabb2 add_op_btn_r = zpl_aabb2_cut_top(&add_op_r, 22.5f);
add_op_btn_r.min.y += panel_scroll.y;
add_op_btn_r.max.y += panel_scroll.y;
zpl_aabb2_cut_bottom(&add_op_btn_r, 2.5f); zpl_aabb2_cut_bottom(&add_op_btn_r, 2.5f);
if (GuiButton(aabb2_ray(add_op_btn_r), default_ops[i].name)) { if (GuiButton(aabb2_ray(add_op_btn_r), default_ops[i].name)) {
texed_add_op(default_ops[i].kind); texed_add_op(default_ops[i].kind);
} }
} }
EndScissorMode();
} }
// NOTE(zaklaus): recalculate height based on ops count
Rectangle panel_rec = aabb2_ray(r);
static Vector2 panel_scroll = {99, -20};
float list_y = zpl_array_count(ctx.ops)*25.0f;
if (list_y >= (r.max.y-r.min.y)) r.min.x += 12.0f;
else r.min.x += 2.0f;
r.max.y = r.min.y + list_y;
Rectangle view = GuiScrollPanel(panel_rec, aabb2_ray(r), &panel_scroll);
BeginScissorMode(view.x, view.y, view.width, view.height);
// NOTE(zaklaus): operator list // NOTE(zaklaus): operator list
for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) { for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) {
zpl_aabb2 op_item_r = zpl_aabb2_cut_top(&r, 25.0f); zpl_aabb2 op_item_r = zpl_aabb2_cut_top(&r, 25.0f);
op_item_r.min.y += panel_scroll.y;
op_item_r.max.y += panel_scroll.y;
zpl_aabb2_cut_top(&op_item_r, 2.5f); zpl_aabb2_cut_top(&op_item_r, 2.5f);
zpl_aabb2_cut_bottom(&op_item_r, 2.5f); zpl_aabb2_cut_bottom(&op_item_r, 2.5f);
Rectangle list_item = aabb2_ray(op_item_r); Rectangle list_item = aabb2_ray(op_item_r);
@ -227,6 +252,8 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
GuiDrawText(zpl_bprintf("%s %s", ctx.ops[i].name, ctx.ops[i].is_locked ? "(locked)" : ""), GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha)); GuiDrawText(zpl_bprintf("%s %s", ctx.ops[i].name, ctx.ops[i].is_locked ? "(locked)" : ""), GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha));
} }
EndScissorMode();
} }
void texed_draw_props_pane(zpl_aabb2 r) { void texed_draw_props_pane(zpl_aabb2 r) {