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};
106 enable_event
= enable_event
|| is_theme_enabled(i
);
107 sb_set_title_text(NULL
, Icon_NOICON
, i
);
109 toggle_events(enable_event
);
111 if (is_theme_enabled(screen
))
113 bool first_boot
= theme_stack_top
[screen
] == 0;
114 /* remove the left overs from the previous screen.
115 * could cause a tiny flicker. Redo your screen code if that happens */
116 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
117 screens
[screen
].backdrop_show(sb_get_backdrop(screen
));
119 if (!first_boot
&& (!was_enabled
[screen
] || force
))
121 struct viewport deadspace
, user
;
122 viewport_set_defaults(&user
, screen
);
123 deadspace
= user
; /* get colours and everything */
127 deadspace
.width
= screens
[screen
].lcdwidth
;
128 deadspace
.height
= user
.y
;
129 if (deadspace
.width
&& deadspace
.height
)
131 screens
[screen
].set_viewport(&deadspace
);
132 screens
[screen
].clear_viewport();
133 screens
[screen
].update_viewport();
136 deadspace
.y
= user
.y
+ user
.height
;
137 deadspace
.height
= screens
[screen
].lcdheight
- deadspace
.y
;
138 if (deadspace
.width
&& deadspace
.height
)
140 screens
[screen
].set_viewport(&deadspace
);
141 screens
[screen
].clear_viewport();
142 screens
[screen
].update_viewport();
147 deadspace
.width
= user
.x
;
148 deadspace
.height
= screens
[screen
].lcdheight
;
149 if (deadspace
.width
&& deadspace
.height
)
151 screens
[screen
].set_viewport(&deadspace
);
152 screens
[screen
].clear_viewport();
153 screens
[screen
].update_viewport();
156 deadspace
.x
= user
.x
+ user
.width
;
157 deadspace
.width
= screens
[screen
].lcdwidth
- deadspace
.x
;
158 if (deadspace
.width
&& deadspace
.height
)
160 screens
[screen
].set_viewport(&deadspace
);
161 screens
[screen
].clear_viewport();
162 screens
[screen
].update_viewport();
165 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)!first_boot
);
169 #if LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1)
170 screens
[screen
].backdrop_show(NULL
);
172 screens
[screen
].stop_scroll();
174 /* let list initialize viewport in case viewport dimensions is changed. */
175 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
177 was_enabled
[i
] = is_theme_enabled(i
);
180 void viewportmanager_theme_enable(enum screen_type screen
, bool enable
,
181 struct viewport
*viewport
)
183 int top
= ++theme_stack_top
[screen
];
184 if (top
>= VPSTACK_DEPTH
-1)
185 panicf("Stack overflow... viewportmanager");
186 theme_stack
[screen
][top
].enabled
= enable
;
187 theme_stack
[screen
][top
].vp
= viewport
;
188 toggle_theme(screen
, false);
189 /* then be nice and set the viewport up */
191 viewport_set_defaults(viewport
, screen
);
194 void viewportmanager_theme_undo(enum screen_type screen
, bool force_redraw
)
196 int top
= --theme_stack_top
[screen
];
198 panicf("Stack underflow... viewportmanager");
200 toggle_theme(screen
, force_redraw
);
204 static bool is_theme_enabled(enum screen_type screen
)
206 int top
= theme_stack_top
[screen
];
207 return theme_stack
[screen
][top
].enabled
;
209 #endif /* HAVE_LCD_BITMAP */
211 int viewport_get_nb_lines(const struct viewport
*vp
)
213 #ifdef HAVE_LCD_BITMAP
214 return vp
->height
/font_get(vp
->font
)->height
;
221 static void viewportmanager_redraw(void* data
)
226 #ifdef HAVE_LCD_BITMAP
227 if (statusbar_position(i
) == STATUSBAR_CUSTOM
)
228 sb_skin_update(i
, NULL
!= data
);
229 else if (statusbar_position(i
) != STATUSBAR_OFF
)
231 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
!= data
);
235 void viewportmanager_init()
237 #ifdef HAVE_LCD_BITMAP
241 theme_stack_top
[i
] = -1; /* the next call fixes this to 0 */
242 /* We always want the theme enabled by default... */
243 viewportmanager_theme_enable(i
, true, NULL
);
246 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
250 #ifdef HAVE_LCD_BITMAP
251 void viewportmanager_theme_changed(const int which
)
254 #ifdef HAVE_BUTTONBAR
255 if (which
& THEME_BUTTONBAR
)
256 { /* don't handle further, the custom ui viewport ignores the buttonbar,
257 * as does viewport_set_defaults(), since only lists use it*/
258 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
261 if (which
& THEME_UI_VIEWPORT
)
264 if (which
& THEME_LANGUAGE
)
267 if (which
& THEME_STATUSBAR
)
271 /* This can probably be done better...
272 * disable the theme so it's forced to do a full redraw */
273 viewportmanager_theme_enable(i
, false, NULL
);
274 viewportmanager_theme_undo(i
, true);
277 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
280 #ifdef HAVE_TOUCHSCREEN
281 /* check if a point (x and y coordinates) are within a viewport */
282 bool viewport_point_within_vp(const struct viewport
*vp
,
283 const int x
, const int y
)
285 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
286 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
287 return (is_x
&& is_y
);
289 #endif /* HAVE_TOUCHSCREEN */
291 static void set_default_align_flags(struct viewport
*vp
)
293 vp
->flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
294 if (UNLIKELY(lang_is_rtl()))
295 vp
->flags
|= VP_FLAG_ALIGN_RIGHT
;
298 #endif /* HAVE_LCD_BITMAP */
299 #endif /* __PCTOOL__ */
301 #ifdef HAVE_LCD_COLOR
302 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
304 #define ARG_STRING(_depth) "dddddgg"
308 void viewport_set_fullscreen(struct viewport
*vp
,
309 const enum screen_type screen
)
313 vp
->width
= screens
[screen
].lcdwidth
;
314 vp
->height
= screens
[screen
].lcdheight
;
316 #ifdef HAVE_LCD_BITMAP
318 set_default_align_flags(vp
);
320 vp
->font
= FONT_UI
+ screen
; /* default to UI to discourage SYSFONT use */
321 vp
->drawmode
= DRMODE_SOLID
;
323 #ifdef HAVE_REMOTE_LCD
324 /* We only need this test if there is a remote LCD */
325 if (screen
== SCREEN_MAIN
)
328 vp
->fg_pattern
= FG_FALLBACK
;
329 vp
->bg_pattern
= BG_FALLBACK
;
330 #ifdef HAVE_LCD_COLOR
331 vp
->lss_pattern
= global_settings
.lss_color
;
332 vp
->lse_pattern
= global_settings
.lse_color
;
333 vp
->lst_pattern
= global_settings
.lst_color
;
338 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
339 if (screen
== SCREEN_REMOTE
)
341 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
342 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
348 void viewport_set_defaults(struct viewport
*vp
,
349 const enum screen_type screen
)
351 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
353 struct viewport
*sbs_area
= NULL
;
354 if (!is_theme_enabled(screen
))
356 viewport_set_fullscreen(vp
, screen
);
359 sbs_area
= sb_skin_get_info_vp(screen
);
364 #endif /* HAVE_LCD_BITMAP */
365 viewport_set_fullscreen(vp
, screen
);
369 #ifdef HAVE_LCD_BITMAP
370 const char* viewport_parse_viewport(struct viewport
*vp
,
371 enum screen_type screen
,
373 const char separator
)
375 /* parse the list to the viewport struct */
376 const char *ptr
= bufptr
;
390 /* Work out the depth of this display */
391 depth
= screens
[screen
].depth
;
392 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
395 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
396 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
401 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
404 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
405 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
406 &vp
->fg_pattern
,&vp
->bg_pattern
)))
414 /* X and Y *must* be set */
415 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
417 /* check for negative values */
419 vp
->x
+= screens
[screen
].lcdwidth
;
421 vp
->y
+= screens
[screen
].lcdheight
;
424 * and negative width/height which means "extend to edge minus value */
425 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
426 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
427 else if (vp
->width
< 0)
428 vp
->width
= (vp
->width
+ screens
[screen
].lcdwidth
) - vp
->x
;
429 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
430 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
431 else if (vp
->height
< 0)
432 vp
->height
= (vp
->height
+ screens
[screen
].lcdheight
) - vp
->y
;
434 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
435 if (!LIST_VALUE_PARSED(set
, PL_FG
))
436 vp
->fg_pattern
= FG_FALLBACK
;
437 if (!LIST_VALUE_PARSED(set
, PL_BG
))
438 vp
->bg_pattern
= BG_FALLBACK
;
439 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
441 #ifdef HAVE_LCD_COLOR
442 vp
->lss_pattern
= global_settings
.lss_color
;
443 vp
->lse_pattern
= global_settings
.lse_color
;
444 vp
->lst_pattern
= global_settings
.lst_color
;
447 /* Validate the viewport dimensions - we know that the numbers are
448 non-negative integers, ignore bars and assume the viewport takes them
450 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
451 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
452 (vp
->y
>= screens
[screen
].lcdheight
) ||
453 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
458 /* Default to using the user font if the font was an invalid number or '-'
459 * font 1 is *always* the UI font for the current screen
460 * 2 is always the first extra font */
461 if (!LIST_VALUE_PARSED(set
, PL_FONT
))
464 /* Set the defaults for fields not user-specified */
465 vp
->drawmode
= DRMODE_SOLID
;
467 set_default_align_flags(vp
);