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
40 #ifdef HAVE_REMOTE_LCD
41 #define REMOTE_FG_FALLBACK LCD_REMOTE_DEFAULT_FG
42 #define REMOTE_BG_FALLBACK LCD_REMOTE_DEFAULT_BG
46 /* all below isn't needed for pc tools (i.e. checkwps/wps editor)
47 * only viewport_parse_viewport() is */
52 #include "statusbar.h"
53 #include "appevents.h"
55 #ifdef HAVE_LCD_BITMAP
58 #include "statusbar-skinned.h"
59 #include "skin_engine/skin_engine.h"
62 #define VPSTACK_DEPTH 16
63 struct viewport_stack_item
69 #ifdef HAVE_LCD_BITMAP
70 static void viewportmanager_redraw(void* data
);
72 static int theme_stack_top
[NB_SCREENS
]; /* the last item added */
73 static struct viewport_stack_item theme_stack
[NB_SCREENS
][VPSTACK_DEPTH
];
74 static bool is_theme_enabled(enum screen_type screen
);
77 static void toggle_events(bool enable
)
81 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
82 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
83 add_event(LCD_EVENT_ACTIVATION
, false, do_sbs_update_callback
);
85 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false,
86 do_sbs_update_callback
);
87 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false,
88 do_sbs_update_callback
);
92 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
93 remove_event(LCD_EVENT_ACTIVATION
, do_sbs_update_callback
);
95 remove_event(PLAYBACK_EVENT_TRACK_CHANGE
, do_sbs_update_callback
);
96 remove_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, do_sbs_update_callback
);
97 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
102 static void toggle_theme(enum screen_type screen
, bool force
)
104 bool enable_event
= false;
105 static bool was_enabled
[NB_SCREENS
] = {false};
106 static bool after_boot
[NB_SCREENS
] = {false};
111 enable_event
= enable_event
|| is_theme_enabled(i
);
112 sb_set_title_text(NULL
, Icon_NOICON
, i
);
114 toggle_events(enable_event
);
116 if (is_theme_enabled(screen
))
118 bool first_boot
= theme_stack_top
[screen
] == 0;
119 /* remove the left overs from the previous screen.
120 * could cause a tiny flicker. Redo your screen code if that happens */
121 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
122 skin_backdrop_show(sb_get_backdrop(screen
));
124 if (LIKELY(after_boot
[screen
]) && (!was_enabled
[screen
] || force
))
126 struct viewport deadspace
, user
;
127 viewport_set_defaults(&user
, screen
);
128 deadspace
= user
; /* get colours and everything */
132 deadspace
.width
= screens
[screen
].lcdwidth
;
133 deadspace
.height
= user
.y
;
134 if (deadspace
.width
&& deadspace
.height
)
136 screens
[screen
].set_viewport(&deadspace
);
137 screens
[screen
].clear_viewport();
138 screens
[screen
].update_viewport();
141 deadspace
.y
= user
.y
+ user
.height
;
142 deadspace
.height
= screens
[screen
].lcdheight
- deadspace
.y
;
143 if (deadspace
.width
&& deadspace
.height
)
145 screens
[screen
].set_viewport(&deadspace
);
146 screens
[screen
].clear_viewport();
147 screens
[screen
].update_viewport();
152 deadspace
.width
= user
.x
;
153 deadspace
.height
= screens
[screen
].lcdheight
;
154 if (deadspace
.width
&& deadspace
.height
)
156 screens
[screen
].set_viewport(&deadspace
);
157 screens
[screen
].clear_viewport();
158 screens
[screen
].update_viewport();
161 deadspace
.x
= user
.x
+ user
.width
;
162 deadspace
.width
= screens
[screen
].lcdwidth
- deadspace
.x
;
163 if (deadspace
.width
&& deadspace
.height
)
165 screens
[screen
].set_viewport(&deadspace
);
166 screens
[screen
].clear_viewport();
167 screens
[screen
].update_viewport();
169 screens
[screen
].set_viewport(NULL
);
171 intptr_t force
= first_boot
?0:1;
173 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)force
);
177 #if LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1)
178 screens
[screen
].backdrop_show(NULL
);
180 screens
[screen
].stop_scroll();
182 /* let list initialize viewport in case viewport dimensions is changed. */
183 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
185 was_enabled
[i
] = is_theme_enabled(i
);
186 #ifdef HAVE_TOUCHSCREEN
187 sb_bypass_touchregions(!is_theme_enabled(SCREEN_MAIN
));
189 after_boot
[screen
] = true;
192 void viewportmanager_theme_enable(enum screen_type screen
, bool enable
,
193 struct viewport
*viewport
)
195 int top
= ++theme_stack_top
[screen
];
196 if (top
>= VPSTACK_DEPTH
-1)
197 panicf("Stack overflow... viewportmanager");
198 theme_stack
[screen
][top
].enabled
= enable
;
199 theme_stack
[screen
][top
].vp
= viewport
;
200 toggle_theme(screen
, false);
201 /* then be nice and set the viewport up */
203 viewport_set_defaults(viewport
, screen
);
206 void viewportmanager_theme_undo(enum screen_type screen
, bool force_redraw
)
208 int top
= --theme_stack_top
[screen
];
210 panicf("Stack underflow... viewportmanager");
212 toggle_theme(screen
, force_redraw
);
216 static bool is_theme_enabled(enum screen_type screen
)
218 int top
= theme_stack_top
[screen
];
219 return theme_stack
[screen
][top
].enabled
;
221 #endif /* HAVE_LCD_BITMAP */
223 int viewport_get_nb_lines(const struct viewport
*vp
)
225 #ifdef HAVE_LCD_BITMAP
226 return vp
->height
/font_get(vp
->font
)->height
;
233 static void viewportmanager_redraw(void* data
)
238 #ifdef HAVE_LCD_BITMAP
239 if (is_theme_enabled(i
))
240 sb_skin_update(i
, NULL
!= data
);
243 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
, NULL
);
248 void viewportmanager_init()
250 #ifdef HAVE_LCD_BITMAP
254 theme_stack_top
[i
] = -1; /* the next call fixes this to 0 */
255 /* We always want the theme enabled by default... */
256 viewportmanager_theme_enable(i
, true, NULL
);
259 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
263 #ifdef HAVE_LCD_BITMAP
264 void viewportmanager_theme_changed(const int which
)
267 #ifdef HAVE_BUTTONBAR
268 if (which
& THEME_BUTTONBAR
)
269 { /* don't handle further, the custom ui viewport ignores the buttonbar,
270 * as does viewport_set_defaults(), since only lists use it*/
271 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
274 if (which
& THEME_UI_VIEWPORT
)
277 if (which
& THEME_LANGUAGE
)
280 if (which
& THEME_STATUSBAR
)
284 /* This can probably be done better...
285 * disable the theme so it's forced to do a full redraw */
286 viewportmanager_theme_enable(i
, false, NULL
);
287 viewportmanager_theme_undo(i
, true);
290 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
293 #ifdef HAVE_TOUCHSCREEN
294 /* check if a point (x and y coordinates) are within a viewport */
295 bool viewport_point_within_vp(const struct viewport
*vp
,
296 const int x
, const int y
)
298 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
299 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
300 return (is_x
&& is_y
);
302 #endif /* HAVE_TOUCHSCREEN */
304 static void set_default_align_flags(struct viewport
*vp
)
306 vp
->flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
307 if (UNLIKELY(lang_is_rtl()))
308 vp
->flags
|= VP_FLAG_ALIGN_RIGHT
;
311 #endif /* HAVE_LCD_BITMAP */
312 #endif /* __PCTOOL__ */
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
376 int get_viewport_default_colour(enum screen_type screen
, bool fgcolour
)
378 (void)screen
; (void)fgcolour
;
379 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
383 #if (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
384 if (screen
== SCREEN_REMOTE
)
385 colour
= REMOTE_FG_FALLBACK
;
388 #if defined(HAVE_LCD_COLOR)
389 colour
= global_settings
.fg_color
;
391 colour
= FG_FALLBACK
;
396 #if (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
397 if (screen
== SCREEN_REMOTE
)
398 colour
= REMOTE_BG_FALLBACK
;
401 #if defined(HAVE_LCD_COLOR)
402 colour
= global_settings
.bg_color
;
404 colour
= BG_FALLBACK
;
410 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */