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"
60 static int statusbar_enabled
= 0;
62 #ifdef HAVE_LCD_BITMAP
66 int active
[NB_SCREENS
];
69 static struct viewport custom_vp
[NB_SCREENS
];
71 /* callbacks for GUI_EVENT_* events */
72 static void viewportmanager_ui_vp_changed(void *param
);
73 static void statusbar_toggled(void* param
);
74 static unsigned viewport_init_ui_vp(void);
76 static void viewportmanager_redraw(void* data
);
78 int viewport_get_nb_lines(struct viewport
*vp
)
80 #ifdef HAVE_LCD_BITMAP
81 return vp
->height
/font_get(vp
->font
)->height
;
88 static bool showing_bars(enum screen_type screen
)
90 if (statusbar_enabled
& VP_SB_ONSCREEN(screen
))
92 #ifdef HAVE_LCD_BITMAP
93 bool ignore
= statusbar_enabled
& VP_SB_IGNORE_SETTING(screen
);
94 return ignore
|| (statusbar_position(screen
));
102 void viewport_set_fullscreen(struct viewport
*vp
, enum screen_type screen
)
105 vp
->width
= screens
[screen
].lcdwidth
;
107 #ifdef HAVE_LCD_BITMAP
108 vp
->drawmode
= DRMODE_SOLID
;
109 vp
->font
= FONT_UI
; /* default to UI to discourage SYSFONT use */
111 vp
->height
= screens
[screen
].lcdheight
;
112 if (statusbar_position(screen
) != STATUSBAR_BOTTOM
&& showing_bars(screen
))
113 vp
->y
= STATUSBAR_HEIGHT
;
119 vp
->height
= screens
[screen
].lcdheight
- (showing_bars(screen
)?STATUSBAR_HEIGHT
:0);
122 #ifdef HAVE_REMOTE_LCD
123 /* We only need this test if there is a remote LCD */
124 if (screen
== SCREEN_MAIN
)
127 vp
->fg_pattern
= FG_FALLBACK
;
128 vp
->bg_pattern
= BG_FALLBACK
;
129 LINE_SEL_FROM_SETTINGS(vp
);
133 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
134 if (screen
== SCREEN_REMOTE
)
136 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
137 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
142 void viewport_set_defaults(struct viewport
*vp
, enum screen_type screen
)
144 #ifdef HAVE_LCD_BITMAP
145 if (ui_vp_info
.active
[screen
])
146 *vp
= ui_vp_info
.vp
[screen
];
149 viewport_set_fullscreen(vp
, screen
);
152 void viewportmanager_init(void)
154 #ifdef HAVE_LCD_BITMAP
156 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggled
);
157 retval
= viewport_init_ui_vp();
159 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
160 ui_vp_info
.vp
= custom_vp
;
162 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
165 int viewportmanager_get_statusbar(void)
167 return statusbar_enabled
;
170 int viewportmanager_set_statusbar(int enabled
)
172 int old
= statusbar_enabled
;
173 statusbar_enabled
= enabled
;
180 gui_statusbar_draw(&statusbars
.statusbars
[i
], true);
182 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
186 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
191 static void viewportmanager_redraw(void* data
)
198 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
!= data
);
201 #ifdef HAVE_LCD_BITMAP
203 static void statusbar_toggled(void* param
)
206 /* update vp manager for the new setting and reposition vps
208 viewportmanager_theme_changed(THEME_STATUSBAR
);
211 void viewportmanager_theme_changed(int which
)
214 #ifdef HAVE_BUTTONBAR
215 if (which
& THEME_BUTTONBAR
)
216 { /* don't handle further, the custom ui viewport ignores the buttonbar,
217 * as does viewport_set_defaults(), since only lists use it*/
218 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
221 if (which
& THEME_UI_VIEWPORT
)
223 int retval
= viewport_init_ui_vp();
224 /* reset the ui viewport */
226 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
229 add_event(GUI_EVENT_REFRESH
, false, viewportmanager_ui_vp_changed
);
231 remove_event(GUI_EVENT_REFRESH
, viewportmanager_ui_vp_changed
);
232 /* and point to it */
233 ui_vp_info
.vp
= custom_vp
;
235 if (which
& THEME_STATUSBAR
)
237 statusbar_enabled
= VP_SB_HIDE_ALL
;
241 if (statusbar_position(i
) != STATUSBAR_OFF
)
242 statusbar_enabled
|= VP_SB_ONSCREEN(i
);
245 if (statusbar_enabled
!= VP_SB_HIDE_ALL
)
246 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
248 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
250 /* reposition viewport to fit statusbar, only if not using the ui vp */
254 if (!ui_vp_info
.active
[i
])
255 viewport_set_fullscreen(&custom_vp
[i
], i
);
258 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
261 static void viewportmanager_ui_vp_changed(void *param
)
263 /* if the user changed the theme, we need to initiate a full redraw */
265 /* cast param to a function */
266 void (*draw_func
)(void) = ((void(*)(void))param
);
267 /* start with clearing the screen */
269 screens
[i
].clear_display();
270 /* redraw the statusbar if it was enabled */
271 viewportmanager_set_statusbar(statusbar_enabled
);
272 /* call the passed function which will redraw the content of
273 * the current screen */
280 void viewport_set_current_vp(struct viewport
* vp
)
285 ui_vp_info
.vp
= custom_vp
;
287 /* must be done after the assignment above or event handler get old vps */
288 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
291 struct viewport
* viewport_get_current_vp(void)
293 return ui_vp_info
.vp
;
296 bool viewport_ui_vp_get_state(enum screen_type screen
)
298 return ui_vp_info
.active
[screen
];
302 * (re)parse the UI vp from the settings
304 * 0 if no UI vp is used at all
305 * else the bit for the screen (1<<screen) is set
307 static unsigned viewport_init_ui_vp(void)
312 FOR_NB_SCREENS(screen
)
314 #ifdef HAVE_REMOTE_LCD
315 if ((screen
== SCREEN_REMOTE
))
316 setting
= global_settings
.remote_ui_vp_config
;
319 setting
= global_settings
.ui_vp_config
;
322 if (!(viewport_parse_viewport(&custom_vp
[screen
], screen
,
324 viewport_set_fullscreen(&custom_vp
[screen
], screen
);
326 ret
|= BIT_N(screen
);
331 #ifdef HAVE_TOUCHSCREEN
332 /* check if a point (x and y coordinates) are within a viewport */
333 bool viewport_point_within_vp(const struct viewport
*vp
, int x
, int y
)
335 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
336 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
337 return (is_x
&& is_y
);
339 #endif /* HAVE_TOUCHSCREEN */
340 #endif /* HAVE_LCD_BITMAP */
341 #endif /* __PCTOOL__ */
343 #ifdef HAVE_LCD_COLOR
344 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
346 #define ARG_STRING(_depth) "dddddgg"
349 #ifdef HAVE_LCD_BITMAP
350 const char* viewport_parse_viewport(struct viewport
*vp
,
351 enum screen_type screen
,
353 const char separator
)
355 /* parse the list to the viewport struct */
356 const char *ptr
= bufptr
;
370 /* Work out the depth of this display */
371 depth
= screens
[screen
].depth
;
372 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
375 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
376 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
381 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
384 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
385 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
386 &vp
->fg_pattern
,&vp
->bg_pattern
)))
394 /* X and Y *must* be set */
395 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
399 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
400 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
401 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
402 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
404 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
405 if (!LIST_VALUE_PARSED(set
, PL_FG
))
406 vp
->fg_pattern
= FG_FALLBACK
;
407 if (!LIST_VALUE_PARSED(set
, PL_BG
))
408 vp
->bg_pattern
= BG_FALLBACK
;
409 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
411 LINE_SEL_FROM_SETTINGS(vp
);
413 /* Validate the viewport dimensions - we know that the numbers are
414 non-negative integers, ignore bars and assume the viewport takes them
416 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
417 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
418 (vp
->y
>= screens
[screen
].lcdheight
) ||
419 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
424 /* Default to using the user font if the font was an invalid number or '-'*/
425 if (((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
))
426 || !LIST_VALUE_PARSED(set
, PL_FONT
)
430 /* Set the defaults for fields not user-specified */
431 vp
->drawmode
= DRMODE_SOLID
;