diff --git a/common/menu-entry.c b/common/menu-entry.c index 1b4eec9..a546cb2 100644 --- a/common/menu-entry.c +++ b/common/menu-entry.c @@ -17,6 +17,11 @@ void menuEntryFree(menuEntry_s* me) { me->icon_gfx = NULL; } + if (me->icon_gfx_small) { + free(me->icon_gfx_small); + me->icon_gfx_small = NULL; + } + if (me->nacp) { free(me->nacp); me->nacp = NULL; @@ -301,6 +306,78 @@ void menuEntryParseIcon(menuEntry_s* me) { memcpy(me->icon_gfx, imageptr, imagesize); njDone(); + + me->icon_gfx_small = downscaleIcon(me->icon_gfx); +} + +uint8_t *downscaleIcon(const uint8_t *image) { + uint8_t *out = (uint8_t*)malloc(140*140*3); + + if (out == NULL) { + return NULL; + } + + int tmpx, tmpy; + int pos; + float sourceX, sourceY; + int destWidth = 140, destHeight = 140; + float xScale = 256.0 / (float)destWidth; + float yScale = 256.0 / (float)destHeight; + int pixelX, pixelY; + uint8_t r1, r2, r3, r4; + uint8_t g1, g2, g3, g4; + uint8_t b1, b2, b3, b4; + float fx, fy, fx1, fy1; + int w1, w2, w3, w4; + + for (tmpx=0; tmpx> 8); + out[pos+1] = (uint8_t)((g1 * w1 + g2 * w2 + g3 * w3 + g4 * w4) >> 8); + out[pos+2] = (uint8_t)((b1 * w1 + b2 * w2 + b3 * w3 + b4 * w4) >> 8); + } + } + + return out; } void menuEntryParseNacp(menuEntry_s* me) { diff --git a/common/menu.c b/common/menu.c index c384efc..0d6b5eb 100644 --- a/common/menu.c +++ b/common/menu.c @@ -26,21 +26,23 @@ static void drawImage(int x, int y, int width, int height, const uint8_t *image) } } +uint8_t *folder_icon_small; +uint8_t *switchicon_questionmark_small; + static void drawEntry(menuEntry_s* me, int n, int is_active) { int x, y; - int start_y = 96 + 108 - 32;//*(n % 2); - int end_y = start_y + 288; - int start_x = 64 + (256+16)*n;//(n / 2); - int end_x = /*1280 - 64*/start_x + 256; - uint8_t *imageptr = NULL; + int start_y = 720 - 100 - 140;//*(n % 2); + int end_y = start_y + 140 + 32; + int start_x = 64 + (140 + 40) * n;//(n / 2); + int end_x = start_x + 140; + const uint8_t *smallimg = NULL; + const uint8_t *largeimg = NULL; char tmpstr[1024]; - color_t border_color0 = MakeColor(255, 255, 255, 255); - color_t border_color1 = MakeColor(255, 255, 255, 255); + color_t border_color = MakeColor(255, 255, 255, 255); if (is_active) { - border_color0 = MakeColor(171, 224, 245, 255); - border_color1 = MakeColor(189, 228, 242, 255); + border_color = MakeColor(73, 103, 169, 255); } //{ @@ -53,23 +55,21 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) { } //DrawPixelRaw(x, start_y , border_color0); - DrawPixelRaw(x, end_y , border_color0); - DrawPixelRaw(x, start_y-1, border_color0); - DrawPixelRaw(x, end_y +1, border_color0); - DrawPixelRaw(x, start_y-2, border_color0); - DrawPixelRaw(x, end_y +2, border_color0); + DrawPixelRaw(x, end_y , border_color); + DrawPixelRaw(x, start_y-1, border_color); + DrawPixelRaw(x, end_y +1, border_color); + DrawPixelRaw(x, start_y-2, border_color); + DrawPixelRaw(x, end_y +2, border_color); + DrawPixelRaw(x, start_y-3, border_color); + DrawPixelRaw(x, end_y +3, border_color); if (is_active) { - DrawPixelRaw(x, start_y-3, border_color0); - DrawPixelRaw(x, end_y +3, border_color0); - DrawPixelRaw(x, start_y-4, border_color0); - DrawPixelRaw(x, end_y +4, border_color0); - DrawPixelRaw(x, start_y-5, border_color1); - DrawPixelRaw(x, end_y +5, border_color1); - } - else { - DrawPixelRaw(x, start_y-3, border_color1); - DrawPixelRaw(x, end_y +3, border_color1); + DrawPixelRaw(x, start_y-3, border_color); + DrawPixelRaw(x, end_y +3, border_color); + DrawPixelRaw(x, start_y-4, border_color); + DrawPixelRaw(x, end_y +4, border_color); + DrawPixelRaw(x, start_y-5, border_color); + DrawPixelRaw(x, end_y +5, border_color); } } @@ -81,23 +81,19 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) { break; } - DrawPixelRaw(start_x , y, border_color0); - DrawPixelRaw(end_x , y, border_color0); - DrawPixelRaw(start_x-1, y, border_color0); - DrawPixelRaw(end_x +1, y, border_color0); - DrawPixelRaw(start_x-2, y, border_color0); - DrawPixelRaw(end_x +2, y, border_color0); + DrawPixelRaw(start_x , y, border_color); + DrawPixelRaw(end_x , y, border_color); + DrawPixelRaw(start_x-1, y, border_color); + DrawPixelRaw(end_x +1, y, border_color); + DrawPixelRaw(start_x-2, y, border_color); + DrawPixelRaw(end_x +2, y, border_color); + DrawPixelRaw(start_x-3, y, border_color); + DrawPixelRaw(end_x +3, y, border_color); if (is_active) { - DrawPixelRaw(start_x-3, y, border_color0); - DrawPixelRaw(end_x +3, y, border_color0); - DrawPixelRaw(start_x-4, y, border_color0); - DrawPixelRaw(end_x +4, y, border_color0); - DrawPixelRaw(start_x-5, y, border_color1); - } - else { - DrawPixelRaw(start_x-3, y, border_color1); - //DrawPixelRaw(end_x +3, y, border_color1); + DrawPixelRaw(start_x-4, y, border_color); + DrawPixelRaw(end_x +4, y, border_color); + DrawPixelRaw(start_x-5, y, border_color); } } //} @@ -108,24 +104,40 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) { } } - if (me->icon_gfx) - imageptr = me->icon_gfx; - else if (me->type == ENTRY_TYPE_FOLDER) - imageptr = (uint8_t*)folder_icon_bin; - else - imageptr = (uint8_t*)switchicon_questionmark_bin; + if (me->icon_gfx_small && me->icon_gfx) { + smallimg = me->icon_gfx_small; + largeimg = me->icon_gfx; + } + else if (me->type == ENTRY_TYPE_FOLDER) { + smallimg = folder_icon_small; + largeimg = folder_icon_bin; + } + else { + smallimg = switchicon_questionmark_small; + largeimg = switchicon_questionmark_bin; + } - if (imageptr) drawImage(start_x, start_y+32, 256, 256, imageptr); + if (smallimg) { + drawImage(start_x, start_y + 32, 140, 140, smallimg); + } + + if (is_active && largeimg) { + drawImage(740, 100, 256, 256, largeimg); + } DrawTextTruncate(tahoma12, start_x + 8, start_y + 8, MakeColor(64, 64, 64, 255), me->name, 256 - 32, "..."); if (is_active) { - start_x = 64; - start_y = 96 + 32 + 288 + 64; + start_x = 200; + start_y = 155; + DrawText(tahoma24, start_x, start_y, MakeColor(255, 255, 255, 255), me->name); memset(tmpstr, 0, sizeof(tmpstr)); - snprintf(tmpstr, sizeof(tmpstr)-1, "Name: %s\nAuthor: %s\nVersion: %s", me->name, me->author, me->version); - DrawText(tahoma12, start_x, start_y, MakeColor(255, 255, 255, 255), tmpstr); + snprintf(tmpstr, sizeof(tmpstr)-1, "Author: %s", me->author); + DrawText(tahoma12, start_x, start_y + 28 + 30, MakeColor(255, 255, 255, 255), tmpstr); + memset(tmpstr, 0, sizeof(tmpstr)); + snprintf(tmpstr, sizeof(tmpstr)-1, "Version: %s", me->version); + DrawText(tahoma12, start_x, start_y + 28 + 30 + 18 + 6, MakeColor(255, 255, 255, 255), tmpstr); } } @@ -139,13 +151,16 @@ void menuStartup() { #endif menuScan(path); + + folder_icon_small = downscaleIcon(folder_icon_bin); + switchicon_questionmark_small = downscaleIcon(switchicon_questionmark_bin); } color_t waveBlendAdd(color_t a, color_t b, float alpha) { return MakeColor(a.r+(b.r*alpha), a.g+b.g*alpha, a.b + b.b*alpha, 255); } -const int ENABLE_WAVE_BLENDING = 1; +const int ENABLE_WAVE_BLENDING = 0; double timer; void drawWave(float timer, color_t color, float height, float phase, float speed) { @@ -161,7 +176,13 @@ void drawWave(float timer, color_t color, float height, float phase, float speed for (y=wave_top_y; y<720; y++) { alpha = clamp(y-wave_top_y, 0.0, 1.0) * 0.3; existing_color = FetchPixelColor(x, y); - new_color = ENABLE_WAVE_BLENDING ? waveBlendAdd(existing_color, color, alpha) : color; + + if (ENABLE_WAVE_BLENDING || alpha < 0.3) { + new_color = waveBlendAdd(existing_color, color, alpha); + } + else { + new_color = color; + } DrawPixelRaw(x, y, new_color); } @@ -181,14 +202,14 @@ void menuLoop() { } } - DrawText(tahoma24, 64, 64, MakeColor(255, 255, 255, 255), "The Homebrew Launcher"); - DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16, MakeColor(255, 255, 255, 255), "v1.0.0"); - DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16 + 16, MakeColor(255, 255, 255, 255), menu->dirname); + drawWave(timer, MakeColor(73, 103, 169, 255), 320.0, 0.0, 3.0); + drawWave(timer, MakeColor(66, 154, 159, 255), 300.0, 2.0, 3.5); + drawWave(timer, MakeColor(96, 204, 204, 255), 280.0, 4.0, -2.5); + timer += 0.05; - drawWave(timer, MakeColor(73, 103, 169, 255), 160.0, 0.0, 3.0); - drawWave(timer, MakeColor(66, 154, 159, 255), 150.0, 2.0, 3.5); - drawWave(timer, MakeColor(96, 204, 204, 255), 140.0, 4.0, -2.5); - timer += 0.025; + DrawText(tahoma24, 40, 30, MakeColor(255, 255, 255, 255), "hbl"); + DrawText(tahoma12, 40 + 46, 30 + 16, MakeColor(255, 255, 255, 255), "v1.0.0"); + DrawText(tahoma12, 40, 720 - 32 - 16, MakeColor(255, 255, 255, 255), menu->dirname); if (menu->nEntries==0) { diff --git a/common/menu.h b/common/menu.h index 3083291..9a19f77 100644 --- a/common/menu.h +++ b/common/menu.h @@ -45,6 +45,7 @@ struct menuEntry_s_tag uint8_t *icon; size_t icon_size; uint8_t *icon_gfx; + uint8_t *icon_gfx_small; NacpStruct *nacp; }; @@ -54,6 +55,7 @@ void menuEntryFree(menuEntry_s* me); bool fileExists(const char* path); bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut); void menuEntryParseIcon(menuEntry_s* me); +uint8_t *downscaleIcon(const uint8_t *image); void menuEntryParseNacp(menuEntry_s* me); menu_s* menuGetCurrent(void);