add slider prop control
parent
d195b7756b
commit
9e4120284d
BIN
art/demo.ecotex
BIN
art/demo.ecotex
Binary file not shown.
1458
art/gen/demo.h
1458
art/gen/demo.h
File diff suppressed because it is too large
Load Diff
BIN
art/gen/demo.png
BIN
art/gen/demo.png
Binary file not shown.
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 5.7 KiB |
|
@ -37,6 +37,7 @@ typedef enum {
|
|||
TPARAM_INT,
|
||||
TPARAM_COLOR,
|
||||
TPARAM_STRING,
|
||||
TPARAM_SLIDER,
|
||||
|
||||
TPARAM_FORCE_UINT8 = UINT8_MAX
|
||||
} td_param_kind;
|
||||
|
@ -48,7 +49,9 @@ typedef struct {
|
|||
bool edit_mode;
|
||||
|
||||
union {
|
||||
float flt;
|
||||
struct {
|
||||
float flt, old_flt;
|
||||
};
|
||||
uint32_t u32;
|
||||
int32_t i32;
|
||||
Color color;
|
||||
|
@ -64,6 +67,8 @@ typedef enum {
|
|||
TOP_DRAW_IMAGE,
|
||||
TOP_DRAW_TEXT,
|
||||
TOP_RESIZE_IMAGE,
|
||||
TOP_COLOR_CONTRAST,
|
||||
TOP_COLOR_BRIGHTNESS,
|
||||
|
||||
TOP_FORCE_UINT8 = UINT8_MAX
|
||||
} td_op_kind;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
static inline
|
||||
float texed_map_value(float v, float min, float max);
|
||||
|
||||
void texed_process_ops(void) {
|
||||
for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) {
|
||||
|
@ -75,6 +77,12 @@ void texed_process_ops(void) {
|
|||
ImageResizeNN(&ctx.img, w, h);
|
||||
}
|
||||
}break;
|
||||
case TOP_COLOR_CONTRAST: {
|
||||
ImageColorContrast(&ctx.img, texed_map_value(op->params[0].flt, -100.0f, 100.0f));
|
||||
}break;
|
||||
case TOP_COLOR_BRIGHTNESS: {
|
||||
ImageColorBrightness(&ctx.img, (int)texed_map_value(op->params[0].flt, -255.0f, 255.0f));
|
||||
}break;
|
||||
default: {
|
||||
zpl_printf("%s\n", "unsupported op!");
|
||||
}break;
|
||||
|
@ -90,6 +98,7 @@ void texed_process_params(void) {
|
|||
td_param *p = &op->params[j];
|
||||
|
||||
switch (p->kind) {
|
||||
case TPARAM_SLIDER:
|
||||
case TPARAM_FLOAT: {
|
||||
p->flt = (float)zpl_str_to_f64(p->str, NULL);
|
||||
}break;
|
||||
|
@ -113,3 +122,9 @@ void texed_process_params(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline
|
||||
float texed_map_value(float v, float min, float max) {
|
||||
float slope = max-min;
|
||||
return min + zpl_round(slope * v);
|
||||
}
|
|
@ -1,44 +1,38 @@
|
|||
|
||||
#define PARAM(k,n,v) { .kind = k, .name = n, .str = v }
|
||||
#define PARAMS(n) .num_params = n, .params = (td_param[])
|
||||
#define PARAM_DEF_COLOR "000000ff"
|
||||
|
||||
static td_op default_ops[] = {
|
||||
{
|
||||
OP(TOP_NEW_IMAGE),
|
||||
.is_locked = true,
|
||||
.num_params = 3,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(3) {
|
||||
PARAM(TPARAM_COORD, "w", "64"),
|
||||
PARAM(TPARAM_COORD, "h", "64"),
|
||||
PARAM(TPARAM_COLOR, "color", "ffffffff"),
|
||||
}
|
||||
},
|
||||
{
|
||||
},{
|
||||
OP(TOP_DRAW_RECT),
|
||||
.num_params = 5,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(5) {
|
||||
PARAM(TPARAM_COORD, "x", "0"),
|
||||
PARAM(TPARAM_COORD, "y", "0"),
|
||||
PARAM(TPARAM_COORD, "w", "10"),
|
||||
PARAM(TPARAM_COORD, "h", "10"),
|
||||
PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
|
||||
}
|
||||
},
|
||||
{
|
||||
},{
|
||||
OP(TOP_DRAW_LINE),
|
||||
.num_params = 5,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(5) {
|
||||
PARAM(TPARAM_COORD, "x1", "0"),
|
||||
PARAM(TPARAM_COORD, "y1", "0"),
|
||||
PARAM(TPARAM_COORD, "x2", "64"),
|
||||
PARAM(TPARAM_COORD, "y2", "64"),
|
||||
PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
|
||||
}
|
||||
},
|
||||
{
|
||||
},{
|
||||
OP(TOP_DRAW_IMAGE),
|
||||
.num_params = 6,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(6) {
|
||||
PARAM(TPARAM_STRING, "src", "samples/test.png"),
|
||||
PARAM(TPARAM_COORD, "x", "0"),
|
||||
PARAM(TPARAM_COORD, "y", "0"),
|
||||
|
@ -46,36 +40,40 @@ static td_op default_ops[] = {
|
|||
PARAM(TPARAM_COORD, "h", "-1"),
|
||||
PARAM(TPARAM_COLOR, "tint", "ffffffff"),
|
||||
}
|
||||
},
|
||||
{
|
||||
},{
|
||||
OP(TOP_DRAW_TEXT),
|
||||
.num_params = 5,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(5) {
|
||||
PARAM(TPARAM_STRING, "text", "hello world"),
|
||||
PARAM(TPARAM_COORD, "x", "0"),
|
||||
PARAM(TPARAM_COORD, "y", "0"),
|
||||
PARAM(TPARAM_COORD, "size", "16"),
|
||||
PARAM(TPARAM_COLOR, "color", PARAM_DEF_COLOR),
|
||||
}
|
||||
},
|
||||
{
|
||||
},{
|
||||
OP(TOP_DITHER),
|
||||
.num_params = 4,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(4) {
|
||||
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,
|
||||
.params = (td_param[]) {
|
||||
PARAMS(3) {
|
||||
PARAM(TPARAM_COORD, "w", "64"),
|
||||
PARAM(TPARAM_COORD, "h", "64"),
|
||||
PARAM(TPARAM_COORD, "mode (0=nearest,1=bicubic)", "0"),
|
||||
}
|
||||
},{
|
||||
OP(TOP_COLOR_CONTRAST),
|
||||
PARAMS(1) {
|
||||
PARAM(TPARAM_SLIDER, "contrast", "0.5")
|
||||
}
|
||||
},{
|
||||
OP(TOP_COLOR_BRIGHTNESS),
|
||||
PARAMS(1) {
|
||||
PARAM(TPARAM_SLIDER, "brightness", "0.5")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ void texed_draw_topbar(zpl_aabb2 r) {
|
|||
void texed_draw_oplist_pane(zpl_aabb2 r) {
|
||||
// NOTE(zaklaus): add operator
|
||||
{
|
||||
zpl_aabb2 add_op_r = zpl_aabb2_cut_right(&r, 120.0f);
|
||||
zpl_aabb2 add_op_r = zpl_aabb2_cut_right(&r, 180.0f);
|
||||
DrawAABB(add_op_r, GetColor(0x122025));
|
||||
add_op_r = zpl_aabb2_contract(&add_op_r, 3.0f);
|
||||
|
||||
|
@ -240,7 +240,7 @@ void texed_draw_props_pane(zpl_aabb2 r) {
|
|||
|
||||
zpl_aabb2 column_1_r = zpl_aabb2_cut_left(&r, dims.width/2.0f);
|
||||
zpl_aabb2 column_2_r = r;
|
||||
float prop_height = 40.0f;
|
||||
float prop_height = 20.0f;
|
||||
int prop_column_treshold = (int)zpl_floor(dims.height / prop_height);
|
||||
|
||||
for (int i = 0; i < op->num_params; i += 1) {
|
||||
|
@ -280,6 +280,14 @@ void texed_draw_props_pane(zpl_aabb2 r) {
|
|||
}
|
||||
if (is_color_editing) GuiLock();
|
||||
}break;
|
||||
case TPARAM_SLIDER: {
|
||||
p->flt = GuiSlider(aabb2_ray(tbox_r), NULL, zpl_bprintf("%.02f", p->flt), p->flt, 0.0f, 1.0f);
|
||||
if (p->old_flt != p->flt) {
|
||||
sprintf(p->str, "%f", p->flt);
|
||||
p->old_flt = p->flt;
|
||||
texed_repaint_preview();
|
||||
}
|
||||
}break;
|
||||
case TPARAM_COORD: {
|
||||
if (GuiValueBox(aabb2_ray(tbox_r), NULL, &p->i32, INT32_MIN, INT32_MAX, p->edit_mode)) {
|
||||
p->edit_mode = !p->edit_mode;
|
||||
|
|
Loading…
Reference in New Issue