Themeplaza browser (#140)
* builds at least * meh, multithreading will come later. or never * movement added, and correct grid mode * switching splash/themes when in browser mode * closer to the actual themeplaza menu * bring back downloading from qr * show a download screen when downloading from browser * fix selecting with touchscreen in browser mode * update readme for jansson * fix quitting with start in browser mode * add jump menu for browser mode * rotate is broken, add working touchscreen page changing * allow quitting preview mode with B in browser mode * proper way to have portlibs * add searching * show error when search has no results * always free entries and icon ids
This commit is contained in:
209
source/draw.c
209
source/draw.c
@@ -40,11 +40,14 @@ void init_screens(void)
|
||||
pp2d_set_screen_color(GFX_BOTTOM, COLOR_BACKGROUND);
|
||||
|
||||
pp2d_load_texture_png(TEXTURE_ARROW, "romfs:/arrow.png");
|
||||
pp2d_load_texture_png(TEXTURE_ARROW_SIDE, "romfs:/arrow_side.png");
|
||||
pp2d_load_texture_png(TEXTURE_SHUFFLE, "romfs:/shuffle.png");
|
||||
pp2d_load_texture_png(TEXTURE_INSTALLED, "romfs:/installed.png");
|
||||
pp2d_load_texture_png(TEXTURE_RELOAD, "romfs:/reload.png");
|
||||
pp2d_load_texture_png(TEXTURE_PREVIEW_ICON, "romfs:/preview.png");
|
||||
pp2d_load_texture_png(TEXTURE_DOWNLOAD, "romfs:/download.png");
|
||||
pp2d_load_texture_png(TEXTURE_PREVIEW_ICON, "romfs:/preview.png");
|
||||
pp2d_load_texture_png(TEXTURE_BROWSE, "romfs:/browse.png");
|
||||
pp2d_load_texture_png(TEXTURE_LIST, "romfs:/list.png");
|
||||
pp2d_load_texture_png(TEXTURE_EXIT, "romfs:/exit.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_0, "romfs:/battery0.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_1, "romfs:/battery1.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_2, "romfs:/battery2.png");
|
||||
@@ -169,12 +172,12 @@ bool draw_confirm(const char* conf_msg, Entry_List_s* list)
|
||||
return false;
|
||||
}
|
||||
|
||||
void draw_preview(int preview_offset)
|
||||
void draw_preview(ssize_t previewID, int preview_offset)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP, GFX_LEFT);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, preview_offset, 0, 400, 240);
|
||||
pp2d_draw_texture_part(previewID, 0, 0, preview_offset, 0, 400, 240);
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40 + preview_offset, 240, 320, 240);
|
||||
pp2d_draw_texture_part(previewID, 0, 0, 40 + preview_offset, 240, 320, 240);
|
||||
}
|
||||
|
||||
void draw_install(InstallType type)
|
||||
@@ -191,6 +194,15 @@ void draw_install(InstallType type)
|
||||
case INSTALL_LOADING_ICONS:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Loading icons, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_REMOTE_THEMES:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading theme list, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_REMOTE_SPLASHES:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading splash list, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_REMOTE_PREVIEW:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading preview, please wait...");
|
||||
break;
|
||||
case INSTALL_SINGLE:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a single theme...");
|
||||
break;
|
||||
@@ -257,6 +269,109 @@ static void draw_instructions(Instructions_s instructions)
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_entry_info(Entry_s * entry)
|
||||
{
|
||||
float wrap = 363;
|
||||
|
||||
wchar_t author[0x41] = {0};
|
||||
utf16_to_utf32((u32*)author, entry->author, 0x40);
|
||||
pp2d_draw_text(20, 35, 0.5, 0.5, COLOR_WHITE, "By ");
|
||||
pp2d_draw_wtext_wrap(40, 35, 0.5, 0.5, COLOR_WHITE, wrap, author);
|
||||
|
||||
wchar_t title[0x41] = {0};
|
||||
utf16_to_utf32((u32*)title, entry->name, 0x40);
|
||||
pp2d_draw_wtext_wrap(20, 50, 0.7, 0.7, COLOR_WHITE, wrap, title);
|
||||
|
||||
int width = (int)pp2d_get_wtext_width(title, 0.7, 0.7);
|
||||
int height = (int)pp2d_get_wtext_height(title, 0.7, 0.7);
|
||||
int count = ((width - (width % (int)wrap))/wrap) + 1;
|
||||
|
||||
wchar_t description[0x81] = {0};
|
||||
utf16_to_utf32((u32*)description, entry->desc, 0x80);
|
||||
pp2d_draw_wtext_wrap(20, 50+count*height, 0.5, 0.5, COLOR_WHITE, wrap, description);
|
||||
}
|
||||
|
||||
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions)
|
||||
{
|
||||
draw_base_interface();
|
||||
EntryMode current_mode = list->mode;
|
||||
|
||||
const char* mode_string[MODE_AMOUNT] = {
|
||||
"ThemePlaza Theme mode",
|
||||
"ThemePlaza Splash mode",
|
||||
};
|
||||
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, mode_string[current_mode]);
|
||||
|
||||
draw_instructions(instructions);
|
||||
|
||||
int selected_entry = list->selected_entry;
|
||||
Entry_s * current_entry = &list->entries[selected_entry];
|
||||
draw_entry_info(current_entry);
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
pp2d_draw_text(7, 3, 0.6, 0.6, COLOR_WHITE, "Search...");
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_LIST, 320-96, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_EXIT, 320-72, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_PREVIEW_ICON, 320-48, 0, COLOR_WHITE);
|
||||
pp2d_draw_textf(320-24+2.5, -3, 1, 1, COLOR_WHITE, "%c", mode_string[!list->mode][11]);
|
||||
|
||||
pp2d_draw_texture(TEXTURE_ARROW_SIDE, 3, 114);
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW_SIDE, 308, 114, HORIZONTAL);
|
||||
|
||||
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
||||
{
|
||||
if(i >= list->entries_count) break;
|
||||
|
||||
current_entry = &list->entries[i];
|
||||
|
||||
wchar_t name[0x41] = {0};
|
||||
utf16_to_utf32((u32*)name, current_entry->name, 0x40);
|
||||
|
||||
int vertical_offset = 0;
|
||||
int horizontal_offset = i - list->scroll;
|
||||
vertical_offset = horizontal_offset/list->entries_per_screen_h;
|
||||
horizontal_offset %= list->entries_per_screen_h;
|
||||
|
||||
horizontal_offset *= list->entry_size;
|
||||
vertical_offset *= list->entry_size;
|
||||
vertical_offset += 24;
|
||||
horizontal_offset += 16;
|
||||
|
||||
if(!current_entry->placeholder_color)
|
||||
{
|
||||
ssize_t id = list->icons_ids[i];
|
||||
pp2d_draw_texture(id, horizontal_offset, vertical_offset);
|
||||
}
|
||||
else
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, list->entry_size, list->entry_size, current_entry->placeholder_color);
|
||||
|
||||
if(i == selected_entry)
|
||||
{
|
||||
unsigned int border_width = 3;
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, border_width, list->entry_size, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, list->entry_size, border_width, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset+list->entry_size-border_width, list->entry_size, border_width, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(horizontal_offset+list->entry_size-border_width, vertical_offset, border_width, list->entry_size, COLOR_CURSOR);
|
||||
}
|
||||
}
|
||||
|
||||
char entries_count_str[0x20] = {0};
|
||||
sprintf(entries_count_str, "/%" JSON_INTEGER_FORMAT, list->tp_page_count);
|
||||
float x = 316;
|
||||
x -= pp2d_get_text_width(entries_count_str, 0.6, 0.6);
|
||||
pp2d_draw_text(x, 219, 0.6, 0.6, COLOR_WHITE, entries_count_str);
|
||||
|
||||
char selected_entry_str[0x20] = {0};
|
||||
sprintf(selected_entry_str, "%" JSON_INTEGER_FORMAT, list->tp_current_page);
|
||||
x -= pp2d_get_text_width(selected_entry_str, 0.6, 0.6);
|
||||
pp2d_draw_text(x, 219, 0.6, 0.6, COLOR_WHITE, selected_entry_str);
|
||||
|
||||
pp2d_draw_text(176, 219, 0.6, 0.6, COLOR_WHITE, "Page:");
|
||||
}
|
||||
|
||||
void draw_interface(Entry_List_s* list, Instructions_s instructions)
|
||||
{
|
||||
draw_base_interface();
|
||||
@@ -287,26 +402,22 @@ void draw_interface(Entry_List_s* list, Instructions_s instructions)
|
||||
pp2d_texture_blend(COLOR_YELLOW);
|
||||
pp2d_texture_scale(1.25, 1.4);
|
||||
pp2d_texture_draw();
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_EXIT, 320-120, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_DOWNLOAD, 320-96, 0, COLOR_WHITE);
|
||||
for(int i = 0; i < MODE_AMOUNT; i++)
|
||||
pp2d_draw_textf(320-(24*(i+1))+2.5, -3, 1, 1, COLOR_WHITE, "%c", mode_string[i][0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
draw_instructions(instructions);
|
||||
|
||||
int selected_entry = list->selected_entry;
|
||||
Entry_s current_entry = list->entries[selected_entry];
|
||||
|
||||
wchar_t title[0x41] = {0};
|
||||
utf16_to_utf32((u32*)title, current_entry.name, 0x40);
|
||||
pp2d_draw_wtext_wrap(20, 30, 0.7, 0.7, COLOR_WHITE, 380, title);
|
||||
|
||||
wchar_t author[0x41] = {0};
|
||||
utf16_to_utf32((u32*)author, current_entry.author, 0x40);
|
||||
pp2d_draw_text(20, 50, 0.5, 0.5, COLOR_WHITE, "By: ");
|
||||
pp2d_draw_wtext_wrap(44, 50, 0.5, 0.5, COLOR_WHITE, 380, author);
|
||||
|
||||
wchar_t description[0x81] = {0};
|
||||
utf16_to_utf32((u32*)description, current_entry.desc, 0x80);
|
||||
pp2d_draw_wtext_wrap(20, 65, 0.5, 0.5, COLOR_WHITE, 363, description);
|
||||
Entry_s * current_entry = &list->entries[selected_entry];
|
||||
draw_entry_info(current_entry);
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
@@ -314,59 +425,65 @@ void draw_interface(Entry_List_s* list, Instructions_s instructions)
|
||||
{
|
||||
case MODE_THEMES:
|
||||
pp2d_draw_textf(7, 3, 0.6, 0.6, list->shuffle_count <= 10 && list->shuffle_count >= 2 ? COLOR_WHITE : COLOR_RED, "Shuffle: %i/10", list->shuffle_count);
|
||||
pp2d_draw_texture_blend(TEXTURE_SHUFFLE, 320-120, 0, COLOR_WHITE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_RELOAD, 320-96, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_PREVIEW_ICON, 320-72, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_DOWNLOAD, 320-48, 0, COLOR_WHITE);
|
||||
pp2d_draw_textf(320-24+2.5, -3, 1, 1, COLOR_WHITE, "%c", *mode_string[!list->mode]);
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_DOWNLOAD, 320-120, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_BROWSE, 320-96, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_EXIT, 320-72, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_PREVIEW_ICON, 320-48, 0, COLOR_WHITE);
|
||||
pp2d_draw_textf(320-24+2.5, -3, 1, 1, COLOR_WHITE, "%c", mode_string[!list->mode][0]);
|
||||
|
||||
// Show arrows if there are themes out of bounds
|
||||
//----------------------------------------------------------------
|
||||
if(list->scroll > 0)
|
||||
pp2d_draw_texture(TEXTURE_ARROW, 155, 6);
|
||||
if(list->scroll + ENTRIES_PER_SCREEN < list->entries_count)
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW, 155, 224, VERTICAL);
|
||||
pp2d_draw_texture(TEXTURE_ARROW, 152, 4);
|
||||
if(list->scroll + list->entries_loaded < list->entries_count)
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW, 152, 220, VERTICAL);
|
||||
|
||||
for(int i = list->scroll; i < (ENTRIES_PER_SCREEN + list->scroll); i++)
|
||||
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
||||
{
|
||||
if(i >= list->entries_count) break;
|
||||
|
||||
current_entry = list->entries[i];
|
||||
current_entry = &list->entries[i];
|
||||
|
||||
wchar_t name[0x41] = {0};
|
||||
utf16_to_utf32((u32*)name, current_entry.name, 0x40);
|
||||
utf16_to_utf32((u32*)name, current_entry->name, 0x40);
|
||||
|
||||
int vertical_offset = i - list->scroll;
|
||||
int horizontal_offset = 0;
|
||||
horizontal_offset *= list->entry_size;
|
||||
vertical_offset *= list->entry_size;
|
||||
vertical_offset += 24;
|
||||
|
||||
int vertical_offset = 48 * (i - list->scroll);
|
||||
u32 font_color = COLOR_WHITE;
|
||||
|
||||
if(i == list->selected_entry)
|
||||
if(i == selected_entry)
|
||||
{
|
||||
font_color = COLOR_BLACK;
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 320, 48, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(0, vertical_offset, 320, list->entry_size, COLOR_CURSOR);
|
||||
}
|
||||
pp2d_draw_wtext(54, 40 + vertical_offset, 0.55, 0.55, font_color, name);
|
||||
if(!current_entry.placeholder_color)
|
||||
|
||||
pp2d_draw_wtext(list->entry_size+6, vertical_offset + 16, 0.55, 0.55, font_color, name);
|
||||
|
||||
if(current_entry->in_shuffle)
|
||||
pp2d_draw_texture_blend(TEXTURE_SHUFFLE, 320-24-4, vertical_offset, font_color);
|
||||
if(current_entry->installed)
|
||||
pp2d_draw_texture_blend(TEXTURE_INSTALLED, 320-24-4, vertical_offset + 22, font_color);
|
||||
|
||||
if(!current_entry->placeholder_color)
|
||||
{
|
||||
ssize_t id = 0;
|
||||
if(list->entries_count > ICONS_OFFSET_AMOUNT*ENTRIES_PER_SCREEN)
|
||||
id = list->icons_ids[ICONS_VISIBLE][i - list->scroll];
|
||||
if(list->entries_count > list->entries_loaded*ICONS_OFFSET_AMOUNT)
|
||||
id = list->icons_ids[ICONS_VISIBLE*list->entries_loaded + (i - list->scroll)];
|
||||
else
|
||||
id = ((size_t *)list->icons_ids)[i];
|
||||
pp2d_draw_texture(id, 0, 24 + vertical_offset);
|
||||
id = list->icons_ids[i];
|
||||
pp2d_draw_texture(id, horizontal_offset, vertical_offset);
|
||||
}
|
||||
else
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 48, 48, current_entry.placeholder_color);
|
||||
|
||||
if(current_entry.in_shuffle)
|
||||
pp2d_draw_texture_blend(TEXTURE_SHUFFLE, 320-24-4, 24 + vertical_offset, font_color);
|
||||
if(current_entry.installed)
|
||||
pp2d_draw_texture_blend(TEXTURE_INSTALLED, 320-24-4, 24 + 22 + vertical_offset, font_color);
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, list->entry_size, list->entry_size, current_entry->placeholder_color);
|
||||
}
|
||||
|
||||
char entries_count_str[0x20] = {0};
|
||||
|
||||
Reference in New Issue
Block a user