Splash previews
This commit is contained in:
@@ -47,4 +47,6 @@ int splash_count;
|
|||||||
Result get_splashes(Splash_s** splashes_list, int *splash_count);
|
Result get_splashes(Splash_s** splashes_list, int *splash_count);
|
||||||
void splash_install(Splash_s splash_to_install);
|
void splash_install(Splash_s splash_to_install);
|
||||||
void splash_delete();
|
void splash_delete();
|
||||||
|
void load_splash_preview(Splash_s *splash);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -121,6 +121,8 @@ void take_picture(void)
|
|||||||
}
|
}
|
||||||
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
||||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
||||||
|
pp2d_draw_rectangle(0, 216, 400, 24, RGBA8(55, 122, 168, 255));
|
||||||
|
pp2d_draw_text_center(GFX_TOP, 220, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Hold \uE005 To Quit");
|
||||||
pp2d_end_draw();
|
pp2d_end_draw();
|
||||||
free(rgba8_buf);
|
free(rgba8_buf);
|
||||||
pp2d_free_texture(TEXTURE_QR);
|
pp2d_free_texture(TEXTURE_QR);
|
||||||
|
|||||||
@@ -287,12 +287,13 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
|
|||||||
pp2d_end_draw();
|
pp2d_end_draw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Splash_s current_splash = splashes_list[selected_splash];
|
Splash_s current_splash = splashes_list[selected_splash];
|
||||||
|
|
||||||
if (preview_mode)
|
if (preview_mode)
|
||||||
{
|
{
|
||||||
// TODO: Splash Previews
|
pp2d_begin_draw(GFX_TOP);
|
||||||
|
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 0, 0, 400, 240);
|
||||||
|
pp2d_draw_on(GFX_BOTTOM);
|
||||||
|
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40, 240, 320, 240);
|
||||||
} else {
|
} else {
|
||||||
draw_base_interface();
|
draw_base_interface();
|
||||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");
|
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
|||||||
|
|
||||||
u64 size;
|
u64 size;
|
||||||
FSFILE_GetSize(file, &size);
|
FSFILE_GetSize(file, &size);
|
||||||
*buf = malloc(size);
|
*buf = calloc(1, size);
|
||||||
FSFILE_Read(file, NULL, 0, *buf, size);
|
FSFILE_Read(file, NULL, 0, *buf, size);
|
||||||
FSFILE_Close(file);
|
FSFILE_Close(file);
|
||||||
return size;
|
return size;
|
||||||
@@ -139,7 +139,7 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
|||||||
unz_file_info *file_info = malloc(sizeof(unz_file_info));
|
unz_file_info *file_info = malloc(sizeof(unz_file_info));
|
||||||
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
|
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
|
||||||
file_size = file_info->uncompressed_size;
|
file_size = file_info->uncompressed_size;
|
||||||
*buf = malloc(file_size);
|
*buf = calloc(1, file_size);
|
||||||
unzOpenCurrentFile(zip_handle);
|
unzOpenCurrentFile(zip_handle);
|
||||||
unzReadCurrentFile(zip_handle, *buf, file_size);
|
unzReadCurrentFile(zip_handle, *buf, file_size);
|
||||||
unzCloseCurrentFile(zip_handle);
|
unzCloseCurrentFile(zip_handle);
|
||||||
|
|||||||
@@ -159,10 +159,16 @@ int main(void)
|
|||||||
{
|
{
|
||||||
if (!preview_mode)
|
if (!preview_mode)
|
||||||
{
|
{
|
||||||
if (!current_theme->has_preview)
|
if (!splash_mode)
|
||||||
load_theme_preview(current_theme);
|
{
|
||||||
|
if (!current_theme->has_preview)
|
||||||
|
load_theme_preview(current_theme);
|
||||||
|
|
||||||
preview_mode = current_theme->has_preview;
|
preview_mode = current_theme->has_preview;
|
||||||
|
} else {
|
||||||
|
load_splash_preview(current_splash);
|
||||||
|
preview_mode = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
preview_mode = false;
|
preview_mode = false;
|
||||||
|
|||||||
@@ -29,6 +29,61 @@
|
|||||||
#include "themes.h"
|
#include "themes.h"
|
||||||
#include "pp2d/pp2d/pp2d.h"
|
#include "pp2d/pp2d/pp2d.h"
|
||||||
|
|
||||||
|
void load_splash_preview(Splash_s *splash)
|
||||||
|
{
|
||||||
|
//free the previously loaded preview. wont do anything if there wasnt one
|
||||||
|
pp2d_free_texture(TEXTURE_PREVIEW);
|
||||||
|
|
||||||
|
char *preview_buffer = NULL;
|
||||||
|
u64 size = 0;
|
||||||
|
if (!(splash->is_zip))
|
||||||
|
{
|
||||||
|
u16 path_to_preview[0x106] = {0};
|
||||||
|
strucat(path_to_preview, splash->path);
|
||||||
|
struacat(path_to_preview, "/preview.png");
|
||||||
|
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_preview), ArchiveSD, &preview_buffer);
|
||||||
|
} else {
|
||||||
|
size = zip_file_to_buf("preview.png", splash->path, &preview_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!size)
|
||||||
|
{
|
||||||
|
free(preview_buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 * image = NULL;
|
||||||
|
unsigned int width = 0, height = 0;
|
||||||
|
|
||||||
|
int result = lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size);
|
||||||
|
if (result == 0) // no error
|
||||||
|
{
|
||||||
|
for (u32 i = 0; i < width; i++)
|
||||||
|
{
|
||||||
|
for (u32 j = 0; j < height; j++)
|
||||||
|
{
|
||||||
|
u32 p = (i + j*width) * 4;
|
||||||
|
|
||||||
|
u8 r = *(u8*)(image + p);
|
||||||
|
u8 g = *(u8*)(image + p + 1);
|
||||||
|
u8 b = *(u8*)(image + p + 2);
|
||||||
|
u8 a = *(u8*)(image + p + 3);
|
||||||
|
|
||||||
|
*(image + p) = a;
|
||||||
|
*(image + p + 1) = b;
|
||||||
|
*(image + p + 2) = g;
|
||||||
|
*(image + p + 3) = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(image);
|
||||||
|
free(preview_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
|
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
|
||||||
{
|
{
|
||||||
char *info_buffer = NULL;
|
char *info_buffer = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user