1
0
Fork 0
forked from len0rd/rockbox

Abstracted settings user interface into set_bool, set_int and set_option.

Removed the unnecessary menu entry ids.
Made playlist_shuffle and scroll_speed proper global settings.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1220 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2002-06-27 01:08:11 +00:00
parent b45491df8f
commit 60b356ea25
8 changed files with 173 additions and 246 deletions

View file

@ -31,15 +31,13 @@
#include "sokoban.h"
extern void tetris(void);
enum { Tetris, Sokoban, numgames };
void games_menu(void)
{
int m;
struct menu_items items[] = {
{ Tetris, "Tetris", tetris },
{ Sokoban, "Sokoban", sokoban },
{ "Tetris", tetris },
{ "Sokoban", sokoban },
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );

View file

@ -125,19 +125,16 @@ void show_credits(void)
void main_menu(void)
{
int m;
enum {
Games, Screensavers, Version, Gen_Settings, Sound_Settings,
};
/* main menu */
struct menu_items items[] = {
{ Sound_Settings, "Sound Settings", sound_menu },
{ Gen_Settings, "General Settings", settings_menu },
{ "Sound Settings", sound_menu },
{ "General Settings", settings_menu },
#ifdef HAVE_LCD_BITMAP
{ Games, "Games", games_menu },
{ Screensavers, "Screensavers", screensavers_menu },
{ "Games", games_menu },
{ "Screensavers", screensavers_menu },
#endif
{ Version, "Version", show_credits },
{ "Version", show_credits },
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );

View file

@ -23,7 +23,6 @@
#include <stdbool.h>
struct menu_items {
int id;
char *desc;
void (*function) (void);
};

View file

@ -32,15 +32,13 @@
#include "boxes.h"
extern void bounce(void);
enum { Boxes, Bounce, numsavers };
void screensavers_menu(void)
{
int m;
struct menu_items items[] = {
{ Boxes, "Boxes", boxes },
{ Bounce, "Bounce", bounce },
{ "Boxes", boxes },
{ "Bounce", bounce },
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );

View file

@ -23,6 +23,8 @@
#include "disk.h"
#include "panic.h"
#include "debug.h"
#include "button.h"
#include "lcd.h"
struct user_settings global_settings;
@ -101,3 +103,130 @@ void display_current_settings( struct user_settings *settings )
settings = settings;
#endif
}
void set_bool(char* string, bool* variable )
{
bool done = false;
lcd_clear_display();
lcd_puts_scroll(0,0,string);
while ( !done ) {
lcd_puts(0, 1, *variable ? "on " : "off");
lcd_update();
switch ( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
break;
default:
*variable = !*variable;
break;
}
}
lcd_stop_scroll();
}
void set_int(char* string,
char* unit,
int* variable,
void (*function)(int),
int step,
int min,
int max )
{
bool done = false;
lcd_clear_display();
lcd_puts_scroll(0,0,string);
while (!done) {
char str[32];
snprintf(str,sizeof str,"%d %s ", *variable, unit);
lcd_puts(0,1,str);
lcd_update();
switch( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
*variable += step;
if(*variable > max )
*variable = max;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
*variable -= step;
if(*variable < min )
*variable = min;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
break;
}
if ( function )
function(*variable);
}
lcd_stop_scroll();
}
void set_option(char* string, int* variable, char* options[], int numoptions )
{
bool done = false;
lcd_clear_display();
lcd_puts_scroll(0,0,string);
while ( !done ) {
lcd_puts(0, 1, options[*variable]);
lcd_update();
switch ( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
if ( *variable < (numoptions-1) )
(*variable)++;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
if ( *variable > 0 )
(*variable)--;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
break;
}
}
lcd_stop_scroll();
}

View file

@ -54,6 +54,8 @@ struct user_settings
int loop_playlist; /* do we return to top of playlist at end? */
bool mp3filter;
int scroll_speed;
bool playlist_shuffle;
/* while playing screen settings */
int wps_display;
@ -67,6 +69,16 @@ void reload_all_settings( struct user_settings *settings );
void reset_settings( struct user_settings *settings );
void display_current_settings( struct user_settings *settings );
void set_bool(char* string, bool* variable );
void set_option(char* string, int* variable, char* options[], int numoptions );
void set_int(char* string,
char* unit,
int* variable,
void (*function)(int),
int step,
int min,
int max );
/* global settings */
extern struct user_settings global_settings;

View file

@ -33,190 +33,44 @@
#include "backlight.h"
#include "playlist.h" /* for playlist_shuffle */
enum { Shuffle, Backlight, Scroll, Wps, numsettings };
static void shuffle(void)
{
bool done = false;
set_bool( "[Shuffle]", &global_settings.playlist_shuffle );
}
lcd_clear_display();
lcd_puts(0,0,"[Shuffle]");
while ( !done ) {
lcd_puts(0, 1, playlist_shuffle ? "on " : "off");
lcd_update();
switch ( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
#endif
done = true;
break;
default:
playlist_shuffle = !playlist_shuffle;
break;
}
}
static void mp3_filter(void)
{
set_bool( "[MP3/M3U filter]", &global_settings.mp3filter );
}
static void backlight_timer(void)
{
bool done = false;
int timer = global_settings.backlight;
char str[16];
lcd_clear_display();
lcd_puts_scroll(0,0,"Backlight");
while (!done) {
snprintf(str,sizeof str,"Timeout: %d s ", timer);
lcd_puts(0,1,str);
lcd_update();
switch( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
timer++;
if(timer > 60)
timer = 60;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
timer--;
if ( timer < 0 )
timer = 0;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
global_settings.backlight = timer;
backlight_on();
break;
}
}
set_int( "[Backlight]", "s", &global_settings.backlight,
backlight_time, 1, 0, 60 );
backlight_on();
}
static void scroll_speed(void)
{
bool done=false;
int speed=10;
char str[16];
lcd_clear_display();
lcd_puts_scroll(0,0,"Scroll speed indicator");
while (!done) {
snprintf(str,sizeof str,"Speed: %d ",speed);
lcd_puts(0,1,str);
lcd_update();
lcd_scroll_speed(speed);
switch( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
speed++;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
speed--;
if ( speed < 1 )
speed = 1;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
lcd_stop_scroll();
break;
}
}
set_int("Scroll speed indicator...", "", &global_settings.scroll_speed,
&lcd_scroll_speed, 1, 1, 20 );
}
void wps_set(void)
static void wps_set(void)
{
/* Simple menu for selecting what the display shows during playback */
bool done = false;
int itemp = 0;
char* names[] = { "Id3 ", "File ", "Parse" };
lcd_clear_display();
lcd_puts(0,0,"[Display]");
while (!done) {
lcd_puts(0,1,names[itemp]);
lcd_update();
switch ( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
itemp--;
if (itemp <= 0)
itemp = 0;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
itemp++;
if (itemp >= 2)
itemp = 2;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
break;
default:
itemp = 0;
break;
}
}
global_settings.wps_display = itemp; //savedsettings[itemp];
set_option("[WPS display]", &global_settings.wps_display, names, 3 );
}
void settings_menu(void)
{
int m;
struct menu_items items[] = {
{ Shuffle, "Shuffle", shuffle },
{ Backlight, "Backlight Timer", backlight_timer },
{ Scroll, "Scroll speed", scroll_speed },
{ Wps, "While Playing", wps_set },
{ "Shuffle", shuffle },
{ "MP3/M3U filter", mp3_filter },
{ "Backlight Timer", backlight_timer },
{ "Scroll speed", scroll_speed },
{ "While Playing", wps_set },
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );

View file

@ -19,92 +19,32 @@
#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include "lcd.h"
#include "menu.h"
#include "sound_menu.h"
#include "mpeg.h"
#include "button.h"
#include "kernel.h"
#include "sprintf.h"
#include "settings.h"
typedef void (*settingfunc)(int);
enum { Volume, Bass, Treble, numsettings };
static const char* names[] = { "Volume", "Bass", "Treble" };
static settingfunc funcs[] = { mpeg_volume, mpeg_bass, mpeg_treble };
static void soundsetting(int setting, int *value)
{
char buf[32];
bool done = false;
lcd_clear_display();
snprintf(buf,sizeof buf,"[%s]",names[setting]);
lcd_puts(0,0,buf);
while ( !done ) {
snprintf(buf,sizeof buf,"%d %% ", *value);
lcd_puts(0,1,buf);
lcd_update();
switch ( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_RIGHT:
#endif
*value += 2;
if ( *value >= 100 )
*value = 100;
(funcs[setting])(*value);
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_LEFT:
#endif
*value -= 2;
if ( *value <= 0 )
*value = 0;
(funcs[setting])(*value);
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
case BUTTON_MENU:
#endif
done = true;
break;
}
}
}
static void volume(void)
{
soundsetting(Volume, &global_settings.volume);
set_int("Volume","%", &global_settings.volume, mpeg_volume, 2, 0, 100);
}
static void bass(void)
{
soundsetting(Bass, &global_settings.bass);
set_int("Bass","%", &global_settings.bass, mpeg_bass, 2, 0, 100);
};
static void treble(void)
{
soundsetting(Treble, &global_settings.treble);
set_int("Treble","%", &global_settings.treble, mpeg_treble, 2, 0, 100);
}
void sound_menu(void)
{
int m;
struct menu_items items[] = {
{ Volume, "Volume", volume },
{ Bass, "Bass", bass },
{ Treble, "Treble", treble }
{ "Volume", volume },
{ "Bass", bass },
{ "Treble", treble }
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );