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 */
47 #include "statusbar.h"
48 #include "appevents.h"
50 #ifdef HAVE_LCD_BITMAP
53 #include "statusbar-skinned.h"
57 #define VPSTACK_DEPTH 16
58 struct viewport_stack_item
64 #ifdef HAVE_LCD_BITMAP
65 static void viewportmanager_redraw(void* data
);
67 static int theme_stack_top
[NB_SCREENS
]; /* the last item added */
68 static struct viewport_stack_item theme_stack
[NB_SCREENS
][VPSTACK_DEPTH
];
69 static bool is_theme_enabled(enum screen_type screen
);
72 static void toggle_events(bool enable
)
76 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
77 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
78 add_event(LCD_EVENT_ACTIVATION
, false, do_sbs_update_callback
);
80 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false,
81 do_sbs_update_callback
);
82 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false,
83 do_sbs_update_callback
);
87 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
88 remove_event(LCD_EVENT_ACTIVATION
, do_sbs_update_callback
);
90 remove_event(PLAYBACK_EVENT_TRACK_CHANGE
, do_sbs_update_callback
);
91 remove_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, do_sbs_update_callback
);
92 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
97 static void toggle_theme(enum screen_type screen
, bool force
)
99 bool enable_event
= false;
100 static bool was_enabled
[NB_SCREENS
] = {false};
101 static bool after_boot
[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 (LIKELY(after_boot
[screen
]) && (!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();
164 screens
[screen
].set_viewport(NULL
);
166 intptr_t force
= first_boot
?0:1;
167 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)force
);
171 #if LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1)
172 screens
[screen
].backdrop_show(NULL
);
174 screens
[screen
].stop_scroll();
176 /* let list initialize viewport in case viewport dimensions is changed. */
177 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
179 was_enabled
[i
] = is_theme_enabled(i
);
181 after_boot
[screen
] = true;
184 void viewportmanager_theme_enable(enum screen_type screen
, bool enable
,
185 struct viewport
*viewport
)
187 int top
= ++theme_stack_top
[screen
];
188 if (top
>= VPSTACK_DEPTH
-1)
189 panicf("Stack overflow... viewportmanager");
190 theme_stack
[screen
][top
].enabled
= enable
;
191 theme_stack
[screen
][top
].vp
= viewport
;
192 toggle_theme(screen
, false);
193 /* then be nice and set the viewport up */
195 viewport_set_defaults(viewport
, screen
);
198 void viewportmanager_theme_undo(enum screen_type screen
, bool force_redraw
)
200 int top
= --theme_stack_top
[screen
];
202 panicf("Stack underflow... viewportmanager");
204 toggle_theme(screen
, force_redraw
);
208 static bool is_theme_enabled(enum screen_type screen
)
210 int top
= theme_stack_top
[screen
];
211 return theme_stack
[screen
][top
].enabled
;
213 #endif /* HAVE_LCD_BITMAP */
215 int viewport_get_nb_lines(const struct viewport
*vp
)
217 #ifdef HAVE_LCD_BITMAP
218 return vp
->height
/font_get(vp
->font
)->height
;
225 static void viewportmanager_redraw(void* data
)
230 #ifdef HAVE_LCD_BITMAP
231 if (is_theme_enabled(i
))
232 sb_skin_update(i
, NULL
!= data
);
235 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
, NULL
);
240 void viewportmanager_init()
242 #ifdef HAVE_LCD_BITMAP
246 theme_stack_top
[i
] = -1; /* the next call fixes this to 0 */
247 /* We always want the theme enabled by default... */
248 viewportmanager_theme_enable(i
, true, NULL
);
251 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
255 #ifdef HAVE_LCD_BITMAP
256 void viewportmanager_theme_changed(const int which
)
259 #ifdef HAVE_BUTTONBAR
260 if (which
& THEME_BUTTONBAR
)
261 { /* don't handle further, the custom ui viewport ignores the buttonbar,
262 * as does viewport_set_defaults(), since only lists use it*/
263 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
266 if (which
& THEME_UI_VIEWPORT
)
269 if (which
& THEME_LANGUAGE
)
272 if (which
& THEME_STATUSBAR
)
276 /* This can probably be done better...
277 * disable the theme so it's forced to do a full redraw */
278 viewportmanager_theme_enable(i
, false, NULL
);
279 viewportmanager_theme_undo(i
, true);
282 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
285 #ifdef HAVE_TOUCHSCREEN
286 /* check if a point (x and y coordinates) are within a viewport */
287 bool viewport_point_within_vp(const struct viewport
*vp
,
288 const int x
, const int y
)
290 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
291 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
292 return (is_x
&& is_y
);
294 #endif /* HAVE_TOUCHSCREEN */
296 static void set_default_align_flags(struct viewport
*vp
)
298 vp
->flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
299 if (UNLIKELY(lang_is_rtl()))
300 vp
->flags
|= VP_FLAG_ALIGN_RIGHT
;
303 #endif /* HAVE_LCD_BITMAP */
304 #endif /* __PCTOOL__ */
306 #ifdef HAVE_LCD_COLOR
307 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
309 #define ARG_STRING(_depth) "dddddgg"
313 void viewport_set_fullscreen(struct viewport
*vp
,
314 const enum screen_type screen
)
318 vp
->width
= screens
[screen
].lcdwidth
;
319 vp
->height
= screens
[screen
].lcdheight
;
321 #ifdef HAVE_LCD_BITMAP
323 set_default_align_flags(vp
);
325 vp
->font
= FONT_UI
+ screen
; /* default to UI to discourage SYSFONT use */
326 vp
->drawmode
= DRMODE_SOLID
;
328 #ifdef HAVE_REMOTE_LCD
329 /* We only need this test if there is a remote LCD */
330 if (screen
== SCREEN_MAIN
)
333 vp
->fg_pattern
= FG_FALLBACK
;
334 vp
->bg_pattern
= BG_FALLBACK
;
335 #ifdef HAVE_LCD_COLOR
336 vp
->lss_pattern
= global_settings
.lss_color
;
337 vp
->lse_pattern
= global_settings
.lse_color
;
338 vp
->lst_pattern
= global_settings
.lst_color
;
343 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
344 if (screen
== SCREEN_REMOTE
)
346 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
347 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
353 void viewport_set_defaults(struct viewport
*vp
,
354 const enum screen_type screen
)
356 #if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
357 struct viewport
*sbs_area
= NULL
;
358 if (!is_theme_enabled(screen
))
360 viewport_set_fullscreen(vp
, screen
);
363 sbs_area
= sb_skin_get_info_vp(screen
);
368 #endif /* HAVE_LCD_BITMAP */
369 viewport_set_fullscreen(vp
, screen
);
373 #ifdef HAVE_LCD_BITMAP
374 const char* viewport_parse_viewport(struct viewport
*vp
,
375 enum screen_type screen
,
377 const char separator
)
379 /* parse the list to the viewport struct */
380 const char *ptr
= bufptr
;
394 /* Work out the depth of this display */
395 depth
= screens
[screen
].depth
;
396 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
399 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
400 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
405 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
408 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
409 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
410 &vp
->fg_pattern
,&vp
->bg_pattern
)))
418 /* X and Y *must* be set */
419 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
421 /* check for negative values */
423 vp
->x
+= screens
[screen
].lcdwidth
;
425 vp
->y
+= screens
[screen
].lcdheight
;
428 * and negative width/height which means "extend to edge minus value */
429 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
430 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
431 else if (vp
->width
< 0)
432 vp
->width
= (vp
->width
+ screens
[screen
].lcdwidth
) - vp
->x
;
433 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
434 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
435 else if (vp
->height
< 0)
436 vp
->height
= (vp
->height
+ screens
[screen
].lcdheight
) - vp
->y
;
438 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
439 if (!LIST_VALUE_PARSED(set
, PL_FG
))
440 vp
->fg_pattern
= FG_FALLBACK
;
441 if (!LIST_VALUE_PARSED(set
, PL_BG
))
442 vp
->bg_pattern
= BG_FALLBACK
;
443 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
445 #ifdef HAVE_LCD_COLOR
446 vp
->lss_pattern
= global_settings
.lss_color
;
447 vp
->lse_pattern
= global_settings
.lse_color
;
448 vp
->lst_pattern
= global_settings
.lst_color
;
451 /* Validate the viewport dimensions - we know that the numbers are
452 non-negative integers, ignore bars and assume the viewport takes them
454 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
455 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
456 (vp
->y
>= screens
[screen
].lcdheight
) ||
457 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
462 /* Default to using the user font if the font was an invalid number or '-'
463 * font 1 is *always* the UI font for the current screen
464 * 2 is always the first extra font */
465 if (!LIST_VALUE_PARSED(set
, PL_FONT
))
468 /* Set the defaults for fields not user-specified */
469 vp
->drawmode
= DRMODE_SOLID
;
471 set_default_align_flags(vp
);