Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / gui / skin_engine / skin_backdrops.c
blob77de8bdc1aa7a9021181524442f1f1bf3cd2fedf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 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 "config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include "string-extra.h"
26 #include "settings.h"
27 #include "skin_buffer.h"
28 #include "wps_internals.h"
29 #include "skin_engine.h"
31 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
33 static struct skin_backdrop {
34 char name[MAX_FILENAME+1];
35 char *buffer;
36 enum screen_type screen;
37 } backdrops[SKINNABLE_SCREENS_COUNT*NB_SCREENS];
39 void skin_backdrop_init(void)
41 int i;
42 for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
44 backdrops[i].name[0] = '\0';
45 backdrops[i].buffer = NULL;
49 /* load a backdrop into the skin buffer.
50 * reuse buffers if the file is already loaded */
51 char* skin_backdrop_load(char* backdrop, char *bmpdir, enum screen_type screen)
53 int i;
54 struct skin_backdrop *bdrop = NULL;
55 char filename[MAX_PATH];
56 size_t buf_size;
57 bool loaded = false;
58 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
59 if (screen == SCREEN_REMOTE)
60 buf_size = REMOTE_LCD_BACKDROP_BYTES;
61 else
62 #endif
63 buf_size = LCD_BACKDROP_BYTES;
65 if (backdrop[0] == '-')
67 #if NB_SCREENS > 1
68 if (screen == SCREEN_REMOTE)
70 return NULL; /* remotes don't have a backdrop setting (yet!) */
72 else
73 #endif
75 char settings_bdrop = global_settings.backdrop_file[0];
76 if (settings_bdrop == '\0' || settings_bdrop == '-')
78 return NULL; /* backdrop setting not set */
80 snprintf(filename, sizeof(filename), "%s/%s.bmp",
81 BACKDROP_DIR, global_settings.backdrop_file);
84 else
86 get_image_filename(backdrop, bmpdir, filename, sizeof(filename));
89 for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
91 if (!strcmp(backdrops[i].name, backdrop) && backdrops[i].screen == screen)
93 return backdrops[i].buffer;
95 else if (!bdrop && backdrops[i].buffer == NULL)
97 bdrop = &backdrops[i];
100 if (!bdrop)
101 return NULL; /* too many backdrops loaded */
103 bdrop->buffer = skin_buffer_alloc(buf_size);
104 if (!bdrop->buffer)
105 return NULL;
106 loaded = screens[screen].backdrop_load(filename, bdrop->buffer);
107 bdrop->screen = screen;
108 strlcpy(bdrop->name, backdrop, MAX_FILENAME+1);
110 return loaded ? bdrop->buffer : NULL;
112 #else
114 void skin_backdrop_init(void)
117 #endif