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 FG_FALLBACK global_settings.fg_color
35 #define BG_FALLBACK global_settings.bg_color
37 #define FG_FALLBACK LCD_DEFAULT_FG
38 #define BG_FALLBACK LCD_DEFAULT_BG
41 #ifdef HAVE_LCD_BITMAP
42 static void set_default_align_flags(struct viewport
*vp
);
45 /* all below isn't needed for pc tools (i.e. checkwps/wps editor)
46 * only viewport_parse_viewport() is */
52 #include "statusbar.h"
53 #include "appevents.h"
54 #ifdef HAVE_LCD_BITMAP
57 #include "statusbar-skinned.h"
61 static int statusbar_enabled
= 0;
63 #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(const 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
94 ignore
= statusbar_enabled
& VP_SB_IGNORE_SETTING(screen
);
95 return ignore
|| (statusbar_position(screen
) != STATUSBAR_OFF
);
104 void viewportmanager_init(void)
106 #ifdef HAVE_LCD_BITMAP
107 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggled
);
109 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
112 int viewportmanager_get_statusbar(void)
114 return statusbar_enabled
;
117 int viewportmanager_set_statusbar(const int enabled
)
119 int old
= statusbar_enabled
;
122 statusbar_enabled
= enabled
;
127 && statusbar_position(i
) != STATUSBAR_CUSTOM
)
129 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
130 gui_statusbar_draw(&statusbars
.statusbars
[i
], true);
133 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
136 #ifdef HAVE_LCD_BITMAP
139 sb_skin_set_state(showing_bars(i
)
140 && statusbar_position(i
) == STATUSBAR_CUSTOM
, i
);
146 static void viewportmanager_redraw(void* data
)
153 && statusbar_position(i
) != STATUSBAR_CUSTOM
)
154 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
!= data
);
157 #ifdef HAVE_LCD_BITMAP
159 static void statusbar_toggled(void* param
)
162 /* update vp manager for the new setting and reposition vps
164 viewportmanager_theme_changed(THEME_STATUSBAR
);
167 void viewportmanager_theme_changed(const int which
)
170 #ifdef HAVE_BUTTONBAR
171 if (which
& THEME_BUTTONBAR
)
172 { /* don't handle further, the custom ui viewport ignores the buttonbar,
173 * as does viewport_set_defaults(), since only lists use it*/
174 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
177 if (which
& THEME_UI_VIEWPORT
)
179 int retval
= viewport_init_ui_vp();
180 /* reset the ui viewport */
182 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
183 /* and point to it */
184 ui_vp_info
.vp
= custom_vp
;
186 else if (which
& THEME_LANGUAGE
)
187 { /* THEME_UI_VIEWPORT handles rtl already */
189 set_default_align_flags(&custom_vp
[i
]);
191 if (which
& THEME_STATUSBAR
)
193 statusbar_enabled
= 0;
196 if (statusbar_position(i
) != STATUSBAR_OFF
)
197 statusbar_enabled
|= VP_SB_ONSCREEN(i
);
200 viewportmanager_set_statusbar(statusbar_enabled
);
202 /* reposition viewport to fit statusbar, only if not using the ui vp */
206 if (!ui_vp_info
.active
[i
])
207 viewport_set_fullscreen(&custom_vp
[i
], i
);
214 event_add
|= ui_vp_info
.active
[i
];
215 event_add
|= (statusbar_position(i
) == STATUSBAR_CUSTOM
);
219 add_event(GUI_EVENT_REFRESH
, false, viewportmanager_ui_vp_changed
);
221 remove_event(GUI_EVENT_REFRESH
, viewportmanager_ui_vp_changed
);
223 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
226 static void viewportmanager_ui_vp_changed(void *param
)
228 /* if the user changed the theme, we need to initiate a full redraw */
230 /* cast param to a function */
231 void (*draw_func
)(void) = ((void(*)(void))param
);
232 /* start with clearing the screen */
234 screens
[i
].clear_display();
235 /* redraw the statusbar if it was enabled */
236 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)true);
237 /* call the passed function which will redraw the content of
238 * the current screen */
239 if (draw_func
!= NULL
)
246 * (re)parse the UI vp from the settings
248 * 0 if no UI vp is used at all
249 * else the bit for the screen (1<<screen) is set
251 static unsigned viewport_init_ui_vp(void)
256 FOR_NB_SCREENS(screen
)
258 #ifdef HAVE_REMOTE_LCD
259 if ((screen
== SCREEN_REMOTE
))
260 setting
= global_settings
.remote_ui_vp_config
;
263 setting
= global_settings
.ui_vp_config
;
266 if (!(viewport_parse_viewport(&custom_vp
[screen
], screen
,
268 viewport_set_fullscreen(&custom_vp
[screen
], screen
);
270 ret
|= BIT_N(screen
);
275 #ifdef HAVE_TOUCHSCREEN
276 /* check if a point (x and y coordinates) are within a viewport */
277 bool viewport_point_within_vp(const struct viewport
*vp
,
278 const int x
, const int y
)
280 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
281 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
282 return (is_x
&& is_y
);
284 #endif /* HAVE_TOUCHSCREEN */
285 #endif /* HAVE_LCD_BITMAP */
286 #endif /* __PCTOOL__ */
288 #ifdef HAVE_LCD_COLOR
289 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
291 #define ARG_STRING(_depth) "dddddgg"
295 void viewport_set_fullscreen(struct viewport
*vp
,
296 const enum screen_type screen
)
300 vp
->width
= screens
[screen
].lcdwidth
;
301 vp
->height
= screens
[screen
].lcdheight
;
303 #ifdef HAVE_LCD_BITMAP
304 set_default_align_flags(vp
);
305 vp
->font
= FONT_UI
; /* default to UI to discourage SYSFONT use */
306 vp
->drawmode
= DRMODE_SOLID
;
308 #ifdef HAVE_REMOTE_LCD
309 /* We only need this test if there is a remote LCD */
310 if (screen
== SCREEN_MAIN
)
313 vp
->fg_pattern
= FG_FALLBACK
;
314 vp
->bg_pattern
= BG_FALLBACK
;
315 #ifdef HAVE_LCD_COLOR
316 vp
->lss_pattern
= global_settings
.lss_color
;
317 vp
->lse_pattern
= global_settings
.lse_color
;
318 vp
->lst_pattern
= global_settings
.lst_color
;
323 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
324 if (screen
== SCREEN_REMOTE
)
326 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
327 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
333 void viewport_set_defaults(struct viewport
*vp
,
334 const enum screen_type screen
)
337 1) If the "ui viewport" setting is set, and a sbs is loaded which specifies a %Vi
338 return the intersection of those two viewports
339 2) If only one of the "ui viewport" setting, or sbs %Vi is set
341 3) No user viewports set
342 return the full display
344 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
346 struct viewport
*sbs_area
= NULL
, *user_setting
= NULL
;
347 /* get the two viewports */
348 if (ui_vp_info
.active
[screen
])
349 user_setting
= &ui_vp_info
.vp
[screen
];
350 if (sb_skin_get_state(screen
))
351 sbs_area
= sb_skin_get_info_vp(screen
);
352 /* have both? get their intersection */
353 if (sbs_area
&& user_setting
)
355 struct viewport
*a
= sbs_area
, *b
= user_setting
;
356 /* if ui vp and info vp overlap, intersect */
357 if (a
->x
< b
->x
+ b
->width
&&
358 a
->x
+ a
->width
> b
->x
&&
359 a
->y
< b
->y
+ b
->height
&&
360 a
->y
+ a
->height
> b
->y
)
362 /* copy from ui vp first (for other field),fix coordinates after */
364 vp
->x
= MAX(a
->x
, b
->x
);
365 vp
->y
= MAX(a
->y
, b
->y
);
366 vp
->width
= MIN(a
->x
+ a
->width
, b
->x
+ b
->width
) - vp
->x
;
367 vp
->height
= MIN(a
->y
+ a
->height
, b
->y
+ b
->height
) - vp
->y
;
370 /* else (no overlap at all) fall back to info vp from sbs, that
371 * has no redraw problems */
374 /* if only one is active use it
375 * or if the above check for overlapping failed, use info vp then, because
376 * that doesn't give redraw problems */
379 else if (user_setting
)
381 /* have neither so its fullscreen which was fixed at the beginning */
383 #endif /* HAVE_LCD_BITMAP */
384 viewport_set_fullscreen(vp
, screen
);
388 #ifdef HAVE_LCD_BITMAP
390 static void set_default_align_flags(struct viewport
*vp
)
392 vp
->flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
394 if (UNLIKELY(lang_is_rtl()))
395 vp
->flags
|= VP_FLAG_ALIGN_RIGHT
;
399 const char* viewport_parse_viewport(struct viewport
*vp
,
400 enum screen_type screen
,
402 const char separator
)
404 /* parse the list to the viewport struct */
405 const char *ptr
= bufptr
;
419 /* Work out the depth of this display */
420 depth
= screens
[screen
].depth
;
421 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
424 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
425 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
430 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
433 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
434 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
435 &vp
->fg_pattern
,&vp
->bg_pattern
)))
443 /* X and Y *must* be set */
444 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
446 /* check for negative values */
448 vp
->x
+= screens
[screen
].lcdwidth
;
450 vp
->y
+= screens
[screen
].lcdheight
;
453 * and negative width/height which means "extend to edge minus value */
454 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
455 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
456 else if (vp
->width
< 0)
457 vp
->width
= (vp
->width
+ screens
[screen
].lcdwidth
) - vp
->x
;
458 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
459 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
460 else if (vp
->height
< 0)
461 vp
->height
= (vp
->height
+ screens
[screen
].lcdheight
) - vp
->y
;
463 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
464 if (!LIST_VALUE_PARSED(set
, PL_FG
))
465 vp
->fg_pattern
= FG_FALLBACK
;
466 if (!LIST_VALUE_PARSED(set
, PL_BG
))
467 vp
->bg_pattern
= BG_FALLBACK
;
468 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
470 #ifdef HAVE_LCD_COLOR
471 vp
->lss_pattern
= global_settings
.lss_color
;
472 vp
->lse_pattern
= global_settings
.lse_color
;
473 vp
->lst_pattern
= global_settings
.lst_color
;
476 /* Validate the viewport dimensions - we know that the numbers are
477 non-negative integers, ignore bars and assume the viewport takes them
479 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
480 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
481 (vp
->y
>= screens
[screen
].lcdheight
) ||
482 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
487 /* Default to using the user font if the font was an invalid number or '-'*/
488 if (((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
))
489 || !LIST_VALUE_PARSED(set
, PL_FONT
)
493 /* Set the defaults for fields not user-specified */
494 vp
->drawmode
= DRMODE_SOLID
;
495 set_default_align_flags(vp
);