diff options
-rw-r--r-- | apps/gui/select.c | 61 | ||||
-rw-r--r-- | apps/gui/select.h | 13 | ||||
-rw-r--r-- | apps/sound_menu.c | 7 |
3 files changed, 51 insertions, 30 deletions
diff --git a/apps/gui/select.c b/apps/gui/select.c index 58747fbd85..95a3083714 100644 --- a/apps/gui/select.c +++ b/apps/gui/select.c | |||
@@ -44,11 +44,11 @@ void gui_select_init_numeric(struct gui_select * select, | |||
44 | select->min_value=min_value; | 44 | select->min_value=min_value; |
45 | select->max_value=max_value+1; | 45 | select->max_value=max_value+1; |
46 | select->option=init_value; | 46 | select->option=init_value; |
47 | select->nb_decimals=0; | ||
48 | select->step=step; | 47 | select->step=step; |
49 | select->extra_string=unit; | 48 | select->extra_string=unit; |
50 | select->formatter=formatter; | 49 | select->formatter=formatter; |
51 | select->items=NULL; | 50 | select->items=NULL; |
51 | select->limit_loop=false; | ||
52 | } | 52 | } |
53 | 53 | ||
54 | void gui_select_init_items(struct gui_select * select, | 54 | void gui_select_init_items(struct gui_select * select, |
@@ -63,19 +63,24 @@ void gui_select_init_items(struct gui_select * select, | |||
63 | select->min_value=0; | 63 | select->min_value=0; |
64 | select->max_value=nb_items; | 64 | select->max_value=nb_items; |
65 | select->option=selected; | 65 | select->option=selected; |
66 | select->nb_decimals=0; | ||
67 | select->step=1; | 66 | select->step=1; |
68 | select->formatter=NULL; | 67 | select->formatter=NULL; |
69 | select->items=items; | 68 | select->items=items; |
69 | select->limit_loop=false; | ||
70 | } | 70 | } |
71 | 71 | ||
72 | void gui_select_next(struct gui_select * select) | 72 | void gui_select_next(struct gui_select * select) |
73 | { | 73 | { |
74 | if(select->option + select->step >= select->max_value) | 74 | if(select->option + select->step >= select->max_value) |
75 | if(select->option==select->max_value-1) | 75 | { |
76 | select->option=select->min_value; | 76 | if(!select->limit_loop) |
77 | else | 77 | { |
78 | select->option=select->max_value-1; | 78 | if(select->option==select->max_value-1) |
79 | select->option=select->min_value; | ||
80 | else | ||
81 | select->option=select->max_value-1; | ||
82 | } | ||
83 | } | ||
79 | else | 84 | else |
80 | select->option+=select->step; | 85 | select->option+=select->step; |
81 | } | 86 | } |
@@ -83,10 +88,15 @@ void gui_select_next(struct gui_select * select) | |||
83 | void gui_select_prev(struct gui_select * select) | 88 | void gui_select_prev(struct gui_select * select) |
84 | { | 89 | { |
85 | if(select->option - select->step < select->min_value) | 90 | if(select->option - select->step < select->min_value) |
86 | if(select->option==select->min_value) | 91 | { |
87 | select->option=select->max_value-1; | 92 | if(!select->limit_loop) |
88 | else | 93 | { |
89 | select->option=select->min_value; | 94 | if(select->option==select->min_value) |
95 | select->option=select->max_value-1; | ||
96 | else | ||
97 | select->option=select->min_value; | ||
98 | } | ||
99 | } | ||
90 | else | 100 | else |
91 | select->option-=select->step; | 101 | select->option-=select->step; |
92 | } | 102 | } |
@@ -124,27 +134,33 @@ void gui_syncselect_draw(struct gui_select * select) | |||
124 | 134 | ||
125 | bool gui_syncselect_do_button(struct gui_select * select, int button) | 135 | bool gui_syncselect_do_button(struct gui_select * select, int button) |
126 | { | 136 | { |
127 | bool moved=false; | 137 | gui_select_limit_loop(select, false); |
128 | switch(button) | 138 | switch(button) |
129 | { | 139 | { |
130 | case SELECT_INC : | ||
131 | case SELECT_INC | BUTTON_REPEAT : | 140 | case SELECT_INC | BUTTON_REPEAT : |
132 | #ifdef SELECT_RC_INC | 141 | #ifdef SELECT_RC_INC |
133 | case SELECT_RC_INC : | ||
134 | case SELECT_RC_INC | BUTTON_REPEAT : | 142 | case SELECT_RC_INC | BUTTON_REPEAT : |
135 | #endif | 143 | #endif |
144 | gui_select_limit_loop(select, true); | ||
145 | case SELECT_INC : | ||
146 | #ifdef SELECT_RC_INC | ||
147 | case SELECT_RC_INC : | ||
148 | #endif | ||
136 | gui_select_next(select); | 149 | gui_select_next(select); |
137 | moved=true; | 150 | return(true); |
138 | break; | 151 | |
139 | case SELECT_DEC : | ||
140 | case SELECT_DEC | BUTTON_REPEAT : | 152 | case SELECT_DEC | BUTTON_REPEAT : |
141 | #ifdef SELECT_RC_DEC | 153 | #ifdef SELECT_RC_DEC |
142 | case SELECT_RC_DEC : | ||
143 | case SELECT_RC_DEC | BUTTON_REPEAT : | 154 | case SELECT_RC_DEC | BUTTON_REPEAT : |
144 | #endif | 155 | #endif |
156 | gui_select_limit_loop(select, true); | ||
157 | case SELECT_DEC : | ||
158 | #ifdef SELECT_RC_DEC | ||
159 | case SELECT_RC_DEC : | ||
160 | #endif | ||
145 | gui_select_prev(select); | 161 | gui_select_prev(select); |
146 | moved=true; | 162 | return(true); |
147 | break; | 163 | |
148 | case SELECT_OK : | 164 | case SELECT_OK : |
149 | #ifdef SELECT_RC_OK | 165 | #ifdef SELECT_RC_OK |
150 | case SELECT_RC_OK : | 166 | case SELECT_RC_OK : |
@@ -156,7 +172,8 @@ bool gui_syncselect_do_button(struct gui_select * select, int button) | |||
156 | case SELECT_OK2 : | 172 | case SELECT_OK2 : |
157 | #endif | 173 | #endif |
158 | gui_select_validate(select); | 174 | gui_select_validate(select); |
159 | break; | 175 | return(false); |
176 | |||
160 | case SELECT_CANCEL : | 177 | case SELECT_CANCEL : |
161 | #ifdef SELECT_CANCEL2 | 178 | #ifdef SELECT_CANCEL2 |
162 | case SELECT_CANCEL2 : | 179 | case SELECT_CANCEL2 : |
@@ -170,8 +187,8 @@ bool gui_syncselect_do_button(struct gui_select * select, int button) | |||
170 | gui_select_cancel(select); | 187 | gui_select_cancel(select); |
171 | gui_syncselect_draw(select); | 188 | gui_syncselect_draw(select); |
172 | sleep(HZ/2); | 189 | sleep(HZ/2); |
173 | break; | 190 | return(false); |
174 | } | 191 | } |
175 | return(moved); | 192 | return(false); |
176 | } | 193 | } |
177 | 194 | ||
diff --git a/apps/gui/select.h b/apps/gui/select.h index 87ecb1c75c..a584b53991 100644 --- a/apps/gui/select.h +++ b/apps/gui/select.h | |||
@@ -80,7 +80,6 @@ struct gui_select | |||
80 | int max_value; | 80 | int max_value; |
81 | int step; | 81 | int step; |
82 | int option; | 82 | int option; |
83 | int nb_decimals; | ||
84 | const char * extra_string; | 83 | const char * extra_string; |
85 | /* In the case the option is a number */ | 84 | /* In the case the option is a number */ |
86 | void (*formatter)(char* dest, | 85 | void (*formatter)(char* dest, |
@@ -88,6 +87,7 @@ struct gui_select | |||
88 | int variable, | 87 | int variable, |
89 | const char* unit); | 88 | const char* unit); |
90 | const struct opt_items * items; | 89 | const struct opt_items * items; |
90 | bool limit_loop; | ||
91 | }; | 91 | }; |
92 | 92 | ||
93 | /* | 93 | /* |
@@ -183,6 +183,17 @@ extern void gui_select_draw(struct gui_select * select, struct screen * display) | |||
183 | (select)->validated | 183 | (select)->validated |
184 | 184 | ||
185 | /* | 185 | /* |
186 | * Tells the select wether it should stop when reaching the min/max value | ||
187 | * or should continue (by going to max/min) | ||
188 | * - select : the select struct | ||
189 | * - scroll : | ||
190 | * - true : stops when reaching min/max | ||
191 | * - false : continues to go to max/min when reaching min/max | ||
192 | */ | ||
193 | #define gui_select_limit_loop(select, loop) \ | ||
194 | (select)->limit_loop=loop | ||
195 | |||
196 | /* | ||
186 | * Draws the select on all the screens | 197 | * Draws the select on all the screens |
187 | * - select : the select struct | 198 | * - select : the select struct |
188 | */ | 199 | */ |
diff --git a/apps/sound_menu.c b/apps/sound_menu.c index 20e44f767c..d9d2194045 100644 --- a/apps/sound_menu.c +++ b/apps/sound_menu.c | |||
@@ -43,13 +43,6 @@ | |||
43 | #include "mas.h" | 43 | #include "mas.h" |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | static const char* const fmt[] = | ||
47 | { | ||
48 | "", /* no decimals */ | ||
49 | "%d.%d %s ", /* 1 decimal */ | ||
50 | "%d.%02d %s " /* 2 decimals */ | ||
51 | }; | ||
52 | |||
53 | int selected_setting; /* Used by the callback */ | 46 | int selected_setting; /* Used by the callback */ |
54 | void dec_sound_formatter(char *buffer, int buffer_size, int val, const char * unit) | 47 | void dec_sound_formatter(char *buffer, int buffer_size, int val, const char * unit) |
55 | { | 48 | { |