2005-11-22 03:38:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Kevin Ferrare
|
2007-07-11 05:41:23 +00:00
|
|
|
* Copyright (C) 2007 by Jonathan Gordon
|
2005-11-22 03:38:07 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-11-22 03:38:07 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-07-11 05:41:23 +00:00
|
|
|
#include <stdlib.h>
|
2010-05-06 21:04:40 +00:00
|
|
|
#include "string-extra.h"
|
2007-07-11 05:41:23 +00:00
|
|
|
#include "config.h"
|
2012-03-27 23:52:15 +00:00
|
|
|
#include "system.h"
|
2005-11-22 03:38:07 +00:00
|
|
|
#include "option_select.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "lang.h"
|
2007-07-11 05:41:23 +00:00
|
|
|
#include "talk.h"
|
|
|
|
#include "settings_list.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "action.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "splash.h"
|
2008-11-05 09:30:20 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "quickscreen.h"
|
2007-07-11 05:41:23 +00:00
|
|
|
|
2007-10-15 10:33:01 +00:00
|
|
|
|
2008-05-15 06:58:36 +00:00
|
|
|
static int selection_to_val(const struct settings_list *setting, int selection);
|
2008-05-28 10:55:39 +00:00
|
|
|
int option_value_as_int(const struct settings_list *setting)
|
|
|
|
{
|
|
|
|
int type = (setting->flags & F_T_MASK);
|
|
|
|
int temp = 0;
|
|
|
|
if (type == F_T_BOOL)
|
|
|
|
temp = *(bool*)setting->setting?1:0;
|
|
|
|
else if (type == F_T_UINT || type == F_T_INT)
|
|
|
|
temp = *(int*)setting->setting;
|
|
|
|
return temp;
|
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
static const char *unit_strings[] =
|
|
|
|
{
|
|
|
|
[UNIT_INT] = "", [UNIT_MS] = "ms",
|
|
|
|
[UNIT_SEC] = "s", [UNIT_MIN] = "min",
|
2007-11-26 23:10:20 +00:00
|
|
|
[UNIT_HOUR]= "hr", [UNIT_KHZ] = "kHz",
|
2007-07-11 05:41:23 +00:00
|
|
|
[UNIT_DB] = "dB", [UNIT_PERCENT] = "%",
|
|
|
|
[UNIT_MAH] = "mAh", [UNIT_PIXEL] = "px",
|
|
|
|
[UNIT_PER_SEC] = "per sec",
|
|
|
|
[UNIT_HERTZ] = "Hz",
|
|
|
|
[UNIT_MB] = "MB", [UNIT_KBIT] = "kb/s",
|
2007-08-18 23:03:03 +00:00
|
|
|
[UNIT_PM_TICK] = "units/10ms",
|
2007-07-11 05:41:23 +00:00
|
|
|
};
|
2007-11-25 17:36:21 +00:00
|
|
|
/* these two vars are needed so arbitrary values can be added to the
|
|
|
|
TABLE_SETTING settings if the F_ALLOW_ARBITRARY_VALS flag is set */
|
|
|
|
static int table_setting_oldval = 0, table_setting_array_position = 0;
|
2009-08-20 16:47:44 +00:00
|
|
|
const char *option_get_valuestring(const struct settings_list *setting,
|
|
|
|
char *buffer, int buf_len,
|
|
|
|
intptr_t temp_var)
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
2009-08-20 16:47:44 +00:00
|
|
|
const char* str = buffer;
|
2007-07-11 05:41:23 +00:00
|
|
|
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
|
|
|
|
{
|
|
|
|
bool val = (bool)temp_var;
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(buffer, str(val? setting->bool_setting->lang_yes :
|
2008-09-24 20:03:53 +00:00
|
|
|
setting->bool_setting->lang_no), buf_len);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
#if 0 /* probably dont need this one */
|
|
|
|
else if ((setting->flags & F_FILENAME) == F_FILENAME)
|
|
|
|
{
|
|
|
|
struct filename_setting *info = setting->filename_setting;
|
|
|
|
snprintf(buffer, buf_len, "%s%s%s", info->prefix,
|
|
|
|
(char*)temp_var, info->suffix);
|
|
|
|
}
|
|
|
|
#endif
|
2007-11-25 17:36:21 +00:00
|
|
|
else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) ||
|
|
|
|
((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING))
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
2007-11-25 17:36:21 +00:00
|
|
|
const struct int_setting *int_info = setting->int_setting;
|
|
|
|
const struct table_setting *tbl_info = setting->table_setting;
|
|
|
|
const char *unit;
|
2009-08-20 16:47:44 +00:00
|
|
|
const char* (*formatter)(char*, size_t, int, const char*);
|
2007-11-25 17:36:21 +00:00
|
|
|
if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
|
|
|
|
{
|
|
|
|
formatter = int_info->formatter;
|
|
|
|
unit = unit_strings[int_info->unit];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
formatter = tbl_info->formatter;
|
|
|
|
unit = unit_strings[tbl_info->unit];
|
|
|
|
}
|
|
|
|
if (formatter)
|
2009-08-20 16:47:44 +00:00
|
|
|
str = formatter(buffer, buf_len, (int)temp_var, unit);
|
2007-07-11 05:41:23 +00:00
|
|
|
else
|
2007-11-25 17:36:21 +00:00
|
|
|
snprintf(buffer, buf_len, "%d %s", (int)temp_var, unit?unit:"");
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
|
|
|
|
{
|
2009-10-10 09:55:28 +00:00
|
|
|
char sign = ' ';
|
|
|
|
const char *unit = sound_unit(setting->sound_setting->setting);
|
2010-05-12 05:23:02 +00:00
|
|
|
int val = sound_val2phys(setting->sound_setting->setting, (int)temp_var);
|
2007-07-11 05:41:23 +00:00
|
|
|
if (sound_numdecimals(setting->sound_setting->setting))
|
|
|
|
{
|
|
|
|
int integer, dec;
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
sign = '-';
|
|
|
|
val = abs(val);
|
|
|
|
}
|
2009-10-10 09:55:28 +00:00
|
|
|
integer = val / 10;
|
|
|
|
dec = val % 10;
|
2007-07-11 05:41:23 +00:00
|
|
|
snprintf(buffer, buf_len, "%c%d.%d %s", sign, integer, dec, unit);
|
|
|
|
}
|
|
|
|
else
|
2010-05-12 05:23:02 +00:00
|
|
|
snprintf(buffer, buf_len, "%d %s", val, unit);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)
|
|
|
|
{
|
|
|
|
if (setting->flags & F_CHOICETALKS)
|
|
|
|
{
|
|
|
|
int setting_id;
|
2007-11-25 17:36:21 +00:00
|
|
|
const struct choice_setting *info = setting->choice_setting;
|
2007-08-15 13:16:16 +00:00
|
|
|
if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY)
|
|
|
|
{
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(buffer, str(info->talks[(int)temp_var]), buf_len);
|
2007-08-15 13:16:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
find_setting(setting->setting, &setting_id);
|
|
|
|
cfg_int_to_string(setting_id, (int)temp_var, buffer, buf_len);
|
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-10 09:55:28 +00:00
|
|
|
int value = (int)temp_var;
|
2007-07-11 05:41:23 +00:00
|
|
|
char *val = P2STR(setting->choice_setting->desc[value]);
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(buffer, val, buf_len);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-20 16:47:44 +00:00
|
|
|
return str;
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2008-05-04 08:11:28 +00:00
|
|
|
void option_talk_value(const struct settings_list *setting, int value, bool enqueue)
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
|
|
|
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
|
|
|
|
{
|
2009-05-21 14:15:24 +00:00
|
|
|
bool val = (value==1);
|
2007-07-11 05:41:23 +00:00
|
|
|
talk_id(val? setting->bool_setting->lang_yes :
|
2008-05-04 08:11:28 +00:00
|
|
|
setting->bool_setting->lang_no, enqueue);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
#if 0 /* probably dont need this one */
|
|
|
|
else if ((setting->flags & F_FILENAME) == F_FILENAME)
|
|
|
|
{
|
2008-05-04 08:11:28 +00:00
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
#endif
|
2007-11-25 17:36:21 +00:00
|
|
|
else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) ||
|
2008-05-04 08:11:28 +00:00
|
|
|
((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING))
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
2007-11-25 17:36:21 +00:00
|
|
|
const struct int_setting *int_info = setting->int_setting;
|
|
|
|
const struct table_setting *tbl_info = setting->table_setting;
|
|
|
|
int unit;
|
2007-11-26 23:10:20 +00:00
|
|
|
int32_t (*get_talk_id)(int, int);
|
2007-11-25 17:36:21 +00:00
|
|
|
if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
|
|
|
|
{
|
|
|
|
unit = int_info->unit;
|
|
|
|
get_talk_id = int_info->get_talk_id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit = tbl_info->unit;
|
|
|
|
get_talk_id = tbl_info->get_talk_id;
|
|
|
|
}
|
|
|
|
if (get_talk_id)
|
2008-05-04 08:11:28 +00:00
|
|
|
talk_id(get_talk_id(value, unit), enqueue);
|
2007-11-25 17:36:21 +00:00
|
|
|
else
|
2008-05-04 08:11:28 +00:00
|
|
|
talk_value(value, unit, enqueue);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
|
|
|
|
{
|
2007-11-24 11:18:29 +00:00
|
|
|
int talkunit = UNIT_INT;
|
2010-05-12 06:44:29 +00:00
|
|
|
int sound_setting = setting->sound_setting->setting;
|
|
|
|
const char *unit = sound_unit(sound_setting);
|
|
|
|
int decimals = sound_numdecimals(sound_setting);
|
|
|
|
int phys = sound_val2phys(sound_setting, value);
|
2007-11-24 11:18:29 +00:00
|
|
|
if (!strcmp(unit, "dB"))
|
|
|
|
talkunit = UNIT_DB;
|
|
|
|
else if (!strcmp(unit, "%"))
|
2007-07-11 05:41:23 +00:00
|
|
|
talkunit = UNIT_PERCENT;
|
2007-11-24 11:18:29 +00:00
|
|
|
else if (!strcmp(unit, "Hz"))
|
2007-07-11 05:41:23 +00:00
|
|
|
talkunit = UNIT_HERTZ;
|
2010-05-12 06:44:29 +00:00
|
|
|
talk_value_decimal(phys, talkunit, decimals, false);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)
|
|
|
|
{
|
|
|
|
if (setting->flags & F_CHOICETALKS)
|
|
|
|
{
|
2008-05-04 08:11:28 +00:00
|
|
|
talk_id(setting->choice_setting->talks[value], enqueue);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-04 08:11:28 +00:00
|
|
|
talk_id(P2ID(setting->choice_setting->desc[value]), enqueue);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-04 08:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int option_talk(int selected_item, void * data)
|
|
|
|
{
|
|
|
|
struct settings_list *setting = (struct settings_list *)data;
|
|
|
|
int temp_var = selection_to_val(setting, selected_item);
|
|
|
|
option_talk_value(setting, temp_var, false);
|
2007-10-21 00:22:49 +00:00
|
|
|
return 0;
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2008-02-05 09:09:38 +00:00
|
|
|
|
2010-09-06 13:33:49 +00:00
|
|
|
#if defined(HAVE_QUICKSCREEN) || defined(HAVE_RECORDING) || defined(HAVE_TOUCHSCREEN)
|
2008-05-28 10:55:39 +00:00
|
|
|
/* only the quickscreen and recording trigger needs this */
|
2008-05-15 06:58:36 +00:00
|
|
|
void option_select_next_val(const struct settings_list *setting,
|
2008-05-03 12:30:40 +00:00
|
|
|
bool previous, bool apply)
|
2008-02-05 09:09:38 +00:00
|
|
|
{
|
|
|
|
int val = 0;
|
2008-05-03 12:30:40 +00:00
|
|
|
int *value = setting->setting;
|
2008-02-05 09:09:38 +00:00
|
|
|
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
|
|
|
|
{
|
2008-05-03 12:30:40 +00:00
|
|
|
*(bool*)value = !*(bool*)value;
|
|
|
|
if (apply && setting->bool_setting->option_callback)
|
|
|
|
setting->bool_setting->option_callback(*(bool*)value);
|
|
|
|
return;
|
2008-02-05 09:09:38 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
|
|
|
|
{
|
2008-05-03 12:30:40 +00:00
|
|
|
struct int_setting *info = (struct int_setting *)setting->int_setting;
|
2009-10-03 12:56:16 +00:00
|
|
|
bool neg_step = (info->step < 0);
|
2008-05-03 12:30:40 +00:00
|
|
|
if (!previous)
|
|
|
|
{
|
2009-10-03 12:56:16 +00:00
|
|
|
val = *value + info->step;
|
|
|
|
if (neg_step ? (val < info->max) : (val > info->max))
|
2008-05-03 12:30:40 +00:00
|
|
|
val = info->min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-03 12:56:16 +00:00
|
|
|
val = *value - info->step;
|
|
|
|
if (neg_step ? (val > info->min) : (val < info->min))
|
2008-05-03 12:30:40 +00:00
|
|
|
val = info->max;
|
|
|
|
}
|
2009-10-03 12:56:16 +00:00
|
|
|
*value = val;
|
2008-05-03 12:30:40 +00:00
|
|
|
if (apply && info->option_callback)
|
2008-05-28 10:41:07 +00:00
|
|
|
info->option_callback(val);
|
2008-02-05 09:09:38 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
|
|
|
|
{
|
|
|
|
int setting_id = setting->sound_setting->setting;
|
|
|
|
int steps = sound_steps(setting_id);
|
|
|
|
int min = sound_min(setting_id);
|
|
|
|
int max = sound_max(setting_id);
|
2008-05-03 12:30:40 +00:00
|
|
|
if (!previous)
|
|
|
|
{
|
|
|
|
val = *value + steps;
|
|
|
|
if (val >= max)
|
|
|
|
val = min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = *value - steps;
|
|
|
|
if (val < min)
|
|
|
|
val = max;
|
|
|
|
}
|
2009-10-03 12:56:16 +00:00
|
|
|
*value = val;
|
2011-09-07 13:33:05 +00:00
|
|
|
if (apply)
|
|
|
|
sound_set(setting_id, val);
|
2008-02-05 09:09:38 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)
|
|
|
|
{
|
2008-05-03 12:30:40 +00:00
|
|
|
struct choice_setting *info = (struct choice_setting *)setting->choice_setting;
|
|
|
|
if (!previous)
|
|
|
|
{
|
|
|
|
val = *value + 1;
|
|
|
|
if (val >= info->count)
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = *value - 1;
|
|
|
|
if (val < 0)
|
|
|
|
val = info->count-1;
|
|
|
|
}
|
2009-10-03 12:56:16 +00:00
|
|
|
*value = val;
|
2008-05-03 12:30:40 +00:00
|
|
|
if (apply && info->option_callback)
|
2008-05-28 10:41:07 +00:00
|
|
|
info->option_callback(val);
|
2008-02-05 09:09:38 +00:00
|
|
|
}
|
2008-05-15 06:58:36 +00:00
|
|
|
else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)
|
|
|
|
{
|
|
|
|
const struct table_setting *tbl_info = setting->table_setting;
|
|
|
|
int i, add;
|
|
|
|
add = previous?tbl_info->count-1:1;
|
|
|
|
for (i=0; i<tbl_info->count;i++)
|
|
|
|
{
|
|
|
|
if ((*value == tbl_info->values[i]) ||
|
|
|
|
(settings->flags&F_ALLOW_ARBITRARY_VALS &&
|
|
|
|
*value < tbl_info->values[i]))
|
|
|
|
{
|
|
|
|
val = tbl_info->values[(i+add)%tbl_info->count];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-03 12:56:16 +00:00
|
|
|
*value = val;
|
2011-09-07 13:33:05 +00:00
|
|
|
if (apply && tbl_info->option_callback)
|
|
|
|
tbl_info->option_callback(val);
|
2008-05-15 06:58:36 +00:00
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2008-02-05 08:21:54 +00:00
|
|
|
#endif
|
2007-07-11 05:41:23 +00:00
|
|
|
|
2008-05-15 06:58:36 +00:00
|
|
|
static int selection_to_val(const struct settings_list *setting, int selection)
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
2011-05-01 13:48:28 +00:00
|
|
|
/* rockbox: comment 'set but unused' variables
|
|
|
|
int min = 0;
|
|
|
|
*/
|
|
|
|
int max = 0, step = 1;
|
2007-07-11 05:41:23 +00:00
|
|
|
if (((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) ||
|
|
|
|
((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING))
|
|
|
|
return selection;
|
2007-11-25 17:36:21 +00:00
|
|
|
else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)
|
|
|
|
{
|
|
|
|
const struct table_setting *info = setting->table_setting;
|
|
|
|
if (setting->flags&F_ALLOW_ARBITRARY_VALS &&
|
|
|
|
table_setting_array_position != -1 &&
|
|
|
|
(selection >= table_setting_array_position))
|
|
|
|
{
|
|
|
|
if (selection == table_setting_array_position)
|
|
|
|
return table_setting_oldval;
|
|
|
|
return info->values[selection-1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return info->values[selection];
|
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
|
|
|
|
{
|
|
|
|
int setting_id = setting->sound_setting->setting;
|
2007-10-15 10:33:01 +00:00
|
|
|
#ifndef ASCENDING_INT_SETTINGS
|
2007-07-11 05:41:23 +00:00
|
|
|
step = sound_steps(setting_id);
|
|
|
|
max = sound_max(setting_id);
|
2011-05-01 13:48:28 +00:00
|
|
|
/* min = sound_min(setting_id); */
|
2007-10-15 10:33:01 +00:00
|
|
|
#else
|
|
|
|
step = -sound_steps(setting_id);
|
2011-05-01 13:48:28 +00:00
|
|
|
/* min = sound_max(setting_id); */
|
2007-10-15 10:33:01 +00:00
|
|
|
max = sound_min(setting_id);
|
|
|
|
#endif
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
|
|
|
|
{
|
2007-11-25 17:36:21 +00:00
|
|
|
const struct int_setting *info = setting->int_setting;
|
2007-10-15 10:33:01 +00:00
|
|
|
#ifndef ASCENDING_INT_SETTINGS
|
2011-05-01 13:48:28 +00:00
|
|
|
/* min = info->min; */
|
2007-07-11 05:41:23 +00:00
|
|
|
max = info->max;
|
|
|
|
step = info->step;
|
2007-10-15 07:57:11 +00:00
|
|
|
#else
|
|
|
|
max = info->min;
|
2011-05-01 13:48:28 +00:00
|
|
|
/* min = info->max; */
|
2007-10-15 07:57:11 +00:00
|
|
|
step = -info->step;
|
|
|
|
#endif
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
return max- (selection * step);
|
|
|
|
}
|
2009-08-20 16:47:44 +00:00
|
|
|
|
|
|
|
static const char * value_setting_get_name_cb(int selected_item,
|
|
|
|
void * data,
|
|
|
|
char *buffer,
|
|
|
|
size_t buffer_len)
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
|
|
|
selected_item = selection_to_val(data, selected_item);
|
2008-04-09 15:25:17 +00:00
|
|
|
return option_get_valuestring(data, buffer, buffer_len, selected_item);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wrapper to convert from int param to bool param in option_screen */
|
|
|
|
static void (*boolfunction)(bool);
|
|
|
|
static void bool_funcwrapper(int value)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
boolfunction(true);
|
|
|
|
else
|
|
|
|
boolfunction(false);
|
|
|
|
}
|
|
|
|
|
2008-05-15 06:58:36 +00:00
|
|
|
static void val_to_selection(const struct settings_list *setting, int oldvalue,
|
2008-04-20 14:12:28 +00:00
|
|
|
int *nb_items, int *selected,
|
|
|
|
void (**function)(int))
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
|
|
|
int var_type = setting->flags&F_T_MASK;
|
|
|
|
/* 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)
|
|
|
|
{
|
2008-04-20 14:12:28 +00:00
|
|
|
*nb_items = setting->choice_setting->count;
|
|
|
|
*selected = oldvalue;
|
|
|
|
*function = setting->choice_setting->option_callback;
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2007-11-25 17:36:21 +00:00
|
|
|
else if (setting->flags&F_TABLE_SETTING)
|
|
|
|
{
|
|
|
|
const struct table_setting *info = setting->table_setting;
|
|
|
|
int i;
|
2008-04-20 14:12:28 +00:00
|
|
|
*nb_items = info->count;
|
|
|
|
*selected = -1;
|
2007-11-25 17:36:21 +00:00
|
|
|
table_setting_array_position = -1;
|
2008-04-20 14:12:28 +00:00
|
|
|
for (i=0;*selected==-1 && i<*nb_items;i++)
|
2007-11-25 17:36:21 +00:00
|
|
|
{
|
|
|
|
if (setting->flags&F_ALLOW_ARBITRARY_VALS &&
|
|
|
|
(oldvalue < info->values[i]))
|
|
|
|
{
|
|
|
|
table_setting_oldval = oldvalue;
|
|
|
|
table_setting_array_position = i;
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = i;
|
2008-04-20 14:44:36 +00:00
|
|
|
(*nb_items)++;
|
2007-11-25 17:36:21 +00:00
|
|
|
}
|
|
|
|
else if (oldvalue == info->values[i])
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = i;
|
2007-11-25 17:36:21 +00:00
|
|
|
}
|
2008-04-20 14:12:28 +00:00
|
|
|
*function = info->option_callback;
|
2007-11-25 17:36:21 +00:00
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
else if (setting->flags&F_T_SOUND)
|
|
|
|
{
|
|
|
|
int setting_id = setting->sound_setting->setting;
|
|
|
|
int steps = sound_steps(setting_id);
|
|
|
|
int min = sound_min(setting_id);
|
|
|
|
int max = sound_max(setting_id);
|
2008-04-20 14:12:28 +00:00
|
|
|
*nb_items = (max-min)/steps + 1;
|
2007-10-15 12:34:43 +00:00
|
|
|
#ifndef ASCENDING_INT_SETTINGS
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = (max - oldvalue) / steps;
|
2007-10-15 12:34:43 +00:00
|
|
|
#else
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = (oldvalue - min) / steps;
|
2007-10-15 12:34:43 +00:00
|
|
|
#endif
|
2008-04-20 14:12:28 +00:00
|
|
|
*function = sound_get_fn(setting_id);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-25 17:36:21 +00:00
|
|
|
const struct int_setting *info = setting->int_setting;
|
2007-07-11 05:41:23 +00:00
|
|
|
int min, max, step;
|
2007-10-15 10:33:01 +00:00
|
|
|
max = info->max;
|
|
|
|
min = info->min;
|
|
|
|
step = info->step;
|
2008-04-20 14:12:28 +00:00
|
|
|
*nb_items = (max-min)/step + 1;
|
2007-10-15 12:34:43 +00:00
|
|
|
#ifndef ASCENDING_INT_SETTINGS
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = (max - oldvalue) / step;
|
2007-10-15 12:34:43 +00:00
|
|
|
#else
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = (oldvalue - min) / step;
|
2007-10-15 12:34:43 +00:00
|
|
|
#endif
|
2008-04-20 14:12:28 +00:00
|
|
|
*function = info->option_callback;
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (var_type == F_T_BOOL)
|
|
|
|
{
|
2008-04-20 14:12:28 +00:00
|
|
|
*selected = oldvalue;
|
|
|
|
*nb_items = 2;
|
2007-07-11 05:41:23 +00:00
|
|
|
boolfunction = setting->bool_setting->option_callback;
|
|
|
|
if (boolfunction)
|
2008-04-20 14:12:28 +00:00
|
|
|
*function = bool_funcwrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-15 06:58:36 +00:00
|
|
|
bool option_screen(const struct settings_list *setting,
|
2008-04-23 11:07:40 +00:00
|
|
|
struct viewport parent[NB_SCREENS],
|
2008-04-20 14:12:28 +00:00
|
|
|
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;
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2008-04-20 14:12:28 +00:00
|
|
|
else return false; /* only int/bools can go here */
|
2011-06-01 14:41:49 +00:00
|
|
|
push_current_activity(ACTIVITY_OPTIONSELECT);
|
2008-04-20 14:12:28 +00:00
|
|
|
gui_synclist_init(&lists, value_setting_get_name_cb,
|
2008-04-23 11:07:40 +00:00
|
|
|
(void*)setting, false, 1, parent);
|
2008-04-20 14:12:28 +00:00
|
|
|
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);
|
2007-07-11 05:41:23 +00:00
|
|
|
gui_synclist_set_nb_items(&lists, nb_items);
|
|
|
|
gui_synclist_select_item(&lists, selected);
|
|
|
|
|
|
|
|
gui_synclist_limit_scroll(&lists, true);
|
|
|
|
gui_synclist_draw(&lists);
|
|
|
|
/* talk the item */
|
2007-10-21 00:22:49 +00:00
|
|
|
gui_synclist_speak_item(&lists);
|
2007-07-11 05:41:23 +00:00
|
|
|
while (!done)
|
|
|
|
{
|
2009-12-18 06:51:36 +00:00
|
|
|
if (list_do_action(CONTEXT_LIST, HZ, /* HZ so the status bar redraws */
|
2007-10-21 00:22:49 +00:00
|
|
|
&lists, &action,
|
2007-07-11 05:41:23 +00:00
|
|
|
allow_wrap? LIST_WRAP_UNLESS_HELD: LIST_WRAP_OFF))
|
|
|
|
{
|
2008-07-17 13:04:11 +00:00
|
|
|
/* setting changed */
|
2007-07-11 05:41:23 +00:00
|
|
|
selected = gui_synclist_get_sel_pos(&lists);
|
|
|
|
*variable = selection_to_val(setting, selected);
|
2008-07-17 13:04:11 +00:00
|
|
|
if (var_type == F_T_BOOL && !use_temp_var)
|
|
|
|
*(bool*)setting->setting = (*variable==1);
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2007-10-21 00:22:49 +00:00
|
|
|
else if (action == ACTION_NONE)
|
|
|
|
continue;
|
2007-07-11 05:41:23 +00:00
|
|
|
else if (action == ACTION_STD_CANCEL)
|
|
|
|
{
|
2008-07-17 13:04:11 +00:00
|
|
|
/* setting canceled, restore old value if changed */
|
|
|
|
if (*variable != oldvalue)
|
2007-07-11 05:41:23 +00:00
|
|
|
{
|
2008-07-17 13:04:11 +00:00
|
|
|
*variable = oldvalue;
|
|
|
|
if (var_type == F_T_BOOL && !use_temp_var)
|
|
|
|
*(bool*)setting->setting = (oldvalue==1);
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ/2, ID2P(LANG_CANCEL));
|
2008-07-17 13:04:11 +00:00
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
done = true;
|
|
|
|
}
|
2008-04-20 14:12:28 +00:00
|
|
|
else if (action == ACTION_STD_CONTEXT)
|
|
|
|
{
|
2008-07-17 13:04:11 +00:00
|
|
|
/* reset setting to default */
|
2008-04-20 14:12:28 +00:00
|
|
|
reset_setting(setting, variable);
|
|
|
|
if (var_type == F_T_BOOL && !use_temp_var)
|
2008-07-17 13:04:11 +00:00
|
|
|
*(bool*)setting->setting = (*variable==1);
|
2008-04-20 14:12:28 +00:00
|
|
|
val_to_selection(setting, *variable, &nb_items,
|
2008-11-05 09:30:20 +00:00
|
|
|
&selected, &function);
|
2008-04-20 14:12:28 +00:00
|
|
|
gui_synclist_select_item(&lists, selected);
|
|
|
|
gui_synclist_draw(&lists);
|
|
|
|
gui_synclist_speak_item(&lists);
|
|
|
|
}
|
2007-07-11 05:41:23 +00:00
|
|
|
else if (action == ACTION_STD_OK)
|
|
|
|
{
|
2008-07-17 13:04:11 +00:00
|
|
|
/* setting accepted, store now if it used a temp var */
|
|
|
|
if (use_temp_var)
|
|
|
|
{
|
|
|
|
if (var_type == F_T_INT || var_type == F_T_UINT)
|
|
|
|
*(int*)setting->setting = *variable;
|
|
|
|
else
|
|
|
|
*(bool*)setting->setting = (*variable==1);
|
|
|
|
}
|
|
|
|
settings_save();
|
2007-07-11 05:41:23 +00:00
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else if(default_event_handler(action) == SYS_USB_CONNECTED)
|
|
|
|
return true;
|
|
|
|
/* callback */
|
|
|
|
if ( function )
|
|
|
|
function(*variable);
|
2009-11-01 02:36:51 +00:00
|
|
|
/* if the volume is changing we need to let the skins know */
|
|
|
|
if (function == sound_get_fn(SOUND_VOLUME))
|
|
|
|
global_status.last_volume_change = current_tick;
|
2007-07-11 05:41:23 +00:00
|
|
|
}
|
2011-06-01 14:41:49 +00:00
|
|
|
pop_current_activity();
|
2007-07-11 05:41:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-17 13:04:11 +00:00
|
|
|
|