Use API call instead of accessing a global variable for receiving the current thread.
[kugel-rb.git] / apps / gui / skin_engine / skin_backdrops.c
blobfd786a7882506a0703887c56f7643804696eeaf4
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 <string.h>
25 #include <stdlib.h>
27 #include "settings.h"
28 #include "skin_buffer.h"
29 #include "wps_internals.h"
30 #include "skin_engine.h"
32 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
34 static struct skin_backdrop {
35 char name[MAX_FILENAME+1];
36 char *buffer;
37 enum screen_type screen;
38 } backdrops[SKINNABLE_SCREENS_COUNT*NB_SCREENS];
40 void skin_backdrop_init(void)
42 int i;
43 for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
45 backdrops[i].name[0] = '\0';
46 backdrops[i].buffer = NULL;
50 /* load a backdrop into the skin buffer.
51 * reuse buffers if the file is already loaded */
52 char* skin_backdrop_load(char* backdrop, char *bmpdir, enum screen_type screen)
54 int i;
55 struct skin_backdrop *bdrop = NULL;
56 char filename[MAX_PATH];
57 size_t buf_size;
58 bool loaded = false;
59 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
60 if (screen == SCREEN_REMOTE)
61 buf_size = REMOTE_LCD_BACKDROP_BYTES;
62 else
63 #endif
64 buf_size = LCD_BACKDROP_BYTES;
66 if (backdrop[0] == '-')
68 #if NB_SCREENS > 1
69 if (screen == SCREEN_REMOTE)
71 return NULL; /* remotes don't have a backdrop setting (yet!) */
73 else
74 #endif
76 char settings_bdrop = global_settings.backdrop_file[0];
77 if (settings_bdrop == '\0' || settings_bdrop == '-')
79 return NULL; /* backdrop setting not set */
81 snprintf(filename, sizeof(filename), "%s/%s.bmp",
82 BACKDROP_DIR, global_settings.backdrop_file);
85 else
87 get_image_filename(backdrop, bmpdir, filename, sizeof(filename));
90 for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
92 if (!strcmp(backdrops[i].name, backdrop) && backdrops[i].screen == screen)
94 return backdrops[i].buffer;
96 else if (!bdrop && backdrops[i].buffer == NULL)
98 bdrop = &backdrops[i];
101 if (!bdrop)
102 return NULL; /* too many backdrops loaded */
104 bdrop->buffer = skin_buffer_alloc(buf_size);
105 if (!bdrop->buffer)
106 return NULL;
107 loaded = screens[screen].backdrop_load(filename, bdrop->buffer);
108 bdrop->screen = screen;
109 strlcpy(bdrop->name, backdrop, MAX_FILENAME+1);
111 return loaded ? bdrop->buffer : NULL;
113 #else
115 void skin_backdrop_init(void)
118 #endif