Remove unneeded symbols and improve the comment to the VP parsing function
[kugel-rb.git] / apps / gui / viewport.c
blobef527d90ccf43b636513e93196774300b57ef62c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <stdlib.h>
23 #include "config.h"
24 #include "lcd.h"
25 #include "lcd-remote.h"
26 #include "font.h"
27 #include "sprintf.h"
28 #include "string.h"
29 #include "settings.h"
30 #include "kernel.h"
31 #include "system.h"
32 #include "misc.h"
33 #include "viewport.h"
34 #include "statusbar.h"
35 #include "screen_access.h"
36 #include "appevents.h"
40 /*some short cuts for fg/bg/line selector handling */
41 #ifdef HAVE_LCD_COLOR
42 #define LINE_SEL_FROM_SETTINGS(vp) \
43 do { \
44 vp->lss_pattern = global_settings.lss_color; \
45 vp->lse_pattern = global_settings.lse_color; \
46 vp->lst_pattern = global_settings.lst_color; \
47 } while (0)
48 #define FG_FALLBACK global_settings.fg_color
49 #define BG_FALLBACK global_settings.bg_color
50 #else
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
55 #endif
57 static int statusbar_enabled = 0;
59 int viewport_get_nb_lines(struct viewport *vp)
61 #ifdef HAVE_LCD_BITMAP
62 return vp->height/font_get(vp->font)->height;
63 #else
64 (void)vp;
65 return 2;
66 #endif
69 static bool showing_bars(enum screen_type screen)
71 if (statusbar_enabled & VP_SB_ONSCREEN(screen))
73 #ifdef HAVE_LCD_BITMAP
74 bool ignore = statusbar_enabled & VP_SB_IGNORE_SETTING(screen);
75 return ignore || (statusbar_position(screen));
76 #else
77 return true;
78 #endif
80 return false;
83 void viewport_set_defaults(struct viewport *vp, enum screen_type screen)
85 vp->x = 0;
86 vp->width = screens[screen].lcdwidth;
88 #ifdef HAVE_LCD_BITMAP
89 vp->drawmode = DRMODE_SOLID;
90 vp->font = FONT_UI; /* default to UI to discourage SYSFONT use */
92 vp->height = screens[screen].lcdheight;
93 if (statusbar_position(screen) != STATUSBAR_BOTTOM && showing_bars(screen))
94 vp->y = STATUSBAR_HEIGHT;
95 else
96 vp->y = 0;
97 #else
98 vp->y = 0;
99 #endif
100 vp->height = screens[screen].lcdheight - (showing_bars(screen)?STATUSBAR_HEIGHT:0);
102 #if LCD_DEPTH > 1
103 #ifdef HAVE_REMOTE_LCD
104 /* We only need this test if there is a remote LCD */
105 if (screen == SCREEN_MAIN)
106 #endif
108 vp->fg_pattern = FG_FALLBACK;
109 vp->bg_pattern = BG_FALLBACK;
110 LINE_SEL_FROM_SETTINGS(vp);
112 #endif
114 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
115 if (screen == SCREEN_REMOTE)
117 vp->fg_pattern = LCD_REMOTE_DEFAULT_FG;
118 vp->bg_pattern = LCD_REMOTE_DEFAULT_BG;
120 #endif
124 int viewportmanager_set_statusbar(int enabled)
126 int old = statusbar_enabled;
127 statusbar_enabled = enabled;
128 if (enabled)
130 int i;
131 FOR_NB_SCREENS(i)
133 if (showing_bars(i))
134 gui_statusbar_draw(&statusbars.statusbars[i], true);
136 add_event(GUI_EVENT_ACTIONUPDATE, false, viewportmanager_draw_statusbars);
138 else
140 remove_event(GUI_EVENT_ACTIONUPDATE, viewportmanager_draw_statusbars);
142 return old;
145 void viewportmanager_draw_statusbars(void* data)
147 int i;
149 FOR_NB_SCREENS(i)
151 if (showing_bars(i))
152 gui_statusbar_draw(&statusbars.statusbars[i], (bool)data);
156 void viewportmanager_statusbar_changed(void* data)
158 (void)data;
159 statusbar_enabled = 0;
160 if (global_settings.statusbar != STATUSBAR_OFF)
161 statusbar_enabled = VP_SB_ONSCREEN(SCREEN_MAIN);
162 #ifdef HAVE_REMOTE_LCD
163 if (global_settings.remote_statusbar != STATUSBAR_OFF)
164 statusbar_enabled |= VP_SB_ONSCREEN(SCREEN_REMOTE);
165 #endif
166 viewportmanager_set_statusbar(statusbar_enabled);
169 #ifdef HAVE_LCD_COLOR
170 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
171 #else
172 #define ARG_STRING(_depth) "dddddgg"
173 #endif
175 #ifdef HAVE_LCD_BITMAP
176 const char* viewport_parse_viewport(struct viewport *vp,
177 enum screen_type screen,
178 const char *bufptr,
179 const char separator)
181 /* parse the list to the viewport struct */
182 const char *ptr = bufptr;
183 int depth;
184 uint32_t set = 0;
186 enum {
187 PL_X = 0,
188 PL_Y,
189 PL_WIDTH,
190 PL_HEIGHT,
191 PL_FONT,
192 PL_FG,
193 PL_BG,
196 /* Work out the depth of this display */
197 depth = screens[screen].depth;
198 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
199 if (depth == 1)
201 if (!(ptr = parse_list("ddddd", &set, separator, ptr,
202 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font)))
203 return NULL;
205 else
206 #endif
207 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
208 if (depth >= 2)
210 if (!(ptr = parse_list(ARG_STRING(depth), &set, separator, ptr,
211 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font,
212 &vp->fg_pattern,&vp->bg_pattern)))
213 return NULL;
215 else
216 #undef ARG_STRING
217 #endif
220 /* X and Y *must* be set */
221 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
222 return NULL;
224 /* fix defaults */
225 if (!LIST_VALUE_PARSED(set, PL_WIDTH))
226 vp->width = screens[screen].lcdwidth - vp->x;
227 if (!LIST_VALUE_PARSED(set, PL_HEIGHT))
228 vp->height = screens[screen].lcdheight - vp->y;
230 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
231 if (!LIST_VALUE_PARSED(set, PL_FG))
232 vp->fg_pattern = FG_FALLBACK;
233 if (!LIST_VALUE_PARSED(set, PL_BG))
234 vp->bg_pattern = BG_FALLBACK;
235 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
237 LINE_SEL_FROM_SETTINGS(vp);
239 /* Validate the viewport dimensions - we know that the numbers are
240 non-negative integers, ignore bars and assume the viewport takes them
241 * into account */
242 if ((vp->x >= screens[screen].lcdwidth) ||
243 ((vp->x + vp->width) > screens[screen].lcdwidth) ||
244 (vp->y >= screens[screen].lcdheight) ||
245 ((vp->y + vp->height) > screens[screen].lcdheight))
247 return NULL;
250 /* Default to using the user font if the font was an invalid number or '-'*/
251 if (((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))
252 || !LIST_VALUE_PARSED(set, PL_FONT)
254 vp->font = FONT_UI;
256 /* Set the defaults for fields not user-specified */
257 vp->drawmode = DRMODE_SOLID;
259 return ptr;
262 #endif /* HAVE_LCD_BITMAP */