autodetection: convert path to native separators before displaying it.
[Rockbox.git] / apps / menus / display_menu.c
blob5ba8c2ecb113226ab819b96fef378f5af28208cf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <limits.h>
23 #include "config.h"
24 #include "lang.h"
25 #include "action.h"
26 #include "settings.h"
27 #include "menu.h"
28 #include "tree.h"
29 #include "list.h"
30 #ifdef HAVE_LCD_BITMAP
31 #include "peakmeter.h"
32 #endif
33 #include "talk.h"
34 #include "color_picker.h"
35 #include "lcd.h"
36 #include "lcd-remote.h"
37 #include "backdrop.h"
39 #ifdef HAVE_BACKLIGHT
40 static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item)
42 (void)this_item;
43 switch (action)
45 case ACTION_EXIT_MENUITEM:
46 set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
47 #ifdef HAVE_REMOTE_LCD
48 set_remote_backlight_filter_keypress(
49 global_settings.remote_bl_filter_first_keypress);
50 #endif
52 break;
54 return action;
56 #endif
57 #ifdef HAVE_LCD_FLIP
58 static int flipdisplay_callback(int action,const struct menu_item_ex *this_item)
60 (void)this_item;
61 switch (action)
63 case ACTION_EXIT_MENUITEM:
64 button_set_flip(global_settings.flip_display);
65 lcd_set_flip(global_settings.flip_display);
66 lcd_update();
67 #ifdef HAVE_REMOTE_LCD
68 lcd_remote_set_flip(global_settings.remote_flip_display);
69 lcd_remote_update();
70 #endif
71 break;
73 return action;
75 #endif
77 /***********************************/
78 /* LCD MENU */
79 #ifdef HAVE_BACKLIGHT
80 MENUITEM_SETTING(backlight_timeout, &global_settings.backlight_timeout, NULL);
81 #if CONFIG_CHARGING
82 MENUITEM_SETTING(backlight_timeout_plugged,
83 &global_settings.backlight_timeout_plugged, NULL);
84 #endif
85 #ifdef HAS_BUTTON_HOLD
86 MENUITEM_SETTING(backlight_on_button_hold,
87 &global_settings.backlight_on_button_hold, NULL);
88 #endif
89 MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
90 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
91 MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
92 MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
93 #endif
94 MENUITEM_SETTING(bl_filter_first_keypress,
95 &global_settings.bl_filter_first_keypress,
96 filterfirstkeypress_callback);
97 #ifdef HAVE_LCD_SLEEP_SETTING
98 MENUITEM_SETTING(lcd_sleep_after_backlight_off,
99 &global_settings.lcd_sleep_after_backlight_off, NULL);
100 #endif
101 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
102 MENUITEM_SETTING(brightness_item, &global_settings.brightness, NULL);
103 #endif
104 #endif /* HAVE_BACKLIGHT */
105 #ifdef HAVE_LCD_CONTRAST
106 MENUITEM_SETTING(contrast, &global_settings.contrast, NULL);
107 #endif
108 #ifdef HAVE_LCD_BITMAP
109 #ifdef HAVE_LCD_INVERT
110 MENUITEM_SETTING(invert, &global_settings.invert, NULL);
111 #endif
112 #ifdef HAVE_LCD_FLIP
113 MENUITEM_SETTING(flip_display, &global_settings.flip_display, flipdisplay_callback);
114 #endif
115 #endif /* HAVE_LCD_BITMAP */
117 /* now the actual menu */
118 MAKE_MENU(lcd_settings,ID2P(LANG_LCD_MENU),
119 NULL, Icon_Display_menu
120 #ifdef HAVE_BACKLIGHT
121 ,&backlight_timeout
122 # if CONFIG_CHARGING
123 ,&backlight_timeout_plugged
124 # endif
125 # ifdef HAS_BUTTON_HOLD
126 ,&backlight_on_button_hold
127 # endif
128 ,&caption_backlight
129 # if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
130 ,&backlight_fade_in, &backlight_fade_out
131 # endif
132 ,&bl_filter_first_keypress
133 # ifdef HAVE_LCD_SLEEP_SETTING
134 ,&lcd_sleep_after_backlight_off
135 # endif
136 # ifdef HAVE_BACKLIGHT_BRIGHTNESS
137 ,&brightness_item
138 # endif
139 #endif /* HAVE_BACKLIGHT */
140 #ifdef HAVE_LCD_CONTRAST
141 ,&contrast
142 #endif
143 #ifdef HAVE_LCD_BITMAP
144 # ifdef HAVE_LCD_INVERT
145 ,&invert
146 # endif
147 # ifdef HAVE_LCD_FLIP
148 ,&flip_display
149 # endif
150 #endif /* HAVE_LCD_BITMAP */
152 /* LCD MENU */
153 /***********************************/
156 /********************************/
157 /* Remote LCD settings menu */
158 #ifdef HAVE_REMOTE_LCD
159 MENUITEM_SETTING(remote_backlight_timeout,
160 &global_settings.remote_backlight_timeout, NULL);
162 #if CONFIG_CHARGING
163 MENUITEM_SETTING(remote_backlight_timeout_plugged,
164 &global_settings.remote_backlight_timeout_plugged, NULL);
165 #endif
167 #ifdef HAS_REMOTE_BUTTON_HOLD
168 MENUITEM_SETTING(remote_backlight_on_button_hold,
169 &global_settings.remote_backlight_on_button_hold, NULL);
170 #endif
172 MENUITEM_SETTING(remote_caption_backlight,
173 &global_settings.remote_caption_backlight, NULL);
174 MENUITEM_SETTING(remote_bl_filter_first_keypress,
175 &global_settings.remote_bl_filter_first_keypress,
176 filterfirstkeypress_callback);
177 MENUITEM_SETTING(remote_contrast,
178 &global_settings.remote_contrast, NULL);
179 MENUITEM_SETTING(remote_invert,
180 &global_settings.remote_invert, NULL);
182 MENUITEM_SETTING(remote_flip_display,
183 &global_settings.remote_flip_display, flipdisplay_callback);
185 #ifdef HAVE_REMOTE_LCD_TICKING
186 int ticking_callback(int action,const struct menu_item_ex *this_item)
188 (void)this_item;
189 switch (action)
191 case ACTION_EXIT_MENUITEM:
192 lcd_remote_emireduce(global_settings.remote_reduce_ticking);
193 break;
195 return action;
197 MENUITEM_SETTING(remote_reduce_ticking,
198 &global_settings.remote_reduce_ticking, ticking_callback);
199 #endif
201 MAKE_MENU(lcd_remote_settings, ID2P(LANG_LCD_REMOTE_MENU),
202 NULL, Icon_Remote_Display_menu,
203 &remote_backlight_timeout,
204 #if CONFIG_CHARGING
205 &remote_backlight_timeout_plugged,
206 #endif
207 #ifdef HAS_REMOTE_BUTTON_HOLD
208 &remote_backlight_on_button_hold,
209 #endif
210 &remote_caption_backlight, &remote_bl_filter_first_keypress,
211 &remote_contrast, &remote_invert, &remote_flip_display
212 #ifdef HAVE_REMOTE_LCD_TICKING
213 ,&remote_reduce_ticking
214 #endif
217 #endif /* HAVE_REMOTE_LCD */
218 /* Remote LCD settings menu */
219 /********************************/
221 /***********************************/
222 /* SCROLL MENU */
223 MENUITEM_SETTING_W_TEXT(scroll_speed, &global_settings.scroll_speed,
224 ID2P(LANG_SCROLL), NULL);
225 MENUITEM_SETTING(scroll_delay, &global_settings.scroll_delay, NULL);
226 #ifdef HAVE_LCD_BITMAP
227 MENUITEM_SETTING_W_TEXT(scroll_step, &global_settings.scroll_step,
228 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
229 #endif
230 MENUITEM_SETTING(bidir_limit, &global_settings.bidir_limit, NULL);
231 #ifdef HAVE_REMOTE_LCD
232 MENUITEM_SETTING_W_TEXT(remote_scroll_speed, &global_settings.remote_scroll_speed,
233 ID2P(LANG_SCROLL), NULL);
234 MENUITEM_SETTING(remote_scroll_delay, &global_settings.remote_scroll_delay, NULL);
235 MENUITEM_SETTING_W_TEXT(remote_scroll_step, &global_settings.remote_scroll_step,
236 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
237 MENUITEM_SETTING(remote_bidir_limit, &global_settings.remote_bidir_limit, NULL);
239 MAKE_MENU(remote_scroll_sets, ID2P(LANG_REMOTE_SCROLL_SETS), 0, Icon_NOICON,
240 &remote_scroll_speed, &remote_scroll_delay,
241 &remote_scroll_step, &remote_bidir_limit);
242 #endif /* HAVE_REMOTE_LCD */
243 #ifdef HAVE_LCD_CHARCELLS
244 MENUITEM_SETTING(jump_scroll, &global_settings.jump_scroll, NULL);
245 MENUITEM_SETTING(jump_scroll_delay, &global_settings.jump_scroll_delay, NULL);
246 #endif
247 /* list acceleration */
248 #ifndef HAVE_SCROLLWHEEL
249 MENUITEM_SETTING(list_accel_start_delay,
250 &global_settings.list_accel_start_delay, NULL);
251 MENUITEM_SETTING(list_accel_wait, &global_settings.list_accel_wait, NULL);
252 #endif /* HAVE_SCROLLWHEEL */
253 #ifdef HAVE_LCD_BITMAP
254 static int screenscroll_callback(int action,const struct menu_item_ex *this_item)
256 (void)this_item;
257 switch (action)
259 case ACTION_EXIT_MENUITEM:
260 gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view);
261 break;
263 return action;
265 MENUITEM_SETTING(offset_out_of_view, &global_settings.offset_out_of_view,
266 screenscroll_callback);
267 MENUITEM_SETTING(screen_scroll_step, &global_settings.screen_scroll_step, NULL);
268 #endif
269 MENUITEM_SETTING(scroll_paginated, &global_settings.scroll_paginated, NULL);
271 MAKE_MENU(scroll_settings_menu, ID2P(LANG_SCROLL_MENU), 0, Icon_NOICON,
272 &scroll_speed, &scroll_delay,
273 #ifdef HAVE_LCD_BITMAP
274 &scroll_step,
275 #endif
276 &bidir_limit,
277 #ifdef HAVE_REMOTE_LCD
278 &remote_scroll_sets,
279 #endif
280 #ifdef HAVE_LCD_CHARCELLS
281 &jump_scroll, &jump_scroll_delay,
282 #endif
283 #ifdef HAVE_LCD_BITMAP
284 &offset_out_of_view, &screen_scroll_step,
285 #endif
286 &scroll_paginated,
287 #ifndef HAVE_SCROLLWHEEL
288 &list_accel_start_delay, &list_accel_wait
289 #endif
291 /* SCROLL MENU */
292 /***********************************/
294 /***********************************/
295 /* BARS MENU */
296 #ifdef HAVE_LCD_BITMAP
297 static int statusbar_callback(int action,const struct menu_item_ex *this_item)
299 (void)this_item;
300 switch (action)
302 case ACTION_EXIT_MENUITEM:
303 /* this should be changed so only the viewports are reloaded */
304 settings_apply(false);
305 break;
307 return action;
309 MENUITEM_SETTING(scrollbar_item, &global_settings.scrollbar, NULL);
310 MENUITEM_SETTING(statusbar, &global_settings.statusbar, statusbar_callback);
311 #if CONFIG_KEYPAD == RECORDER_PAD
312 MENUITEM_SETTING(buttonbar, &global_settings.buttonbar, NULL);
313 #endif
314 MENUITEM_SETTING(volume_type, &global_settings.volume_type, NULL);
315 MENUITEM_SETTING(battery_display, &global_settings.battery_display, NULL);
316 MAKE_MENU(bars_menu, ID2P(LANG_BARS_MENU), 0, Icon_NOICON,
317 &scrollbar_item, &statusbar,
318 #if CONFIG_KEYPAD == RECORDER_PAD
319 &buttonbar,
320 #endif
321 &volume_type, &battery_display);
322 #endif /* HAVE_LCD_BITMAP */
323 /* BARS MENU */
324 /***********************************/
327 /***********************************/
328 /* PEAK METER MENU */
330 #ifdef HAVE_LCD_BITMAP
331 static int peakmeter_callback(int action,const struct menu_item_ex *this_item)
333 (void)this_item;
334 switch (action)
336 case ACTION_EXIT_MENUITEM:
337 peak_meter_init_times(global_settings.peak_meter_release,
338 global_settings.peak_meter_hold,
339 global_settings.peak_meter_clip_hold);
340 break;
342 return action;
344 MENUITEM_SETTING(peak_meter_hold,
345 &global_settings.peak_meter_hold, peakmeter_callback);
346 MENUITEM_SETTING(peak_meter_clip_hold,
347 &global_settings.peak_meter_clip_hold, peakmeter_callback);
348 #ifdef HAVE_RECORDING
349 MENUITEM_SETTING(peak_meter_clipcounter,
350 &global_settings.peak_meter_clipcounter, NULL);
351 #endif
352 MENUITEM_SETTING(peak_meter_release,
353 &global_settings.peak_meter_release, peakmeter_callback);
355 * Menu to select wether the scale of the meter
356 * displays dBfs of linear values.
358 static int peak_meter_scale(void) {
359 bool retval = false;
360 bool use_dbfs = global_settings.peak_meter_dbfs;
361 retval = set_bool_options(str(LANG_PM_SCALE),
362 &use_dbfs,
363 STR(LANG_PM_DBFS), STR(LANG_PM_LINEAR),
364 NULL);
366 /* has the user really changed the scale? */
367 if (use_dbfs != global_settings.peak_meter_dbfs) {
369 /* store the change */
370 global_settings.peak_meter_dbfs = use_dbfs;
371 peak_meter_set_use_dbfs(use_dbfs);
373 /* If the user changed the scale mode the meaning of
374 peak_meter_min (peak_meter_max) has changed. Thus we have
375 to convert the values stored in global_settings. */
376 if (use_dbfs) {
378 /* we only store -dBfs */
379 global_settings.peak_meter_min = -peak_meter_get_min() / 100;
380 global_settings.peak_meter_max = -peak_meter_get_max() / 100;
382 /* limit the returned value to the allowed range */
383 if(global_settings.peak_meter_min > 89)
384 global_settings.peak_meter_min = 89;
385 } else {
386 int max;
388 /* linear percent */
389 global_settings.peak_meter_min = peak_meter_get_min();
391 /* converting dBfs -> percent results in a precision loss.
392 I assume that the user doesn't bother that conversion
393 dBfs <-> percent isn't symmetrical for odd values but that
394 he wants 0 dBfs == 100%. Thus I 'correct' the percent value
395 resulting from dBfs -> percent manually here */
396 max = peak_meter_get_max();
397 global_settings.peak_meter_max = max < 99 ? max : 100;
399 settings_apply_pm_range();
401 return retval;
405 * Adjust the min value of the value range that
406 * the peak meter shall visualize.
408 static int peak_meter_min(void) {
409 bool retval = false;
410 if (global_settings.peak_meter_dbfs) {
412 /* for dBfs scale */
413 int range_max = -global_settings.peak_meter_max;
414 int min = -global_settings.peak_meter_min;
416 retval = set_int(str(LANG_PM_MIN), str(LANG_PM_DBFS), UNIT_DB,
417 &min, NULL, 1, -89, range_max, NULL);
419 global_settings.peak_meter_min = - min;
422 /* for linear scale */
423 else {
424 int min = global_settings.peak_meter_min;
426 retval = set_int(str(LANG_PM_MIN), "%", UNIT_PERCENT,
427 &min, NULL,
428 1, 0, global_settings.peak_meter_max - 1, NULL);
430 global_settings.peak_meter_min = (unsigned char)min;
433 settings_apply_pm_range();
434 return retval;
439 * Adjust the max value of the value range that
440 * the peak meter shall visualize.
442 static int peak_meter_max(void) {
443 bool retval = false;
444 if (global_settings.peak_meter_dbfs) {
446 /* for dBfs scale */
447 int range_min = -global_settings.peak_meter_min;
448 int max = -global_settings.peak_meter_max;;
450 retval = set_int(str(LANG_PM_MAX), str(LANG_PM_DBFS), UNIT_DB,
451 &max, NULL, 1, range_min, 0, NULL);
453 global_settings.peak_meter_max = - max;
457 /* for linear scale */
458 else {
459 int max = global_settings.peak_meter_max;
461 retval = set_int(str(LANG_PM_MAX), "%", UNIT_PERCENT,
462 &max, NULL,
463 1, global_settings.peak_meter_min + 1, 100, NULL);
465 global_settings.peak_meter_max = (unsigned char)max;
468 settings_apply_pm_range();
469 return retval;
471 MENUITEM_FUNCTION(peak_meter_scale_item, 0, ID2P(LANG_PM_SCALE),
472 peak_meter_scale, NULL, NULL, Icon_NOICON);
473 MENUITEM_FUNCTION(peak_meter_min_item, 0, ID2P(LANG_PM_MIN),
474 peak_meter_min, NULL, NULL, Icon_NOICON);
475 MENUITEM_FUNCTION(peak_meter_max_item, 0, ID2P(LANG_PM_MAX),
476 peak_meter_max, NULL, NULL, Icon_NOICON);
477 MAKE_MENU(peak_meter_menu, ID2P(LANG_PM_MENU), NULL, Icon_NOICON,
478 &peak_meter_release, &peak_meter_hold,
479 &peak_meter_clip_hold,
480 #ifdef HAVE_RECORDING
481 &peak_meter_clipcounter,
482 #endif
483 &peak_meter_scale_item, &peak_meter_min_item, &peak_meter_max_item);
484 #endif /* HAVE_LCD_BITMAP */
485 /* PEAK METER MENU */
486 /***********************************/
490 MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL);
493 MAKE_MENU(display_menu, ID2P(LANG_DISPLAY),
494 NULL, Icon_Display_menu,
495 &lcd_settings,
496 #ifdef HAVE_REMOTE_LCD
497 &lcd_remote_settings,
498 #endif
499 &scroll_settings_menu,
500 #ifdef HAVE_LCD_BITMAP
501 &bars_menu, &peak_meter_menu,
502 #endif
503 &codepage_setting,