1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "core_alloc.h"
26 #include "string-extra.h"
28 #include "wps_internals.h"
29 #include "skin_engine.h"
31 #if !defined(__PCTOOL__) && \
32 ((LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)))
34 #define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
35 static struct skin_backdrop
{
38 enum screen_type screen
;
41 } backdrops
[NB_BDROPS
];
43 #define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
44 static int handle_being_loaded
;
45 static int current_lcd_backdrop
[NB_SCREENS
];
47 static int buflib_move_callback(int handle
, void* current
, void* new)
50 if (handle
== handle_being_loaded
)
51 return BUFLIB_CB_CANNOT_MOVE
;
52 for (i
=0; i
<NB_BDROPS
; i
++)
54 if (backdrops
[i
].buffer
== current
)
56 backdrops
[i
].buffer
= new;
61 skin_backdrop_show(current_lcd_backdrop
[i
]);
64 static struct buflib_callbacks buflib_ops
= {buflib_move_callback
, NULL
};
65 static bool first_go
= true;
66 void skin_backdrop_init(void)
70 for (i
=0; i
<NB_BDROPS
; i
++)
73 backdrops
[i
].buflib_handle
= -1;
75 skin_backdrop_unload(i
);
76 backdrops
[i
].name
[0] = '\0';
77 backdrops
[i
].buffer
= NULL
;
78 backdrops
[i
].loaded
= false;
83 current_lcd_backdrop
[i
] = -1;
84 handle_being_loaded
= -1;
87 int skin_backdrop_assign(char* backdrop
, char *bmpdir
,
88 enum screen_type screen
)
90 char filename
[MAX_PATH
];
94 if (backdrop
[0] == '-')
98 filename
[2] = '\0'; /* we check this later to see if we actually have an
99 image to load. != '\0' means display the image */
103 get_image_filename(backdrop
, bmpdir
, filename
, sizeof(filename
));
105 for (i
=0; i
<NB_BDROPS
; i
++)
107 if (!backdrops
[i
].name
[0] && free
< 0)
109 if (!strcmp(backdrops
[i
].name
, filename
) && backdrops
[i
].screen
== screen
)
118 strlcpy(backdrops
[free
].name
, filename
,
119 sizeof (backdrops
[free
].name
));
120 backdrops
[free
].buffer
= NULL
;
121 backdrops
[free
].screen
= screen
;
127 bool skin_backdrops_preload(void)
132 for (i
=0; i
<NB_BDROPS
; i
++)
134 if (backdrops
[i
].name
[0] && !backdrops
[i
].buffer
)
137 enum screen_type screen
= backdrops
[i
].screen
;
138 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
139 if (screen
== SCREEN_REMOTE
)
140 buf_size
= REMOTE_LCD_BACKDROP_BYTES
;
143 buf_size
= LCD_BACKDROP_BYTES
;
145 filename
= backdrops
[i
].name
;
146 if (screen
== SCREEN_MAIN
&& global_settings
.backdrop_file
[0] &&
147 global_settings
.backdrop_file
[0] != '-' && filename
[0] == '-')
149 filename
= global_settings
.backdrop_file
;
151 if (*filename
&& *filename
!= '-')
153 backdrops
[i
].buflib_handle
= core_alloc_ex(filename
, buf_size
, &buflib_ops
);
154 if (backdrops
[i
].buflib_handle
> 0)
156 backdrops
[i
].buffer
= core_get_data(backdrops
[i
].buflib_handle
);
157 handle_being_loaded
= backdrops
[i
].buflib_handle
;
158 backdrops
[i
].loaded
=
159 screens
[screen
].backdrop_load(filename
, backdrops
[i
].buffer
);
160 handle_being_loaded
= -1;
161 if (!backdrops
[i
].loaded
)
167 if (backdrops
[i
].name
[0] == '-' && backdrops
[i
].loaded
)
168 backdrops
[i
].name
[2] = '.';
174 void skin_backdrop_show(int backdrop_id
)
178 enum screen_type screen
= backdrops
[backdrop_id
].screen
;
179 if ((backdrops
[backdrop_id
].loaded
== false) ||
180 (backdrops
[backdrop_id
].name
[0] == '-' &&
181 backdrops
[backdrop_id
].name
[2] == '\0'))
183 screens
[screen
].backdrop_show(NULL
);
184 current_lcd_backdrop
[screen
] = -1;
186 else if (backdrops
[backdrop_id
].buffer
)
188 screens
[screen
].backdrop_show(backdrops
[backdrop_id
].buffer
);
189 current_lcd_backdrop
[screen
] = backdrop_id
;
193 void skin_backdrop_unload(int backdrop_id
)
195 if (backdrops
[backdrop_id
].buflib_handle
> 0)
196 core_free(backdrops
[backdrop_id
].buflib_handle
);
197 backdrops
[backdrop_id
].buffer
= NULL
;
198 backdrops
[backdrop_id
].buflib_handle
= -1;
201 void skin_backdrop_load_setting(void)
204 for(i
=0;i
<SKINNABLE_SCREENS_COUNT
*NB_SCREENS
;i
++)
206 if (backdrops
[i
].name
[0] == '-' && backdrops
[i
].screen
== SCREEN_MAIN
)
208 if (global_settings
.backdrop_file
[0] &&
209 global_settings
.backdrop_file
[0] != '-')
211 if (!backdrops
[i
].buffer
)
214 backdrops
[i
].buflib_handle
=
215 core_alloc_ex(global_settings
.backdrop_file
,
216 LCD_BACKDROP_BYTES
, &buflib_ops
);
217 if (backdrops
[i
].buflib_handle
< 0)
219 backdrops
[i
].buffer
= core_get_data(backdrops
[i
].buflib_handle
);
220 handle_being_loaded
= backdrops
[i
].buflib_handle
;
221 loaded
= screens
[SCREEN_MAIN
].backdrop_load(
222 global_settings
.backdrop_file
,
223 backdrops
[i
].buffer
);
224 handle_being_loaded
= -1;
225 backdrops
[i
].name
[2] = loaded
? '.' : '\0';
230 backdrops
[i
].name
[2] = '\0';
233 else if (backdrops
[i
].name
[0] == '-')
235 backdrops
[i
].name
[2] = '\0';
241 #elif defined(__PCTOOL__)
243 int skin_backdrop_assign(char* backdrop
, char *bmpdir
,
244 enum screen_type screen
)
251 void skin_backdrop_unload(int backdrop_id
)
257 void skin_backdrop_init(void)