#include #include "common.h" #include "invalid_icon_bin.h" #include "folder_icon_bin.h" void launchMenuEntryTask(menuEntry_s* arg) { menuEntry_s* me = arg; if (me->type == ENTRY_TYPE_FOLDER) menuScan(me->path); //changeDirTask(me->path); else launchMenuEntry(me); } typedef enum { IMAGE_MODE_RGB24, IMAGE_MODE_RGBA32 } ImageMode; //Draws an RGB888 or RGBA8888 image. static void drawImage(int x, int y, int width, int height, const uint8_t *image, ImageMode mode) { int tmpx, tmpy; int pos; color_t current_color; for (tmpx=0; tmpx= border_start_x + shadow_inset && x <= border_end_x - shadow_inset) { DrawPixel(x, end_y +shadow_y, shadow_color); } } } for (y=border_start_y; yicon_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 = invalid_icon_small; largeimg = invalid_icon_bin; } if (smallimg) { drawImage(start_x, start_y + 32, 140, 140, smallimg, IMAGE_MODE_RGB24); } if (is_active && largeimg) { drawImage(117, 100, 256, 256, largeimg, IMAGE_MODE_RGB24); shadow_start_y = 100+256; border_start_x = 117; border_end_x = 117+256; for (x=border_start_x; x= border_start_x + shadow_inset && x <= border_end_x - shadow_inset) { DrawPixel(x, shadow_y, shadow_color); } } } } DrawTextTruncate(interuiregular14, start_x + 4, start_y + 4, MakeColor(64, 64, 64, 255), me->name, 140 - 32, "..."); if (is_active) { start_x = 1280 - 790; start_y = 135; DrawTextTruncate(interuimedium30, start_x, start_y, themeCurrent.textColor, me->name, 1280 - start_x - 120 ,"..."); if (me->type != ENTRY_TYPE_FOLDER) { memset(tmpstr, 0, sizeof(tmpstr)); snprintf(tmpstr, sizeof(tmpstr)-1, "Author: %s", me->author); DrawText(interuiregular14, start_x, start_y + 28 + 30, themeCurrent.textColor, tmpstr); memset(tmpstr, 0, sizeof(tmpstr)); snprintf(tmpstr, sizeof(tmpstr)-1, "Version: %s", me->version); DrawText(interuiregular14, start_x, start_y + 28 + 30 + 18 + 6, themeCurrent.textColor, tmpstr); drawImage(1280 - 126 - 30, 720 - 48, 32, 32, themeCurrent.buttonAImage, IMAGE_MODE_RGBA32); DrawText(interuiregular18, 1280 - 90 - 30, 720 - 47, themeCurrent.textColor, "Launch"); } else { drawImage(1280 - 126 - 30, 720 - 48, 32, 32, themeCurrent.buttonAImage, IMAGE_MODE_RGBA32); DrawText(interuiregular18, 1280 - 90 - 30, 720 - 47, themeCurrent.textColor, "Open"); } } } color_t waveGradients[3][720]; void precomputeWaveColors(int id, color_t baseColor, int height) { int y; int alpha; float dark_mult, dark_sub = 75; color_t color; for (y=0; y<720; y++) { alpha = y - (720 - height); if (alpha < 0) color = baseColor; else { dark_mult = clamp((float)(alpha - 50) / (float)height, 0.0, 1.0); color = MakeColor(baseColor.r - dark_sub * dark_mult, baseColor.g - dark_sub * dark_mult, baseColor.b - dark_sub * dark_mult, 255); } waveGradients[id][y] = color; } } void menuStartup() { const char *path; #ifdef SWITCH path = "sdmc:/switch"; #else path = "switch"; #endif menuScan(path); folder_icon_small = downscaleIcon(folder_icon_bin); invalid_icon_small = downscaleIcon(invalid_icon_bin); precomputeWaveColors(0, themeCurrent.backWaveColor, 295); precomputeWaveColors(1, themeCurrent.middleWaveColor, 290); precomputeWaveColors(2, themeCurrent.frontWaveColor, 280); } 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); } void drawWave(int id, float timer, color_t color, int height, float phase, float speed) { int x, y; float wave_top_y, alpha; color_t existing_color, new_color; height = 720 - height; for (x=0; x<1280; x++) { wave_top_y = approxSin(x*speed/1280.0+timer+phase) * 10.0 + height; for (y=wave_top_y; y<720; y++) { alpha = y-wave_top_y; existing_color = FetchPixelColor(x, y); if (themeCurrent.enableWaveBlending) { new_color = waveBlendAdd(existing_color, color, clamp(alpha, 0.0, 1.0) * 0.3); } else if (alpha < 0.3) { // anti-aliasing alpha = fabs(alpha); new_color = MakeColor(color.r * (1.0 - alpha) + existing_color.r * alpha, color.g * (1.0 - alpha) + existing_color.g * alpha, color.b * (1.0 - alpha) + existing_color.b * alpha, 255); } else { // darken closer to bottom of the waves new_color = waveGradients[id][y]; } DrawPixelRaw(x, y, new_color); } } } void drawTime() { char timeString[9]; time_t unixTime = time(NULL); struct tm* timeStruct = gmtime((const time_t *)&unixTime); int hours = timeStruct->tm_hour; int minutes = timeStruct->tm_min; int seconds = timeStruct->tm_sec; sprintf(timeString, "%02d:%02d:%02d", hours, minutes, seconds); DrawText(interuimedium20, 1280 - (9 * 16) - 30, 30, MakeColor(255, 255, 255, 255), timeString); } void drawBackBtn(menu_s* menu, bool emptyDir) { int x_image = 1280 - 252 - 30; int x_text = 1280 - 216 - 30; if(emptyDir) { x_image = 1280 - 126 - 30; x_text = 1280 - 90 - 30; } #ifdef SWITCH if (strcmp( menu->dirname, "sdmc:/") != 0) #else if (strcmp( menu->dirname, "/") != 0) #endif { drawImage(x_image, 720 - 48, 32, 32, themeCurrent.buttonBImage, IMAGE_MODE_RGBA32); DrawText(interuiregular18, x_text, 720 - 47, themeCurrent.textColor, "Back"); } } void menuLoop() { menuEntry_s* me; menu_s* menu = menuGetCurrent(); int i; int x, y; for (x=0; x<1280; x++) { for (y=0; y<720; y++) { DrawPixelRaw(x, y, themeCurrent.backgroundColor); } } drawWave(0, timer, themeCurrent.backWaveColor, 295, 0.0, 3.0); drawWave(1, timer, themeCurrent.middleWaveColor, 290, 2.0, 3.5); drawWave(2, timer, themeCurrent.frontWaveColor, 280, 4.0, -2.5); timer += 0.05; drawImage(40, 20, 140, 60, themeCurrent.hbmenuLogoImage, IMAGE_MODE_RGBA32); DrawText(interuiregular14, 180, 46, themeCurrent.textColor, "v2.0.0"); DrawTextTruncate(interuiregular18, 40, 720 - 47, themeCurrent.textColor, menu->dirname, 918, "..."); //drawTime(); if (menu->nEntries==0) { DrawText(interuiregular14, 64, 128, themeCurrent.textColor, textGetString(StrId_NoAppsFound_Msg)); drawBackBtn(menu, true); } else { static int x = 0; static int v = 0; if (menu->nEntries > 7) { int wanted_x = clamp(-menu->curEntry * (140 + 30), -(menu->nEntries - 7) * (140 + 30), 0); x += v; v += (wanted_x - x) / 3; v /= 2; } else { x = v = 0; } // Draw menu entries for (me = menu->firstEntry, i = 0; me; me = me->next, i ++) { int entry_start_x = 29 + i * (140 + 30); int screen_width = 1280; if (entry_start_x >= (screen_width - x)) break; drawEntry(me, entry_start_x + x, i==menu->curEntry); } drawBackBtn(menu, false); } }