summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-06-27 01:08:11 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-06-27 01:08:11 +0000
commit60b356ea25dca1b103eec7a59ace90a710db31fe (patch)
tree042bf8e9e7ee698287fa36f85855c9db861d3e49
parentb45491df8fd4093eb79235cffb2f68c2e2228bfd (diff)
downloadrockbox-60b356ea25dca1b103eec7a59ace90a710db31fe.tar.gz
rockbox-60b356ea25dca1b103eec7a59ace90a710db31fe.zip
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
-rw-r--r--apps/games_menu.c6
-rw-r--r--apps/main_menu.c13
-rw-r--r--apps/menu.h1
-rw-r--r--apps/screensavers_menu.c6
-rw-r--r--apps/settings.c129
-rw-r--r--apps/settings.h12
-rw-r--r--apps/settings_menu.c180
-rw-r--r--apps/sound_menu.c72
8 files changed, 173 insertions, 246 deletions
diff --git a/apps/games_menu.c b/apps/games_menu.c
index 34405825cd..1d30fbbcce 100644
--- a/apps/games_menu.c
+++ b/apps/games_menu.c
@@ -31,15 +31,13 @@
31#include "sokoban.h" 31#include "sokoban.h"
32extern void tetris(void); 32extern void tetris(void);
33 33
34enum { Tetris, Sokoban, numgames };
35
36void games_menu(void) 34void games_menu(void)
37{ 35{
38 int m; 36 int m;
39 37
40 struct menu_items items[] = { 38 struct menu_items items[] = {
41 { Tetris, "Tetris", tetris }, 39 { "Tetris", tetris },
42 { Sokoban, "Sokoban", sokoban }, 40 { "Sokoban", sokoban },
43 }; 41 };
44 42
45 m=menu_init( items, sizeof items / sizeof(struct menu_items) ); 43 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
diff --git a/apps/main_menu.c b/apps/main_menu.c
index 9665ce8896..5fdb66a420 100644
--- a/apps/main_menu.c
+++ b/apps/main_menu.c
@@ -125,19 +125,16 @@ void show_credits(void)
125void main_menu(void) 125void main_menu(void)
126{ 126{
127 int m; 127 int m;
128 enum {
129 Games, Screensavers, Version, Gen_Settings, Sound_Settings,
130 };
131 128
132 /* main menu */ 129 /* main menu */
133 struct menu_items items[] = { 130 struct menu_items items[] = {
134 { Sound_Settings, "Sound Settings", sound_menu }, 131 { "Sound Settings", sound_menu },
135 { Gen_Settings, "General Settings", settings_menu }, 132 { "General Settings", settings_menu },
136#ifdef HAVE_LCD_BITMAP 133#ifdef HAVE_LCD_BITMAP
137 { Games, "Games", games_menu }, 134 { "Games", games_menu },
138 { Screensavers, "Screensavers", screensavers_menu }, 135 { "Screensavers", screensavers_menu },
139#endif 136#endif
140 { Version, "Version", show_credits }, 137 { "Version", show_credits },
141 }; 138 };
142 139
143 m=menu_init( items, sizeof items / sizeof(struct menu_items) ); 140 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
diff --git a/apps/menu.h b/apps/menu.h
index aea81f5e4e..0871e502c8 100644
--- a/apps/menu.h
+++ b/apps/menu.h
@@ -23,7 +23,6 @@
23#include <stdbool.h> 23#include <stdbool.h>
24 24
25struct menu_items { 25struct menu_items {
26 int id;
27 char *desc; 26 char *desc;
28 void (*function) (void); 27 void (*function) (void);
29}; 28};
diff --git a/apps/screensavers_menu.c b/apps/screensavers_menu.c
index 41e5e39fee..76553cf328 100644
--- a/apps/screensavers_menu.c
+++ b/apps/screensavers_menu.c
@@ -32,15 +32,13 @@
32#include "boxes.h" 32#include "boxes.h"
33extern void bounce(void); 33extern void bounce(void);
34 34
35enum { Boxes, Bounce, numsavers };
36
37void screensavers_menu(void) 35void screensavers_menu(void)
38{ 36{
39 int m; 37 int m;
40 38
41 struct menu_items items[] = { 39 struct menu_items items[] = {
42 { Boxes, "Boxes", boxes }, 40 { "Boxes", boxes },
43 { Bounce, "Bounce", bounce }, 41 { "Bounce", bounce },
44 }; 42 };
45 43
46 m=menu_init( items, sizeof items / sizeof(struct menu_items) ); 44 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
diff --git a/apps/settings.c b/apps/settings.c
index f6566f41a1..61aaf40b66 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -23,6 +23,8 @@
23#include "disk.h" 23#include "disk.h"
24#include "panic.h" 24#include "panic.h"
25#include "debug.h" 25#include "debug.h"
26#include "button.h"
27#include "lcd.h"
26 28
27struct user_settings global_settings; 29struct user_settings global_settings;
28 30
@@ -101,3 +103,130 @@ void display_current_settings( struct user_settings *settings )
101 settings = settings; 103 settings = settings;
102#endif 104#endif
103} 105}
106
107void set_bool(char* string, bool* variable )
108{
109 bool done = false;
110
111 lcd_clear_display();
112 lcd_puts_scroll(0,0,string);
113
114 while ( !done ) {
115 lcd_puts(0, 1, *variable ? "on " : "off");
116 lcd_update();
117
118 switch ( button_get(true) ) {
119#ifdef HAVE_RECORDER_KEYPAD
120 case BUTTON_LEFT:
121#else
122 case BUTTON_STOP:
123 case BUTTON_MENU:
124#endif
125 done = true;
126 break;
127
128 default:
129 *variable = !*variable;
130 break;
131 }
132 }
133 lcd_stop_scroll();
134}
135
136void set_int(char* string,
137 char* unit,
138 int* variable,
139 void (*function)(int),
140 int step,
141 int min,
142 int max )
143{
144 bool done = false;
145
146 lcd_clear_display();
147 lcd_puts_scroll(0,0,string);
148
149 while (!done) {
150 char str[32];
151 snprintf(str,sizeof str,"%d %s ", *variable, unit);
152 lcd_puts(0,1,str);
153 lcd_update();
154
155 switch( button_get(true) ) {
156#ifdef HAVE_RECORDER_KEYPAD
157 case BUTTON_UP:
158#else
159 case BUTTON_RIGHT:
160#endif
161 *variable += step;
162 if(*variable > max )
163 *variable = max;
164 break;
165
166#ifdef HAVE_RECORDER_KEYPAD
167 case BUTTON_DOWN:
168#else
169 case BUTTON_LEFT:
170#endif
171 *variable -= step;
172 if(*variable < min )
173 *variable = min;
174 break;
175
176#ifdef HAVE_RECORDER_KEYPAD
177 case BUTTON_LEFT:
178#else
179 case BUTTON_STOP:
180 case BUTTON_MENU:
181#endif
182 done = true;
183 break;
184 }
185 if ( function )
186 function(*variable);
187 }
188 lcd_stop_scroll();
189}
190
191void set_option(char* string, int* variable, char* options[], int numoptions )
192{
193 bool done = false;
194
195 lcd_clear_display();
196 lcd_puts_scroll(0,0,string);
197
198 while ( !done ) {
199 lcd_puts(0, 1, options[*variable]);
200 lcd_update();
201
202 switch ( button_get(true) ) {
203#ifdef HAVE_RECORDER_KEYPAD
204 case BUTTON_UP:
205#else
206 case BUTTON_RIGHT:
207#endif
208 if ( *variable < (numoptions-1) )
209 (*variable)++;
210 break;
211
212#ifdef HAVE_RECORDER_KEYPAD
213 case BUTTON_DOWN:
214#else
215 case BUTTON_LEFT:
216#endif
217 if ( *variable > 0 )
218 (*variable)--;
219 break;
220
221#ifdef HAVE_RECORDER_KEYPAD
222 case BUTTON_LEFT:
223#else
224 case BUTTON_STOP:
225 case BUTTON_MENU:
226#endif
227 done = true;
228 break;
229 }
230 }
231 lcd_stop_scroll();
232}
diff --git a/apps/settings.h b/apps/settings.h
index b4a8fde56e..d3b891c790 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -54,6 +54,8 @@ struct user_settings
54 54
55 int loop_playlist; /* do we return to top of playlist at end? */ 55 int loop_playlist; /* do we return to top of playlist at end? */
56 bool mp3filter; 56 bool mp3filter;
57 int scroll_speed;
58 bool playlist_shuffle;
57 59
58 /* while playing screen settings */ 60 /* while playing screen settings */
59 int wps_display; 61 int wps_display;
@@ -67,6 +69,16 @@ void reload_all_settings( struct user_settings *settings );
67void reset_settings( struct user_settings *settings ); 69void reset_settings( struct user_settings *settings );
68void display_current_settings( struct user_settings *settings ); 70void display_current_settings( struct user_settings *settings );
69 71
72void set_bool(char* string, bool* variable );
73void set_option(char* string, int* variable, char* options[], int numoptions );
74void set_int(char* string,
75 char* unit,
76 int* variable,
77 void (*function)(int),
78 int step,
79 int min,
80 int max );
81
70/* global settings */ 82/* global settings */
71extern struct user_settings global_settings; 83extern struct user_settings global_settings;
72 84
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 00c5dfb77d..a27f4feac1 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -33,190 +33,44 @@
33#include "backlight.h" 33#include "backlight.h"
34#include "playlist.h" /* for playlist_shuffle */ 34#include "playlist.h" /* for playlist_shuffle */
35 35
36enum { Shuffle, Backlight, Scroll, Wps, numsettings };
37
38static void shuffle(void) 36static void shuffle(void)
39{ 37{
40 bool done = false; 38 set_bool( "[Shuffle]", &global_settings.playlist_shuffle );
41 39}
42 lcd_clear_display();
43 lcd_puts(0,0,"[Shuffle]");
44
45 while ( !done ) {
46 lcd_puts(0, 1, playlist_shuffle ? "on " : "off");
47 lcd_update();
48
49 switch ( button_get(true) ) {
50#ifdef HAVE_RECORDER_KEYPAD
51 case BUTTON_LEFT:
52#else
53 case BUTTON_STOP:
54#endif
55 done = true;
56 break;
57 40
58 default: 41static void mp3_filter(void)
59 playlist_shuffle = !playlist_shuffle; 42{
60 break; 43 set_bool( "[MP3/M3U filter]", &global_settings.mp3filter );
61 }
62 }
63} 44}
64 45
65static void backlight_timer(void) 46static void backlight_timer(void)
66{ 47{
67 bool done = false; 48 set_int( "[Backlight]", "s", &global_settings.backlight,
68 int timer = global_settings.backlight; 49 backlight_time, 1, 0, 60 );
69 char str[16]; 50 backlight_on();
70
71 lcd_clear_display();
72 lcd_puts_scroll(0,0,"Backlight");
73
74 while (!done) {
75 snprintf(str,sizeof str,"Timeout: %d s ", timer);
76 lcd_puts(0,1,str);
77 lcd_update();
78 switch( button_get(true) ) {
79#ifdef HAVE_RECORDER_KEYPAD
80 case BUTTON_UP:
81#else
82 case BUTTON_RIGHT:
83#endif
84 timer++;
85 if(timer > 60)
86 timer = 60;
87 break;
88
89#ifdef HAVE_RECORDER_KEYPAD
90 case BUTTON_DOWN:
91#else
92 case BUTTON_LEFT:
93#endif
94 timer--;
95 if ( timer < 0 )
96 timer = 0;
97 break;
98
99#ifdef HAVE_RECORDER_KEYPAD
100 case BUTTON_LEFT:
101#else
102 case BUTTON_STOP:
103 case BUTTON_MENU:
104#endif
105 done = true;
106 global_settings.backlight = timer;
107 backlight_on();
108 break;
109 }
110 }
111} 51}
112 52
113static void scroll_speed(void) 53static void scroll_speed(void)
114{ 54{
115 bool done=false; 55 set_int("Scroll speed indicator...", "", &global_settings.scroll_speed,
116 int speed=10; 56 &lcd_scroll_speed, 1, 1, 20 );
117 char str[16];
118
119 lcd_clear_display();
120 lcd_puts_scroll(0,0,"Scroll speed indicator");
121
122 while (!done) {
123 snprintf(str,sizeof str,"Speed: %d ",speed);
124 lcd_puts(0,1,str);
125 lcd_update();
126 lcd_scroll_speed(speed);
127 switch( button_get(true) ) {
128#ifdef HAVE_RECORDER_KEYPAD
129 case BUTTON_UP:
130#else
131 case BUTTON_RIGHT:
132#endif
133 speed++;
134 break;
135
136#ifdef HAVE_RECORDER_KEYPAD
137 case BUTTON_DOWN:
138#else
139 case BUTTON_LEFT:
140#endif
141 speed--;
142 if ( speed < 1 )
143 speed = 1;
144 break;
145
146#ifdef HAVE_RECORDER_KEYPAD
147 case BUTTON_LEFT:
148#else
149 case BUTTON_STOP:
150 case BUTTON_MENU:
151#endif
152 done = true;
153 lcd_stop_scroll();
154 break;
155 }
156 }
157} 57}
158 58
159 59static void wps_set(void)
160void wps_set(void)
161{ 60{
162 /* Simple menu for selecting what the display shows during playback */
163
164 bool done = false;
165 int itemp = 0;
166 char* names[] = { "Id3 ", "File ", "Parse" }; 61 char* names[] = { "Id3 ", "File ", "Parse" };
167 62 set_option("[WPS display]", &global_settings.wps_display, names, 3 );
168 lcd_clear_display();
169 lcd_puts(0,0,"[Display]");
170
171 while (!done) {
172 lcd_puts(0,1,names[itemp]);
173 lcd_update();
174
175 switch ( button_get(true) ) {
176#ifdef HAVE_RECORDER_KEYPAD
177 case BUTTON_DOWN:
178#else
179 case BUTTON_LEFT:
180#endif
181 itemp--;
182 if (itemp <= 0)
183 itemp = 0;
184 break;
185#ifdef HAVE_RECORDER_KEYPAD
186 case BUTTON_UP:
187#else
188 case BUTTON_RIGHT:
189#endif
190 itemp++;
191 if (itemp >= 2)
192 itemp = 2;
193 break;
194#ifdef HAVE_RECORDER_KEYPAD
195 case BUTTON_LEFT:
196#else
197 case BUTTON_STOP:
198 case BUTTON_MENU:
199#endif
200 done = true;
201 break;
202 default:
203 itemp = 0;
204 break;
205 }
206 }
207
208
209 global_settings.wps_display = itemp; //savedsettings[itemp];
210} 63}
211 64
212void settings_menu(void) 65void settings_menu(void)
213{ 66{
214 int m; 67 int m;
215 struct menu_items items[] = { 68 struct menu_items items[] = {
216 { Shuffle, "Shuffle", shuffle }, 69 { "Shuffle", shuffle },
217 { Backlight, "Backlight Timer", backlight_timer }, 70 { "MP3/M3U filter", mp3_filter },
218 { Scroll, "Scroll speed", scroll_speed }, 71 { "Backlight Timer", backlight_timer },
219 { Wps, "While Playing", wps_set }, 72 { "Scroll speed", scroll_speed },
73 { "While Playing", wps_set },
220 }; 74 };
221 75
222 m=menu_init( items, sizeof items / sizeof(struct menu_items) ); 76 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
diff --git a/apps/sound_menu.c b/apps/sound_menu.c
index 21b98ab7ef..183c3439a3 100644
--- a/apps/sound_menu.c
+++ b/apps/sound_menu.c
@@ -19,92 +19,32 @@
19#include "config.h" 19#include "config.h"
20#include <stdio.h> 20#include <stdio.h>
21#include <stdbool.h> 21#include <stdbool.h>
22#include "lcd.h"
23#include "menu.h" 22#include "menu.h"
24#include "sound_menu.h"
25#include "mpeg.h" 23#include "mpeg.h"
26#include "button.h"
27#include "kernel.h"
28#include "sprintf.h"
29#include "settings.h" 24#include "settings.h"
30 25
31typedef void (*settingfunc)(int);
32enum { Volume, Bass, Treble, numsettings };
33
34static const char* names[] = { "Volume", "Bass", "Treble" };
35static settingfunc funcs[] = { mpeg_volume, mpeg_bass, mpeg_treble };
36
37static void soundsetting(int setting, int *value)
38{
39 char buf[32];
40 bool done = false;
41
42 lcd_clear_display();
43 snprintf(buf,sizeof buf,"[%s]",names[setting]);
44 lcd_puts(0,0,buf);
45
46 while ( !done ) {
47 snprintf(buf,sizeof buf,"%d %% ", *value);
48 lcd_puts(0,1,buf);
49 lcd_update();
50
51 switch ( button_get(true) ) {
52#ifdef HAVE_RECORDER_KEYPAD
53 case BUTTON_UP:
54#else
55 case BUTTON_RIGHT:
56#endif
57 *value += 2;
58 if ( *value >= 100 )
59 *value = 100;
60 (funcs[setting])(*value);
61 break;
62
63#ifdef HAVE_RECORDER_KEYPAD
64 case BUTTON_DOWN:
65#else
66 case BUTTON_LEFT:
67#endif
68 *value -= 2;
69 if ( *value <= 0 )
70 *value = 0;
71 (funcs[setting])(*value);
72 break;
73
74#ifdef HAVE_RECORDER_KEYPAD
75 case BUTTON_LEFT:
76#else
77 case BUTTON_STOP:
78 case BUTTON_MENU:
79#endif
80 done = true;
81 break;
82 }
83 }
84}
85
86static void volume(void) 26static void volume(void)
87{ 27{
88 soundsetting(Volume, &global_settings.volume); 28 set_int("Volume","%", &global_settings.volume, mpeg_volume, 2, 0, 100);
89} 29}
90 30
91static void bass(void) 31static void bass(void)
92{ 32{
93 soundsetting(Bass, &global_settings.bass); 33 set_int("Bass","%", &global_settings.bass, mpeg_bass, 2, 0, 100);
94}; 34};
95 35
96static void treble(void) 36static void treble(void)
97{ 37{
98 soundsetting(Treble, &global_settings.treble); 38 set_int("Treble","%", &global_settings.treble, mpeg_treble, 2, 0, 100);
99} 39}
100 40
101void sound_menu(void) 41void sound_menu(void)
102{ 42{
103 int m; 43 int m;
104 struct menu_items items[] = { 44 struct menu_items items[] = {
105 { Volume, "Volume", volume }, 45 { "Volume", volume },
106 { Bass, "Bass", bass }, 46 { "Bass", bass },
107 { Treble, "Treble", treble } 47 { "Treble", treble }
108 }; 48 };
109 49
110 m=menu_init( items, sizeof items / sizeof(struct menu_items) ); 50 m=menu_init( items, sizeof items / sizeof(struct menu_items) );