diff options
Diffstat (limited to 'apps/gui')
| -rw-r--r-- | apps/gui/option_select.c | 131 |
1 files changed, 75 insertions, 56 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index cee445d..d48dd73 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -349,73 +349,41 @@ static void bool_funcwrapper(int value) boolfunction(false); } -bool option_screen(struct settings_list *setting, - bool use_temp_var, unsigned char* option_title) +static void val_to_selection(struct settings_list *setting, int oldvalue, + int *nb_items, int *selected, + void (**function)(int)) { - int action; - bool done = false; - struct gui_synclist lists; - int oldvalue, nb_items = 0, selected = 0, temp_var; - int *variable; - bool allow_wrap = setting->flags & F_NO_WRAP ? false : true; int var_type = setting->flags&F_T_MASK; - void (*function)(int) = NULL; - char *title; - if (var_type == F_T_INT || var_type == F_T_UINT) - { - variable = use_temp_var ? &temp_var: (int*)setting->setting; - temp_var = oldvalue = *(int*)setting->setting; - } - else if (var_type == F_T_BOOL) - { - /* bools always use the temp variable... - if use_temp_var is false it will be copied to setting->setting every change */ - variable = &temp_var; - temp_var = oldvalue = *(bool*)setting->setting?1:0; - } - else return false; /* only int/bools can go here */ - gui_synclist_init(&lists, value_setting_get_name_cb, - (void*)setting, false, 1, NULL); - if (setting->lang_id == -1) - title = (char*)setting->cfg_vals; - else - title = P2STR(option_title); - - gui_synclist_set_title(&lists, title, Icon_Questionmark); - gui_synclist_set_icon_callback(&lists, NULL); - if(global_settings.talk_menu) - gui_synclist_set_voice_callback(&lists, option_talk); - /* set the number of items and current selection */ if (var_type == F_T_INT || var_type == F_T_UINT) { if (setting->flags&F_CHOICE_SETTING) { - nb_items = setting->choice_setting->count; - selected = oldvalue; - function = setting->choice_setting->option_callback; + *nb_items = setting->choice_setting->count; + *selected = oldvalue; + *function = setting->choice_setting->option_callback; } else if (setting->flags&F_TABLE_SETTING) { const struct table_setting *info = setting->table_setting; int i; - nb_items = info->count; - selected = -1; + *nb_items = info->count; + *selected = -1; table_setting_array_position = -1; - for (i=0;selected==-1 && i<nb_items;i++) + for (i=0;*selected==-1 && i<*nb_items;i++) { if (setting->flags&F_ALLOW_ARBITRARY_VALS && (oldvalue < info->values[i])) { table_setting_oldval = oldvalue; table_setting_array_position = i; - selected = i; - nb_items++; + *selected = i; + *nb_items++; } else if (oldvalue == info->values[i]) - selected = i; + *selected = i; } - function = info->option_callback; + *function = info->option_callback; } else if (setting->flags&F_T_SOUND) { @@ -423,13 +391,13 @@ bool option_screen(struct settings_list *setting, int steps = sound_steps(setting_id); int min = sound_min(setting_id); int max = sound_max(setting_id); - nb_items = (max-min)/steps + 1; + *nb_items = (max-min)/steps + 1; #ifndef ASCENDING_INT_SETTINGS - selected = (max - oldvalue) / steps; + *selected = (max - oldvalue) / steps; #else - selected = (oldvalue - min) / steps; + *selected = (oldvalue - min) / steps; #endif - function = sound_get_fn(setting_id); + *function = sound_get_fn(setting_id); } else { @@ -438,23 +406,63 @@ bool option_screen(struct settings_list *setting, max = info->max; min = info->min; step = info->step; - nb_items = (max-min)/step + 1; + *nb_items = (max-min)/step + 1; #ifndef ASCENDING_INT_SETTINGS - selected = (max - oldvalue) / step; + *selected = (max - oldvalue) / step; #else - selected = (oldvalue - min) / step; + *selected = (oldvalue - min) / step; #endif - function = info->option_callback; + *function = info->option_callback; } } else if (var_type == F_T_BOOL) { - selected = oldvalue; - nb_items = 2; + *selected = oldvalue; + *nb_items = 2; boolfunction = setting->bool_setting->option_callback; if (boolfunction) - function = bool_funcwrapper; + *function = bool_funcwrapper; + } +} + +bool option_screen(struct settings_list *setting, + bool use_temp_var, unsigned char* option_title) +{ + int action; + bool done = false; + struct gui_synclist lists; + int oldvalue, nb_items = 0, selected = 0, temp_var; + int *variable; + bool allow_wrap = setting->flags & F_NO_WRAP ? false : true; + int var_type = setting->flags&F_T_MASK; + void (*function)(int) = NULL; + char *title; + if (var_type == F_T_INT || var_type == F_T_UINT) + { + variable = use_temp_var ? &temp_var: (int*)setting->setting; + temp_var = oldvalue = *(int*)setting->setting; + } + else if (var_type == F_T_BOOL) + { + /* bools always use the temp variable... + if use_temp_var is false it will be copied to setting->setting every change */ + variable = &temp_var; + temp_var = oldvalue = *(bool*)setting->setting?1:0; } + else return false; /* only int/bools can go here */ + gui_synclist_init(&lists, value_setting_get_name_cb, + (void*)setting, false, 1, NULL); + if (setting->lang_id == -1) + title = (char*)setting->cfg_vals; + else + title = P2STR(option_title); + + gui_synclist_set_title(&lists, title, Icon_Questionmark); + gui_synclist_set_icon_callback(&lists, NULL); + if(global_settings.talk_menu) + gui_synclist_set_voice_callback(&lists, option_talk); + + val_to_selection(setting, oldvalue, &nb_items, &selected, &function); gui_synclist_set_nb_items(&lists, nb_items); gui_synclist_select_item(&lists, selected); @@ -506,6 +514,17 @@ bool option_screen(struct settings_list *setting, gui_syncsplash(HZ/2, ID2P(LANG_CANCEL)); done = true; } + else if (action == ACTION_STD_CONTEXT) + { + reset_setting(setting, variable); + if (var_type == F_T_BOOL && !use_temp_var) + *(bool*)setting->setting = temp_var==1?true:false; + val_to_selection(setting, *variable, &nb_items, + &selected, &function); + gui_synclist_select_item(&lists, selected); + gui_synclist_draw(&lists); + gui_synclist_speak_item(&lists); + } else if (action == ACTION_STD_OK) { done = true; |