1
0
Fork 0
forked from len0rd/rockbox

Make volume and battery level enums dynamic, inspired by patch 4802. Almost backwards compatible; for the battery level, the first enum is used when the level is unknown, while the remaining enums are used as before.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10756 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2006-08-26 13:25:33 +00:00
parent 5f74d61357
commit dd87c364a0

View file

@ -456,6 +456,7 @@ static char* get_tag(struct wps_data* wps_data,
int *intval) int *intval)
{ {
struct mp3entry *id3 = cid3; /* default to current song */ struct mp3entry *id3 = cid3; /* default to current song */
int limit = *intval;
#ifndef HAVE_LCD_CHARCELLS #ifndef HAVE_LCD_CHARCELLS
(void)wps_data; (void)wps_data;
#endif #endif
@ -705,7 +706,7 @@ static char* get_tag(struct wps_data* wps_data,
case 'v': /* volume */ case 'v': /* volume */
*flags |= WPS_REFRESH_DYNAMIC; *flags |= WPS_REFRESH_DYNAMIC;
snprintf(buf, buf_size, "%d", global_settings.volume); snprintf(buf, buf_size, "%d", global_settings.volume);
*intval = 10 * (global_settings.volume *intval = limit * (global_settings.volume
- sound_min(SOUND_VOLUME)) - sound_min(SOUND_VOLUME))
/ (sound_max(SOUND_VOLUME) / (sound_max(SOUND_VOLUME)
- sound_min(SOUND_VOLUME)) + 1; - sound_min(SOUND_VOLUME)) + 1;
@ -780,14 +781,16 @@ static char* get_tag(struct wps_data* wps_data,
case 'l': /* battery level */ case 'l': /* battery level */
{ {
int l = battery_level(); int l = battery_level();
limit = MAX(limit, 2);
if (l > -1) if (l > -1)
{ {
snprintf(buf, buf_size, "%d", l); snprintf(buf, buf_size, "%d", l);
*intval = l / 20 + 1; /* First enum is used for "unknown level". */
*intval = (limit - 1) * l / 100 + 1 + 1;
} }
else else
{ {
*intval = 6; *intval = 0;
return "?"; return "?";
} }
return buf; return buf;
@ -1121,11 +1124,14 @@ static void clear_image_pos(struct gui_wps *gwps, int n)
* fmt - string to skip it. Should point to somewhere after the leading * fmt - string to skip it. Should point to somewhere after the leading
* "<" char (and before or at the last ">"). * "<" char (and before or at the last ">").
* num - number of |'s to skip, or 0 to skip to the end (the ">"). * num - number of |'s to skip, or 0 to skip to the end (the ">").
* enums - If not NULL, set to the number of |'s found in the current
* conditional (sub-conditionals are ignored). num should be 0
* to find all |'s.
* *
* Returns the new position in fmt. * Returns the new position in fmt.
*/ */
static const char* skip_conditional(struct gui_wps *gwps, const char* fmt, static const char* skip_conditional(struct gui_wps *gwps, const char* fmt,
int num) int num, int *enums)
{ {
int level = 1; int level = 1;
int count = num; int count = num;
@ -1135,6 +1141,8 @@ static const char* skip_conditional(struct gui_wps *gwps, const char* fmt,
int last_x=-1, last_y=-1, last_w=-1, last_h=-1; int last_x=-1, last_y=-1, last_w=-1, last_h=-1;
if(gwps) if(gwps)
data = gwps->data; data = gwps->data;
if (enums)
*enums = 0;
#else #else
(void)gwps; (void)gwps;
#endif #endif
@ -1168,6 +1176,8 @@ static const char* skip_conditional(struct gui_wps *gwps, const char* fmt,
case '|': case '|':
if(1 == level) { if(1 == level) {
if (enums)
(*enums)++;
last_alternative = fmt; last_alternative = fmt;
if(num) { if(num) {
count--; count--;
@ -1279,7 +1289,7 @@ static void format_display(struct gui_wps *gwps, char* buf,
case '>': case '>':
if (level > 0) if (level > 0)
{ {
fmt = skip_conditional(NULL,fmt, 0); fmt = skip_conditional(NULL, fmt, 0, NULL);
level--; level--;
continue; continue;
} }
@ -1366,6 +1376,10 @@ static void format_display(struct gui_wps *gwps, char* buf,
case '?': case '?':
fmt++; fmt++;
/* Get number of "|" chars in the current conditional;
* used by get_tag when calculating levels.
*/
skip_conditional(NULL, fmt, 0, &intval);
value = get_tag(gwps->data, id3, nid3, fmt, temp_buf, value = get_tag(gwps->data, id3, nid3, fmt, temp_buf,
sizeof(temp_buf),&tag_length, sizeof(temp_buf),&tag_length,
subline_time_mult, flags, &intval); subline_time_mult, flags, &intval);
@ -1379,15 +1393,16 @@ static void format_display(struct gui_wps *gwps, char* buf,
/* No value, so skip to else part, using a sufficiently high /* No value, so skip to else part, using a sufficiently high
value to "hit" the last part of the conditional */ value to "hit" the last part of the conditional */
if ((!value) || (!strlen(value))) if ((!value) || (!strlen(value)))
fmt = skip_conditional(gwps, fmt, 1000); fmt = skip_conditional(gwps, fmt, 1000, NULL);
else else
if(intval > 1) /* enum */ if(intval > 1) /* enum */
fmt = skip_conditional(gwps, fmt, intval - 1); fmt = skip_conditional(gwps, fmt, intval - 1, NULL);
level++; level++;
break; break;
default: default:
intval = 1;
value = get_tag(gwps->data, id3, nid3, fmt, temp_buf, value = get_tag(gwps->data, id3, nid3, fmt, temp_buf,
sizeof(temp_buf), &tag_length, sizeof(temp_buf), &tag_length,
subline_time_mult, flags,&intval); subline_time_mult, flags,&intval);