lcd-m6sp.c: remove \r
[kugel-rb.git] / apps / gui / statusbar-skinned.c
blob168b17fa385ce27ffb31c1da850928067c697595
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Thomas Martitz
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 "config.h"
24 #include "action.h"
25 #include "system.h"
26 #include "settings.h"
27 #include "appevents.h"
28 #include "screens.h"
29 #include "screen_access.h"
30 #include "skin_engine/skin_engine.h"
31 #include "skin_engine/wps_internals.h"
32 #include "viewport.h"
33 #include "statusbar.h"
34 #include "statusbar-skinned.h"
35 #include "debug.h"
36 #include "font.h"
37 #include "icon.h"
40 /* currently only one wps_state is needed */
41 extern struct wps_state wps_state; /* from wps.c */
42 static struct gui_wps sb_skin[NB_SCREENS] = {{ .data = NULL }};
43 static struct wps_data sb_skin_data[NB_SCREENS] = {{ .wps_loaded = 0 }};
44 static struct wps_sync_data sb_skin_sync_data = { .do_full_update = false };
46 /* initial setup of wps_data */
47 static int update_delay = DEFAULT_UPDATE_DELAY;
49 bool sb_set_title_text(char* title, enum themable_icons icon, enum screen_type screen)
51 int i;
52 bool retval = false;
53 for(i=0; i<sb_skin_data[screen].num_tokens; i++)
55 if (sb_skin_data[screen].tokens[i].type == WPS_TOKEN_LIST_TITLE_TEXT)
57 sb_skin_data[screen].tokens[i].value.data = title;
58 retval = true;
60 else if (sb_skin_data[screen].tokens[i].type == WPS_TOKEN_LIST_TITLE_ICON)
62 /* Icon_NOICON == -1 which the skin engine wants at position 1, so + 2 */
63 sb_skin_data[screen].tokens[i].value.i = icon+2;
66 return retval;
70 void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile)
72 struct wps_data *data = sb_skin[screen].data;
74 int success;
75 success = buf && skin_data_load(screen, data, buf, isfile);
77 if (success)
78 { /* hide the sb's default viewport because it has nasty effect with stuff
79 * not part of the statusbar,
80 * hence .sbs's without any other vps are unsupported*/
81 struct skin_viewport *vp = find_viewport(VP_DEFAULT_LABEL, data);
82 struct skin_token_list *next_vp = data->viewports->next;
84 if (!next_vp)
85 { /* no second viewport, let parsing fail */
86 success = false;
88 /* hide this viewport, forever */
89 vp->hidden_flags = VP_NEVER_VISIBLE;
90 sb_set_info_vp(screen, VP_INFO_LABEL|VP_DEFAULT_LABEL);
93 if (!success && isfile)
94 sb_create_from_settings(screen);
96 static char infovp_label[NB_SCREENS];
97 static char oldinfovp_label[NB_SCREENS];
98 void sb_set_info_vp(enum screen_type screen, char label)
100 infovp_label[screen] = label;
103 struct viewport *sb_skin_get_info_vp(enum screen_type screen)
105 if (oldinfovp_label[screen] != infovp_label[screen])
107 /* UI viewport changed, so force a redraw */
108 oldinfovp_label[screen] = infovp_label[screen];
109 viewportmanager_theme_enable(screen, false, NULL);
110 viewportmanager_theme_undo(screen, true);
112 return &find_viewport(infovp_label[screen], sb_skin[screen].data)->vp;
115 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
116 char* sb_get_backdrop(enum screen_type screen)
118 return sb_skin[screen].data->backdrop;
121 bool sb_set_backdrop(enum screen_type screen, char* filename)
123 if (!filename)
125 sb_skin[screen].data->backdrop = NULL;
126 return true;
128 else if (!sb_skin[screen].data->backdrop)
130 /* need to make room on the buffer */
131 size_t buf_size;
132 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
133 if (screen == SCREEN_REMOTE)
134 buf_size = REMOTE_LCD_BACKDROP_BYTES;
135 else
136 #endif
137 buf_size = LCD_BACKDROP_BYTES;
138 sb_skin[screen].data->backdrop = skin_buffer_alloc(buf_size);
139 if (!sb_skin[screen].data->backdrop)
140 return false;
143 if (!screens[screen].backdrop_load(filename, sb_skin[screen].data->backdrop))
144 sb_skin[screen].data->backdrop = NULL;
145 return sb_skin[screen].data->backdrop != NULL;
148 #endif
149 void sb_skin_update(enum screen_type screen, bool force)
151 static long next_update[NB_SCREENS] = {0};
152 int i = screen;
153 if (TIME_AFTER(current_tick, next_update[i]) || force)
155 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
156 /* currently, all remotes are readable without backlight
157 * so still update those */
158 if (lcd_active() || (i != SCREEN_MAIN))
159 #endif
160 skin_update(&sb_skin[i], force?
161 WPS_REFRESH_ALL : WPS_REFRESH_NON_STATIC);
162 next_update[i] = current_tick + update_delay; /* don't update too often */
163 sb_skin[SCREEN_MAIN].sync_data->do_full_update = false;
167 void do_sbs_update_callback(void *param)
169 (void)param;
170 /* the WPS handles changing the actual id3 data in the id3 pointers
171 * we imported, we just want a full update */
172 sb_skin_sync_data.do_full_update = true;
173 /* force timeout in wps main loop, so that the update is instantly */
174 queue_post(&button_queue, BUTTON_NONE, 0);
177 void sb_skin_set_update_delay(int delay)
179 update_delay = delay;
182 /* This creates and loads a ".sbs" based on the user settings for:
183 * - regular statusbar
184 * - colours
185 * - ui viewport
186 * - backdrop
188 void sb_create_from_settings(enum screen_type screen)
190 char buf[128], *ptr, *ptr2;
191 int len, remaining = sizeof(buf);
192 int bar_position = statusbar_position(screen);
193 ptr = buf;
194 ptr[0] = '\0';
196 /* setup the inbuilt statusbar */
197 if (bar_position != STATUSBAR_OFF)
199 int y = 0, height = STATUSBAR_HEIGHT;
200 if (bar_position == STATUSBAR_BOTTOM)
202 y = screens[screen].lcdheight - STATUSBAR_HEIGHT;
204 len = snprintf(ptr, remaining, "%%V(0,%d,-,%d,0)\n%%wi\n",
205 y, height);
206 remaining -= len;
207 ptr += len;
209 /* %Vi viewport, colours handled by the parser */
210 #if NB_SCREENS > 1
211 if (screen == SCREEN_REMOTE)
212 ptr2 = global_settings.remote_ui_vp_config;
213 else
214 #endif
215 ptr2 = global_settings.ui_vp_config;
217 if (ptr2[0] && ptr2[0] != '-') /* from ui viewport setting */
219 len = snprintf(ptr, remaining, "%%ax%%Vi(-,%s)\n", ptr2);
221 else
223 int y = 0, height;
224 switch (bar_position)
226 case STATUSBAR_TOP:
227 y = STATUSBAR_HEIGHT;
228 case STATUSBAR_BOTTOM:
229 height = screens[screen].lcdheight - STATUSBAR_HEIGHT;
230 break;
231 default:
232 height = screens[screen].lcdheight;
234 len = snprintf(ptr, remaining, "%%ax%%Vi(-,0,%d,-,%d,1)\n",
235 y, height);
237 sb_skin_data_load(screen, buf, false);
240 void sb_skin_init(void)
242 int i;
243 FOR_NB_SCREENS(i)
245 #ifdef HAVE_ALBUMART
246 sb_skin_data[i].albumart = NULL;
247 sb_skin_data[i].playback_aa_slot = -1;
248 #endif
249 sb_skin[i].data = &sb_skin_data[i];
250 sb_skin[i].display = &screens[i];
251 /* Currently no seperate wps_state needed/possible
252 so use the only available ( "global" ) one */
253 sb_skin[i].state = &wps_state;
254 sb_skin[i].sync_data = &sb_skin_sync_data;
258 #ifdef HAVE_TOUCHSCREEN
259 static bool bypass_sb_touchregions = true;
260 void sb_bypass_touchregions(bool enable)
262 bypass_sb_touchregions = enable;
265 int sb_touch_to_button(int context)
267 static int last_context = -1;
268 int button, offset;
269 if (bypass_sb_touchregions)
270 return ACTION_TOUCHSCREEN;
272 if (last_context != context)
273 skin_disarm_touchregions(&sb_skin_data[SCREEN_MAIN]);
274 last_context = context;
275 button = skin_get_touchaction(&sb_skin_data[SCREEN_MAIN], &offset);
277 switch (button)
279 #ifdef HAVE_VOLUME_IN_LIST
280 case ACTION_WPS_VOLUP:
281 return ACTION_LIST_VOLUP;
282 case ACTION_WPS_VOLDOWN:
283 return ACTION_LIST_VOLDOWN;
284 #endif
285 /* TODO */
287 return button;
289 #endif