summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2018-03-29 00:09:50 -0700
committerMichael Pavone <pavone@retrodev.com>2018-03-29 00:09:50 -0700
commitc6aa109d0462c56a4363c6393a19f9e4f5bf5ae5 (patch)
tree2ad331887e462214e9894664a06e61edf65ed150
parente507fb1b6c36237cd243dba90e5ab036e9160e37 (diff)
Added vsync to video settings
-rw-r--r--nuklear_ui/blastem_nuklear.c88
1 files changed, 50 insertions, 38 deletions
diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c
index 1d68844..66f30b5 100644
--- a/nuklear_ui/blastem_nuklear.c
+++ b/nuklear_ui/blastem_nuklear.c
@@ -622,12 +622,61 @@ shader_prog *get_shader_list(uint32_t *num_out)
return progs;
}
+int32_t find_match(const char **options, uint32_t num_options, char *path, char *def)
+{
+ char *setting = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval;
+ int32_t selected = -1;
+ for (uint32_t i = 0; i < num_options; i++)
+ {
+ if (!strcmp(setting, options[i])) {
+ selected = i;
+ break;
+ }
+ }
+ if (selected == -1) {
+ for (uint32_t i = 0; i < num_options; i++)
+ {
+ if (!strcmp(def, options[i])) {
+ selected = i;
+ break;
+ }
+ }
+ }
+ return selected;
+}
+
+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)
+{
+ nk_label(context, label, NK_TEXT_LEFT);
+ int32_t next = nk_combo(context, opt_display, num_options, current, 30, nk_vec2(300, 300));
+ if (next != current) {
+ config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(options[next])}, TVAL_PTR);
+ }
+ return next;
+}
+
+int32_t settings_dropdown(struct nk_context *context, char *label, const char **options, uint32_t num_options, int32_t current, char *path)
+{
+ return settings_dropdown_ex(context, label, options, options, num_options, current, path);
+}
+
void view_video_settings(struct nk_context *context)
{
+ const char *vsync_opts[] = {"on", "off", "tear"};
+ const char *vsync_opt_names[] = {
+ "On",
+ "Off",
+ "On, tear if late"
+ };
+ const uint32_t num_vsync_opts = sizeof(vsync_opts)/sizeof(*vsync_opts);
static shader_prog *progs;
static char **prog_names;
static uint32_t num_progs;
static uint32_t selected_prog;
+ static int32_t selected_vsync = -1;
+ if (selected_vsync < 0) {
+ selected_vsync = find_match(vsync_opts, num_vsync_opts, "video\0vsync\0", "off");
+ }
if(!progs) {
progs = get_shader_list(&num_progs);
prog_names = calloc(num_progs, sizeof(char*));
@@ -656,6 +705,7 @@ void view_video_settings(struct nk_context *context)
settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0);
settings_toggle(context, "Open GL", "video\0gl\0", 1);
settings_toggle(context, "Scanlines", "video\0scanlines\0", 0);
+ selected_vsync = settings_dropdown_ex(context, "VSync", vsync_opts, vsync_opt_names, num_vsync_opts, selected_vsync, "video\0vsync\0");
settings_int_input(context, "Windowed Width", "video\0width\0", "640");
nk_label(context, "Shader", NK_TEXT_LEFT);
uint32_t next_selected = nk_combo(context, (const char **)prog_names, num_progs, selected_prog, 30, nk_vec2(300, 300));
@@ -680,44 +730,6 @@ void view_video_settings(struct nk_context *context)
}
}
-int32_t find_match(const char **options, uint32_t num_options, char *path, char *def)
-{
- char *setting = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval;
- int32_t selected = -1;
- for (uint32_t i = 0; i < num_options; i++)
- {
- if (!strcmp(setting, options[i])) {
- selected = i;
- break;
- }
- }
- if (selected == -1) {
- for (uint32_t i = 0; i < num_options; i++)
- {
- if (!strcmp(def, options[i])) {
- selected = i;
- break;
- }
- }
- }
- return selected;
-}
-
-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)
-{
- nk_label(context, label, NK_TEXT_LEFT);
- int32_t next = nk_combo(context, opt_display, num_options, current, 30, nk_vec2(300, 300));
- if (next != current) {
- config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(options[next])}, TVAL_PTR);
- }
- return next;
-}
-
-int32_t settings_dropdown(struct nk_context *context, char *label, const char **options, uint32_t num_options, int32_t current, char *path)
-{
- return settings_dropdown_ex(context, label, options, options, num_options, current, path);
-}
-
void view_audio_settings(struct nk_context *context)
{
const char *rates[] = {