Refactor menu driver's 'load wallpaper' function

This commit is contained in:
twinaphex 2015-02-23 23:32:59 +01:00
parent 3536ac86e4
commit 6ce7e5b571
4 changed files with 51 additions and 42 deletions

View File

@ -512,9 +512,8 @@ static void glui_context_destroy(void)
glDeleteTextures(1, &glui->textures.bg.id);
}
static bool glui_load_wallpaper(const char *path)
static bool glui_load_wallpaper(void *data)
{
struct texture_image ti = {0};
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_resolve();
@ -525,29 +524,19 @@ static bool glui_load_wallpaper(const char *path)
if (!glui)
return false;
if (!path)
return false;
if (glui->textures.bg.id)
glDeleteTextures(1, &glui->textures.bg.id);
if (! path_file_exists(path))
return false;
texture_image_load(&ti, path);
strlcpy(glui->textures.bg.path, path, sizeof(glui->textures.bg.path));
glui->textures.bg.id = menu_texture_load(&ti,
glui->textures.bg.id = menu_texture_load(data,
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
texture_image_free(&ti);
return true;
}
static void glui_context_reset(void)
{
const char *path = NULL;
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_resolve();
@ -570,8 +559,19 @@ static void glui_context_reset(void)
glui->textures.bg.path, "bg.png",
sizeof(glui->textures.bg.path));
if (path_file_exists(glui->textures.bg.path))
glui_load_wallpaper(glui->textures.bg.path);
path = glui->textures.bg.path;
if (path_file_exists(path))
{
struct texture_image ti = {0};
texture_image_load(&ti, path);
strlcpy(glui->textures.bg.path, path, sizeof(glui->textures.bg.path));
glui_load_wallpaper(&ti);
texture_image_free(&ti);
}
}
static void glui_navigation_clear(bool pending_push)

View File

@ -1391,9 +1391,8 @@ static bool xmb_font_init_first(const gl_font_renderer_t **font_driver,
font_path, xmb_font_size);
}
static bool xmb_load_wallpaper(const char *path)
static bool xmb_load_wallpaper(void *data)
{
struct texture_image ti = {0};
xmb_handle_t *xmb = NULL;
menu_handle_t *menu = menu_driver_resolve();
@ -1404,23 +1403,15 @@ static bool xmb_load_wallpaper(const char *path)
if (!xmb)
return false;
if (!path)
if (!data)
return false;
if (xmb->textures.bg.id)
glDeleteTextures(1, &xmb->textures.bg.id);
if (! path_file_exists(path))
return false;
texture_image_load(&ti, path);
strlcpy(xmb->textures.bg.path, path, sizeof(xmb->textures.bg.path));
xmb->textures.bg.id = menu_texture_load(&ti,
xmb->textures.bg.id = menu_texture_load(data,
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
texture_image_free(&ti);
return true;
}
@ -1467,12 +1458,6 @@ static void xmb_context_reset(void)
xmb_font_init_first(&gl->font_driver, &xmb->font.buf, gl, fontpath, xmb->font.size);
if (*g_settings.menu.wallpaper)
strlcpy(xmb->textures.bg.path, g_settings.menu.wallpaper,
sizeof(xmb->textures.bg.path));
else
fill_pathname_join(xmb->textures.bg.path, iconpath,
"bg.png", sizeof(xmb->textures.bg.path));
fill_pathname_join(xmb->textures.list[XMB_TEXTURE_SETTINGS].path, iconpath,
"settings.png", sizeof(xmb->textures.list[XMB_TEXTURE_SETTINGS].path));
fill_pathname_join(xmb->textures.list[XMB_TEXTURE_SETTING].path, iconpath,
@ -1536,7 +1521,26 @@ static void xmb_context_reset(void)
texture_image_free(&ti);
}
xmb_load_wallpaper(xmb->textures.bg.path);
{
char path[PATH_MAX_LENGTH];
struct texture_image ti = {0};
fill_pathname_join(path, iconpath,
"bg.png", sizeof(path));
if (*g_settings.menu.wallpaper)
strlcpy(path, g_settings.menu.wallpaper,
sizeof(path));
if ( path_file_exists(path))
{
texture_image_load(&ti, path);
xmb_load_wallpaper(&ti);
texture_image_free(&ti);
}
}
xmb->settings_node.icon = xmb->textures.list[XMB_TEXTURE_SETTINGS].id;
xmb->settings_node.alpha = xmb->categories.active.alpha;

View File

@ -228,7 +228,7 @@ typedef struct menu_ctx_driver
void (*list_cache)(bool, unsigned);
void (*list_set_selection)(file_list_t *list);
int (*entry_iterate)(unsigned);
bool (*load_background)(const char * path);
bool (*load_background)(void *data);
const char *ident;
} menu_ctx_driver_t;

View File

@ -607,15 +607,20 @@ static int action_ok_menu_wallpaper_load(const char *path,
fill_pathname_join(wallpaper_path, menu_path, path, sizeof(wallpaper_path));
if (!path_file_exists(wallpaper_path))
goto end;
if (path_file_exists(wallpaper_path))
{
struct texture_image ti = {0};
strlcpy(g_settings.menu.wallpaper, wallpaper_path, sizeof(g_settings.menu.wallpaper));
strlcpy(g_settings.menu.wallpaper, wallpaper_path, sizeof(g_settings.menu.wallpaper));
if (driver.menu_ctx && driver.menu_ctx->load_background)
driver.menu_ctx->load_background(wallpaper_path);
texture_image_load(&ti, wallpaper_path);
if (driver.menu_ctx && driver.menu_ctx->load_background)
driver.menu_ctx->load_background(&ti);
texture_image_free(&ti);
}
end:
menu_list_pop_stack_by_needle(menu->menu_list, setting->name);
return 0;