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"
34 #include "statusbar.h"
35 #include "screen_access.h"
36 #include "appevents.h"
40 /*some short cuts for fg/bg/line selector handling */
42 #define LINE_SEL_FROM_SETTINGS(vp) \
44 vp->lss_pattern = global_settings.lss_color; \
45 vp->lse_pattern = global_settings.lse_color; \
46 vp->lst_pattern = global_settings.lst_color; \
48 #define FG_FALLBACK global_settings.fg_color
49 #define BG_FALLBACK global_settings.bg_color
51 /* mono/greyscale doesn't have most of the above */
52 #define LINE_SEL_FROM_SETTINGS(vp)
53 #define FG_FALLBACK LCD_DEFAULT_FG
54 #define BG_FALLBACK LCD_DEFAULT_BG
57 static int statusbar_enabled
= 0;
59 #ifdef HAVE_LCD_BITMAP
66 static struct viewport custom_vp
[NB_SCREENS
];
68 /* callbacks for GUI_EVENT_* events */
69 static void viewportmanager_ui_vp_changed(void *param
);
70 static void statusbar_toggled(void* param
);
71 static int viewport_init_ui_vp(void);
73 static void viewportmanager_redraw(void* data
);
75 int viewport_get_nb_lines(struct viewport
*vp
)
77 #ifdef HAVE_LCD_BITMAP
78 return vp
->height
/font_get(vp
->font
)->height
;
85 static bool showing_bars(enum screen_type screen
)
87 if (statusbar_enabled
& VP_SB_ONSCREEN(screen
))
89 #ifdef HAVE_LCD_BITMAP
90 bool ignore
= statusbar_enabled
& VP_SB_IGNORE_SETTING(screen
);
91 return ignore
|| (statusbar_position(screen
));
99 void viewport_set_fullscreen(struct viewport
*vp
, enum screen_type screen
)
102 vp
->width
= screens
[screen
].lcdwidth
;
104 #ifdef HAVE_LCD_BITMAP
105 vp
->drawmode
= DRMODE_SOLID
;
106 vp
->font
= FONT_UI
; /* default to UI to discourage SYSFONT use */
108 vp
->height
= screens
[screen
].lcdheight
;
109 if (statusbar_position(screen
) != STATUSBAR_BOTTOM
&& showing_bars(screen
))
110 vp
->y
= STATUSBAR_HEIGHT
;
116 vp
->height
= screens
[screen
].lcdheight
- (showing_bars(screen
)?STATUSBAR_HEIGHT
:0);
119 #ifdef HAVE_REMOTE_LCD
120 /* We only need this test if there is a remote LCD */
121 if (screen
== SCREEN_MAIN
)
124 vp
->fg_pattern
= FG_FALLBACK
;
125 vp
->bg_pattern
= BG_FALLBACK
;
126 LINE_SEL_FROM_SETTINGS(vp
);
130 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
131 if (screen
== SCREEN_REMOTE
)
133 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
134 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
139 void viewport_set_defaults(struct viewport
*vp
, enum screen_type screen
)
141 #ifdef HAVE_LCD_BITMAP
142 if (ui_vp_info
.active
)
143 *vp
= custom_vp
[screen
];
146 viewport_set_fullscreen(vp
, screen
);
149 void viewportmanager_init(void)
151 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
152 #ifdef HAVE_LCD_BITMAP
153 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggled
);
154 ui_vp_info
.active
= viewport_init_ui_vp();
155 ui_vp_info
.vp
= custom_vp
;
159 int viewportmanager_get_statusbar(void)
161 return statusbar_enabled
;
164 int viewportmanager_set_statusbar(int enabled
)
166 int old
= statusbar_enabled
;
167 statusbar_enabled
= enabled
;
174 gui_statusbar_draw(&statusbars
.statusbars
[i
], true);
176 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
180 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
185 static void viewportmanager_redraw(void* data
)
192 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
!= data
);
195 #ifdef HAVE_LCD_BITMAP
197 static void statusbar_toggled(void* param
)
200 /* update vp manager for the new setting and reposition vps
202 viewportmanager_theme_changed(THEME_STATUSBAR
);
205 void viewportmanager_theme_changed(int which
)
207 if (which
& THEME_UI_VIEWPORT
)
209 /* reset the ui viewport */
210 if ((ui_vp_info
.active
= viewport_init_ui_vp()))
211 add_event(GUI_EVENT_REFRESH
, false, viewportmanager_ui_vp_changed
);
213 remove_event(GUI_EVENT_REFRESH
, viewportmanager_ui_vp_changed
);
214 /* and point to it */
215 ui_vp_info
.vp
= custom_vp
;
217 if (which
& THEME_STATUSBAR
)
219 statusbar_enabled
= 0;
220 if (global_settings
.statusbar
!= STATUSBAR_OFF
)
221 statusbar_enabled
= VP_SB_ONSCREEN(SCREEN_MAIN
);
222 #ifdef HAVE_REMOTE_LCD
223 if (global_settings
.remote_statusbar
!= STATUSBAR_OFF
)
224 statusbar_enabled
|= VP_SB_ONSCREEN(SCREEN_REMOTE
);
226 if (statusbar_enabled
)
227 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
229 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
231 /* reposition viewport to fit statusbar, only if not using the ui vp */
232 if (!ui_vp_info
.active
)
236 viewport_set_fullscreen(&custom_vp
[i
], i
);
241 static void viewportmanager_ui_vp_changed(void *param
)
243 /* if the user changed the theme, we need to initiate a full redraw */
245 /* cast param to a function */
246 void (*draw_func
)(void) = ((void(*)(void))param
);
247 /* start with clearing the screen */
249 screens
[i
].clear_display();
250 /* redraw the statusbar if it was enabled */
251 viewportmanager_set_statusbar(statusbar_enabled
);
252 /* call the passed function which will redraw the content of
253 * the current screen */
260 void viewport_set_current_vp(struct viewport
* vp
)
265 ui_vp_info
.vp
= custom_vp
;
268 struct viewport
* viewport_get_current_vp(void)
270 return ui_vp_info
.vp
;
273 #ifdef HAVE_LCD_COLOR
274 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
276 #define ARG_STRING(_depth) "dddddgg"
279 const char* viewport_parse_viewport(struct viewport
*vp
,
280 enum screen_type screen
,
282 const char separator
)
284 /* parse the list to the viewport struct */
285 const char *ptr
= bufptr
;
299 /* Work out the depth of this display */
300 depth
= screens
[screen
].depth
;
301 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
304 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
305 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
310 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
313 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
314 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
315 &vp
->fg_pattern
,&vp
->bg_pattern
)))
323 /* X and Y *must* be set */
324 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
328 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
329 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
330 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
331 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
333 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
334 if (!LIST_VALUE_PARSED(set
, PL_FG
))
335 vp
->fg_pattern
= FG_FALLBACK
;
336 if (!LIST_VALUE_PARSED(set
, PL_BG
))
337 vp
->bg_pattern
= BG_FALLBACK
;
338 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
340 LINE_SEL_FROM_SETTINGS(vp
);
342 /* Validate the viewport dimensions - we know that the numbers are
343 non-negative integers, ignore bars and assume the viewport takes them
345 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
346 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
347 (vp
->y
>= screens
[screen
].lcdheight
) ||
348 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
353 /* Default to using the user font if the font was an invalid number or '-'*/
354 if (((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
))
355 || !LIST_VALUE_PARSED(set
, PL_FONT
)
359 /* Set the defaults for fields not user-specified */
360 vp
->drawmode
= DRMODE_SOLID
;
366 * (re)parse the UI vp from the settings
368 * 0 if no UI vp is used
369 * >0 if it's used at least partly (on multiscreen targets)
370 * NB_SCREENS if all screens have a UI vp
372 static int viewport_init_ui_vp(void)
374 int screen
, ret
= NB_SCREENS
;
375 FOR_NB_SCREENS(screen
)
377 #ifdef HAVE_REMOTE_LCD
378 if ((screen
== SCREEN_REMOTE
))
380 if(!(viewport_parse_viewport(&custom_vp
[screen
], screen
,
381 global_settings
.remote_ui_vp_config
, ',')))
383 viewport_set_fullscreen(&custom_vp
[screen
], screen
);
390 if (!(viewport_parse_viewport(&custom_vp
[screen
], screen
,
391 global_settings
.ui_vp_config
, ',')))
393 viewport_set_fullscreen(&custom_vp
[screen
], screen
);
401 #endif /* HAVE_LCD_BITMAP */