1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by 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 ****************************************************************************/
25 #include "lcd-remote.h"
28 #include "screen_access.h"
32 /*some short cuts for fg/bg/line selector handling */
34 #define LINE_SEL_FROM_SETTINGS(vp) \
36 vp->lss_pattern = global_settings.lss_color; \
37 vp->lse_pattern = global_settings.lse_color; \
38 vp->lst_pattern = global_settings.lst_color; \
40 #define FG_FALLBACK global_settings.fg_color
41 #define BG_FALLBACK global_settings.bg_color
43 /* mono/greyscale doesn't have most of the above */
44 #define LINE_SEL_FROM_SETTINGS(vp)
45 #define FG_FALLBACK LCD_DEFAULT_FG
46 #define BG_FALLBACK LCD_DEFAULT_BG
49 /* all below isn't needed for pc tools (i.e. checkwps/wps editor)
50 * only viewport_parse_viewport() is */
56 #include "statusbar.h"
57 #include "appevents.h"
58 #ifdef HAVE_LCD_BITMAP
62 static int statusbar_enabled
= 0;
64 #ifdef HAVE_LCD_BITMAP
65 static void set_default_align_flags(struct viewport
*vp
);
69 int active
[NB_SCREENS
];
72 static struct viewport custom_vp
[NB_SCREENS
];
74 /* callbacks for GUI_EVENT_* events */
75 static void viewportmanager_ui_vp_changed(void *param
);
76 static void statusbar_toggled(void* param
);
77 static unsigned viewport_init_ui_vp(void);
79 static void viewportmanager_redraw(void* data
);
81 int viewport_get_nb_lines(const struct viewport
*vp
)
83 #ifdef HAVE_LCD_BITMAP
84 return vp
->height
/font_get(vp
->font
)->height
;
91 static bool showing_bars(enum screen_type screen
)
93 if (statusbar_enabled
& VP_SB_ONSCREEN(screen
))
95 #ifdef HAVE_LCD_BITMAP
96 bool ignore
= statusbar_enabled
& VP_SB_IGNORE_SETTING(screen
);
97 return ignore
|| (statusbar_position(screen
));
105 void viewport_set_fullscreen(struct viewport
*vp
,
106 const enum screen_type screen
)
109 vp
->width
= screens
[screen
].lcdwidth
;
111 #ifdef HAVE_LCD_BITMAP
112 set_default_align_flags(vp
);
113 vp
->drawmode
= DRMODE_SOLID
;
114 vp
->font
= FONT_UI
; /* default to UI to discourage SYSFONT use */
116 vp
->height
= screens
[screen
].lcdheight
;
117 if (statusbar_position(screen
) != STATUSBAR_BOTTOM
118 && showing_bars(screen
))
119 vp
->y
= STATUSBAR_HEIGHT
;
125 vp
->height
= screens
[screen
].lcdheight
126 - (showing_bars(screen
)?STATUSBAR_HEIGHT
:0);
129 #ifdef HAVE_REMOTE_LCD
130 /* We only need this test if there is a remote LCD */
131 if (screen
== SCREEN_MAIN
)
134 vp
->fg_pattern
= FG_FALLBACK
;
135 vp
->bg_pattern
= BG_FALLBACK
;
136 LINE_SEL_FROM_SETTINGS(vp
);
140 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
141 if (screen
== SCREEN_REMOTE
)
143 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
144 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
150 void viewport_set_defaults(struct viewport
*vp
,
151 const enum screen_type screen
)
153 #ifdef HAVE_LCD_BITMAP
154 if (ui_vp_info
.active
[screen
])
155 *vp
= ui_vp_info
.vp
[screen
];
158 viewport_set_fullscreen(vp
, screen
);
162 void viewportmanager_init(void)
164 #ifdef HAVE_LCD_BITMAP
166 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggled
);
167 retval
= viewport_init_ui_vp();
169 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
170 ui_vp_info
.vp
= custom_vp
;
172 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
175 int viewportmanager_get_statusbar(void)
177 return statusbar_enabled
;
180 int viewportmanager_set_statusbar(const int enabled
)
182 int old
= statusbar_enabled
;
183 statusbar_enabled
= enabled
;
190 gui_statusbar_draw(&statusbars
.statusbars
[i
], true);
192 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
196 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
201 static void viewportmanager_redraw(void* data
)
208 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
!= data
);
211 #ifdef HAVE_LCD_BITMAP
213 static void statusbar_toggled(void* param
)
216 /* update vp manager for the new setting and reposition vps
218 viewportmanager_theme_changed(THEME_STATUSBAR
);
221 void viewportmanager_theme_changed(const int which
)
224 #ifdef HAVE_BUTTONBAR
225 if (which
& THEME_BUTTONBAR
)
226 { /* don't handle further, the custom ui viewport ignores the buttonbar,
227 * as does viewport_set_defaults(), since only lists use it*/
228 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
231 if (which
& THEME_UI_VIEWPORT
)
233 int retval
= viewport_init_ui_vp();
234 /* reset the ui viewport */
236 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
239 add_event(GUI_EVENT_REFRESH
, false, viewportmanager_ui_vp_changed
);
241 remove_event(GUI_EVENT_REFRESH
, viewportmanager_ui_vp_changed
);
242 /* and point to it */
243 ui_vp_info
.vp
= custom_vp
;
245 else if (which
& THEME_LANGUAGE
)
246 { /* THEME_UI_VIEWPORT handles rtl already */
248 set_default_align_flags(&custom_vp
[i
]);
250 if (which
& THEME_STATUSBAR
)
252 statusbar_enabled
= VP_SB_HIDE_ALL
;
256 if (statusbar_position(i
) != STATUSBAR_OFF
)
257 statusbar_enabled
|= VP_SB_ONSCREEN(i
);
260 if (statusbar_enabled
!= VP_SB_HIDE_ALL
)
261 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
263 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
265 /* reposition viewport to fit statusbar, only if not using the ui vp */
269 if (!ui_vp_info
.active
[i
])
270 viewport_set_fullscreen(&custom_vp
[i
], i
);
273 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
276 static void viewportmanager_ui_vp_changed(void *param
)
278 /* if the user changed the theme, we need to initiate a full redraw */
280 /* cast param to a function */
281 void (*draw_func
)(void) = ((void(*)(void))param
);
282 /* start with clearing the screen */
284 screens
[i
].clear_display();
285 /* redraw the statusbar if it was enabled */
286 viewportmanager_set_statusbar(statusbar_enabled
);
287 /* call the passed function which will redraw the content of
288 * the current screen */
295 void viewport_set_current_vp(struct viewport
* vp
)
300 ui_vp_info
.vp
= custom_vp
;
302 /* must be done after the assignment above or event handler get old vps */
303 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
306 struct viewport
* viewport_get_current_vp(void)
308 return ui_vp_info
.vp
;
311 bool viewport_ui_vp_get_state(enum screen_type screen
)
313 return ui_vp_info
.active
[screen
];
317 * (re)parse the UI vp from the settings
319 * 0 if no UI vp is used at all
320 * else the bit for the screen (1<<screen) is set
322 static unsigned viewport_init_ui_vp(void)
327 FOR_NB_SCREENS(screen
)
329 #ifdef HAVE_REMOTE_LCD
330 if ((screen
== SCREEN_REMOTE
))
331 setting
= global_settings
.remote_ui_vp_config
;
334 setting
= global_settings
.ui_vp_config
;
337 if (!(viewport_parse_viewport(&custom_vp
[screen
], screen
,
339 viewport_set_fullscreen(&custom_vp
[screen
], screen
);
341 ret
|= BIT_N(screen
);
346 #ifdef HAVE_TOUCHSCREEN
347 /* check if a point (x and y coordinates) are within a viewport */
348 bool viewport_point_within_vp(const struct viewport
*vp
,
349 const int x
, const int y
)
351 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
352 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
353 return (is_x
&& is_y
);
355 #endif /* HAVE_TOUCHSCREEN */
356 #endif /* HAVE_LCD_BITMAP */
357 #endif /* __PCTOOL__ */
359 #ifdef HAVE_LCD_COLOR
360 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
362 #define ARG_STRING(_depth) "dddddgg"
365 #ifdef HAVE_LCD_BITMAP
367 static void set_default_align_flags(struct viewport
*vp
)
369 vp
->flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
371 if (UNLIKELY(lang_is_rtl()))
372 vp
->flags
|= VP_FLAG_ALIGN_RIGHT
;
376 const char* viewport_parse_viewport(struct viewport
*vp
,
377 enum screen_type screen
,
379 const char separator
)
381 /* parse the list to the viewport struct */
382 const char *ptr
= bufptr
;
396 /* Work out the depth of this display */
397 depth
= screens
[screen
].depth
;
398 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
401 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
402 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
407 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
410 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
411 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
412 &vp
->fg_pattern
,&vp
->bg_pattern
)))
420 /* X and Y *must* be set */
421 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
425 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
426 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
427 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
428 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
430 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
431 if (!LIST_VALUE_PARSED(set
, PL_FG
))
432 vp
->fg_pattern
= FG_FALLBACK
;
433 if (!LIST_VALUE_PARSED(set
, PL_BG
))
434 vp
->bg_pattern
= BG_FALLBACK
;
435 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
437 LINE_SEL_FROM_SETTINGS(vp
);
439 /* Validate the viewport dimensions - we know that the numbers are
440 non-negative integers, ignore bars and assume the viewport takes them
442 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
443 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
444 (vp
->y
>= screens
[screen
].lcdheight
) ||
445 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
450 /* Default to using the user font if the font was an invalid number or '-'*/
451 if (((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
))
452 || !LIST_VALUE_PARSED(set
, PL_FONT
)
456 /* Set the defaults for fields not user-specified */
457 vp
->drawmode
= DRMODE_SOLID
;
458 set_default_align_flags(vp
);