diff options
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | atom_inspector_nk.c | 144 | ||||
-rw-r--r-- | midi_inspector_nk.c | 16 | ||||
-rw-r--r-- | osc_inspector_nk.c | 15 | ||||
-rw-r--r-- | sherlock_nk.c | 87 | ||||
-rw-r--r-- | sherlock_nk.h | 3 |
6 files changed, 183 insertions, 84 deletions
@@ -1 +1 @@ -0.17.125 +0.17.127 diff --git a/atom_inspector_nk.c b/atom_inspector_nk.c index 6f1e2be..6f6ccd2 100644 --- a/atom_inspector_nk.c +++ b/atom_inspector_nk.c @@ -196,22 +196,9 @@ _atom_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat uri = handle->unmap->unmap(handle->unmap->handle, body->type); } - const bool is_primitive = (body->type == handle->forge.Bool) - || (body->type == handle->forge.Int) - || (body->type == handle->forge.Long) - || (body->type == handle->forge.Float) - || (body->type == handle->forge.Double); - /* - || (body->type == handle->forge.String) - || (body->type == handle->forge.URI) - || (body->type == handle->forge.URID) - || (body->type == handle->forge.Path) - || (body->type == handle->forge.Literal); - */ - - nk_layout_row_begin(ctx, NK_DYNAMIC, widget_h, 3 + is_primitive); + const float entry [4] = {0.1, 0.65, 0.15, 0.1}; + nk_layout_row(ctx, NK_DYNAMIC, widget_h, 4, entry); { - nk_layout_row_push(ctx, 0.1); if(l % 2 == 0) { struct nk_rect b = nk_widget_bounds(ctx); @@ -222,7 +209,6 @@ _atom_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat } nk_labelf_colored(ctx, NK_TEXT_LEFT, yellow, "+%04"PRIi64, frames); - nk_layout_row_push(ctx, is_primitive ? 0.6 : 0.8); if(nk_select_label(ctx, uri, NK_TEXT_LEFT, handle->selected == body)) { handle->ttl_dirty = handle->ttl_dirty @@ -230,64 +216,62 @@ _atom_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat handle->selected = body; } - if(is_primitive) + if(body->type == handle->forge.Bool) + { + const LV2_Atom_Bool *ref = (const LV2_Atom_Bool *)body; + nk_labelf_colored(ctx, NK_TEXT_RIGHT, violet, "%s", ref->body ? "true" : "false"); + } + else if(body->type == handle->forge.Int) + { + const LV2_Atom_Int *ref = (const LV2_Atom_Int *)body; + nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%"PRIi32, ref->body); + } + else if(body->type == handle->forge.Long) + { + const LV2_Atom_Long *ref = (const LV2_Atom_Long *)body; + nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%"PRIi64, ref->body); + } + else if(body->type == handle->forge.Float) + { + const LV2_Atom_Float *ref = (const LV2_Atom_Float *)body; + nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%f", ref->body); + } + else if(body->type == handle->forge.Double) + { + const LV2_Atom_Double *ref = (const LV2_Atom_Double *)body; + nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%lf", ref->body); + } + /* + else if(body->type == handle->forge.String) + { + nk_label_colored(ctx, LV2_ATOM_BODY_CONST(body), NK_TEXT_RIGHT, red); + } + else if(body->type == handle->forge.URI) + { + nk_label_colored(ctx, LV2_ATOM_BODY_CONST(body), NK_TEXT_RIGHT, yellow); + } + else if(body->type == handle->forge.URID) + { + const LV2_Atom_URID *urid = (const LV2_Atom_URID *)body; + const char *_uri = handle->unmap->unmap(handle->unmap->handle, urid->body); + nk_label_colored(ctx, _uri, NK_TEXT_RIGHT, yellow); + } + else if(body->type == handle->forge.Path) + { + nk_label_colored(ctx, LV2_ATOM_BODY_CONST(body), NK_TEXT_RIGHT, red); + } + else if(body->type == handle->forge.Literal) + { + nk_label_colored(ctx, LV2_ATOM_CONTENTS_CONST(LV2_Atom_Literal, body), NK_TEXT_RIGHT, red); + } + */ + else { - nk_layout_row_push(ctx, 0.2); - if(body->type == handle->forge.Bool) - { - const LV2_Atom_Bool *ref = (const LV2_Atom_Bool *)body; - nk_labelf_colored(ctx, NK_TEXT_RIGHT, violet, "%s", ref->body ? "true" : "false"); - } - else if(body->type == handle->forge.Int) - { - const LV2_Atom_Int *ref = (const LV2_Atom_Int *)body; - nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%"PRIi32, ref->body); - } - else if(body->type == handle->forge.Long) - { - const LV2_Atom_Long *ref = (const LV2_Atom_Long *)body; - nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%"PRIi64, ref->body); - } - else if(body->type == handle->forge.Float) - { - const LV2_Atom_Float *ref = (const LV2_Atom_Float *)body; - nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%f", ref->body); - } - else if(body->type == handle->forge.Double) - { - const LV2_Atom_Double *ref = (const LV2_Atom_Double *)body; - nk_labelf_colored(ctx, NK_TEXT_RIGHT, green, "%lf", ref->body); - } - /* - else if(body->type == handle->forge.String) - { - nk_label_colored(ctx, LV2_ATOM_BODY_CONST(body), NK_TEXT_RIGHT, red); - } - else if(body->type == handle->forge.URI) - { - nk_label_colored(ctx, LV2_ATOM_BODY_CONST(body), NK_TEXT_RIGHT, yellow); - } - else if(body->type == handle->forge.URID) - { - const LV2_Atom_URID *urid = (const LV2_Atom_URID *)body; - const char *_uri = handle->unmap->unmap(handle->unmap->handle, urid->body); - nk_label_colored(ctx, _uri, NK_TEXT_RIGHT, yellow); - } - else if(body->type == handle->forge.Path) - { - nk_label_colored(ctx, LV2_ATOM_BODY_CONST(body), NK_TEXT_RIGHT, red); - } - else if(body->type == handle->forge.Literal) - { - nk_label_colored(ctx, LV2_ATOM_CONTENTS_CONST(LV2_Atom_Literal, body), NK_TEXT_RIGHT, red); - } - */ + nk_spacing(ctx, 1); } - nk_layout_row_push(ctx, 0.1); nk_labelf_colored(ctx, NK_TEXT_RIGHT, blue, "%"PRIu32, body->size); } - nk_layout_row_end(ctx); } break; } } @@ -295,30 +279,38 @@ _atom_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat nk_list_view_end(&lview); } - nk_layout_row_dynamic(ctx, widget_h, 5); + const float n = 5; + const float r0 = 1.f / n; + const float r1 = 0.1f / 3; + const float r2 = r0 - r1; + const float footer [10] = {r1, r2, r1, r2, r1, r2, r1, r2, r1, r2}; + nk_layout_row(ctx, NK_DYNAMIC, widget_h, 10, footer); { - const int32_t state_overwrite = nk_check_label(ctx, "overwrite", handle->state.overwrite); + const int32_t state_overwrite = _check(ctx, handle->state.overwrite); if(state_overwrite != handle->state.overwrite) { handle->state.overwrite = state_overwrite; _toggle(handle, handle->urid.overwrite, handle->state.overwrite, true); } + nk_label(ctx, "overwrite", NK_TEXT_LEFT); - const int32_t state_block = nk_check_label(ctx, "block", handle->state.block); + const int32_t state_block = _check(ctx, handle->state.block); if(state_block != handle->state.block) { handle->state.block = state_block; _toggle(handle, handle->urid.block, handle->state.block, true); } + nk_label(ctx, "block", NK_TEXT_LEFT); - const int32_t state_follow = nk_check_label(ctx, "follow", handle->state.follow); + const int32_t state_follow = _check(ctx, handle->state.follow); if(state_follow != handle->state.follow) { handle->state.follow = state_follow; _toggle(handle, handle->urid.follow, handle->state.follow, true); } + nk_label(ctx, "follow", NK_TEXT_LEFT); - const int32_t state_pretty = nk_check_label(ctx, "pretty", handle->state.pretty); + const int32_t state_pretty = _check(ctx, handle->state.pretty); if(state_pretty != handle->state.pretty) { handle->state.pretty = state_pretty; @@ -327,13 +319,15 @@ _atom_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat handle->ttl_dirty = true; sratom_set_pretty_numbers(handle->sratom, handle->state.pretty); } + nk_label(ctx, "pretty", NK_TEXT_LEFT); - const int32_t state_time = nk_check_label(ctx, "time", handle->state.time); + const int32_t state_time = _check(ctx, handle->state.time); if(state_time != handle->state.time) { handle->state.time = state_time; _toggle(handle, handle->urid.time, handle->state.time, true); } + nk_label(ctx, "time", NK_TEXT_LEFT); } const bool max_reached = handle->n_item >= MAX_LINES; diff --git a/midi_inspector_nk.c b/midi_inspector_nk.c index 0dfb577..eb00907 100644 --- a/midi_inspector_nk.c +++ b/midi_inspector_nk.c @@ -483,28 +483,36 @@ _midi_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *dat nk_list_view_end(&lview); } - nk_layout_row_dynamic(ctx, widget_h, 3); + const float n = 3; + const float r0 = 1.f / n; + const float r1 = 0.1f / 3; + const float r2 = r0 - r1; + const float footer [6] = {r1, r2, r1, r2, r1, r2}; + nk_layout_row(ctx, NK_DYNAMIC, widget_h, 6, footer); { - const int32_t state_overwrite = nk_check_label(ctx, "overwrite", handle->state.overwrite); + const int32_t state_overwrite = _check(ctx, handle->state.overwrite); if(state_overwrite != handle->state.overwrite) { handle->state.overwrite = state_overwrite; _toggle(handle, handle->urid.overwrite, handle->state.overwrite, true); } + nk_label(ctx, "overwrite", NK_TEXT_LEFT); - const int32_t state_block = nk_check_label(ctx, "block", handle->state.block); + const int32_t state_block = _check(ctx, handle->state.block); if(state_block != handle->state.block) { handle->state.block = state_block; _toggle(handle, handle->urid.block, handle->state.block, true); } + nk_label(ctx, "block", NK_TEXT_LEFT); - const int32_t state_follow = nk_check_label(ctx, "follow", handle->state.follow); + const int32_t state_follow = _check(ctx, handle->state.follow); if(state_follow != handle->state.follow) { handle->state.follow = state_follow; _toggle(handle, handle->urid.follow, handle->state.follow, true); } + nk_label(ctx, "follow", NK_TEXT_LEFT); } const bool max_reached = handle->n_item >= MAX_LINES; diff --git a/osc_inspector_nk.c b/osc_inspector_nk.c index b967976..e819776 100644 --- a/osc_inspector_nk.c +++ b/osc_inspector_nk.c @@ -375,28 +375,35 @@ _osc_inspector_expose(struct nk_context *ctx, struct nk_rect wbounds, void *data nk_list_view_end(&lview); } - nk_layout_row_dynamic(ctx, widget_h, 3); + const float n = 3; + const float r0 = 1.f / n; + const float r1 = 0.1f / 3; const float r2 = r0 - r1; + const float footer [6] = {r1, r2, r1, r2, r1, r2}; + nk_layout_row(ctx, NK_DYNAMIC, widget_h, 6, footer); { - const int32_t state_overwrite = nk_check_label(ctx, "overwrite", handle->state.overwrite); + const int32_t state_overwrite = _check(ctx, handle->state.overwrite); if(state_overwrite != handle->state.overwrite) { handle->state.overwrite = state_overwrite; _toggle(handle, handle->urid.overwrite, handle->state.overwrite, true); } + nk_label(ctx, "overwrite", NK_TEXT_LEFT); - const int32_t state_block = nk_check_label(ctx, "block", handle->state.block); + const int32_t state_block = _check(ctx, handle->state.block); if(state_block != handle->state.block) { handle->state.block = state_block; _toggle(handle, handle->urid.block, handle->state.block, true); } + nk_label(ctx, "block", NK_TEXT_LEFT); - const int32_t state_follow = nk_check_label(ctx, "follow", handle->state.follow); + const int32_t state_follow = _check(ctx, handle->state.follow); if(state_follow != handle->state.follow) { handle->state.follow = state_follow; _toggle(handle, handle->urid.follow, handle->state.follow, true); } + nk_label(ctx, "follow", NK_TEXT_LEFT); } const bool max_reached = handle->n_item >= MAX_LINES; diff --git a/sherlock_nk.c b/sherlock_nk.c index 7652f83..e15a894 100644 --- a/sherlock_nk.c +++ b/sherlock_nk.c @@ -161,6 +161,93 @@ _get_scale (plughandle_t *handle) return nk_pugl_get_scale(&handle->win); } +static int +_dial_bool(struct nk_context *ctx, int32_t *val, struct nk_color color, bool editable) +{ + const int32_t tmp = *val; + struct nk_rect bounds; + const bool left_mouse_click_in_cursor = nk_widget_is_mouse_clicked(ctx, NK_BUTTON_LEFT); + const enum nk_widget_layout_states layout_states = nk_widget(&bounds, ctx); + + if(layout_states != NK_WIDGET_INVALID) + { + enum nk_widget_states states = NK_WIDGET_STATE_INACTIVE; + struct nk_input *in = (ctx->current->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + + if(in && editable) + { + bool mouse_has_scrolled = false; + + if(left_mouse_click_in_cursor) + { + states = NK_WIDGET_STATE_ACTIVED; + } + else if(nk_input_is_mouse_hovering_rect(in, bounds)) + { + if(in->mouse.scroll_delta.y != 0.f) // has scrolling + { + mouse_has_scrolled = true; + in->mouse.scroll_delta.y = 0.f; + } + + states = NK_WIDGET_STATE_HOVER; + } + + if(left_mouse_click_in_cursor || mouse_has_scrolled) + { + *val = !*val; + } + } + + const struct nk_style_item *fg = NULL; + + switch(states) + { + case NK_WIDGET_STATE_HOVER: + { + fg = &ctx->style.progress.cursor_hover; + } break; + case NK_WIDGET_STATE_ACTIVED: + { + fg = &ctx->style.progress.cursor_active; + } break; + default: + { + fg = &ctx->style.progress.cursor_normal; + } break; + } + + struct nk_color fg_color = fg->data.color; + + fg_color.r = (int)fg_color.r * color.r / 0xff; + fg_color.g = (int)fg_color.g * color.g / 0xff; + fg_color.b = (int)fg_color.b * color.b / 0xff; + fg_color.a = (int)fg_color.a * color.a / 0xff; + + struct nk_command_buffer *canv= nk_window_get_canvas(ctx); + const float w2 = bounds.w/2; + const float h2 = bounds.h/2; + const float r1 = NK_MIN(w2, h2); + const float r2 = r1 / 2; + const float cx = bounds.x + w2; + const float cy = bounds.y + h2; + + nk_stroke_arc(canv, cx, cy, r2 - 0, 0.f, 2*M_PI, 2.f, fg_color); + if(*val) + nk_fill_arc(canv, cx, cy, r2 - 2, 0.f, 2*M_PI, fg_color); + } + + return tmp != *val; +} + +int32_t +_check(struct nk_context *ctx, int32_t state) +{ + _dial_bool(ctx, &state, nk_rgb(0xff, 0xff, 0xff), true); + + return state; +} + static LV2UI_Handle instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri, const char *bundle_path, LV2UI_Write_Function write_function, diff --git a/sherlock_nk.h b/sherlock_nk.h index a10bc3c..8a9cf09 100644 --- a/sherlock_nk.h +++ b/sherlock_nk.h @@ -131,4 +131,7 @@ _post_redisplay(plughandle_t *handle); float _get_scale(plughandle_t *handle); +int32_t +_check(struct nk_context *ctx, int32_t state); + #endif // _SHERLOCK_NK_H |