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 /* all below isn't needed for pc tools (i.e. checkwps/wps editor)
42 * only viewport_parse_viewport() is */
48 #include "statusbar.h"
49 #include "appevents.h"
51 #ifdef HAVE_LCD_BITMAP
54 #include "statusbar-skinned.h"
58 #define VPSTACK_DEPTH 16
59 struct viewport_stack_item
65 #ifdef HAVE_LCD_BITMAP
66 static void viewportmanager_redraw(void* data
);
68 static int theme_stack_top
[NB_SCREENS
]; /* the last item added */
69 static struct viewport_stack_item theme_stack
[NB_SCREENS
][VPSTACK_DEPTH
];
70 static bool is_theme_enabled(enum screen_type screen
);
73 static void toggle_events(bool enable
)
77 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
78 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
79 add_event(LCD_EVENT_ACTIVATION
, false, do_sbs_update_callback
);
81 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false,
82 do_sbs_update_callback
);
83 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false,
84 do_sbs_update_callback
);
88 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
89 remove_event(LCD_EVENT_ACTIVATION
, do_sbs_update_callback
);
91 remove_event(PLAYBACK_EVENT_TRACK_CHANGE
, do_sbs_update_callback
);
92 remove_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, do_sbs_update_callback
);
93 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
98 static void toggle_theme(enum screen_type screen
, bool force
)
100 bool enable_event
= false;
101 static bool was_enabled
[NB_SCREENS
] = {false};
102 static bool after_boot
[NB_SCREENS
] = {false};
107 enable_event
= enable_event
|| is_theme_enabled(i
);
108 sb_set_title_text(NULL
, Icon_NOICON
, i
);
110 toggle_events(enable_event
);
112 if (is_theme_enabled(screen
))
114 bool first_boot
= theme_stack_top
[screen
] == 0;
115 /* remove the left overs from the previous screen.
116 * could cause a tiny flicker. Redo your screen code if that happens */
117 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
118 screens
[screen
].backdrop_show(sb_get_backdrop(screen
));
120 if (LIKELY(after_boot
[screen
]) && (!was_enabled
[screen
] || force
))
122 struct viewport deadspace
, user
;
123 viewport_set_defaults(&user
, screen
);
124 deadspace
= user
; /* get colours and everything */
128 deadspace
.width
= screens
[screen
].lcdwidth
;
129 deadspace
.height
= user
.y
;
130 if (deadspace
.width
&& deadspace
.height
)
132 screens
[screen
].set_viewport(&deadspace
);
133 screens
[screen
].clear_viewport();
134 screens
[screen
].update_viewport();
137 deadspace
.y
= user
.y
+ user
.height
;
138 deadspace
.height
= screens
[screen
].lcdheight
- deadspace
.y
;
139 if (deadspace
.width
&& deadspace
.height
)
141 screens
[screen
].set_viewport(&deadspace
);
142 screens
[screen
].clear_viewport();
143 screens
[screen
].update_viewport();
148 deadspace
.width
= user
.x
;
149 deadspace
.height
= screens
[screen
].lcdheight
;
150 if (deadspace
.width
&& deadspace
.height
)
152 screens
[screen
].set_viewport(&deadspace
);
153 screens
[screen
].clear_viewport();
154 screens
[screen
].update_viewport();
157 deadspace
.x
= user
.x
+ user
.width
;
158 deadspace
.width
= screens
[screen
].lcdwidth
- deadspace
.x
;
159 if (deadspace
.width
&& deadspace
.height
)
161 screens
[screen
].set_viewport(&deadspace
);
162 screens
[screen
].clear_viewport();
163 screens
[screen
].update_viewport();
165 screens
[screen
].set_viewport(NULL
);
167 intptr_t force
= first_boot
?0:1;
168 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)force
);
172 #if LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1)
173 screens
[screen
].backdrop_show(NULL
);
175 screens
[screen
].stop_scroll();
177 /* let list initialize viewport in case viewport dimensions is changed. */
178 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
180 was_enabled
[i
] = is_theme_enabled(i
);
182 after_boot
[screen
] = true;
185 void viewportmanager_theme_enable(enum screen_type screen
, bool enable
,
186 struct viewport
*viewport
)
188 int top
= ++theme_stack_top
[screen
];
189 if (top
>= VPSTACK_DEPTH
-1)
190 panicf("Stack overflow... viewportmanager");
191 theme_stack
[screen
][top
].enabled
= enable
;
192 theme_stack
[screen
][top
].vp
= viewport
;
193 toggle_theme(screen
, false);
194 /* then be nice and set the viewport up */
196 viewport_set_defaults(viewport
, screen
);
199 void viewportmanager_theme_undo(enum screen_type screen
, bool force_redraw
)
201 int top
= --theme_stack_top
[screen
];
203 panicf("Stack underflow... viewportmanager");
205 toggle_theme(screen
, force_redraw
);
209 static bool is_theme_enabled(enum screen_type screen
)
211 int top
= theme_stack_top
[screen
];
212 return theme_stack
[screen
][top
].enabled
;
214 #endif /* HAVE_LCD_BITMAP */
216 int viewport_get_nb_lines(const struct viewport
*vp
)
218 #ifdef HAVE_LCD_BITMAP
219 return vp
->height
/font_get(vp
->font
)->height
;
226 static void viewportmanager_redraw(void* data
)
231 #ifdef HAVE_LCD_BITMAP
232 if (is_theme_enabled(i
))
233 sb_skin_update(i
, NULL
!= data
);
236 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
, NULL
);
241 void viewportmanager_init()
243 #ifdef HAVE_LCD_BITMAP
247 theme_stack_top
[i
] = -1; /* the next call fixes this to 0 */
248 /* We always want the theme enabled by default... */
249 viewportmanager_theme_enable(i
, true, NULL
);
252 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
256 #ifdef HAVE_LCD_BITMAP
257 void viewportmanager_theme_changed(const int which
)
260 #ifdef HAVE_BUTTONBAR
261 if (which
& THEME_BUTTONBAR
)
262 { /* don't handle further, the custom ui viewport ignores the buttonbar,
263 * as does viewport_set_defaults(), since only lists use it*/
264 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
267 if (which
& THEME_UI_VIEWPORT
)
270 if (which
& THEME_LANGUAGE
)
273 if (which
& THEME_STATUSBAR
)
277 /* This can probably be done better...
278 * disable the theme so it's forced to do a full redraw */
279 viewportmanager_theme_enable(i
, false, NULL
);
280 viewportmanager_theme_undo(i
, true);
283 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
286 #ifdef HAVE_TOUCHSCREEN
287 /* check if a point (x and y coordinates) are within a viewport */
288 bool viewport_point_within_vp(const struct viewport
*vp
,
289 const int x
, const int y
)
291 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
292 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
293 return (is_x
&& is_y
);
295 #endif /* HAVE_TOUCHSCREEN */
297 static void set_default_align_flags(struct viewport
*vp
)
299 vp
->flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
300 if (UNLIKELY(lang_is_rtl()))
301 vp
->flags
|= VP_FLAG_ALIGN_RIGHT
;
304 #endif /* HAVE_LCD_BITMAP */
305 #endif /* __PCTOOL__ */
307 #ifdef HAVE_LCD_COLOR
308 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
310 #define ARG_STRING(_depth) "dddddgg"
314 void viewport_set_fullscreen(struct viewport
*vp
,
315 const enum screen_type screen
)
319 vp
->width
= screens
[screen
].lcdwidth
;
320 vp
->height
= screens
[screen
].lcdheight
;
322 #ifdef HAVE_LCD_BITMAP
324 set_default_align_flags(vp
);
326 vp
->font
= FONT_UI
+ screen
; /* default to UI to discourage SYSFONT use */
327 vp
->drawmode
= DRMODE_SOLID
;
329 #ifdef HAVE_REMOTE_LCD
330 /* We only need this test if there is a remote LCD */
331 if (screen
== SCREEN_MAIN
)
334 vp
->fg_pattern
= FG_FALLBACK
;
335 vp
->bg_pattern
= BG_FALLBACK
;
336 #ifdef HAVE_LCD_COLOR
337 vp
->lss_pattern
= global_settings
.lss_color
;
338 vp
->lse_pattern
= global_settings
.lse_color
;
339 vp
->lst_pattern
= global_settings
.lst_color
;
344 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
345 if (screen
== SCREEN_REMOTE
)
347 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
348 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
354 void viewport_set_defaults(struct viewport
*vp
,
355 const enum screen_type screen
)
357 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
358 struct viewport
*sbs_area
= NULL
;
359 if (!is_theme_enabled(screen
))
361 viewport_set_fullscreen(vp
, screen
);
364 sbs_area
= sb_skin_get_info_vp(screen
);
369 #endif /* HAVE_LCD_BITMAP */
370 viewport_set_fullscreen(vp
, screen
);
374 #ifdef HAVE_LCD_BITMAP
375 const char* viewport_parse_viewport(struct viewport
*vp
,
376 enum screen_type screen
,
378 const char separator
)
380 /* parse the list to the viewport struct */
381 const char *ptr
= bufptr
;
395 /* Work out the depth of this display */
396 depth
= screens
[screen
].depth
;
397 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
400 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
401 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
406 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
409 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
410 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
411 &vp
->fg_pattern
,&vp
->bg_pattern
)))
419 /* X and Y *must* be set */
420 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
422 /* check for negative values */
424 vp
->x
+= screens
[screen
].lcdwidth
;
426 vp
->y
+= screens
[screen
].lcdheight
;
429 * and negative width/height which means "extend to edge minus value */
430 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
431 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
432 else if (vp
->width
< 0)
433 vp
->width
= (vp
->width
+ screens
[screen
].lcdwidth
) - vp
->x
;
434 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
435 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
436 else if (vp
->height
< 0)
437 vp
->height
= (vp
->height
+ screens
[screen
].lcdheight
) - vp
->y
;
439 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
440 if (!LIST_VALUE_PARSED(set
, PL_FG
))
441 vp
->fg_pattern
= FG_FALLBACK
;
442 if (!LIST_VALUE_PARSED(set
, PL_BG
))
443 vp
->bg_pattern
= BG_FALLBACK
;
444 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
446 #ifdef HAVE_LCD_COLOR
447 vp
->lss_pattern
= global_settings
.lss_color
;
448 vp
->lse_pattern
= global_settings
.lse_color
;
449 vp
->lst_pattern
= global_settings
.lst_color
;
452 /* Validate the viewport dimensions - we know that the numbers are
453 non-negative integers, ignore bars and assume the viewport takes them
455 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
456 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
457 (vp
->y
>= screens
[screen
].lcdheight
) ||
458 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
463 /* Default to using the user font if the font was an invalid number or '-'
464 * font 1 is *always* the UI font for the current screen
465 * 2 is always the first extra font */
466 if (!LIST_VALUE_PARSED(set
, PL_FONT
))
469 /* Set the defaults for fields not user-specified */
470 vp
->drawmode
= DRMODE_SOLID
;
472 set_default_align_flags(vp
);