blob: 7d79e5f04a4cf0dac54aa61d57b096b36ee39ee2 [file] [log] [blame]
Jonathan Gordon0e5cec22008-03-05 09:58:30 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Jonathan Gordon
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Jonathan Gordon0e5cec22008-03-05 09:58:30 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
Bertrik Sikken28434692008-04-28 16:18:04 +000022#include <stdlib.h>
Jonathan Gordon0e5cec22008-03-05 09:58:30 +000023#include "config.h"
24#include "lcd.h"
Dave Chapman2b7d48e2008-03-09 23:53:46 +000025#include "lcd-remote.h"
Jonathan Gordon0e5cec22008-03-05 09:58:30 +000026#include "font.h"
Jonathan Gordon0e5cec22008-03-05 09:58:30 +000027#include "viewport.h"
Jonathan Gordon0e5cec22008-03-05 09:58:30 +000028#include "screen_access.h"
Thomas Martitzc0f1c492009-09-13 13:40:58 +000029#include "settings.h"
30#include "misc.h"
Thomas Martitz9bd7b232009-08-09 16:16:55 +000031
Thomas Martitze4bdc082009-08-12 13:04:12 +000032/*some short cuts for fg/bg/line selector handling */
Thomas Martitz9f3fc272009-08-09 17:39:39 +000033#ifdef HAVE_LCD_COLOR
Thomas Martitz9f3fc272009-08-09 17:39:39 +000034#define FG_FALLBACK global_settings.fg_color
35#define BG_FALLBACK global_settings.bg_color
36#else
37#define FG_FALLBACK LCD_DEFAULT_FG
Thomas Martitze4bdc082009-08-12 13:04:12 +000038#define BG_FALLBACK LCD_DEFAULT_BG
Thomas Martitz9f3fc272009-08-09 17:39:39 +000039#endif
Jonathan Gordon5c7be3e2010-05-25 04:02:09 +000040#ifdef HAVE_REMOTE_LCD
41#define REMOTE_FG_FALLBACK LCD_REMOTE_DEFAULT_FG
42#define REMOTE_BG_FALLBACK LCD_REMOTE_DEFAULT_BG
43#endif
44
Thomas Martitz9bd7b232009-08-09 16:16:55 +000045
Thomas Martitzc0f1c492009-09-13 13:40:58 +000046/* all below isn't needed for pc tools (i.e. checkwps/wps editor)
47 * only viewport_parse_viewport() is */
48#ifndef __PCTOOL__
Thomas Martitzc0f1c492009-09-13 13:40:58 +000049#include "string.h"
50#include "kernel.h"
51#include "system.h"
52#include "statusbar.h"
53#include "appevents.h"
Jonathan Gordondd9fbbf2009-12-09 07:44:08 +000054#include "panic.h"
Tomer Shalev5da75072009-10-05 21:32:29 +000055#ifdef HAVE_LCD_BITMAP
Tomer Shalevb0a99382009-10-05 21:13:55 +000056#include "language.h"
Tomer Shalev5da75072009-10-05 21:32:29 +000057#endif
Thomas Martitz1016ee42009-10-19 15:28:15 +000058#include "statusbar-skinned.h"
59#include "debug.h"
60
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +000061#define VPSTACK_DEPTH 16
62struct viewport_stack_item
63{
64 struct viewport* vp;
65 bool enabled;
66};
Jonathan Gordon0e5cec22008-03-05 09:58:30 +000067
Thomas Martitz4c48b592009-08-16 22:20:11 +000068#ifdef HAVE_LCD_BITMAP
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +000069static void viewportmanager_redraw(void* data);
Teruaki Kawashima38efc712010-02-28 14:12:41 +000070
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +000071static int theme_stack_top[NB_SCREENS]; /* the last item added */
72static struct viewport_stack_item theme_stack[NB_SCREENS][VPSTACK_DEPTH];
73static bool is_theme_enabled(enum screen_type screen);
Thomas Martitz4c48b592009-08-16 22:20:11 +000074
Thomas Martitzfeb3a262010-01-27 20:34:51 +000075
76static void toggle_events(bool enable)
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +000077{
Thomas Martitzfeb3a262010-01-27 20:34:51 +000078 if (enable)
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +000079 {
80 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw);
81#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
82 add_event(LCD_EVENT_ACTIVATION, false, do_sbs_update_callback);
83#endif
84 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false,
85 do_sbs_update_callback);
86 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false,
87 do_sbs_update_callback);
Thomas Martitzfeb3a262010-01-27 20:34:51 +000088 }
89 else
90 {
91#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
92 remove_event(LCD_EVENT_ACTIVATION, do_sbs_update_callback);
93#endif
94 remove_event(PLAYBACK_EVENT_TRACK_CHANGE, do_sbs_update_callback);
95 remove_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, do_sbs_update_callback);
96 remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_redraw);
Teruaki Kawashima38efc712010-02-28 14:12:41 +000097 }
Thomas Martitzfeb3a262010-01-27 20:34:51 +000098}
99
100
101static void toggle_theme(enum screen_type screen, bool force)
102{
103 bool enable_event = false;
104 static bool was_enabled[NB_SCREENS] = {false};
Thomas Martitz81ebf2b2010-02-27 21:19:34 +0000105 static bool after_boot[NB_SCREENS] = {false};
Thomas Martitzfeb3a262010-01-27 20:34:51 +0000106 int i;
107
108 FOR_NB_SCREENS(i)
109 {
110 enable_event = enable_event || is_theme_enabled(i);
Jonathan Gordon466e5d92010-02-26 03:45:41 +0000111 sb_set_title_text(NULL, Icon_NOICON, i);
Thomas Martitzfeb3a262010-01-27 20:34:51 +0000112 }
113 toggle_events(enable_event);
114
115 if (is_theme_enabled(screen))
116 {
Jonathan Gordon4c6b3552010-02-26 08:01:41 +0000117 bool first_boot = theme_stack_top[screen] == 0;
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000118 /* remove the left overs from the previous screen.
119 * could cause a tiny flicker. Redo your screen code if that happens */
Jonathan Gordon9955e9a2010-02-08 17:19:15 +0000120#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
Jonathan Gordonfd2fdc22010-02-10 04:19:50 +0000121 screens[screen].backdrop_show(sb_get_backdrop(screen));
Jonathan Gordon9955e9a2010-02-08 17:19:15 +0000122#endif
Thomas Martitz81ebf2b2010-02-27 21:19:34 +0000123 if (LIKELY(after_boot[screen]) && (!was_enabled[screen] || force))
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000124 {
Jonathan Gordon9d1832c2009-12-21 05:19:12 +0000125 struct viewport deadspace, user;
126 viewport_set_defaults(&user, screen);
127 deadspace = user; /* get colours and everything */
128 /* above */
129 deadspace.x = 0;
130 deadspace.y = 0;
131 deadspace.width = screens[screen].lcdwidth;
132 deadspace.height = user.y;
133 if (deadspace.width && deadspace.height)
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000134 {
Jonathan Gordon9d1832c2009-12-21 05:19:12 +0000135 screens[screen].set_viewport(&deadspace);
136 screens[screen].clear_viewport();
137 screens[screen].update_viewport();
138 }
139 /* below */
140 deadspace.y = user.y + user.height;
141 deadspace.height = screens[screen].lcdheight - deadspace.y;
142 if (deadspace.width && deadspace.height)
143 {
144 screens[screen].set_viewport(&deadspace);
145 screens[screen].clear_viewport();
146 screens[screen].update_viewport();
147 }
148 /* left */
149 deadspace.x = 0;
150 deadspace.y = 0;
151 deadspace.width = user.x;
152 deadspace.height = screens[screen].lcdheight;
153 if (deadspace.width && deadspace.height)
154 {
155 screens[screen].set_viewport(&deadspace);
156 screens[screen].clear_viewport();
157 screens[screen].update_viewport();
158 }
159 /* below */
160 deadspace.x = user.x + user.width;
161 deadspace.width = screens[screen].lcdwidth - deadspace.x;
162 if (deadspace.width && deadspace.height)
163 {
164 screens[screen].set_viewport(&deadspace);
165 screens[screen].clear_viewport();
166 screens[screen].update_viewport();
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000167 }
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000168 screens[screen].set_viewport(NULL);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000169 }
Jonathan Gordon92f0aa82010-02-26 08:43:26 +0000170 intptr_t force = first_boot?0:1;
Jonathan Gordona398c282010-06-21 06:04:19 +0000171
Jonathan Gordon92f0aa82010-02-26 08:43:26 +0000172 send_event(GUI_EVENT_ACTIONUPDATE, (void*)force);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000173 }
174 else
175 {
Thomas Martitze18e8062010-01-27 20:45:42 +0000176#if LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1)
Jonathan Gordoneee54232010-01-29 07:52:13 +0000177 screens[screen].backdrop_show(NULL);
Jonathan Gordon25653892010-01-27 06:47:56 +0000178#endif
Thomas Martitzfeb3a262010-01-27 20:34:51 +0000179 screens[screen].stop_scroll();
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000180 }
Jonathan Gordon0900b562009-12-18 06:51:36 +0000181 /* let list initialize viewport in case viewport dimensions is changed. */
182 send_event(GUI_EVENT_THEME_CHANGED, NULL);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000183 FOR_NB_SCREENS(i)
184 was_enabled[i] = is_theme_enabled(i);
Jonathan Gordona398c282010-06-21 06:04:19 +0000185#ifdef HAVE_TOUCHSCREEN
186 sb_bypass_touchregions(!is_theme_enabled(SCREEN_MAIN));
187#endif
Thomas Martitz81ebf2b2010-02-27 21:19:34 +0000188 after_boot[screen] = true;
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000189}
190
191void viewportmanager_theme_enable(enum screen_type screen, bool enable,
192 struct viewport *viewport)
193{
194 int top = ++theme_stack_top[screen];
195 if (top >= VPSTACK_DEPTH-1)
196 panicf("Stack overflow... viewportmanager");
197 theme_stack[screen][top].enabled = enable;
198 theme_stack[screen][top].vp = viewport;
Jonathan Gordon9d1832c2009-12-21 05:19:12 +0000199 toggle_theme(screen, false);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000200 /* then be nice and set the viewport up */
201 if (viewport)
202 viewport_set_defaults(viewport, screen);
203}
204
Jonathan Gordon9d1832c2009-12-21 05:19:12 +0000205void viewportmanager_theme_undo(enum screen_type screen, bool force_redraw)
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000206{
207 int top = --theme_stack_top[screen];
208 if (top < 0)
209 panicf("Stack underflow... viewportmanager");
210
Jonathan Gordon9d1832c2009-12-21 05:19:12 +0000211 toggle_theme(screen, force_redraw);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000212}
213
214
215static bool is_theme_enabled(enum screen_type screen)
216{
217 int top = theme_stack_top[screen];
218 return theme_stack[screen][top].enabled;
219}
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000220#endif /* HAVE_LCD_BITMAP */
Thomas Martitz4c48b592009-08-16 22:20:11 +0000221
Nils Wallménius3c1e2c12009-10-10 08:29:13 +0000222int viewport_get_nb_lines(const struct viewport *vp)
Jonathan Gordon0e5cec22008-03-05 09:58:30 +0000223{
224#ifdef HAVE_LCD_BITMAP
225 return vp->height/font_get(vp->font)->height;
226#else
227 (void)vp;
228 return 2;
229#endif
230}
231
Thomas Martitz4c48b592009-08-16 22:20:11 +0000232static void viewportmanager_redraw(void* data)
Jonathan Gordone385ee12008-12-31 05:59:26 +0000233{
Jonathan Gordon80cb3552009-02-01 11:34:16 +0000234 int i;
235 FOR_NB_SCREENS(i)
236 {
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000237#ifdef HAVE_LCD_BITMAP
Jonathan Gordon1759a292010-03-13 22:26:03 +0000238 if (is_theme_enabled(i))
239 sb_skin_update(i, NULL != data);
Jonathan Gordona9b5f4d2010-03-06 00:29:46 +0000240#else
Jonathan Gordonf1b209c2010-03-06 00:37:01 +0000241 (void)data;
Jonathan Gordona9b5f4d2010-03-06 00:29:46 +0000242 gui_statusbar_draw(&statusbars.statusbars[i], NULL, NULL);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000243#endif
Thomas Martitz4c48b592009-08-16 22:20:11 +0000244 }
245}
Thomas Martitz4c48b592009-08-16 22:20:11 +0000246
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000247void viewportmanager_init()
Thomas Martitz4c48b592009-08-16 22:20:11 +0000248{
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000249#ifdef HAVE_LCD_BITMAP
250 int i;
251 FOR_NB_SCREENS(i)
252 {
253 theme_stack_top[i] = -1; /* the next call fixes this to 0 */
254 /* We always want the theme enabled by default... */
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000255 viewportmanager_theme_enable(i, true, NULL);
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000256 }
257#else
258 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_redraw);
259#endif
Thomas Martitz4c48b592009-08-16 22:20:11 +0000260}
261
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000262#ifdef HAVE_LCD_BITMAP
Thomas Martitza27f2b82009-10-11 00:05:12 +0000263void viewportmanager_theme_changed(const int which)
Thomas Martitz4c48b592009-08-16 22:20:11 +0000264{
Thomas Martitz90a29dd2009-08-29 15:46:32 +0000265 int i;
Thomas Martitz2eb1cb62009-09-07 17:37:06 +0000266#ifdef HAVE_BUTTONBAR
267 if (which & THEME_BUTTONBAR)
268 { /* don't handle further, the custom ui viewport ignores the buttonbar,
269 * as does viewport_set_defaults(), since only lists use it*/
270 screens[SCREEN_MAIN].has_buttonbar = global_settings.buttonbar;
271 }
272#endif
Thomas Martitz4c48b592009-08-16 22:20:11 +0000273 if (which & THEME_UI_VIEWPORT)
274 {
Thomas Martitz4c48b592009-08-16 22:20:11 +0000275 }
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000276 if (which & THEME_LANGUAGE)
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000277 {
Thomas Martitz80003bc2009-10-09 18:39:34 +0000278 }
Thomas Martitz4c48b592009-08-16 22:20:11 +0000279 if (which & THEME_STATUSBAR)
280 {
Thomas Martitz94f76512009-10-16 20:34:04 +0000281 FOR_NB_SCREENS(i)
282 {
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000283 /* This can probably be done better...
284 * disable the theme so it's forced to do a full redraw */
285 viewportmanager_theme_enable(i, false, NULL);
Jonathan Gordon9d1832c2009-12-21 05:19:12 +0000286 viewportmanager_theme_undo(i, true);
Thomas Martitz4c48b592009-08-16 22:20:11 +0000287 }
Jonathan Gordon80cb3552009-02-01 11:34:16 +0000288 }
Thomas Martitz2eb1cb62009-09-07 17:37:06 +0000289 send_event(GUI_EVENT_THEME_CHANGED, NULL);
Jonathan Gordone385ee12008-12-31 05:59:26 +0000290}
291
Thomas Martitzc0f1c492009-09-13 13:40:58 +0000292#ifdef HAVE_TOUCHSCREEN
293/* check if a point (x and y coordinates) are within a viewport */
Thomas Martitza27f2b82009-10-11 00:05:12 +0000294bool viewport_point_within_vp(const struct viewport *vp,
295 const int x, const int y)
Thomas Martitzc0f1c492009-09-13 13:40:58 +0000296{
297 bool is_x = (x >= vp->x && x < (vp->x + vp->width));
298 bool is_y = (y >= vp->y && y < (vp->y + vp->height));
299 return (is_x && is_y);
300}
301#endif /* HAVE_TOUCHSCREEN */
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000302
303static void set_default_align_flags(struct viewport *vp)
304{
305 vp->flags &= ~VP_FLAG_ALIGNMENT_MASK;
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000306 if (UNLIKELY(lang_is_rtl()))
307 vp->flags |= VP_FLAG_ALIGN_RIGHT;
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000308}
309
Thomas Martitzc0f1c492009-09-13 13:40:58 +0000310#endif /* HAVE_LCD_BITMAP */
311#endif /* __PCTOOL__ */
312
Thomas Martitza1b0e162009-08-09 18:44:49 +0000313#ifdef HAVE_LCD_COLOR
Thomas Martitze4bdc082009-08-12 13:04:12 +0000314#define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
Thomas Martitza1b0e162009-08-09 18:44:49 +0000315#else
Thomas Martitze4bdc082009-08-12 13:04:12 +0000316#define ARG_STRING(_depth) "dddddgg"
Thomas Martitza1b0e162009-08-09 18:44:49 +0000317#endif
318
Thomas Martitz6750d652009-11-04 06:56:04 +0000319
320void viewport_set_fullscreen(struct viewport *vp,
321 const enum screen_type screen)
322{
323 vp->x = 0;
324 vp->y = 0;
325 vp->width = screens[screen].lcdwidth;
326 vp->height = screens[screen].lcdheight;
327
328#ifdef HAVE_LCD_BITMAP
Jonathan Gordondd9fbbf2009-12-09 07:44:08 +0000329#ifndef __PCTOOL__
Thomas Martitz6750d652009-11-04 06:56:04 +0000330 set_default_align_flags(vp);
Jonathan Gordondd9fbbf2009-12-09 07:44:08 +0000331#endif
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000332 vp->font = FONT_UI + screen; /* default to UI to discourage SYSFONT use */
Thomas Martitz6750d652009-11-04 06:56:04 +0000333 vp->drawmode = DRMODE_SOLID;
334#if LCD_DEPTH > 1
335#ifdef HAVE_REMOTE_LCD
336 /* We only need this test if there is a remote LCD */
337 if (screen == SCREEN_MAIN)
338#endif
339 {
340 vp->fg_pattern = FG_FALLBACK;
341 vp->bg_pattern = BG_FALLBACK;
342#ifdef HAVE_LCD_COLOR
343 vp->lss_pattern = global_settings.lss_color;
344 vp->lse_pattern = global_settings.lse_color;
345 vp->lst_pattern = global_settings.lst_color;
346#endif
347 }
348#endif
349
350#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
351 if (screen == SCREEN_REMOTE)
352 {
353 vp->fg_pattern = LCD_REMOTE_DEFAULT_FG;
354 vp->bg_pattern = LCD_REMOTE_DEFAULT_BG;
355 }
356#endif
357#endif
358}
359
360void viewport_set_defaults(struct viewport *vp,
361 const enum screen_type screen)
362{
Thomas Martitz6750d652009-11-04 06:56:04 +0000363#if defined(HAVE_LCD_BITMAP) && !defined(__PCTOOL__)
Jonathan Gordoneee54232010-01-29 07:52:13 +0000364 struct viewport *sbs_area = NULL;
Jonathan Gordonb2eb44c2009-12-09 07:25:46 +0000365 if (!is_theme_enabled(screen))
Jonathan Gordoneee54232010-01-29 07:52:13 +0000366 {
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000367 viewport_set_fullscreen(vp, screen);
368 return;
Thomas Martitz6750d652009-11-04 06:56:04 +0000369 }
Jonathan Gordoneee54232010-01-29 07:52:13 +0000370 sbs_area = sb_skin_get_info_vp(screen);
371
Thomas Martitze9c900d2009-11-04 21:08:21 +0000372 if (sbs_area)
Thomas Martitz6750d652009-11-04 06:56:04 +0000373 *vp = *sbs_area;
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000374 else
Thomas Martitz6750d652009-11-04 06:56:04 +0000375#endif /* HAVE_LCD_BITMAP */
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000376 viewport_set_fullscreen(vp, screen);
Thomas Martitz6750d652009-11-04 06:56:04 +0000377}
378
379
Thomas Martitzc0f1c492009-09-13 13:40:58 +0000380#ifdef HAVE_LCD_BITMAP
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000381
382int get_viewport_default_colour(enum screen_type screen, bool fgcolour)
383{
Jonathan Gordon4f3fb962010-06-07 04:11:49 +0000384 (void)screen; (void)fgcolour;
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000385#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
Jonathan Gordon4e0b47c2010-06-07 04:00:39 +0000386 int colour;
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000387 if (fgcolour)
388 {
389#if (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
390 if (screen == SCREEN_REMOTE)
391 colour = REMOTE_FG_FALLBACK;
392 else
393#endif
Jonathan Gordon32455132010-06-07 03:55:40 +0000394#if defined(HAVE_LCD_COLOR)
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000395 colour = global_settings.fg_color;
Jonathan Gordon32455132010-06-07 03:55:40 +0000396#else
397 colour = FG_FALLBACK;
398#endif
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000399 }
400 else
401 {
402#if (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
403 if (screen == SCREEN_REMOTE)
404 colour = REMOTE_BG_FALLBACK;
405 else
406#endif
Jonathan Gordon32455132010-06-07 03:55:40 +0000407#if defined(HAVE_LCD_COLOR)
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000408 colour = global_settings.bg_color;
Jonathan Gordon32455132010-06-07 03:55:40 +0000409#else
410 colour = BG_FALLBACK;
411#endif
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000412 }
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000413 return colour;
Jonathan Gordon4e0b47c2010-06-07 04:00:39 +0000414#else
415 return 0;
416#endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000417}
418
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000419const char* viewport_parse_viewport(struct viewport *vp,
420 enum screen_type screen,
421 const char *bufptr,
422 const char separator)
423{
424 /* parse the list to the viewport struct */
425 const char *ptr = bufptr;
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000426 uint32_t set = 0;
427
428 enum {
429 PL_X = 0,
430 PL_Y,
431 PL_WIDTH,
432 PL_HEIGHT,
433 PL_FONT,
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000434 };
435
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000436 if (!(ptr = parse_list("ddddd", &set, separator, ptr,
437 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font)))
438 return NULL;
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000439
440 /* X and Y *must* be set */
441 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
Alexander Levin3bfc0e72009-08-12 13:37:07 +0000442 return NULL;
Teruaki Kawashima38efc712010-02-28 14:12:41 +0000443 /* check for negative values */
Jonathan Gordonbee59002009-10-28 06:44:37 +0000444 if (vp->x < 0)
445 vp->x += screens[screen].lcdwidth;
446 if (vp->y < 0)
447 vp->y += screens[screen].lcdheight;
Jonathan Gordon0aa035d2009-10-29 03:27:13 +0000448
449 /* fix defaults,
450 * and negative width/height which means "extend to edge minus value */
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000451 if (!LIST_VALUE_PARSED(set, PL_WIDTH))
452 vp->width = screens[screen].lcdwidth - vp->x;
Jonathan Gordon0aa035d2009-10-29 03:27:13 +0000453 else if (vp->width < 0)
454 vp->width = (vp->width + screens[screen].lcdwidth) - vp->x;
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000455 if (!LIST_VALUE_PARSED(set, PL_HEIGHT))
456 vp->height = screens[screen].lcdheight - vp->y;
Jonathan Gordon0aa035d2009-10-29 03:27:13 +0000457 else if (vp->height < 0)
458 vp->height = (vp->height + screens[screen].lcdheight) - vp->y;
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000459
Thomas Martitzf9094282009-08-09 17:47:12 +0000460#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
Jonathan Gordon5b0521c2010-06-07 03:44:11 +0000461 vp->fg_pattern = get_viewport_default_colour(screen, true);
462 vp->bg_pattern = get_viewport_default_colour(screen, false);
Thomas Martitz9f3fc272009-08-09 17:39:39 +0000463#endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
464
Jonathan Gordon0aa035d2009-10-29 03:27:13 +0000465#ifdef HAVE_LCD_COLOR
466 vp->lss_pattern = global_settings.lss_color;
467 vp->lse_pattern = global_settings.lse_color;
468 vp->lst_pattern = global_settings.lst_color;
469#endif
Thomas Martitz9f3fc272009-08-09 17:39:39 +0000470
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000471 /* Validate the viewport dimensions - we know that the numbers are
472 non-negative integers, ignore bars and assume the viewport takes them
473 * into account */
474 if ((vp->x >= screens[screen].lcdwidth) ||
475 ((vp->x + vp->width) > screens[screen].lcdwidth) ||
476 (vp->y >= screens[screen].lcdheight) ||
477 ((vp->y + vp->height) > screens[screen].lcdheight))
478 {
Alexander Levin3bfc0e72009-08-12 13:37:07 +0000479 return NULL;
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000480 }
481
Jonathan Gordon1c2aa352010-02-14 06:26:16 +0000482 /* Default to using the user font if the font was an invalid number or '-'
483 * font 1 is *always* the UI font for the current screen
484 * 2 is always the first extra font */
485 if (!LIST_VALUE_PARSED(set, PL_FONT))
Jonathan Gordonf85103e2010-02-21 19:10:09 +0000486 vp->font = FONT_UI;
Thomas Martitza1b0e162009-08-09 18:44:49 +0000487
488 /* Set the defaults for fields not user-specified */
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000489 vp->drawmode = DRMODE_SOLID;
Jonathan Gordondd9fbbf2009-12-09 07:44:08 +0000490#ifndef __PCTOOL__
Thomas Martitza79dc872009-10-11 12:21:27 +0000491 set_default_align_flags(vp);
Jonathan Gordondd9fbbf2009-12-09 07:44:08 +0000492#endif
Thomas Martitz9bd7b232009-08-09 16:16:55 +0000493
494 return ptr;
495}
Thomas Martitz4c48b592009-08-16 22:20:11 +0000496#endif