summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-09-16 11:12:23 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2023-09-17 13:29:03 -0400
commite8a17b12825031195d52af9b417de3d80ebbef18 (patch)
tree66cc20679337f452c12af5bdc59576977e477baf
parent27aa95afcb898d15cc6350946c3c4c337f7d17c7 (diff)
downloadrockbox-e8a17b12825031195d52af9b417de3d80ebbef18.tar.gz
rockbox-e8a17b12825031195d52af9b417de3d80ebbef18.zip
option_select.c clean-up option_screen
No functional changes Change-Id: I0409b76258ce8af5aa9c2e68a2070b6e25927d1c
-rw-r--r--apps/gui/option_select.c102
1 files changed, 53 insertions, 49 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c
index da6c703f40..af281dc07c 100644
--- a/apps/gui/option_select.c
+++ b/apps/gui/option_select.c
@@ -36,6 +36,8 @@
36#include "menu.h" 36#include "menu.h"
37#include "quickscreen.h" 37#include "quickscreen.h"
38 38
39/* HASFLAG compares value to a (SINGLE) flag returns true if set, false otherwise */
40#define HASFLAG(settings_list, flag) ((settings_list->flags & flag) == flag)
39 41
40static int selection_to_val(const struct settings_list *setting, int selection); 42static int selection_to_val(const struct settings_list *setting, int selection);
41int option_value_as_int(const struct settings_list *setting) 43int option_value_as_int(const struct settings_list *setting)
@@ -65,29 +67,29 @@ const char *option_get_valuestring(const struct settings_list *setting,
65 intptr_t temp_var) 67 intptr_t temp_var)
66{ 68{
67 const char* str = buffer; 69 const char* str = buffer;
68 if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) 70 if (HASFLAG(setting, F_BOOL_SETTING))
69 { 71 {
70 bool val = (bool)temp_var; 72 bool val = (bool)temp_var;
71 strmemccpy(buffer, str(val? setting->bool_setting->lang_yes : 73 strmemccpy(buffer, str(val? setting->bool_setting->lang_yes :
72 setting->bool_setting->lang_no), buf_len); 74 setting->bool_setting->lang_no), buf_len);
73 } 75 }
74#if 0 /* probably dont need this one */ 76#if 0 /* probably dont need this one */
75 else if ((setting->flags & F_FILENAME) == F_FILENAME) 77 else if (HASFLAG(setting, F_FILENAME))
76 { 78 {
77 struct filename_setting *info = setting->filename_setting; 79 struct filename_setting *info = setting->filename_setting;
78 snprintf(buffer, buf_len, "%s%s%s", info->prefix, 80 snprintf(buffer, buf_len, "%s%s%s", info->prefix,
79 (char*)temp_var, info->suffix); 81 (char*)temp_var, info->suffix);
80 } 82 }
81#endif 83#endif
82 else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) || 84 else if ((HASFLAG(setting, F_INT_SETTING)) ||
83 ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)) 85 HASFLAG(setting, F_TABLE_SETTING))
84 { 86 {
85 const struct int_setting *int_info = setting->int_setting; 87 const struct int_setting *int_info = setting->int_setting;
86 const struct table_setting *tbl_info = setting->table_setting; 88 const struct table_setting *tbl_info = setting->table_setting;
87 int info_unit; 89 int info_unit;
88 const char *str_unit; 90 const char *str_unit;
89 const char* (*formatter)(char*, size_t, int, const char*); 91 const char* (*formatter)(char*, size_t, int, const char*);
90 if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 92 if (HASFLAG(setting, F_INT_SETTING))
91 { 93 {
92 formatter = int_info->formatter; 94 formatter = int_info->formatter;
93 info_unit = int_info->unit; 95 info_unit = int_info->unit;
@@ -98,24 +100,26 @@ const char *option_get_valuestring(const struct settings_list *setting,
98 info_unit = tbl_info->unit; 100 info_unit = tbl_info->unit;
99 } 101 }
100 102
101 if ((setting->flags & F_TIME_SETTING) == F_TIME_SETTING) 103 bool is_time_setting = HASFLAG(setting, F_TIME_SETTING);
104 if (is_time_setting)
102 str = option_get_timestring(buffer, buf_len, (long)temp_var, info_unit); 105 str = option_get_timestring(buffer, buf_len, (long)temp_var, info_unit);
103 106
104 str_unit = unit_strings_core[info_unit]; 107 str_unit = unit_strings_core[info_unit];
108
105 if (formatter) 109 if (formatter)
106 str = formatter(buffer, buf_len, (int)temp_var, str_unit); 110 str = formatter(buffer, buf_len, (int)temp_var, str_unit);
107 else if ((setting->flags & F_TIME_SETTING) != F_TIME_SETTING) 111 else if (!is_time_setting)
108 snprintf(buffer, buf_len, "%d %s", (int)temp_var, str_unit?str_unit:""); 112 snprintf(buffer, buf_len, "%d %s", (int)temp_var, str_unit?str_unit:"");
109 } 113 }
110 else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 114 else if (HASFLAG(setting, F_T_SOUND))
111 { 115 {
112 format_sound_value(buffer, buf_len, 116 format_sound_value(buffer, buf_len,
113 setting->sound_setting->setting, 117 setting->sound_setting->setting,
114 temp_var); 118 temp_var);
115 } 119 }
116 else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) 120 else if (HASFLAG(setting, F_CHOICE_SETTING))
117 { 121 {
118 if (setting->flags & F_CHOICETALKS) 122 if (HASFLAG(setting, F_CHOICETALKS))
119 { 123 {
120 const struct choice_setting *info = setting->choice_setting; 124 const struct choice_setting *info = setting->choice_setting;
121 if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY) 125 if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY)
@@ -138,25 +142,26 @@ const char *option_get_valuestring(const struct settings_list *setting,
138} 142}
139void option_talk_value(const struct settings_list *setting, int value, bool enqueue) 143void option_talk_value(const struct settings_list *setting, int value, bool enqueue)
140{ 144{
141 if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) 145
146 if (HASFLAG(setting, F_BOOL_SETTING))
142 { 147 {
143 bool val = (value==1); 148 bool val = (value==1);
144 talk_id(val? setting->bool_setting->lang_yes : 149 talk_id(val? setting->bool_setting->lang_yes :
145 setting->bool_setting->lang_no, enqueue); 150 setting->bool_setting->lang_no, enqueue);
146 } 151 }
147#if 0 /* probably dont need this one */ 152#if 0 /* probably dont need this one */
148 else if ((setting->flags & F_FILENAME) == F_FILENAME) 153 else if (HASFLAG(setting, F_FILENAME))
149 { 154 {
150} 155}
151#endif 156#endif
152 else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) || 157 else if ((HASFLAG(setting, F_INT_SETTING)) ||
153 ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)) 158 HASFLAG(setting, F_TABLE_SETTING))
154 { 159 {
155 const struct int_setting *int_info = setting->int_setting; 160 const struct int_setting *int_info = setting->int_setting;
156 const struct table_setting *tbl_info = setting->table_setting; 161 const struct table_setting *tbl_info = setting->table_setting;
157 int unit; 162 int unit;
158 int32_t (*get_talk_id)(int, int); 163 int32_t (*get_talk_id)(int, int);
159 if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 164 if (HASFLAG(setting, F_INT_SETTING))
160 { 165 {
161 unit = int_info->unit; 166 unit = int_info->unit;
162 get_talk_id = int_info->get_talk_id; 167 get_talk_id = int_info->get_talk_id;
@@ -168,12 +173,12 @@ void option_talk_value(const struct settings_list *setting, int value, bool enqu
168 } 173 }
169 if (get_talk_id) 174 if (get_talk_id)
170 talk_id(get_talk_id(value, unit), enqueue); 175 talk_id(get_talk_id(value, unit), enqueue);
171 else if ((setting->flags & F_TIME_SETTING) == F_TIME_SETTING) 176 else if (HASFLAG(setting, F_TIME_SETTING))
172 talk_time_intervals(value, unit, enqueue); 177 talk_time_intervals(value, unit, enqueue);
173 else 178 else
174 talk_value(value, unit, enqueue); 179 talk_value(value, unit, enqueue);
175 } 180 }
176 else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 181 else if (HASFLAG(setting, F_T_SOUND))
177 { 182 {
178 int talkunit = UNIT_INT; 183 int talkunit = UNIT_INT;
179 int sound_setting = setting->sound_setting->setting; 184 int sound_setting = setting->sound_setting->setting;
@@ -188,9 +193,9 @@ void option_talk_value(const struct settings_list *setting, int value, bool enqu
188 talkunit = UNIT_HERTZ; 193 talkunit = UNIT_HERTZ;
189 talk_value_decimal(phys, talkunit, decimals, enqueue); 194 talk_value_decimal(phys, talkunit, decimals, enqueue);
190 } 195 }
191 else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) 196 else if (HASFLAG(setting, F_CHOICE_SETTING))
192 { 197 {
193 if (setting->flags & F_CHOICETALKS) 198 if (HASFLAG(setting, F_CHOICETALKS))
194 { 199 {
195 talk_id(setting->choice_setting->talks[value], enqueue); 200 talk_id(setting->choice_setting->talks[value], enqueue);
196 } 201 }
@@ -216,14 +221,14 @@ void option_select_next_val(const struct settings_list *setting,
216{ 221{
217 int val = 0; 222 int val = 0;
218 int *value = setting->setting; 223 int *value = setting->setting;
219 if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) 224 if (HASFLAG(setting, F_BOOL_SETTING))
220 { 225 {
221 *(bool*)value = !*(bool*)value; 226 *(bool*)value = !*(bool*)value;
222 if (apply && setting->bool_setting->option_callback) 227 if (apply && setting->bool_setting->option_callback)
223 setting->bool_setting->option_callback(*(bool*)value); 228 setting->bool_setting->option_callback(*(bool*)value);
224 return; 229 return;
225 } 230 }
226 else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 231 else if (HASFLAG(setting, F_INT_SETTING))
227 { 232 {
228 struct int_setting *info = (struct int_setting *)setting->int_setting; 233 struct int_setting *info = (struct int_setting *)setting->int_setting;
229 bool neg_step = (info->step < 0); 234 bool neg_step = (info->step < 0);
@@ -243,7 +248,7 @@ void option_select_next_val(const struct settings_list *setting,
243 if (apply && info->option_callback) 248 if (apply && info->option_callback)
244 info->option_callback(val); 249 info->option_callback(val);
245 } 250 }
246 else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 251 else if (HASFLAG(setting, F_T_SOUND))
247 { 252 {
248 int setting_id = setting->sound_setting->setting; 253 int setting_id = setting->sound_setting->setting;
249 int steps = sound_steps(setting_id); 254 int steps = sound_steps(setting_id);
@@ -265,7 +270,7 @@ void option_select_next_val(const struct settings_list *setting,
265 if (apply) 270 if (apply)
266 sound_set(setting_id, val); 271 sound_set(setting_id, val);
267 } 272 }
268 else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING) 273 else if (HASFLAG(setting, F_CHOICE_SETTING))
269 { 274 {
270 struct choice_setting *info = (struct choice_setting *)setting->choice_setting; 275 struct choice_setting *info = (struct choice_setting *)setting->choice_setting;
271 if (!previous) 276 if (!previous)
@@ -284,7 +289,7 @@ void option_select_next_val(const struct settings_list *setting,
284 if (apply && info->option_callback) 289 if (apply && info->option_callback)
285 info->option_callback(val); 290 info->option_callback(val);
286 } 291 }
287 else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING) 292 else if (HASFLAG(setting, F_TABLE_SETTING))
288 { 293 {
289 const struct table_setting *tbl_info = setting->table_setting; 294 const struct table_setting *tbl_info = setting->table_setting;
290 int i, add; 295 int i, add;
@@ -312,13 +317,15 @@ static int selection_to_val(const struct settings_list *setting, int selection)
312 int min = 0; 317 int min = 0;
313 */ 318 */
314 int max = 0, step = 1; 319 int max = 0, step = 1;
315 if (((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) || 320 if ((HASFLAG(setting, F_BOOL_SETTING)) ||
316 ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)) 321 HASFLAG(setting, F_CHOICE_SETTING))
322 {
317 return selection; 323 return selection;
318 else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING) 324 }
325 else if (HASFLAG(setting, F_TABLE_SETTING))
319 { 326 {
320 const struct table_setting *info = setting->table_setting; 327 const struct table_setting *info = setting->table_setting;
321 if (setting->flags&F_ALLOW_ARBITRARY_VALS && 328 if (HASFLAG(setting, F_ALLOW_ARBITRARY_VALS) &&
322 table_setting_array_position != -1 && 329 table_setting_array_position != -1 &&
323 (selection >= table_setting_array_position)) 330 (selection >= table_setting_array_position))
324 { 331 {
@@ -329,7 +336,7 @@ static int selection_to_val(const struct settings_list *setting, int selection)
329 else 336 else
330 return info->values[selection]; 337 return info->values[selection];
331 } 338 }
332 else if ((setting->flags & F_T_SOUND) == F_T_SOUND) 339 else if (HASFLAG(setting, F_T_SOUND))
333 { 340 {
334 int setting_id = setting->sound_setting->setting; 341 int setting_id = setting->sound_setting->setting;
335 if(global_settings.list_order == LIST_ORDER_DESCENDING) 342 if(global_settings.list_order == LIST_ORDER_DESCENDING)
@@ -346,7 +353,7 @@ static int selection_to_val(const struct settings_list *setting, int selection)
346 max = sound_min(setting_id); 353 max = sound_min(setting_id);
347 } 354 }
348 } 355 }
349 else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING) 356 else if (HASFLAG(setting, F_INT_SETTING))
350 { 357 {
351 const struct int_setting *info = setting->int_setting; 358 const struct int_setting *info = setting->int_setting;
352 if(global_settings.list_order == LIST_ORDER_DESCENDING) 359 if(global_settings.list_order == LIST_ORDER_DESCENDING)
@@ -392,13 +399,13 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue,
392 /* set the number of items and current selection */ 399 /* set the number of items and current selection */
393 if (var_type == F_T_INT || var_type == F_T_UINT) 400 if (var_type == F_T_INT || var_type == F_T_UINT)
394 { 401 {
395 if (setting->flags&F_CHOICE_SETTING) 402 if (HASFLAG(setting, F_CHOICE_SETTING))
396 { 403 {
397 *nb_items = setting->choice_setting->count; 404 *nb_items = setting->choice_setting->count;
398 *selected = oldvalue; 405 *selected = oldvalue;
399 *function = setting->choice_setting->option_callback; 406 *function = setting->choice_setting->option_callback;
400 } 407 }
401 else if (setting->flags&F_TABLE_SETTING) 408 else if (HASFLAG(setting, F_TABLE_SETTING))
402 { 409 {
403 const struct table_setting *info = setting->table_setting; 410 const struct table_setting *info = setting->table_setting;
404 int i; 411 int i;
@@ -407,7 +414,7 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue,
407 table_setting_array_position = -1; 414 table_setting_array_position = -1;
408 for (i=0;*selected==-1 && i<*nb_items;i++) 415 for (i=0;*selected==-1 && i<*nb_items;i++)
409 { 416 {
410 if (setting->flags&F_ALLOW_ARBITRARY_VALS && 417 if (HASFLAG(setting, F_ALLOW_ARBITRARY_VALS) &&
411 (oldvalue < info->values[i])) 418 (oldvalue < info->values[i]))
412 { 419 {
413 table_setting_oldval = oldvalue; 420 table_setting_oldval = oldvalue;
@@ -420,7 +427,7 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue,
420 } 427 }
421 *function = info->option_callback; 428 *function = info->option_callback;
422 } 429 }
423 else if (setting->flags&F_T_SOUND) 430 else if (HASFLAG(setting, F_T_SOUND))
424 { 431 {
425 int setting_id = setting->sound_setting->setting; 432 int setting_id = setting->sound_setting->setting;
426 int steps = sound_steps(setting_id); 433 int steps = sound_steps(setting_id);
@@ -468,11 +475,9 @@ bool option_screen(const struct settings_list *setting,
468 struct gui_synclist lists; 475 struct gui_synclist lists;
469 int oldvalue, nb_items = 0, selected = 0, temp_var; 476 int oldvalue, nb_items = 0, selected = 0, temp_var;
470 int *variable; 477 int *variable;
471 bool allow_wrap = setting->flags & F_NO_WRAP ? false : true; 478 bool allow_wrap = (!HASFLAG(setting, F_NO_WRAP));
472 bool cb_on_select_only = 479 bool cb_on_select_only = HASFLAG(setting, F_CB_ON_SELECT_ONLY);
473 ((setting->flags & F_CB_ON_SELECT_ONLY) == F_CB_ON_SELECT_ONLY); 480 bool cb_on_changed = HASFLAG(setting, F_CB_ONLY_IF_CHANGED);
474 bool cb_on_changed =
475 ((setting->flags & F_CB_ONLY_IF_CHANGED) == F_CB_ONLY_IF_CHANGED);
476 481
477 int var_type = setting->flags&F_T_MASK; 482 int var_type = setting->flags&F_T_MASK;
478 void (*function)(int) = NULL; 483 void (*function)(int) = NULL;
@@ -564,27 +569,26 @@ bool option_screen(const struct settings_list *setting,
564 } 569 }
565 settings_save(); 570 settings_save();
566 done = true; 571 done = true;
567 572 cb_on_select_only = false; /* unset the flag so callback can be called */
568 if (cb_on_select_only && function)
569 {
570 if (!cb_on_changed || (*variable != oldvalue))
571 function(*variable);
572 }
573 } 573 }
574 else if(default_event_handler(action) == SYS_USB_CONNECTED) 574 else if(default_event_handler(action) == SYS_USB_CONNECTED)
575 { 575 {
576 pop_current_activity(); 576 pop_current_activity();
577 return true; 577 return true;
578 } 578 }
579
579 /* callback */ 580 /* callback */
580 if (function && !cb_on_select_only) 581 if (!cb_on_select_only && function)
581 { 582 {
582 if (!cb_on_changed || (*variable != oldvalue)) 583 if (!cb_on_changed || (*variable != oldvalue))
584 {
583 function(*variable); 585 function(*variable);
586 /* if the volume is changing we need to let the skins know */
587 if (function == sound_get_fn(SOUND_VOLUME))
588 global_status.last_volume_change = current_tick;
589 }
584 } 590 }
585 /* if the volume is changing we need to let the skins know */ 591
586 if (function == sound_get_fn(SOUND_VOLUME))
587 global_status.last_volume_change = current_tick;
588 } 592 }
589 pop_current_activity(); 593 pop_current_activity();
590 return false; 594 return false;