Increase MAXTHREADS
[Rockbox.git] / apps / menus / display_menu.c
bloba68defdfd41fbd5b13bc15541c856ebae87ed52d
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"
38 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
39 #include "backdrop.h"
40 #endif
43 #ifdef HAVE_BACKLIGHT
44 int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item)
46 (void)this_item;
47 switch (action)
49 case ACTION_EXIT_MENUITEM:
50 set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
51 #ifdef HAVE_REMOTE_LCD
52 set_remote_backlight_filter_keypress(
53 global_settings.remote_bl_filter_first_keypress);
54 #endif
56 break;
58 return action;
60 #endif
61 #ifdef HAVE_LCD_BITMAP
62 int flipdisplay_callback(int action,const struct menu_item_ex *this_item)
64 (void)this_item;
65 switch (action)
67 case ACTION_EXIT_MENUITEM:
68 button_set_flip(global_settings.flip_display);
69 lcd_set_flip(global_settings.flip_display);
70 #ifdef HAVE_REMOTE_LCD
71 lcd_remote_set_flip(global_settings.remote_flip_display);
72 lcd_remote_update();
73 #endif
74 break;
76 return action;
78 #endif
80 /***********************************/
81 /* LCD MENU */
82 #ifdef HAVE_BACKLIGHT
83 MENUITEM_SETTING(backlight_timeout, &global_settings.backlight_timeout, NULL);
84 #if CONFIG_CHARGING
85 MENUITEM_SETTING(backlight_timeout_plugged,
86 &global_settings.backlight_timeout_plugged, NULL);
87 #endif
88 #ifdef HAS_BUTTON_HOLD
89 MENUITEM_SETTING(backlight_on_button_hold,
90 &global_settings.backlight_on_button_hold, NULL);
91 #endif
92 MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
93 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
94 MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
95 MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
96 #endif
97 MENUITEM_SETTING(bl_filter_first_keypress,
98 &global_settings.bl_filter_first_keypress,
99 filterfirstkeypress_callback);
100 #ifdef HAVE_LCD_SLEEP
101 MENUITEM_SETTING(lcd_sleep_after_backlight_off,
102 &global_settings.lcd_sleep_after_backlight_off, NULL);
103 #endif
104 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
105 MENUITEM_SETTING(brightness_item, &global_settings.brightness, NULL);
106 #endif
107 #endif /* HAVE_BACKLIGHT */
108 #ifdef HAVE_LCD_CONTRAST
109 MENUITEM_SETTING(contrast, &global_settings.contrast, NULL);
110 #endif
111 #ifdef HAVE_LCD_BITMAP
112 #ifdef HAVE_LCD_INVERT
113 MENUITEM_SETTING(invert, &global_settings.invert, NULL);
114 #endif
115 #ifdef HAVE_LCD_FLIP
116 MENUITEM_SETTING(flip_display, &global_settings.flip_display, flipdisplay_callback);
117 #endif
118 #endif /* HAVE_LCD_BITMAP */
120 /* now the actual menu */
121 MAKE_MENU(lcd_settings,ID2P(LANG_LCD_MENU),
122 NULL, Icon_Display_menu
123 #ifdef HAVE_BACKLIGHT
124 ,&backlight_timeout
125 # if CONFIG_CHARGING
126 ,&backlight_timeout_plugged
127 # endif
128 # ifdef HAS_BUTTON_HOLD
129 ,&backlight_on_button_hold
130 # endif
131 ,&caption_backlight
132 # if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
133 ,&backlight_fade_in, &backlight_fade_out
134 # endif
135 ,&bl_filter_first_keypress
136 # ifdef HAVE_LCD_SLEEP
137 ,&lcd_sleep_after_backlight_off
138 # endif
139 # ifdef HAVE_BACKLIGHT_BRIGHTNESS
140 ,&brightness_item
141 # endif
142 #endif /* HAVE_BACKLIGHT */
143 #ifdef HAVE_LCD_CONTRAST
144 ,&contrast
145 #endif
146 #ifdef HAVE_LCD_BITMAP
147 # ifdef HAVE_LCD_INVERT
148 ,&invert
149 # endif
150 # ifdef HAVE_LCD_FLIP
151 ,&flip_display
152 # endif
153 #endif /* HAVE_LCD_BITMAP */
155 /* LCD MENU */
156 /***********************************/
159 /********************************/
160 /* Remote LCD settings menu */
161 #ifdef HAVE_REMOTE_LCD
162 MENUITEM_SETTING(remote_backlight_timeout,
163 &global_settings.remote_backlight_timeout, NULL);
165 #if CONFIG_CHARGING
166 MENUITEM_SETTING(remote_backlight_timeout_plugged,
167 &global_settings.remote_backlight_timeout_plugged, NULL);
168 #endif
170 #ifdef HAS_REMOTE_BUTTON_HOLD
171 MENUITEM_SETTING(remote_backlight_on_button_hold,
172 &global_settings.remote_backlight_on_button_hold, NULL);
173 #endif
175 MENUITEM_SETTING(remote_caption_backlight,
176 &global_settings.remote_caption_backlight, NULL);
177 MENUITEM_SETTING(remote_bl_filter_first_keypress,
178 &global_settings.remote_bl_filter_first_keypress,
179 filterfirstkeypress_callback);
180 MENUITEM_SETTING(remote_contrast,
181 &global_settings.remote_contrast, NULL);
182 MENUITEM_SETTING(remote_invert,
183 &global_settings.remote_invert, NULL);
185 MENUITEM_SETTING(remote_flip_display,
186 &global_settings.remote_flip_display, flipdisplay_callback);
188 #ifdef HAVE_REMOTE_LCD_TICKING
189 int ticking_callback(int action,const struct menu_item_ex *this_item)
191 (void)this_item;
192 switch (action)
194 case ACTION_EXIT_MENUITEM:
195 lcd_remote_emireduce(global_settings.remote_reduce_ticking);
196 break;
198 return action;
200 MENUITEM_SETTING(remote_reduce_ticking,
201 &global_settings.remote_reduce_ticking, ticking_callback);
202 #endif
204 MAKE_MENU(lcd_remote_settings, ID2P(LANG_LCD_REMOTE_MENU),
205 NULL, Icon_Remote_Display_menu,
206 &remote_backlight_timeout,
207 #if CONFIG_CHARGING
208 &remote_backlight_timeout_plugged,
209 #endif
210 #ifdef HAS_REMOTE_BUTTON_HOLD
211 &remote_backlight_on_button_hold,
212 #endif
213 &remote_caption_backlight, &remote_bl_filter_first_keypress,
214 &remote_contrast, &remote_invert, &remote_flip_display
215 #ifdef HAVE_REMOTE_LCD_TICKING
216 ,&remote_reduce_ticking
217 #endif
220 #endif /* HAVE_REMOTE_LCD */
221 /* Remote LCD settings menu */
222 /********************************/
224 /***********************************/
225 /* SCROLL MENU */
226 MENUITEM_SETTING_W_TEXT(scroll_speed, &global_settings.scroll_speed,
227 ID2P(LANG_SCROLL), NULL);
228 MENUITEM_SETTING(scroll_delay, &global_settings.scroll_delay, NULL);
229 #ifdef HAVE_LCD_BITMAP
230 MENUITEM_SETTING_W_TEXT(scroll_step, &global_settings.scroll_step,
231 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
232 #endif
233 MENUITEM_SETTING(bidir_limit, &global_settings.bidir_limit, NULL);
234 #ifdef HAVE_REMOTE_LCD
235 MENUITEM_SETTING_W_TEXT(remote_scroll_speed, &global_settings.remote_scroll_speed,
236 ID2P(LANG_SCROLL), NULL);
237 MENUITEM_SETTING(remote_scroll_delay, &global_settings.remote_scroll_delay, NULL);
238 MENUITEM_SETTING_W_TEXT(remote_scroll_step, &global_settings.remote_scroll_step,
239 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
240 MENUITEM_SETTING(remote_bidir_limit, &global_settings.remote_bidir_limit, NULL);
242 MAKE_MENU(remote_scroll_sets, ID2P(LANG_REMOTE_SCROLL_SETS), 0, Icon_NOICON,
243 &remote_scroll_speed, &remote_scroll_delay,
244 &remote_scroll_step, &remote_bidir_limit);
245 #endif /* HAVE_REMOTE_LCD */
246 #ifdef HAVE_LCD_CHARCELLS
247 MENUITEM_SETTING(jump_scroll, &global_settings.jump_scroll, NULL);
248 MENUITEM_SETTING(jump_scroll_delay, &global_settings.jump_scroll_delay, NULL);
249 #endif
250 /* list acceleration */
251 #ifndef HAVE_SCROLLWHEEL
252 MENUITEM_SETTING(list_accel_start_delay,
253 &global_settings.list_accel_start_delay, NULL);
254 MENUITEM_SETTING(list_accel_wait, &global_settings.list_accel_wait, NULL);
255 #endif /* HAVE_SCROLLWHEEL */
256 #ifdef HAVE_LCD_BITMAP
257 int screenscroll_callback(int action,const struct menu_item_ex *this_item)
259 (void)this_item;
260 switch (action)
262 case ACTION_EXIT_MENUITEM:
263 gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view);
264 break;
266 return action;
268 MENUITEM_SETTING(offset_out_of_view, &global_settings.offset_out_of_view,
269 screenscroll_callback);
270 MENUITEM_SETTING(screen_scroll_step, &global_settings.screen_scroll_step, NULL);
271 #endif
272 MENUITEM_SETTING(scroll_paginated, &global_settings.scroll_paginated, NULL);
274 MAKE_MENU(scroll_settings_menu, ID2P(LANG_SCROLL_MENU), 0, Icon_NOICON,
275 &scroll_speed, &scroll_delay,
276 #ifdef HAVE_LCD_BITMAP
277 &scroll_step,
278 #endif
279 &bidir_limit,
280 #ifdef HAVE_REMOTE_LCD
281 &remote_scroll_sets,
282 #endif
283 #ifdef HAVE_LCD_CHARCELLS
284 &jump_scroll, &jump_scroll_delay,
285 #endif
286 #ifdef HAVE_LCD_BITMAP
287 &offset_out_of_view, &screen_scroll_step,
288 #endif
289 &scroll_paginated,
290 #ifndef HAVE_SCROLLWHEEL
291 &list_accel_start_delay, &list_accel_wait
292 #endif
294 /* SCROLL MENU */
295 /***********************************/
297 /***********************************/
298 /* BARS MENU */
299 #ifdef HAVE_LCD_BITMAP
300 MENUITEM_SETTING(scrollbar_item, &global_settings.scrollbar, NULL);
301 MENUITEM_SETTING(statusbar, &global_settings.statusbar, NULL);
302 #if CONFIG_KEYPAD == RECORDER_PAD
303 MENUITEM_SETTING(buttonbar, &global_settings.buttonbar, NULL);
304 #endif
305 MENUITEM_SETTING(volume_type, &global_settings.volume_type, NULL);
306 MENUITEM_SETTING(battery_display, &global_settings.battery_display, NULL);
307 MAKE_MENU(bars_menu, ID2P(LANG_BARS_MENU), 0, Icon_NOICON,
308 &scrollbar_item, &statusbar,
309 #if CONFIG_KEYPAD == RECORDER_PAD
310 &buttonbar,
311 #endif
312 &volume_type, &battery_display);
313 #endif /* HAVE_LCD_BITMAP */
314 /* BARS MENU */
315 /***********************************/
318 /***********************************/
319 /* PEAK METER MENU */
321 #ifdef HAVE_LCD_BITMAP
322 int peakmeter_callback(int action,const struct menu_item_ex *this_item)
324 (void)this_item;
325 switch (action)
327 case ACTION_EXIT_MENUITEM:
328 peak_meter_init_times(global_settings.peak_meter_release,
329 global_settings.peak_meter_hold,
330 global_settings.peak_meter_clip_hold);
331 break;
333 return action;
335 MENUITEM_SETTING(peak_meter_hold,
336 &global_settings.peak_meter_hold, peakmeter_callback);
337 MENUITEM_SETTING(peak_meter_clip_hold,
338 &global_settings.peak_meter_clip_hold, peakmeter_callback);
339 #ifdef HAVE_RECORDING
340 MENUITEM_SETTING(peak_meter_clipcounter,
341 &global_settings.peak_meter_clipcounter, NULL);
342 #endif
343 MENUITEM_SETTING(peak_meter_release,
344 &global_settings.peak_meter_release, peakmeter_callback);
346 * Menu to select wether the scale of the meter
347 * displays dBfs of linear values.
349 static int peak_meter_scale(void) {
350 bool retval = false;
351 bool use_dbfs = global_settings.peak_meter_dbfs;
352 retval = set_bool_options(str(LANG_PM_SCALE),
353 &use_dbfs,
354 STR(LANG_PM_DBFS), STR(LANG_PM_LINEAR),
355 NULL);
357 /* has the user really changed the scale? */
358 if (use_dbfs != global_settings.peak_meter_dbfs) {
360 /* store the change */
361 global_settings.peak_meter_dbfs = use_dbfs;
362 peak_meter_set_use_dbfs(use_dbfs);
364 /* If the user changed the scale mode the meaning of
365 peak_meter_min (peak_meter_max) has changed. Thus we have
366 to convert the values stored in global_settings. */
367 if (use_dbfs) {
369 /* we only store -dBfs */
370 global_settings.peak_meter_min = -peak_meter_get_min() / 100;
371 global_settings.peak_meter_max = -peak_meter_get_max() / 100;
373 /* limit the returned value to the allowed range */
374 if(global_settings.peak_meter_min > 89)
375 global_settings.peak_meter_min = 89;
376 } else {
377 int max;
379 /* linear percent */
380 global_settings.peak_meter_min = peak_meter_get_min();
382 /* converting dBfs -> percent results in a precision loss.
383 I assume that the user doesn't bother that conversion
384 dBfs <-> percent isn't symmetrical for odd values but that
385 he wants 0 dBfs == 100%. Thus I 'correct' the percent value
386 resulting from dBfs -> percent manually here */
387 max = peak_meter_get_max();
388 global_settings.peak_meter_max = max < 99 ? max : 100;
390 settings_apply_pm_range();
392 return retval;
396 * Adjust the min value of the value range that
397 * the peak meter shall visualize.
399 static int peak_meter_min(void) {
400 bool retval = false;
401 if (global_settings.peak_meter_dbfs) {
403 /* for dBfs scale */
404 int range_max = -global_settings.peak_meter_max;
405 int min = -global_settings.peak_meter_min;
407 retval = set_int(str(LANG_PM_MIN), str(LANG_PM_DBFS), UNIT_DB,
408 &min, NULL, 1, -89, range_max, NULL);
410 global_settings.peak_meter_min = - min;
413 /* for linear scale */
414 else {
415 int min = global_settings.peak_meter_min;
417 retval = set_int(str(LANG_PM_MIN), "%", UNIT_PERCENT,
418 &min, NULL,
419 1, 0, global_settings.peak_meter_max - 1, NULL);
421 global_settings.peak_meter_min = (unsigned char)min;
424 settings_apply_pm_range();
425 return retval;
430 * Adjust the max value of the value range that
431 * the peak meter shall visualize.
433 static int peak_meter_max(void) {
434 bool retval = false;
435 if (global_settings.peak_meter_dbfs) {
437 /* for dBfs scale */
438 int range_min = -global_settings.peak_meter_min;
439 int max = -global_settings.peak_meter_max;;
441 retval = set_int(str(LANG_PM_MAX), str(LANG_PM_DBFS), UNIT_DB,
442 &max, NULL, 1, range_min, 0, NULL);
444 global_settings.peak_meter_max = - max;
448 /* for linear scale */
449 else {
450 int max = global_settings.peak_meter_max;
452 retval = set_int(str(LANG_PM_MAX), "%", UNIT_PERCENT,
453 &max, NULL,
454 1, global_settings.peak_meter_min + 1, 100, NULL);
456 global_settings.peak_meter_max = (unsigned char)max;
459 settings_apply_pm_range();
460 return retval;
462 MENUITEM_FUNCTION(peak_meter_scale_item, 0, ID2P(LANG_PM_SCALE),
463 peak_meter_scale, NULL, NULL, Icon_NOICON);
464 MENUITEM_FUNCTION(peak_meter_min_item, 0, ID2P(LANG_PM_MIN),
465 peak_meter_min, NULL, NULL, Icon_NOICON);
466 MENUITEM_FUNCTION(peak_meter_max_item, 0, ID2P(LANG_PM_MAX),
467 peak_meter_max, NULL, NULL, Icon_NOICON);
468 MAKE_MENU(peak_meter_menu, ID2P(LANG_PM_MENU), NULL, Icon_NOICON,
469 &peak_meter_release, &peak_meter_hold,
470 &peak_meter_clip_hold,
471 #ifdef HAVE_RECORDING
472 &peak_meter_clipcounter,
473 #endif
474 &peak_meter_scale_item, &peak_meter_min_item, &peak_meter_max_item);
475 #endif /* HAVE_LCD_BITMAP */
476 /* PEAK METER MENU */
477 /***********************************/
481 MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL);
484 MAKE_MENU(display_menu, ID2P(LANG_DISPLAY),
485 NULL, Icon_Display_menu,
486 &lcd_settings,
487 #ifdef HAVE_REMOTE_LCD
488 &lcd_remote_settings,
489 #endif
490 &scroll_settings_menu,
491 #ifdef HAVE_LCD_BITMAP
492 &bars_menu, &peak_meter_menu,
493 #endif
494 &codepage_setting,