2010-02-16 05:24:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-02-27 18:07:38 +00:00
|
|
|
* $Id$
|
2010-02-16 05:24:27 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jonathan Gordon
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-09-08 11:24:29 +00:00
|
|
|
#include "core_alloc.h"
|
2010-05-06 21:04:40 +00:00
|
|
|
#include "string-extra.h"
|
2010-02-16 05:24:27 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "wps_internals.h"
|
|
|
|
#include "skin_engine.h"
|
|
|
|
|
|
|
|
#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
|
|
|
|
|
2010-09-14 11:56:50 +00:00
|
|
|
#define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
|
2010-02-16 05:24:27 +00:00
|
|
|
static struct skin_backdrop {
|
2010-06-03 13:32:12 +00:00
|
|
|
char name[MAX_PATH];
|
2010-02-16 05:24:27 +00:00
|
|
|
char *buffer;
|
|
|
|
enum screen_type screen;
|
2010-10-18 07:38:36 +00:00
|
|
|
bool loaded;
|
2011-09-08 11:24:29 +00:00
|
|
|
int buflib_handle;
|
2010-09-14 11:56:50 +00:00
|
|
|
} backdrops[NB_BDROPS];
|
|
|
|
|
|
|
|
#define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
|
2011-09-08 11:24:29 +00:00
|
|
|
int handle_being_loaded;
|
|
|
|
int current_lcd_backdrop[NB_SCREENS];
|
2010-02-16 05:24:27 +00:00
|
|
|
|
2011-09-08 11:24:29 +00:00
|
|
|
int buflib_move_callback(int handle, void* current, void* new)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (handle == handle_being_loaded)
|
|
|
|
return BUFLIB_CB_CANNOT_MOVE;
|
|
|
|
for (i=0; i<NB_BDROPS; i++)
|
|
|
|
{
|
|
|
|
if (backdrops[i].buffer == current)
|
|
|
|
{
|
|
|
|
backdrops[i].buffer = new;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
skin_backdrop_show(current_lcd_backdrop[i]);
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL};
|
|
|
|
static bool first_go = true;
|
2010-02-16 05:24:27 +00:00
|
|
|
void skin_backdrop_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
2011-09-08 11:24:29 +00:00
|
|
|
|
2010-09-14 11:56:50 +00:00
|
|
|
for (i=0; i<NB_BDROPS; i++)
|
2010-02-16 05:24:27 +00:00
|
|
|
{
|
2011-09-08 11:24:29 +00:00
|
|
|
if (first_go)
|
|
|
|
backdrops[i].buflib_handle = -1;
|
|
|
|
else
|
|
|
|
skin_backdrop_unload(i);
|
2010-02-16 05:24:27 +00:00
|
|
|
backdrops[i].name[0] = '\0';
|
|
|
|
backdrops[i].buffer = NULL;
|
2010-10-18 07:38:36 +00:00
|
|
|
backdrops[i].loaded = false;
|
2011-09-08 11:24:29 +00:00
|
|
|
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
2011-09-08 11:24:29 +00:00
|
|
|
first_go = false;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
current_lcd_backdrop[i] = -1;
|
|
|
|
handle_being_loaded = -1;
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 11:56:50 +00:00
|
|
|
int skin_backdrop_assign(char* backdrop, char *bmpdir,
|
|
|
|
enum screen_type screen)
|
2010-02-16 05:24:27 +00:00
|
|
|
{
|
|
|
|
char filename[MAX_PATH];
|
2010-09-14 11:56:50 +00:00
|
|
|
int i, free = -1;
|
|
|
|
if (!backdrop)
|
|
|
|
return -1;
|
2010-02-16 05:24:27 +00:00
|
|
|
if (backdrop[0] == '-')
|
|
|
|
{
|
2010-09-14 11:56:50 +00:00
|
|
|
filename[0] = '-';
|
|
|
|
filename[1] = '\0';
|
|
|
|
filename[2] = '\0'; /* we check this later to see if we actually have an
|
|
|
|
image to load. != '\0' means display the image */
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-06 22:26:31 +00:00
|
|
|
get_image_filename(backdrop, bmpdir, filename, sizeof(filename));
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
2010-09-14 11:56:50 +00:00
|
|
|
for (i=0; i<NB_BDROPS; i++)
|
2010-02-16 05:24:27 +00:00
|
|
|
{
|
2010-09-14 11:56:50 +00:00
|
|
|
if (!backdrops[i].name[0] && free < 0)
|
|
|
|
free = i;
|
2010-06-03 13:32:12 +00:00
|
|
|
if (!strcmp(backdrops[i].name, filename) && backdrops[i].screen == screen)
|
2010-02-16 05:24:27 +00:00
|
|
|
{
|
2010-09-14 11:56:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i < NB_BDROPS)
|
|
|
|
return i;
|
|
|
|
else if (free >= 0)
|
|
|
|
{
|
|
|
|
strlcpy(backdrops[free].name, filename,
|
|
|
|
sizeof (backdrops[free].name));
|
|
|
|
backdrops[free].buffer = NULL;
|
|
|
|
backdrops[free].screen = screen;
|
|
|
|
return free;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool skin_backdrops_preload(void)
|
|
|
|
{
|
|
|
|
bool retval = true;
|
|
|
|
int i;
|
|
|
|
char *filename;
|
|
|
|
for (i=0; i<NB_BDROPS; i++)
|
|
|
|
{
|
|
|
|
if (backdrops[i].name[0] && !backdrops[i].buffer)
|
|
|
|
{
|
|
|
|
size_t buf_size;
|
|
|
|
enum screen_type screen = backdrops[i].screen;
|
|
|
|
#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
|
|
|
|
if (screen == SCREEN_REMOTE)
|
|
|
|
buf_size = REMOTE_LCD_BACKDROP_BYTES;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
buf_size = LCD_BACKDROP_BYTES;
|
|
|
|
|
|
|
|
filename = backdrops[i].name;
|
|
|
|
if (screen == SCREEN_MAIN && global_settings.backdrop_file[0] &&
|
|
|
|
global_settings.backdrop_file[0] != '-' && filename[0] == '-')
|
|
|
|
{
|
2011-04-10 13:25:47 +00:00
|
|
|
filename = global_settings.backdrop_file;
|
2010-09-14 11:56:50 +00:00
|
|
|
}
|
|
|
|
if (*filename && *filename != '-')
|
|
|
|
{
|
2011-09-08 11:24:29 +00:00
|
|
|
backdrops[i].buflib_handle = core_alloc_ex(filename, buf_size, &buflib_ops);
|
|
|
|
if (backdrops[i].buflib_handle > 0)
|
|
|
|
{
|
|
|
|
backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
|
|
|
|
handle_being_loaded = backdrops[i].buflib_handle;
|
|
|
|
backdrops[i].loaded =
|
|
|
|
screens[screen].backdrop_load(filename, backdrops[i].buffer);
|
|
|
|
handle_being_loaded = -1;
|
|
|
|
if (!backdrops[i].loaded)
|
|
|
|
retval = false;
|
|
|
|
}
|
|
|
|
else
|
2010-09-14 11:56:50 +00:00
|
|
|
retval = false;
|
|
|
|
}
|
2010-10-18 07:38:36 +00:00
|
|
|
if (backdrops[i].name[0] == '-' && backdrops[i].loaded)
|
2010-09-14 11:56:50 +00:00
|
|
|
backdrops[i].name[2] = '.';
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
2010-09-14 11:56:50 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void skin_backdrop_show(int backdrop_id)
|
|
|
|
{
|
|
|
|
if (backdrop_id < 0)
|
|
|
|
return;
|
|
|
|
enum screen_type screen = backdrops[backdrop_id].screen;
|
2010-10-18 07:38:36 +00:00
|
|
|
if ((backdrops[backdrop_id].loaded == false) ||
|
|
|
|
(backdrops[backdrop_id].name[0] == '-' &&
|
|
|
|
backdrops[backdrop_id].name[2] == '\0'))
|
|
|
|
{
|
2010-09-19 11:49:33 +00:00
|
|
|
screens[screen].backdrop_show(NULL);
|
2010-10-18 07:38:36 +00:00
|
|
|
}
|
2010-09-19 11:49:33 +00:00
|
|
|
else if (backdrops[backdrop_id].buffer)
|
2010-09-14 11:56:50 +00:00
|
|
|
screens[screen].backdrop_show(backdrops[backdrop_id].buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void skin_backdrop_unload(int backdrop_id)
|
|
|
|
{
|
2011-09-08 11:24:29 +00:00
|
|
|
if (backdrops[backdrop_id].buflib_handle > 0)
|
|
|
|
core_free(backdrops[backdrop_id].buflib_handle);
|
2010-09-14 11:56:50 +00:00
|
|
|
backdrops[backdrop_id].buffer = NULL;
|
2011-09-08 11:24:29 +00:00
|
|
|
backdrops[backdrop_id].buflib_handle = -1;
|
2010-09-14 11:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void skin_backdrop_load_setting(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++)
|
|
|
|
{
|
|
|
|
if (backdrops[i].name[0] == '-' && backdrops[i].screen == SCREEN_MAIN)
|
2010-02-16 05:24:27 +00:00
|
|
|
{
|
2010-09-14 11:56:50 +00:00
|
|
|
if (global_settings.backdrop_file[0] &&
|
|
|
|
global_settings.backdrop_file[0] != '-')
|
|
|
|
{
|
|
|
|
if (!backdrops[i].buffer)
|
2011-09-08 11:24:29 +00:00
|
|
|
{
|
|
|
|
bool loaded;
|
|
|
|
backdrops[i].buflib_handle =
|
|
|
|
core_alloc_ex(global_settings.backdrop_file,
|
|
|
|
LCD_BACKDROP_BYTES, &buflib_ops);
|
|
|
|
if (backdrops[i].buflib_handle < 0)
|
|
|
|
return;
|
|
|
|
backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
|
|
|
|
handle_being_loaded = backdrops[i].buflib_handle;
|
|
|
|
loaded = screens[SCREEN_MAIN].backdrop_load(
|
|
|
|
global_settings.backdrop_file,
|
|
|
|
backdrops[i].buffer);
|
|
|
|
handle_being_loaded = -1;
|
|
|
|
backdrops[i].name[2] = loaded ? '.' : '\0';
|
|
|
|
}
|
2010-09-14 11:56:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
backdrops[i].name[2] = '\0';
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
2010-09-19 11:49:33 +00:00
|
|
|
#if NB_SCREENS > 1
|
|
|
|
else if (backdrops[i].name[0] == '-')
|
|
|
|
{
|
|
|
|
backdrops[i].name[2] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-16 05:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-14 11:56:50 +00:00
|
|
|
|
2010-02-16 05:24:27 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
void skin_backdrop_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|