NK_API int nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size) { int i; int max_height; struct nk_vec2 item_spacing; struct nk_vec2 window_padding; const char *item; NK_ASSERT(ctx); NK_ASSERT(item_getter); if (!ctx || !item_getter) return selected; /* calculate popup window */ item_spacing = ctx->style.window.spacing; window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); max_height = count * item_height + count * (int)item_spacing.y; max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; size.y = NK_MIN(size.y, (float)max_height); item_getter(userdata, selected, &item); if (nk_combo_begin_label(ctx, item, size)) { nk_layout_row_dynamic(ctx, (float)item_height, 1); for (i = 0; i < count; ++i) { item_getter(userdata, i, &item); if (nk_combo_item_label(ctx, item, NK_TEXT_LEFT)) selected = i; } nk_combo_end(ctx); } return selected; }
NK_API int nk_combo(struct nk_context *ctx, const char **items, int count, int selected, int item_height, struct nk_vec2 size) { int i = 0; int max_height; struct nk_vec2 item_spacing; struct nk_vec2 window_padding; NK_ASSERT(ctx); NK_ASSERT(items); NK_ASSERT(ctx->current); if (!ctx || !items ||!count) return selected; item_spacing = ctx->style.window.spacing; window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); max_height = count * item_height + count * (int)item_spacing.y; max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; size.y = NK_MIN(size.y, (float)max_height); if (nk_combo_begin_label(ctx, items[selected], size)) { nk_layout_row_dynamic(ctx, (float)item_height, 1); for (i = 0; i < count; ++i) { if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) selected = i; } nk_combo_end(ctx); } return selected; }
/* =============================================================== * * GRID * * ===============================================================*/ static void grid_demo(struct nk_context *ctx, struct media *media) { static char text[3][64]; static int text_len[3]; static const char *items[] = {"Item 0","item 1","item 2"}; static int selected_item = 0; static int check = 1; int i; nk_style_set_font(ctx, &media->font_20->handle); if (nk_begin(ctx, "Grid Demo", nk_rect(600, 350, 275, 250), NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE| NK_WINDOW_NO_SCROLLBAR)) { nk_style_set_font(ctx, &media->font_18->handle); nk_layout_row_dynamic(ctx, 30, 2); nk_label(ctx, "Floating point:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[0], &text_len[0], 64, nk_filter_float); nk_label(ctx, "Hexadecimal:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[1], &text_len[1], 64, nk_filter_hex); nk_label(ctx, "Binary:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[2], &text_len[2], 64, nk_filter_binary); nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT); nk_checkbox_label(ctx, "Check me", &check); nk_label(ctx, "Combobox:", NK_TEXT_RIGHT); if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 25, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) selected_item = i; nk_combo_end(ctx); } } nk_end(ctx); nk_style_set_font(ctx, &media->font_14->handle); }
/* =============================================================== * * BASIC DEMO * * ===============================================================*/ static void basic_demo(struct nk_context *ctx, struct media *media) { static int image_active; static int check0 = 1; static int check1 = 0; static size_t prog = 80; static int selected_item = 0; static int selected_image = 3; static int selected_icon = 0; static const char *items[] = {"Item 0","item 1","item 2"}; static int piemenu_active = 0; static struct nk_vec2 piemenu_pos; int i = 0; nk_style_set_font(ctx, &media->font_20->handle); nk_begin(ctx, "Basic Demo", nk_rect(320, 50, 275, 610), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE); /*------------------------------------------------ * POPUP BUTTON *------------------------------------------------*/ ui_header(ctx, media, "Popup & Scrollbar & Images"); ui_widget(ctx, media, 35); if (nk_button_image_label(ctx, media->dir, "Images", NK_TEXT_CENTERED)) image_active = !image_active; /*------------------------------------------------ * SELECTED IMAGE *------------------------------------------------*/ ui_header(ctx, media, "Selected Image"); ui_widget_centered(ctx, media, 100); nk_image(ctx, media->images[selected_image]); /*------------------------------------------------ * IMAGE POPUP *------------------------------------------------*/ if (image_active) { struct nk_panel popup; if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Image Popup", 0, nk_rect(265, 0, 320, 220))) { nk_layout_row_static(ctx, 82, 82, 3); for (i = 0; i < 9; ++i) { if (nk_button_image(ctx, media->images[i])) { selected_image = i; image_active = 0; nk_popup_close(ctx); } } nk_popup_end(ctx); } } /*------------------------------------------------ * COMBOBOX *------------------------------------------------*/ ui_header(ctx, media, "Combo box"); ui_widget(ctx, media, 40); if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 35, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) selected_item = i; nk_combo_end(ctx); } ui_widget(ctx, media, 40); if (nk_combo_begin_image_label(ctx, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 35, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_image_label(ctx, media->images[i], items[i], NK_TEXT_RIGHT)) selected_icon = i; nk_combo_end(ctx); } /*------------------------------------------------ * CHECKBOX *------------------------------------------------*/ ui_header(ctx, media, "Checkbox"); ui_widget(ctx, media, 30); nk_checkbox_label(ctx, "Flag 1", &check0); ui_widget(ctx, media, 30); nk_checkbox_label(ctx, "Flag 2", &check1); /*------------------------------------------------ * PROGRESSBAR *------------------------------------------------*/ ui_header(ctx, media, "Progressbar"); ui_widget(ctx, media, 35); nk_progress(ctx, &prog, 100, nk_true); /*------------------------------------------------ * PIEMENU *------------------------------------------------*/ if (nk_input_is_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_RIGHT, nk_window_get_bounds(ctx),nk_true)){ piemenu_pos = ctx->input.mouse.pos; piemenu_active = 1; } if (piemenu_active) { int ret = ui_piemenu(ctx, piemenu_pos, 140, &media->menu[0], 6); if (ret == -2) piemenu_active = 0; if (ret != -1) { fprintf(stdout, "piemenu selected: %d\n", ret); piemenu_active = 0; } } nk_style_set_font(ctx, &media->font_14->handle); nk_end(ctx); }
void draw_credits_tab(struct nk_context *ctx, int *tab_screen_height, struct credits_tab *credits) { static struct time before_time, after_time; const float start_time_ratio[] = { 0.005f, 0.26f, 0.18f, 0.1f, 0.25f, 0.18f }; const float atleast_atmost_ratio[] = { 0.005f, 0.28, 0.1f, 0.36f, 0.1f, 0.1f }; static int start_atleast_int, start_atmost_int; *tab_screen_height = 472; //Start Credits Group nk_layout_row_dynamic(ctx, 210, 1); if(nk_group_begin(ctx, "Start Credits", NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Enable, write below text as soon as possible.", &credits->is_start_text); nk_layout_row_dynamic(ctx, 85, 1); nk_edit_string(ctx, NK_EDIT_BOX, credits->start_text, &credits->start_text_len, 1000, nk_filter_ascii); nk_layout_row(ctx, NK_DYNAMIC, 25, 6, start_time_ratio); nk_spacing(ctx, 1); nk_checkbox_label(ctx, "Before (MM:SS)", &credits->is_before); if (nk_combo_begin_label(ctx, credits->before_time_buffer, nk_vec2(100, 100))) { nk_layout_row_dynamic(ctx, 25, 1); sprintf(credits->before_time_buffer, "%02d:%02d", before_time.minutes, before_time.seconds); before_time.seconds = nk_propertyi(ctx, "#S:", 0, before_time.seconds, 60, 1, 1); before_time.minutes = nk_propertyi(ctx, "#M:", 0, before_time.minutes, 60, 1, 1); nk_combo_end(ctx); } nk_spacing(ctx, 1); nk_checkbox_label(ctx, "After (MM:SS)", &credits->is_after); if (nk_combo_begin_label(ctx, credits->after_time_buffer, nk_vec2(100, 100))) { nk_layout_row_dynamic(ctx, 25, 1); sprintf(credits->after_time_buffer, "%02d:%02d", after_time.minutes, after_time.seconds); after_time.seconds = nk_propertyi(ctx, "#S:", 0, after_time.seconds, 60, 1, 1); after_time.minutes = nk_propertyi(ctx, "#M:", 0, after_time.minutes, 60, 1, 1); nk_combo_end(ctx); } nk_layout_row(ctx, NK_DYNAMIC, 25, 6, atleast_atmost_ratio); nk_spacing(ctx, 1); nk_label(ctx, "Display credits at least", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->start_atleast_sec, &credits->start_atleast_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds and not longer than", NK_TEXT_CENTERED); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->start_atmost_sec, &credits->start_atmost_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds", NK_TEXT_RIGHT); nk_group_end(ctx); } //End Credits Group nk_layout_row_dynamic(ctx, 180, 1); if(nk_group_begin(ctx, "End Credits", NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Enable, write below text after last caption and as close as possible to video end.", &credits->is_end_text); nk_layout_row_dynamic(ctx, 85, 1); nk_edit_string(ctx, NK_EDIT_BOX, credits->end_text, &credits->end_text_len, 1000, nk_filter_ascii); nk_layout_row(ctx,NK_DYNAMIC, 25, 6, atleast_atmost_ratio); nk_spacing(ctx, 1); nk_label(ctx, "Display credits at least", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->end_atleast_sec, &credits->end_atleast_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds and not longer than", NK_TEXT_CENTERED); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->end_atmost_sec, &credits->end_atmost_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds", NK_TEXT_RIGHT); nk_group_end(ctx); } }
/*Tab specific functions*/ void draw_input_tab(struct nk_context *ctx, int *tab_screen_height, struct input_tab *input, struct decoders_tab *decoders) { const float screenful_limit_ratio[] = { 0.47f, 0.3f }; static struct time from_time, until_time; const float stream_type_pid_ratio[] = { 0.7f,0.3f }; const float mpeg_type_ratio[] = { 0.7f,0.3f }; const float teletext_page_ratio[] = { 0.75f,0.25f }; const float stream_teletext_ratio[] = { 0.5f, 0.501f }; const float wait_data_ratio[] = { 0.6f, 0.25f, 0.15f }; const float gen_type_ratio[] = { 0.3f, 0.7f }; const float gen_time_ratio[] = { 0.6f ,0.401f}; const char *split_type[] = { "Individual Files", "Parts of same video. Cut by generic tool", "Parts of same video. Cut by video tool" }; static int split_num; *tab_screen_height = 472; nk_layout_row(ctx, NK_DYNAMIC, 150, 2, gen_time_ratio); //General Group if (nk_group_begin(ctx, "General", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { //Input Type nk_layout_row(ctx, NK_DYNAMIC, 25, 2, gen_type_ratio); nk_label(ctx, "Input Type:", NK_TEXT_LEFT); input->type_select = nk_combo(ctx, input->type, 9, input->type_select, 25, nk_vec2(225, 200)); //Split Type nk_layout_row(ctx, NK_DYNAMIC, 25, 2, gen_type_ratio); nk_label(ctx, "Split Type:", NK_TEXT_LEFT); split_num = nk_combo(ctx, split_type, 3, split_num, 25, nk_vec2(240, 200)); if (split_num == 2) input->is_split = nk_true; nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Live Stream.*", &input->is_live_stream); nk_layout_row(ctx, NK_DYNAMIC, 21, 3, wait_data_ratio); nk_label(ctx, "*Wait when no data arrives for", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, input->wait_data_sec, &input->wait_data_sec_len, 999, nk_filter_decimal); nk_label(ctx, "sec", NK_TEXT_LEFT); nk_group_end(ctx); } //Timing Group if (nk_group_begin(ctx, "Timing", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { //Process From nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Process From: (HH:MM:SS)", &input->is_process_from); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_label(ctx, input->from_time_buffer, nk_vec2(180, 250))) { sprintf(input->from_time_buffer, "%02d:%02d:%02d", from_time.hours, from_time.minutes, from_time.seconds); nk_layout_row_dynamic(ctx, 25, 1); from_time.seconds = nk_propertyi(ctx, "#Seconds:", 0, from_time.seconds, 60, 1, 1); from_time.minutes = nk_propertyi(ctx, "#Minutes:", 0, from_time.minutes, 60, 1, 1); from_time.hours = nk_propertyi(ctx, "#Hours:", 0, from_time.hours, 99, 1, 1); nk_combo_end(ctx); } //Process Until nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Process Until: (HH:MM:SS)", &input->is_process_until); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_label(ctx, input->until_time_buffer, nk_vec2(180, 250))) { sprintf(input->until_time_buffer, "%02d:%02d:%02d", until_time.hours, until_time.minutes, until_time.seconds); nk_layout_row_dynamic(ctx, 25, 1); until_time.seconds = nk_propertyi(ctx, "#Seconds:", 0, until_time.seconds, 60, 1, 1); until_time.minutes = nk_propertyi(ctx, "#Minutes:", 0, until_time.minutes, 60, 1, 1); until_time.hours = nk_propertyi(ctx, "#Hours:", 0, until_time.hours, 99, 1, 1); nk_combo_end(ctx); } nk_group_end(ctx); } nk_layout_row(ctx, NK_DYNAMIC, 150, 2, stream_teletext_ratio); //Elementary Stream Group if (nk_group_begin(ctx, "Elementary Stream", NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Auto", input->elementary_stream == AUTO_DETECT)) { input->elementary_stream = AUTO_DETECT; } nk_layout_row(ctx, NK_DYNAMIC, 25, 2, stream_type_pid_ratio); if (nk_option_label(ctx, "Process stream of type:", input->elementary_stream == STREAM_TYPE)) { input->elementary_stream = STREAM_TYPE; } nk_edit_string(ctx, NK_EDIT_SIMPLE, input->stream_type, &input->stream_type_len, 9, nk_filter_decimal); nk_layout_row(ctx, NK_DYNAMIC, 25, 2, stream_type_pid_ratio); if (nk_option_label(ctx, "Process stream with PID:", input->elementary_stream == STREAM_PID)) { input->elementary_stream = STREAM_PID; } nk_edit_string(ctx, NK_EDIT_SIMPLE, input->stream_pid, &input->stream_pid_len, 9, nk_filter_decimal); nk_layout_row(ctx, NK_DYNAMIC, 25, 2, mpeg_type_ratio); nk_checkbox_label(ctx, "Assume MPEG type is:", &input->is_assume_mpeg); nk_edit_string(ctx, NK_EDIT_SIMPLE, input->mpeg_type, &input->mpeg_type_len, 9, nk_filter_decimal); if(input->teletext_decoder == FORCE) { input->elementary_stream = STREAM_PID; } nk_group_end(ctx); } //Teletext Group if (nk_group_begin(ctx, "Teletext", NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_BORDER)) { if(decoders->teletext_dvb == DVB){ nk_layout_row_dynamic(ctx, 40, 1); nk_label_colored_wrap(ctx, "Teletext is disabled in Decoders->Teletext or DVB.", nk_rgb(255, 56, 38)); } else { nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Auto", input->teletext_decoder == AUTO_DECODE)) { input->teletext_decoder = AUTO_DECODE; } nk_layout_row_dynamic(ctx, 25, 1); if (nk_option_label(ctx, "Force Teletext decoder", input->teletext_decoder == FORCE)) { input->teletext_decoder = FORCE; } nk_layout_row_dynamic(ctx, 25, 1); if (nk_option_label(ctx, "Disable Teletext decoder", input->teletext_decoder == DISABLE)) { input->teletext_decoder = DISABLE; } nk_layout_row(ctx, NK_DYNAMIC, 20, 2, teletext_page_ratio); nk_checkbox_label(ctx, "Process Teletext Page #", &input->is_process_teletext_page); nk_edit_string(ctx, NK_EDIT_SIMPLE, input->teletext_page_number, &input->teletext_page_numer_len, 99999, nk_filter_decimal); } nk_group_end(ctx); } //Screenfuls limit group nk_layout_row(ctx, NK_DYNAMIC, 95, 2, stream_teletext_ratio); if (nk_group_begin(ctx, "'Screenfuls' limit", NK_WINDOW_BORDER | NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR)) { int screenful_limits = atoi(input->screenful_limit_buffer); nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "No limit", input->is_limit == NO_LIMIT)) { input->is_limit = NO_LIMIT; } nk_layout_row(ctx, NK_DYNAMIC, 25, 2, screenful_limit_ratio); if (nk_option_label(ctx, "Screenful Limit:", input->is_limit == LIMITED)) { input->is_limit = LIMITED; } screenful_limits = nk_propertyi(ctx, "", 0, screenful_limits, 999, 1, 1); sprintf(input->screenful_limit_buffer, "%d", screenful_limits); nk_group_end(ctx); } //Clock group if (nk_group_begin(ctx, "Clock", NK_WINDOW_BORDER | NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 20, 3); if (nk_option_label(ctx, "Auto", input->clock_input == AUTO)) { input->clock_input = AUTO; } if (nk_option_label(ctx, "GOP", input->clock_input == GOP)) { input->clock_input = GOP; } if (nk_option_label(ctx, "PTS", input->clock_input == PTS)) { input->clock_input = PTS; } nk_group_end(ctx); } }