make op list order independent

isolation_bkp/dynres
Dominik Madarász 2021-05-16 15:38:30 +02:00
parent fb6862ebae
commit d195b7756b
5 changed files with 41 additions and 28 deletions

View File

@ -61,7 +61,7 @@ typedef enum {
TOP_DRAW_RECT,
TOP_DRAW_LINE,
TOP_DITHER,
TOP_LOAD_IMAGE,
TOP_DRAW_IMAGE,
TOP_DRAW_TEXT,
TOP_RESIZE_IMAGE,
@ -117,9 +117,11 @@ void texed_compose_image(void);
void texed_msgbox_init(char const *title, char const *message, char const *buttons);
void texed_process_ops(void);
void texed_process_params(void);
void texed_add_op(int idx);
void texed_add_op(int kind);
void texed_rem_op(int idx);
void texed_swp_op(int idx, int idx2);
int texed_find_op(int kind);
void texed_draw_oplist_pane(zpl_aabb2 r);
void texed_draw_props_pane(zpl_aabb2 r);
@ -169,7 +171,7 @@ void texed_run(int argc, char **argv) {
Image orig = LoadImage(zpl_bprintf("art/%s", path));
texed_new(orig.width, orig.height);
is_repaint_locked = true;
texed_add_op(TOP_LOAD_IMAGE);
texed_add_op(TOP_DRAW_IMAGE);
td_param *params = ctx.ops[1].params;
zpl_strcpy(params[0].str, path);
is_repaint_locked = false;
@ -336,9 +338,19 @@ void texed_msgbox_init(char const *title, char const *message, char const *butto
ctx.msgbox.buttons = buttons;
}
void texed_add_op(int idx) {
assert(idx >= 0 && idx < DEF_OPS_LEN);
td_op *dop = &default_ops[idx];
int texed_find_op(int kind) {
assert(kind >= 0 && kind < DEF_OPS_LEN);
for (int i = 0; i < DEF_OPS_LEN; i += 1) {
if (default_ops[i].kind == kind) {
return i;
}
}
return -1;
}
void texed_add_op(int kind) {
assert(kind >= 0 && kind < DEF_OPS_LEN);
td_op *dop = &default_ops[texed_find_op(kind)];
td_op op = {
.kind = dop->kind,

View File

@ -33,7 +33,7 @@ void texed_process_ops(void) {
op->params[2].i32,
op->params[3].i32);
}break;
case TOP_LOAD_IMAGE: {
case TOP_DRAW_IMAGE: {
char const *str = zpl_bprintf("art/%s", op->params[0].str);
if (FileExists(str)) {
Image img = LoadImage(str);

View File

@ -36,17 +36,7 @@ static td_op default_ops[] = {
}
},
{
OP(TOP_DITHER),
.num_params = 4,
.params = (td_param[]) {
PARAM(TPARAM_INT, "r_bpp", "8"),
PARAM(TPARAM_INT, "g_bpp", "8"),
PARAM(TPARAM_INT, "b_bpp", "8"),
PARAM(TPARAM_INT, "a_bpp", "8"),
}
},
{
OP(TOP_LOAD_IMAGE),
OP(TOP_DRAW_IMAGE),
.num_params = 6,
.params = (td_param[]) {
PARAM(TPARAM_STRING, "src", "samples/test.png"),
@ -68,6 +58,16 @@ static td_op default_ops[] = {
PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
}
},
{
OP(TOP_DITHER),
.num_params = 4,
.params = (td_param[]) {
PARAM(TPARAM_INT, "r_bpp", "8"),
PARAM(TPARAM_INT, "g_bpp", "8"),
PARAM(TPARAM_INT, "b_bpp", "8"),
PARAM(TPARAM_INT, "a_bpp", "8"),
}
},
{
OP(TOP_RESIZE_IMAGE),
.num_params = 3,

View File

@ -39,7 +39,8 @@ void texed_load(void) {
op->is_hidden = uc.item.as.boolean;
UNPACK(CWP_ITEM_ARRAY);
op->num_params = default_ops[kind].num_params;
int idx = texed_find_op(kind);
op->num_params = default_ops[idx].num_params;
op->params = zpl_malloc(sizeof(td_param)*op->num_params);
int parmarrsize = (int)uc.item.as.array.size;
for (int j = 0; j < parmarrsize; j += 1) {
@ -48,16 +49,16 @@ void texed_load(void) {
zpl_memcopy(p->str, uc.item.as.str.start, uc.item.as.str.length);
// NOTE(zaklaus): fix up other metadata
p->name = default_ops[kind].params[j].name;
p->kind = default_ops[kind].params[j].kind;
p->name = default_ops[idx].params[j].name;
p->kind = default_ops[idx].params[j].kind;
}
// NOTE(zaklaus): resolve missing params
for (int j = parmarrsize; j < default_ops[kind].num_params; j += 1) {
for (int j = parmarrsize; j < default_ops[idx].num_params; j += 1) {
td_param *p = &op->params[j];
p->name = default_ops[kind].params[j].name;
p->kind = default_ops[kind].params[j].kind;
zpl_strcpy(p->str, default_ops[kind].params[j].str);
p->name = default_ops[idx].params[j].name;
p->kind = default_ops[idx].params[j].kind;
zpl_strcpy(p->str, default_ops[idx].params[j].str);
}
}

View File

@ -145,7 +145,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 add_op_btn_r = zpl_aabb2_cut_top(&add_op_r, 22.5f);
zpl_aabb2_cut_bottom(&add_op_btn_r, 2.5f);
if (GuiButton(aabb2_ray(add_op_btn_r), default_ops[i].name)) {
texed_add_op(i);
texed_add_op(default_ops[i].kind);
}
}
}
@ -198,7 +198,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 hidden_r = zpl_aabb2_cut_right(&op_item_r, 20.0f);
if (!default_ops[ctx.ops[i].kind].is_locked) GuiSetState(GUI_STATE_NORMAL);
if (!default_ops[texed_find_op(ctx.ops[i].kind)].is_locked) GuiSetState(GUI_STATE_NORMAL);
if (GuiButton(aabb2_ray(hidden_r), ctx.ops[i].is_hidden ? "#45#" : "#44#")) {
ctx.ops[i].is_hidden = !ctx.ops[i].is_hidden;
texed_repaint_preview();
@ -207,7 +207,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 lock_r = zpl_aabb2_cut_right(&op_item_r, 20.0f);
if (default_ops[ctx.ops[i].kind].is_locked) GuiSetState(GUI_STATE_DISABLED);
if (default_ops[texed_find_op(ctx.ops[i].kind)].is_locked) GuiSetState(GUI_STATE_DISABLED);
if (GuiButton(aabb2_ray(lock_r), ctx.ops[i].is_locked ? "#137#" : "#138#")) {
ctx.ops[i].is_locked = !ctx.ops[i].is_locked;
ctx.is_saved = false;