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"
34 #include "statusbar.h"
35 #include "screen_access.h"
36 #include "appevents.h"
40 /*some short cuts for fg/bg/line selector handling */
42 #define LINE_SEL_FROM_SETTINGS(vp) \
44 vp->lss_pattern = global_settings.lss_color; \
45 vp->lse_pattern = global_settings.lse_color; \
46 vp->lst_pattern = global_settings.lst_color; \
48 #define FG_FALLBACK global_settings.fg_color
49 #define BG_FALLBACK global_settings.bg_color
51 /* mono/greyscale doesn't have most of the above */
52 #define LINE_SEL_FROM_SETTINGS(vp)
53 #define FG_FALLBACK LCD_DEFAULT_FG
54 #define BG_FALLBACK LCD_DEFAULT_BG
57 static int statusbar_enabled
= 0;
59 #ifdef HAVE_LCD_BITMAP
63 int active
[NB_SCREENS
];
66 static struct viewport custom_vp
[NB_SCREENS
];
68 /* callbacks for GUI_EVENT_* events */
69 static void viewportmanager_ui_vp_changed(void *param
);
70 static void statusbar_toggled(void* param
);
71 static unsigned viewport_init_ui_vp(void);
73 static void viewportmanager_redraw(void* data
);
75 int viewport_get_nb_lines(struct viewport
*vp
)
77 #ifdef HAVE_LCD_BITMAP
78 return vp
->height
/font_get(vp
->font
)->height
;
85 static bool showing_bars(enum screen_type screen
)
87 if (statusbar_enabled
& VP_SB_ONSCREEN(screen
))
89 #ifdef HAVE_LCD_BITMAP
90 bool ignore
= statusbar_enabled
& VP_SB_IGNORE_SETTING(screen
);
91 return ignore
|| (statusbar_position(screen
));
99 void viewport_set_fullscreen(struct viewport
*vp
, enum screen_type screen
)
102 vp
->width
= screens
[screen
].lcdwidth
;
104 #ifdef HAVE_LCD_BITMAP
105 vp
->drawmode
= DRMODE_SOLID
;
106 vp
->font
= FONT_UI
; /* default to UI to discourage SYSFONT use */
108 vp
->height
= screens
[screen
].lcdheight
;
109 if (statusbar_position(screen
) != STATUSBAR_BOTTOM
&& showing_bars(screen
))
110 vp
->y
= STATUSBAR_HEIGHT
;
116 vp
->height
= screens
[screen
].lcdheight
- (showing_bars(screen
)?STATUSBAR_HEIGHT
:0);
119 #ifdef HAVE_REMOTE_LCD
120 /* We only need this test if there is a remote LCD */
121 if (screen
== SCREEN_MAIN
)
124 vp
->fg_pattern
= FG_FALLBACK
;
125 vp
->bg_pattern
= BG_FALLBACK
;
126 LINE_SEL_FROM_SETTINGS(vp
);
130 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
131 if (screen
== SCREEN_REMOTE
)
133 vp
->fg_pattern
= LCD_REMOTE_DEFAULT_FG
;
134 vp
->bg_pattern
= LCD_REMOTE_DEFAULT_BG
;
139 void viewport_set_defaults(struct viewport
*vp
, enum screen_type screen
)
141 #ifdef HAVE_LCD_BITMAP
142 if (ui_vp_info
.active
[screen
])
143 *vp
= ui_vp_info
.vp
[screen
];
146 viewport_set_fullscreen(vp
, screen
);
149 void viewportmanager_init(void)
151 #ifdef HAVE_LCD_BITMAP
153 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggled
);
154 retval
= viewport_init_ui_vp();
156 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
157 ui_vp_info
.vp
= custom_vp
;
159 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
162 int viewportmanager_get_statusbar(void)
164 return statusbar_enabled
;
167 int viewportmanager_set_statusbar(int enabled
)
169 int old
= statusbar_enabled
;
170 statusbar_enabled
= enabled
;
177 gui_statusbar_draw(&statusbars
.statusbars
[i
], true);
179 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
183 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
188 static void viewportmanager_redraw(void* data
)
195 gui_statusbar_draw(&statusbars
.statusbars
[i
], NULL
!= data
);
198 #ifdef HAVE_LCD_BITMAP
200 static void statusbar_toggled(void* param
)
203 /* update vp manager for the new setting and reposition vps
205 viewportmanager_theme_changed(THEME_STATUSBAR
);
208 void viewportmanager_theme_changed(int which
)
211 #ifdef HAVE_BUTTONBAR
212 if (which
& THEME_BUTTONBAR
)
213 { /* don't handle further, the custom ui viewport ignores the buttonbar,
214 * as does viewport_set_defaults(), since only lists use it*/
215 screens
[SCREEN_MAIN
].has_buttonbar
= global_settings
.buttonbar
;
218 if (which
& THEME_UI_VIEWPORT
)
220 int retval
= viewport_init_ui_vp();
221 /* reset the ui viewport */
223 ui_vp_info
.active
[i
] = retval
& BIT_N(i
);
226 add_event(GUI_EVENT_REFRESH
, false, viewportmanager_ui_vp_changed
);
228 remove_event(GUI_EVENT_REFRESH
, viewportmanager_ui_vp_changed
);
229 /* and point to it */
230 ui_vp_info
.vp
= custom_vp
;
232 if (which
& THEME_STATUSBAR
)
234 statusbar_enabled
= VP_SB_HIDE_ALL
;
238 if (statusbar_position(i
) != STATUSBAR_OFF
)
239 statusbar_enabled
|= VP_SB_ONSCREEN(i
);
242 if (statusbar_enabled
!= VP_SB_HIDE_ALL
)
243 add_event(GUI_EVENT_ACTIONUPDATE
, false, viewportmanager_redraw
);
245 remove_event(GUI_EVENT_ACTIONUPDATE
, viewportmanager_redraw
);
247 /* reposition viewport to fit statusbar, only if not using the ui vp */
251 if (!ui_vp_info
.active
[i
])
252 viewport_set_fullscreen(&custom_vp
[i
], i
);
255 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
258 static void viewportmanager_ui_vp_changed(void *param
)
260 /* if the user changed the theme, we need to initiate a full redraw */
262 /* cast param to a function */
263 void (*draw_func
)(void) = ((void(*)(void))param
);
264 /* start with clearing the screen */
266 screens
[i
].clear_display();
267 /* redraw the statusbar if it was enabled */
268 viewportmanager_set_statusbar(statusbar_enabled
);
269 /* call the passed function which will redraw the content of
270 * the current screen */
277 void viewport_set_current_vp(struct viewport
* vp
)
282 ui_vp_info
.vp
= custom_vp
;
284 /* must be done after the assignment above or event handler get old vps */
285 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
288 struct viewport
* viewport_get_current_vp(void)
290 return ui_vp_info
.vp
;
293 bool viewport_ui_vp_get_state(enum screen_type screen
)
295 return ui_vp_info
.active
[screen
];
298 #ifdef HAVE_LCD_COLOR
299 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
301 #define ARG_STRING(_depth) "dddddgg"
304 const char* viewport_parse_viewport(struct viewport
*vp
,
305 enum screen_type screen
,
307 const char separator
)
309 /* parse the list to the viewport struct */
310 const char *ptr
= bufptr
;
324 /* Work out the depth of this display */
325 depth
= screens
[screen
].depth
;
326 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
329 if (!(ptr
= parse_list("ddddd", &set
, separator
, ptr
,
330 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
)))
335 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
338 if (!(ptr
= parse_list(ARG_STRING(depth
), &set
, separator
, ptr
,
339 &vp
->x
, &vp
->y
, &vp
->width
, &vp
->height
, &vp
->font
,
340 &vp
->fg_pattern
,&vp
->bg_pattern
)))
348 /* X and Y *must* be set */
349 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
353 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
354 vp
->width
= screens
[screen
].lcdwidth
- vp
->x
;
355 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
356 vp
->height
= screens
[screen
].lcdheight
- vp
->y
;
358 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
359 if (!LIST_VALUE_PARSED(set
, PL_FG
))
360 vp
->fg_pattern
= FG_FALLBACK
;
361 if (!LIST_VALUE_PARSED(set
, PL_BG
))
362 vp
->bg_pattern
= BG_FALLBACK
;
363 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
365 LINE_SEL_FROM_SETTINGS(vp
);
367 /* Validate the viewport dimensions - we know that the numbers are
368 non-negative integers, ignore bars and assume the viewport takes them
370 if ((vp
->x
>= screens
[screen
].lcdwidth
) ||
371 ((vp
->x
+ vp
->width
) > screens
[screen
].lcdwidth
) ||
372 (vp
->y
>= screens
[screen
].lcdheight
) ||
373 ((vp
->y
+ vp
->height
) > screens
[screen
].lcdheight
))
378 /* Default to using the user font if the font was an invalid number or '-'*/
379 if (((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
))
380 || !LIST_VALUE_PARSED(set
, PL_FONT
)
384 /* Set the defaults for fields not user-specified */
385 vp
->drawmode
= DRMODE_SOLID
;
391 * (re)parse the UI vp from the settings
393 * 0 if no UI vp is used at all
394 * else the bit for the screen (1<<screen) is set
396 static unsigned viewport_init_ui_vp(void)
401 FOR_NB_SCREENS(screen
)
403 #ifdef HAVE_REMOTE_LCD
404 if ((screen
== SCREEN_REMOTE
))
405 setting
= global_settings
.remote_ui_vp_config
;
408 setting
= global_settings
.ui_vp_config
;
411 if (!(viewport_parse_viewport(&custom_vp
[screen
], screen
,
413 viewport_set_fullscreen(&custom_vp
[screen
], screen
);
415 ret
|= BIT_N(screen
);
420 #ifdef HAVE_TOUCHSCREEN
421 /* check if a point (x and y coordinates) are within a viewport */
422 bool viewport_point_within_vp(const struct viewport
*vp
, int x
, int y
)
424 bool is_x
= (x
>= vp
->x
&& x
< (vp
->x
+ vp
->width
));
425 bool is_y
= (y
>= vp
->y
&& y
< (vp
->y
+ vp
->height
));
426 return (is_x
&& is_y
);
428 #endif /* HAVE_TOUCHSCREEN */
429 #endif /* HAVE_LCD_BITMAP */