comparison nuklear_ui/blastem_nuklear.c @ 1553:723c00950f41

Added vsync to video settings
author Michael Pavone <pavone@retrodev.com>
date Thu, 29 Mar 2018 00:09:50 -0700
parents 577253765192
children 87350caf6dab
comparison
equal deleted inserted replaced
1552:13a82adb185b 1553:723c00950f41
620 progs = get_shader_progs(entries, num_entries, progs, &num_progs, &prog_storage); 620 progs = get_shader_progs(entries, num_entries, progs, &num_progs, &prog_storage);
621 *num_out = num_progs; 621 *num_out = num_progs;
622 return progs; 622 return progs;
623 } 623 }
624 624
625 int32_t find_match(const char **options, uint32_t num_options, char *path, char *def)
626 {
627 char *setting = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval;
628 int32_t selected = -1;
629 for (uint32_t i = 0; i < num_options; i++)
630 {
631 if (!strcmp(setting, options[i])) {
632 selected = i;
633 break;
634 }
635 }
636 if (selected == -1) {
637 for (uint32_t i = 0; i < num_options; i++)
638 {
639 if (!strcmp(def, options[i])) {
640 selected = i;
641 break;
642 }
643 }
644 }
645 return selected;
646 }
647
648 int32_t settings_dropdown_ex(struct nk_context *context, char *label, const char **options, const char **opt_display, uint32_t num_options, int32_t current, char *path)
649 {
650 nk_label(context, label, NK_TEXT_LEFT);
651 int32_t next = nk_combo(context, opt_display, num_options, current, 30, nk_vec2(300, 300));
652 if (next != current) {
653 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(options[next])}, TVAL_PTR);
654 }
655 return next;
656 }
657
658 int32_t settings_dropdown(struct nk_context *context, char *label, const char **options, uint32_t num_options, int32_t current, char *path)
659 {
660 return settings_dropdown_ex(context, label, options, options, num_options, current, path);
661 }
662
625 void view_video_settings(struct nk_context *context) 663 void view_video_settings(struct nk_context *context)
626 { 664 {
665 const char *vsync_opts[] = {"on", "off", "tear"};
666 const char *vsync_opt_names[] = {
667 "On",
668 "Off",
669 "On, tear if late"
670 };
671 const uint32_t num_vsync_opts = sizeof(vsync_opts)/sizeof(*vsync_opts);
627 static shader_prog *progs; 672 static shader_prog *progs;
628 static char **prog_names; 673 static char **prog_names;
629 static uint32_t num_progs; 674 static uint32_t num_progs;
630 static uint32_t selected_prog; 675 static uint32_t selected_prog;
676 static int32_t selected_vsync = -1;
677 if (selected_vsync < 0) {
678 selected_vsync = find_match(vsync_opts, num_vsync_opts, "video\0vsync\0", "off");
679 }
631 if(!progs) { 680 if(!progs) {
632 progs = get_shader_list(&num_progs); 681 progs = get_shader_list(&num_progs);
633 prog_names = calloc(num_progs, sizeof(char*)); 682 prog_names = calloc(num_progs, sizeof(char*));
634 for (uint32_t i = 0; i < num_progs; i++) 683 for (uint32_t i = 0; i < num_progs; i++)
635 { 684 {
654 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) { 703 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) {
655 nk_layout_row_static(context, 30, width > 300 ? 300 : width, 2); 704 nk_layout_row_static(context, 30, width > 300 ? 300 : width, 2);
656 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0); 705 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0);
657 settings_toggle(context, "Open GL", "video\0gl\0", 1); 706 settings_toggle(context, "Open GL", "video\0gl\0", 1);
658 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0); 707 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0);
708 selected_vsync = settings_dropdown_ex(context, "VSync", vsync_opts, vsync_opt_names, num_vsync_opts, selected_vsync, "video\0vsync\0");
659 settings_int_input(context, "Windowed Width", "video\0width\0", "640"); 709 settings_int_input(context, "Windowed Width", "video\0width\0", "640");
660 nk_label(context, "Shader", NK_TEXT_LEFT); 710 nk_label(context, "Shader", NK_TEXT_LEFT);
661 uint32_t next_selected = nk_combo(context, (const char **)prog_names, num_progs, selected_prog, 30, nk_vec2(300, 300)); 711 uint32_t next_selected = nk_combo(context, (const char **)prog_names, num_progs, selected_prog, 30, nk_vec2(300, 300));
662 if (next_selected != selected_prog) { 712 if (next_selected != selected_prog) {
663 selected_prog = next_selected; 713 selected_prog = next_selected;
676 if (nk_button_label(context, "Back")) { 726 if (nk_button_label(context, "Back")) {
677 pop_view(); 727 pop_view();
678 } 728 }
679 nk_end(context); 729 nk_end(context);
680 } 730 }
681 }
682
683 int32_t find_match(const char **options, uint32_t num_options, char *path, char *def)
684 {
685 char *setting = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval;
686 int32_t selected = -1;
687 for (uint32_t i = 0; i < num_options; i++)
688 {
689 if (!strcmp(setting, options[i])) {
690 selected = i;
691 break;
692 }
693 }
694 if (selected == -1) {
695 for (uint32_t i = 0; i < num_options; i++)
696 {
697 if (!strcmp(def, options[i])) {
698 selected = i;
699 break;
700 }
701 }
702 }
703 return selected;
704 }
705
706 int32_t settings_dropdown_ex(struct nk_context *context, char *label, const char **options, const char **opt_display, uint32_t num_options, int32_t current, char *path)
707 {
708 nk_label(context, label, NK_TEXT_LEFT);
709 int32_t next = nk_combo(context, opt_display, num_options, current, 30, nk_vec2(300, 300));
710 if (next != current) {
711 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(options[next])}, TVAL_PTR);
712 }
713 return next;
714 }
715
716 int32_t settings_dropdown(struct nk_context *context, char *label, const char **options, uint32_t num_options, int32_t current, char *path)
717 {
718 return settings_dropdown_ex(context, label, options, options, num_options, current, path);
719 } 731 }
720 732
721 void view_audio_settings(struct nk_context *context) 733 void view_audio_settings(struct nk_context *context)
722 { 734 {
723 const char *rates[] = { 735 const char *rates[] = {