Fix red: Invert buttons in RTL mode
[kugel-rb.git] / apps / menus / display_menu.c
blob5559ecebe76ea29de3143251f44cd050ec35751e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "appevents.h"
27 #include "lang.h"
28 #include "action.h"
29 #include "settings.h"
30 #include "menu.h"
31 #include "tree.h"
32 #include "list.h"
33 #ifdef HAVE_LCD_BITMAP
34 #include "peakmeter.h"
35 #endif
36 #include "talk.h"
37 #include "lcd.h"
38 #include "lcd-remote.h"
39 #ifdef HAVE_TOUCHSCREEN
40 #include "screens.h"
41 #endif
42 #include "viewport.h"
43 #include "statusbar.h" /* statusbar_vals enum*/
45 #ifdef HAVE_BACKLIGHT
46 static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item)
48 (void)this_item;
49 switch (action)
51 case ACTION_EXIT_MENUITEM:
52 set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
53 #ifdef HAVE_REMOTE_LCD
54 set_remote_backlight_filter_keypress(
55 global_settings.remote_bl_filter_first_keypress);
56 #endif
58 break;
60 return action;
62 #endif
63 #ifdef HAVE_LCD_FLIP
64 static int flipdisplay_callback(int action,const struct menu_item_ex *this_item)
66 (void)this_item;
67 switch (action)
69 case ACTION_EXIT_MENUITEM:
70 button_set_flip(global_settings.flip_display);
71 lcd_set_flip(global_settings.flip_display);
72 lcd_update();
73 #ifdef HAVE_REMOTE_LCD
74 lcd_remote_set_flip(global_settings.remote_flip_display);
75 lcd_remote_update();
76 #endif
77 break;
79 return action;
81 #endif
83 /***********************************/
84 /* LCD MENU */
85 #ifdef HAVE_BACKLIGHT
86 MENUITEM_SETTING(backlight_timeout, &global_settings.backlight_timeout, NULL);
87 #if CONFIG_CHARGING
88 MENUITEM_SETTING(backlight_timeout_plugged,
89 &global_settings.backlight_timeout_plugged, NULL);
90 #endif
91 #ifdef HAS_BUTTON_HOLD
92 MENUITEM_SETTING(backlight_on_button_hold,
93 &global_settings.backlight_on_button_hold, NULL);
94 #endif
95 MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
96 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
97 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
98 MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
99 MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
100 #endif
101 MENUITEM_SETTING(bl_filter_first_keypress,
102 &global_settings.bl_filter_first_keypress,
103 filterfirstkeypress_callback);
104 #ifdef HAVE_LCD_SLEEP_SETTING
105 MENUITEM_SETTING(lcd_sleep_after_backlight_off,
106 &global_settings.lcd_sleep_after_backlight_off, NULL);
107 #endif
108 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
109 MENUITEM_SETTING(brightness_item, &global_settings.brightness, NULL);
110 #endif
111 #endif /* HAVE_BACKLIGHT */
112 #ifdef HAVE_LCD_CONTRAST
113 MENUITEM_SETTING(contrast, &global_settings.contrast, NULL);
114 #endif
115 #ifdef HAVE_LCD_BITMAP
116 #ifdef HAVE_LCD_INVERT
117 MENUITEM_SETTING(invert, &global_settings.invert, NULL);
118 #endif
119 #ifdef HAVE_LCD_FLIP
120 MENUITEM_SETTING(flip_display, &global_settings.flip_display, flipdisplay_callback);
121 #endif
122 #endif /* HAVE_LCD_BITMAP */
124 /* now the actual menu */
125 MAKE_MENU(lcd_settings,ID2P(LANG_LCD_MENU),
126 NULL, Icon_Display_menu
127 #ifdef HAVE_BACKLIGHT
128 ,&backlight_timeout
129 # if CONFIG_CHARGING
130 ,&backlight_timeout_plugged
131 # endif
132 # ifdef HAS_BUTTON_HOLD
133 ,&backlight_on_button_hold
134 # endif
135 ,&caption_backlight
136 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
137 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
138 ,&backlight_fade_in, &backlight_fade_out
139 #endif
140 ,&bl_filter_first_keypress
141 # ifdef HAVE_LCD_SLEEP_SETTING
142 ,&lcd_sleep_after_backlight_off
143 # endif
144 # ifdef HAVE_BACKLIGHT_BRIGHTNESS
145 ,&brightness_item
146 # endif
147 #endif /* HAVE_BACKLIGHT */
148 #ifdef HAVE_LCD_CONTRAST
149 ,&contrast
150 #endif
151 #ifdef HAVE_LCD_BITMAP
152 # ifdef HAVE_LCD_INVERT
153 ,&invert
154 # endif
155 # ifdef HAVE_LCD_FLIP
156 ,&flip_display
157 # endif
158 #endif /* HAVE_LCD_BITMAP */
160 /* LCD MENU */
161 /***********************************/
164 /********************************/
165 /* Remote LCD settings menu */
166 #ifdef HAVE_REMOTE_LCD
167 MENUITEM_SETTING(remote_backlight_timeout,
168 &global_settings.remote_backlight_timeout, NULL);
170 #if CONFIG_CHARGING
171 MENUITEM_SETTING(remote_backlight_timeout_plugged,
172 &global_settings.remote_backlight_timeout_plugged, NULL);
173 #endif
175 #ifdef HAS_REMOTE_BUTTON_HOLD
176 MENUITEM_SETTING(remote_backlight_on_button_hold,
177 &global_settings.remote_backlight_on_button_hold, NULL);
178 #endif
180 MENUITEM_SETTING(remote_caption_backlight,
181 &global_settings.remote_caption_backlight, NULL);
182 MENUITEM_SETTING(remote_bl_filter_first_keypress,
183 &global_settings.remote_bl_filter_first_keypress,
184 filterfirstkeypress_callback);
185 MENUITEM_SETTING(remote_contrast,
186 &global_settings.remote_contrast, NULL);
187 MENUITEM_SETTING(remote_invert,
188 &global_settings.remote_invert, NULL);
190 #ifdef HAVE_LCD_FLIP
191 MENUITEM_SETTING(remote_flip_display,
192 &global_settings.remote_flip_display, flipdisplay_callback);
193 #endif
195 #ifdef HAVE_REMOTE_LCD_TICKING
196 static int ticking_callback(int action,const struct menu_item_ex *this_item)
198 (void)this_item;
199 switch (action)
201 case ACTION_EXIT_MENUITEM:
202 lcd_remote_emireduce(global_settings.remote_reduce_ticking);
203 break;
205 return action;
207 MENUITEM_SETTING(remote_reduce_ticking,
208 &global_settings.remote_reduce_ticking, ticking_callback);
209 #endif
211 MAKE_MENU(lcd_remote_settings, ID2P(LANG_LCD_REMOTE_MENU),
212 NULL, Icon_Remote_Display_menu,
213 &remote_backlight_timeout,
214 #if CONFIG_CHARGING
215 &remote_backlight_timeout_plugged,
216 #endif
217 #ifdef HAS_REMOTE_BUTTON_HOLD
218 &remote_backlight_on_button_hold,
219 #endif
220 &remote_caption_backlight, &remote_bl_filter_first_keypress,
221 &remote_contrast, &remote_invert
223 #ifdef HAVE_LCD_FLIP
224 ,&remote_flip_display
225 #endif
226 #ifdef HAVE_REMOTE_LCD_TICKING
227 ,&remote_reduce_ticking
228 #endif
231 #endif /* HAVE_REMOTE_LCD */
232 /* Remote LCD settings menu */
233 /********************************/
235 /***********************************/
236 /* SCROLL MENU */
237 MENUITEM_SETTING_W_TEXT(scroll_speed, &global_settings.scroll_speed,
238 ID2P(LANG_SCROLL), NULL);
239 MENUITEM_SETTING(scroll_delay, &global_settings.scroll_delay, NULL);
240 #ifdef HAVE_LCD_BITMAP
241 MENUITEM_SETTING_W_TEXT(scroll_step, &global_settings.scroll_step,
242 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
243 #endif
244 MENUITEM_SETTING(bidir_limit, &global_settings.bidir_limit, NULL);
245 #ifdef HAVE_REMOTE_LCD
246 MENUITEM_SETTING_W_TEXT(remote_scroll_speed, &global_settings.remote_scroll_speed,
247 ID2P(LANG_SCROLL), NULL);
248 MENUITEM_SETTING(remote_scroll_delay, &global_settings.remote_scroll_delay, NULL);
249 MENUITEM_SETTING_W_TEXT(remote_scroll_step, &global_settings.remote_scroll_step,
250 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
251 MENUITEM_SETTING(remote_bidir_limit, &global_settings.remote_bidir_limit, NULL);
253 MAKE_MENU(remote_scroll_sets, ID2P(LANG_REMOTE_SCROLL_SETS), 0, Icon_NOICON,
254 &remote_scroll_speed, &remote_scroll_delay,
255 &remote_scroll_step, &remote_bidir_limit);
256 #endif /* HAVE_REMOTE_LCD */
257 #ifdef HAVE_LCD_CHARCELLS
258 MENUITEM_SETTING(jump_scroll, &global_settings.jump_scroll, NULL);
259 MENUITEM_SETTING(jump_scroll_delay, &global_settings.jump_scroll_delay, NULL);
260 #endif
261 /* list acceleration */
262 #ifndef HAVE_WHEEL_ACCELERATION
263 MENUITEM_SETTING(list_accel_start_delay,
264 &global_settings.list_accel_start_delay, NULL);
265 MENUITEM_SETTING(list_accel_wait, &global_settings.list_accel_wait, NULL);
266 #endif /* HAVE_WHEEL_ACCELERATION */
267 #ifdef HAVE_LCD_BITMAP
268 static int screenscroll_callback(int action,const struct menu_item_ex *this_item)
270 (void)this_item;
271 switch (action)
273 case ACTION_EXIT_MENUITEM:
274 gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view);
275 break;
277 return action;
279 MENUITEM_SETTING(offset_out_of_view, &global_settings.offset_out_of_view,
280 screenscroll_callback);
281 MENUITEM_SETTING(screen_scroll_step, &global_settings.screen_scroll_step, NULL);
282 #endif
283 MENUITEM_SETTING(scroll_paginated, &global_settings.scroll_paginated, NULL);
285 MAKE_MENU(scroll_settings_menu, ID2P(LANG_SCROLL_MENU), 0, Icon_NOICON,
286 &scroll_speed, &scroll_delay,
287 #ifdef HAVE_LCD_BITMAP
288 &scroll_step,
289 #endif
290 &bidir_limit,
291 #ifdef HAVE_REMOTE_LCD
292 &remote_scroll_sets,
293 #endif
294 #ifdef HAVE_LCD_CHARCELLS
295 &jump_scroll, &jump_scroll_delay,
296 #endif
297 #ifdef HAVE_LCD_BITMAP
298 &offset_out_of_view, &screen_scroll_step,
299 #endif
300 &scroll_paginated,
301 #ifndef HAVE_WHEEL_ACCELERATION
302 &list_accel_start_delay, &list_accel_wait
303 #endif
305 /* SCROLL MENU */
306 /***********************************/
308 /***********************************/
309 /* PEAK METER MENU */
311 #ifdef HAVE_LCD_BITMAP
312 static int peakmeter_callback(int action,const struct menu_item_ex *this_item)
314 (void)this_item;
315 switch (action)
317 case ACTION_EXIT_MENUITEM:
318 peak_meter_init_times(global_settings.peak_meter_release,
319 global_settings.peak_meter_hold,
320 global_settings.peak_meter_clip_hold);
321 break;
323 return action;
325 MENUITEM_SETTING(peak_meter_hold,
326 &global_settings.peak_meter_hold, peakmeter_callback);
327 MENUITEM_SETTING(peak_meter_clip_hold,
328 &global_settings.peak_meter_clip_hold, peakmeter_callback);
329 #ifdef HAVE_RECORDING
330 MENUITEM_SETTING(peak_meter_clipcounter,
331 &global_settings.peak_meter_clipcounter, NULL);
332 #endif
333 MENUITEM_SETTING(peak_meter_release,
334 &global_settings.peak_meter_release, peakmeter_callback);
336 * Menu to select wether the scale of the meter
337 * displays dBfs of linear values.
339 static int peak_meter_scale(void) {
340 bool retval = false;
341 bool use_dbfs = global_settings.peak_meter_dbfs;
342 retval = set_bool_options(str(LANG_PM_SCALE),
343 &use_dbfs,
344 STR(LANG_PM_DBFS), STR(LANG_PM_LINEAR),
345 NULL);
347 /* has the user really changed the scale? */
348 if (use_dbfs != global_settings.peak_meter_dbfs) {
350 /* store the change */
351 global_settings.peak_meter_dbfs = use_dbfs;
352 peak_meter_set_use_dbfs(use_dbfs);
354 /* If the user changed the scale mode the meaning of
355 peak_meter_min (peak_meter_max) has changed. Thus we have
356 to convert the values stored in global_settings. */
357 if (use_dbfs) {
359 /* we only store -dBfs */
360 global_settings.peak_meter_min = -peak_meter_get_min() / 100;
361 global_settings.peak_meter_max = -peak_meter_get_max() / 100;
363 /* limit the returned value to the allowed range */
364 if(global_settings.peak_meter_min > 89)
365 global_settings.peak_meter_min = 89;
366 } else {
367 int max;
369 /* linear percent */
370 global_settings.peak_meter_min = peak_meter_get_min();
372 /* converting dBfs -> percent results in a precision loss.
373 I assume that the user doesn't bother that conversion
374 dBfs <-> percent isn't symmetrical for odd values but that
375 he wants 0 dBfs == 100%. Thus I 'correct' the percent value
376 resulting from dBfs -> percent manually here */
377 max = peak_meter_get_max();
378 global_settings.peak_meter_max = max < 99 ? max : 100;
380 settings_apply_pm_range();
382 return retval;
386 * Adjust the min value of the value range that
387 * the peak meter shall visualize.
389 static int peak_meter_min(void) {
390 bool retval = false;
391 if (global_settings.peak_meter_dbfs) {
393 /* for dBfs scale */
394 int range_max = -global_settings.peak_meter_max;
395 int min = -global_settings.peak_meter_min;
397 retval = set_int(str(LANG_PM_MIN), str(LANG_PM_DBFS), UNIT_DB,
398 &min, NULL, 1, -89, range_max, NULL);
400 global_settings.peak_meter_min = - min;
403 /* for linear scale */
404 else {
405 int min = global_settings.peak_meter_min;
407 retval = set_int(str(LANG_PM_MIN), "%", UNIT_PERCENT,
408 &min, NULL,
409 1, 0, global_settings.peak_meter_max - 1, NULL);
411 global_settings.peak_meter_min = (unsigned char)min;
414 settings_apply_pm_range();
415 return retval;
420 * Adjust the max value of the value range that
421 * the peak meter shall visualize.
423 static int peak_meter_max(void) {
424 bool retval = false;
425 if (global_settings.peak_meter_dbfs) {
427 /* for dBfs scale */
428 int range_min = -global_settings.peak_meter_min;
429 int max = -global_settings.peak_meter_max;
431 retval = set_int(str(LANG_PM_MAX), str(LANG_PM_DBFS), UNIT_DB,
432 &max, NULL, 1, range_min, 0, NULL);
434 global_settings.peak_meter_max = - max;
438 /* for linear scale */
439 else {
440 int max = global_settings.peak_meter_max;
442 retval = set_int(str(LANG_PM_MAX), "%", UNIT_PERCENT,
443 &max, NULL,
444 1, global_settings.peak_meter_min + 1, 100, NULL);
446 global_settings.peak_meter_max = (unsigned char)max;
449 settings_apply_pm_range();
450 return retval;
452 MENUITEM_FUNCTION(peak_meter_scale_item, 0, ID2P(LANG_PM_SCALE),
453 peak_meter_scale, NULL, NULL, Icon_NOICON);
454 MENUITEM_FUNCTION(peak_meter_min_item, 0, ID2P(LANG_PM_MIN),
455 peak_meter_min, NULL, NULL, Icon_NOICON);
456 MENUITEM_FUNCTION(peak_meter_max_item, 0, ID2P(LANG_PM_MAX),
457 peak_meter_max, NULL, NULL, Icon_NOICON);
458 MAKE_MENU(peak_meter_menu, ID2P(LANG_PM_MENU), NULL, Icon_NOICON,
459 &peak_meter_release, &peak_meter_hold,
460 &peak_meter_clip_hold,
461 #ifdef HAVE_RECORDING
462 &peak_meter_clipcounter,
463 #endif
464 &peak_meter_scale_item, &peak_meter_min_item, &peak_meter_max_item);
465 #endif /* HAVE_LCD_BITMAP */
466 /* PEAK METER MENU */
467 /***********************************/
470 #ifdef HAVE_TOUCHSCREEN
471 static int touch_mode_callback(int action,const struct menu_item_ex *this_item)
473 (void)this_item;
474 switch (action)
476 case ACTION_EXIT_MENUITEM: /* on exit */
477 touchscreen_set_mode(global_settings.touch_mode);
478 break;
480 return action;
482 MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback);
484 MENUITEM_FUNCTION(touchscreen_menu_calibrate, 0, ID2P(LANG_TOUCHSCREEN_CALIBRATE), calibrate,
485 NULL, NULL, Icon_NOICON);
486 MENUITEM_FUNCTION(touchscreen_menu_reset_calibration, 0, ID2P(LANG_TOUCHSCREEN_RESET_CALIBRATION), reset_mapping,
487 NULL, NULL, Icon_NOICON);
489 MAKE_MENU(touchscreen_menu, ID2P(LANG_TOUCHSCREEN_SETTINGS), NULL, Icon_NOICON, &touch_mode,
490 &touchscreen_menu_calibrate, &touchscreen_menu_reset_calibration);
491 #endif
494 MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL);
497 MAKE_MENU(display_menu, ID2P(LANG_DISPLAY),
498 NULL, Icon_Display_menu,
499 &lcd_settings,
500 #ifdef HAVE_REMOTE_LCD
501 &lcd_remote_settings,
502 #endif
503 &scroll_settings_menu,
504 #ifdef HAVE_LCD_BITMAP
505 &peak_meter_menu,
506 #endif
507 &codepage_setting,
508 #ifdef HAVE_TOUCHSCREEN
509 &touchscreen_menu,
510 #endif