diff --git a/common/menu-entry.c b/common/menu-entry.c index 8ac7844..e0d9cb0 100644 --- a/common/menu-entry.c +++ b/common/menu-entry.c @@ -109,12 +109,12 @@ static bool menuEntryImportIconGfx(menuEntry_s* me, uint8_t* icon_gfx, uint8_t* ThemeLayoutObject *layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuActiveEntryIcon]; ThemeLayoutObject *layoutobj2 = &themeCurrent.layoutObjects[ThemeLayoutId_MenuListIcon]; - tmpsize = layoutobj->imageSize[0]*layoutobj->imageSize[1]*3; + tmpsize = layoutobj->size[0]*layoutobj->size[1]*3; me->icon_gfx = (uint8_t*)malloc(tmpsize); if (me->icon_gfx) memcpy(me->icon_gfx, icon_gfx, tmpsize); if (me->icon_gfx) { - tmpsize = layoutobj2->imageSize[0]*layoutobj2->imageSize[1]*3; + tmpsize = layoutobj2->size[0]*layoutobj2->size[1]*3; me->icon_gfx_small = (uint8_t*)malloc(tmpsize); if (me->icon_gfx_small) memcpy(me->icon_gfx_small, icon_gfx_small, tmpsize); @@ -673,22 +673,28 @@ void menuEntryParseIcon(menuEntry_s* me) { size_t imagesize = layoutobj->imageSize[0]*layoutobj->imageSize[1]*3; bool ret=true; - me->icon_gfx = (uint8_t*)malloc(imagesize); + uint8_t *tmp_gfx = (uint8_t*)malloc(imagesize); - if (me->icon_gfx == NULL) ret = false; + if (tmp_gfx == NULL) ret = false; - if (ret) ret = assetsLoadJpgFromMemory(me->icon, me->icon_size, me->icon_gfx, IMAGE_MODE_RGB24, layoutobj->imageSize[0], layoutobj->imageSize[1]); + if (ret) ret = assetsLoadJpgFromMemory(me->icon, me->icon_size, tmp_gfx, IMAGE_MODE_RGB24, layoutobj->imageSize[0], layoutobj->imageSize[1]); + + if (ret) me->icon_gfx = downscaleImg(tmp_gfx, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj->size[0], layoutobj->size[1], IMAGE_MODE_RGB24); + + if (ret && me->icon_gfx==NULL) ret = false; me->icon_size = 0; free(me->icon); me->icon = NULL; - if (ret) me->icon_gfx_small = downscaleImg(me->icon_gfx, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->imageSize[0], layoutobj2->imageSize[1], IMAGE_MODE_RGB24); + if (ret) me->icon_gfx_small = downscaleImg(tmp_gfx, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->size[0], layoutobj2->size[1], IMAGE_MODE_RGB24); if (!ret || me->icon_gfx_small == NULL) { free(me->icon_gfx); me->icon_gfx = NULL; } + + free(tmp_gfx); } uint8_t *downscaleImg(const uint8_t *image, int srcWidth, int srcHeight, int destWidth, int destHeight, ImageMode mode) { @@ -708,6 +714,11 @@ uint8_t *downscaleImg(const uint8_t *image, int srcWidth, int srcHeight, int des return NULL; } + if (srcWidth == destWidth && srcHeight == destHeight) { + memcpy(out, image, destWidth*destHeight*(mode==IMAGE_MODE_RGBA32 ? 4 : 3)); + return out; + } + int tmpx, tmpy; int pos; float sourceX, sourceY; diff --git a/common/menu.c b/common/menu.c index bd931bc..3f8cd71 100644 --- a/common/menu.c +++ b/common/menu.c @@ -9,12 +9,14 @@ char rootPathBase[PATH_MAX]; char rootPath[PATH_MAX+8]; -uint8_t *folder_icon_small; -uint8_t *invalid_icon_small; -uint8_t *theme_icon_small; +uint8_t *folder_icon_large, *folder_icon_small; +uint8_t *invalid_icon_large, *invalid_icon_small; +uint8_t *theme_icon_large, *theme_icon_small; void computeFrontGradient(color_t baseColor, int height); +void menuLoadFileassoc(void); + char *menuGetRootPath(void) { return rootPath; } @@ -119,8 +121,11 @@ void menuHandleXButton(void) { } void menuStartupCommon(void) { + free(folder_icon_large); free(folder_icon_small); + free(invalid_icon_large); free(invalid_icon_small); + free(theme_icon_large); free(theme_icon_small); ThemeLayoutObject *layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuActiveEntryIcon]; @@ -128,27 +133,50 @@ void menuStartupCommon(void) { assetsDataEntry *data = NULL; assetsGetData(AssetId_folder_icon, &data); - folder_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->imageSize[0], layoutobj2->imageSize[1], data->imageMode); + folder_icon_large = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj->size[0], layoutobj->size[1], data->imageMode); + folder_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->size[0], layoutobj2->size[1], data->imageMode); assetsGetData(AssetId_invalid_icon, &data); - invalid_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->imageSize[0], layoutobj2->imageSize[1], data->imageMode); - if(themeGlobalPreset == THEME_PRESET_DARK) { + invalid_icon_large = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj->size[0], layoutobj->size[1], data->imageMode); + invalid_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->size[0], layoutobj2->size[1], data->imageMode); + if(themeGlobalPreset == THEME_PRESET_DARK) assetsGetData(AssetId_theme_icon_dark, &data); - theme_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->imageSize[0], layoutobj2->imageSize[1], data->imageMode); - } - else { + else assetsGetData(AssetId_theme_icon_light, &data); - theme_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->imageSize[0], layoutobj2->imageSize[1], data->imageMode); - } + theme_icon_large = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj->size[0], layoutobj->size[1], data->imageMode); + theme_icon_small = downscaleImg(data->buffer, layoutobj->imageSize[0], layoutobj->imageSize[1], layoutobj2->size[0], layoutobj2->size[1], data->imageMode); layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_FrontWave]; computeFrontGradient(themeCurrent.frontWaveColor, layoutobj->size[1]); } +void menuThemeSelectCurrentEntry(void) { + menu_s* menu = menuGetCurrent(); + char themePath[PATH_MAX] = {0}; + GetThemePathFromConfig(themePath, PATH_MAX); + if (themePath[0]==0) menu->curEntry = 0; + else { + int i; + menuEntry_s* me; + for (i = 0, me = menu->firstEntry; me != NULL; i ++, me = me->next) { + if (strcmp(me->path, themePath)==0) { + menu->curEntry = i; + break; + } + } + } +} + void launchApplyThemeTask(menuEntry_s* arg) { const char* themePath = arg->path; + menu_s* menu = menuGetCurrent(); SetThemePathToConfig(themePath); themeStartup(themeGlobalPreset); menuStartupCommon(); + menuLoadFileassoc(); + if (hbmenu_state == HBMENU_THEME_MENU) { // Normally this should never be used outside of theme-menu. + themeMenuScan(menu->dirname); + menuThemeSelectCurrentEntry(); + } else menuScan(menu->dirname); } bool menuIsNetloaderActive(void) { @@ -300,31 +328,29 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) { } else if (me->type == ENTRY_TYPE_FOLDER) { smallimg = folder_icon_small; - largeimg = assetsGetDataBuffer(AssetId_folder_icon); + largeimg = folder_icon_large; } else if (me->type == ENTRY_TYPE_THEME){ smallimg = theme_icon_small; - if(themeGlobalPreset == THEME_PRESET_DARK) - largeimg = assetsGetDataBuffer(AssetId_theme_icon_dark); - else largeimg = assetsGetDataBuffer(AssetId_theme_icon_light); + largeimg = theme_icon_large; } else { smallimg = invalid_icon_small; - largeimg = assetsGetDataBuffer(AssetId_invalid_icon); + largeimg = invalid_icon_large; } if (smallimg) { layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuListIcon]; - drawImage(start_x + layoutobj->posStart[0], start_y + layoutobj->posStart[1], layoutobj->imageSize[0], layoutobj->imageSize[1], smallimg, IMAGE_MODE_RGB24); + drawImage(start_x + layoutobj->posStart[0], start_y + layoutobj->posStart[1], layoutobj->size[0], layoutobj->size[1], smallimg, IMAGE_MODE_RGB24); } layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuActiveEntryIcon]; if (is_active && largeimg && layoutobj->visible) { - drawImage(layoutobj->posStart[0], layoutobj->posStart[1], layoutobj->imageSize[0], layoutobj->imageSize[1], largeimg, IMAGE_MODE_RGB24); + drawImage(layoutobj->posStart[0], layoutobj->posStart[1], layoutobj->size[0], layoutobj->size[1], largeimg, IMAGE_MODE_RGB24); - shadow_start_y = layoutobj->posStart[1]+layoutobj->imageSize[1]; + shadow_start_y = layoutobj->posStart[1]+layoutobj->size[1]; border_start_x = layoutobj->posStart[0]; - border_end_x = layoutobj->posStart[0]+layoutobj->imageSize[0]; + border_end_x = layoutobj->posStart[0]+layoutobj->size[0]; for (shadow_y=shadow_start_y; shadow_y posEnd[0] < 1) layoutobj->posEnd[0] = 1; + layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuListIcon]; + if (layoutobj->size[0] <= 0 || layoutobj->size[1] <= 0 || layoutobj->size[0] > layoutobj->imageSize[0] || layoutobj->size[1] > layoutobj->imageSize[1]) { + layoutobj->size[0] = layoutobj->imageSize[0]; + layoutobj->size[1] = layoutobj->imageSize[1]; + } + + layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuActiveEntryIcon]; + if (layoutobj->size[0] <= 0 || layoutobj->size[1] <= 0 || layoutobj->size[0] > layoutobj->imageSize[0] || layoutobj->size[1] > layoutobj->imageSize[1]) { + layoutobj->size[0] = layoutobj->imageSize[0]; + layoutobj->size[1] = layoutobj->imageSize[1]; + } + config_destroy(&cfg); #ifdef __SWITCH__