diff --git a/common/language.c b/common/language.c index 945d2c6..c315fcd 100644 --- a/common/language.c +++ b/common/language.c @@ -309,15 +309,25 @@ const char* const g_strings[StrId_Max][16] = STR_KO("확인"), STR_TW("確認"), }, + [StrId_Actions_Apply] = { STR_EN("Apply"), STR_ES("Aplicar"), STR_JP("適用"), STR_KO("대다"), - STR_TW("應用"), + STR_TW("应用"), }, + + [StrId_Actions_Theme_Menu] = + { + STR_EN("Theme Switcher V1.0"), + STR_ES("Versión 1,0 del cambiador de tema"), + STR_JP("テーマスイッチャー版1.0"), + STR_KO("테마 스위처 에디션 1.0"), + STR_TW("主题切换器版本1。0"), + }, /*[StrId_Reboot] = { STR_EN( diff --git a/common/language.h b/common/language.h index bf0c722..331dcf6 100644 --- a/common/language.h +++ b/common/language.h @@ -43,6 +43,8 @@ typedef enum StrId_NetLoaderActive, StrId_NetLoaderTransferring, + StrId_Actions_Theme_Menu, + StrId_Max, } StrId; diff --git a/common/menu.c b/common/menu.c index 2a9e3be..76af412 100644 --- a/common/menu.c +++ b/common/menu.c @@ -500,6 +500,8 @@ void menuLoop() { if(active_entry != NULL) { if(active_entry->type == ENTRY_TYPE_THEME){ + int getX = getXCoordinate(interuiregular18,1180,textGetString(StrId_Actions_Theme_Menu),'r'); + DrawText(interuiregular18, getX , 0 + 47, themeCurrent.textColor, textGetString(StrId_Actions_Theme_Menu)); DrawText(fontscale7, 1280 - 126 - 30 - 32, 720 - 47 + 24, themeCurrent.textColor, themeCurrent.buttonAText); DrawText(interuiregular18, 1280 - 90 - 30 - 32, 720 - 47 + 24, themeCurrent.textColor, textGetString(StrId_Actions_Apply)); } @@ -521,4 +523,4 @@ void menuLoop() { } menuDrawMsgBox(); -} +} \ No newline at end of file diff --git a/common/menu.h b/common/menu.h index f959176..6cd0dfe 100644 --- a/common/menu.h +++ b/common/menu.h @@ -114,7 +114,7 @@ static inline char* getSlash(const char* str) static inline char* removeExtension(const char* str){ const char* p; char* copy = calloc(strlen(str)+1,sizeof(char)); - char *copyHead = copy; + char *copyHead = copy;/*Get copy of the head of the char* to return, otherwise it will return copy->null */ for (p = str; p <= (str+strlen(str)) && *p != '.'; p++){ *copy = *p; copy++; diff --git a/common/text.c b/common/text.c index 638a8bb..8ee3e42 100644 --- a/common/text.c +++ b/common/text.c @@ -42,3 +42,49 @@ const char* textGetString(StrId id) { u64 textGetLanguageCode(void) { return s_textLanguageCode; } +/*Automatically gives you the desired x-coordinate + *based on the string length and desired alignmenr + *rY=reference point... where to align around + *align='t','b','c' translates too (top,bottom,center) + *'t' aligned, top of text aligns with rY, + *you get the rest.... + */ +uint32_t getYCoordinate(u32 font,uint32_t rY,const char* text, const char align){ + uint32_t height_o,width; + GetTextDimensions(font,text,&width,&height_o); + uint32_t height = (uint32_t)height_o; + uint32_t fC = (rY-height); + switch(align){ + case 't': + default: + return rY; + case 'c': + return (rY+(height/2U)); + case 'b': + if(fC<=0U) return 0U; + else return fC; + } +} + +/*Automatically gives you the desired x-coordinate + *based on the string length and desired alignmenr + *rX=reference point... where to align around + *text=string you want to display + *align='r','l','c' translates too (right,left,center) + *'r' aligned, rX location = end of string, you get the rest... + */ +uint32_t getXCoordinate(u32 font,uint32_t rX, const char* text ,const char align){ + uint32_t height,width_o; + GetTextDimensions(font,text,&width_o,&height); + uint32_t fC = (rX-width_o); + switch(align){ + case 'r': + if(fC<0U) return 0U; + else return fC; + case 'c': + return (rX+(width_o/2U)); + case 'l': + default: + return rX; + } +} \ No newline at end of file diff --git a/common/text.h b/common/text.h index b2c47db..f27d844 100644 --- a/common/text.h +++ b/common/text.h @@ -6,3 +6,5 @@ void textInit(void); int textGetLang(void); const char* textGetString(StrId id); u64 textGetLanguageCode(void); +uint32_t getXCoordinate(u32 font,uint32_t rX, const char* text,const char align); +uint32_t getYCoordinate(u32 font,uint32_t rY, const char* text,const char align); diff --git a/common/theme.c b/common/theme.c index 8f3bad6..c97b50f 100644 --- a/common/theme.c +++ b/common/theme.c @@ -15,8 +15,8 @@ bool colorFromSetting(config_setting_t *rgba, color_t *col) { void themeStartup(ThemePreset preset) { globalPreset = preset; - char* buttonAText = calloc(7,sizeof(char)); - char* buttonBText = calloc(7,sizeof(char)); + char* buttonAText = calloc(7,sizeof(char));/*Must initialize the character arrays on the heap*/ + char* buttonBText = calloc(7,sizeof(char));/*so that they are not destroyed whenever themeStartup function ends*/ switch (preset) { case THEME_PRESET_LIGHT: default: @@ -37,8 +37,8 @@ void themeStartup(ThemePreset preset) { .highlightColor = MakeColor(91, 237, 224, 255), .separatorColor = MakeColor(219, 218, 219, 255), .enableWaveBlending = 0, - .buttonAText = buttonAText, - .buttonBText = buttonBText, + .buttonAText = buttonAText,/*setting the buttonAText = "\uE0E0" directly allocates the literal on the stack */ + .buttonBText = buttonBText,/*and sets the buttonAText to point to the address of the literal which is why calloc is used above*/ //.buttonAImage = button_a_light_bin, //.buttonBImage = button_b_light_bin, .hbmenuLogoImage = hbmenu_logo_light_bin @@ -63,10 +63,10 @@ void themeStartup(ThemePreset preset) { char tmp_path[PATH_MAX] = {0}; #ifdef __SWITCH__ - tmp_path[0] = '/'; + tmp_path[0] = '/';/*will this work on the windows version?*/ #endif - strncat(tmp_path, "config/nx-hbmenu/themes/theme.cfg", sizeof(tmp_path)-2); + strncat(tmp_path, "config/nx-hbmenu/themes/theme.cfg", sizeof(tmp_path)-2);/*Same thing here? will it work on windows?*/ theme_t *themeDefault; config_t cfg = {0}; @@ -76,10 +76,10 @@ void themeStartup(ThemePreset preset) { int waveBlending; const char *AText, *BText; bool good_cfg = config_read_file(&cfg, tmp_path); - struct stat buffer; - if(!good_cfg){ + if(!good_cfg){//config file is messed up config_t tmp = {0}; cfg = tmp;//clear the config + config_init(&cfg);/*reinitize so that we can create the theme.cfg with the default theme (TODO:NightlyFox)*/ } switch (preset) { case THEME_PRESET_LIGHT: @@ -88,8 +88,9 @@ void themeStartup(ThemePreset preset) { if (good_cfg) theme = config_lookup(&cfg, "lightTheme"); else{ - if(stat(tmp_path,&buffer)==0); - //TODO: theme.cfg file does not exist or is corrupted/misconfigured! overwrite with default theme. + /*(TODO:NightlyFox) + theme.cfg file does not exist or is corrupted/misconfigured! + setup config here with default themes*/ } break; @@ -98,12 +99,14 @@ void themeStartup(ThemePreset preset) { if (good_cfg) theme = config_lookup(&cfg, "darkTheme"); else{ - if(stat(tmp_path,&buffer)==0); - //TODO: theme.cfg file does not exist or is corrupted/misconfigured! overwrite with default theme. + /*(TODO:NightlyFox) theme.cfg + file does not exist or is corrupted/misconfigured! + setup config here with default themes*/ } break; } - + /*(TODO:NightlyFox) write the config here + so you only have to do it once*/ if (good_cfg) { if (theme != NULL) { if (!colorFromSetting(config_setting_lookup(theme, "textColor"), &text))