diff --git a/common/common.h b/common/common.h index 4457ab5..3a3d2d7 100644 --- a/common/common.h +++ b/common/common.h @@ -152,6 +152,8 @@ void DrawPixel(uint32_t x, uint32_t y, color_t clr); void DrawText(u32 font, uint32_t x, uint32_t y, color_t clr, const char* text); void DrawTextTruncate(u32 font, uint32_t x, uint32_t y, color_t clr, const char* text, uint32_t max_width, const char* end_text); void GetTextDimensions(u32 font, const char* text, uint32_t* width_out, uint32_t* height_out); +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); bool fontInitialize(void); void fontExit(); diff --git a/common/font.c b/common/font.c index 769133a..3c5a2c2 100644 --- a/common/font.c +++ b/common/font.c @@ -376,3 +376,49 @@ void fontExit() if (s_font_libret==0) FT_Done_FreeType(s_font_library); } +/*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/menu-list.c b/common/menu-list.c index 27d510d..566f5da 100644 --- a/common/menu-list.c +++ b/common/menu-list.c @@ -174,10 +174,6 @@ int themeMenuScan(const char* target) { snprintf(tmp_path, sizeof(tmp_path)-1, "%s/%s", s_menu[!s_curMenu].dirname, dp->d_name); const char* ext = getExtension(dp->d_name); - char* name = removeExtension(dp->d_name); - replaceCharacter(name,'_',' '); - if(strcmp(dp->d_name,"theme.cfg")==0)//This theme is already the currently applied theme, dont load it - continue; if (strcasecmp(ext, ".cfg")==0) me = menuCreateEntry(ENTRY_TYPE_THEME); @@ -186,11 +182,10 @@ int themeMenuScan(const char* target) { strncpy(me->path, tmp_path, sizeof(me->path)-1); me->path[sizeof(me->path)-1] = 0; - if (menuEntryLoad(me,(const char*)name, shortcut)) + if (menuEntryLoad(me,dp->d_name, shortcut)) menuAddEntry(me); else menuDeleteEntry(me); - free(name);//This was allocated by calloc and copied over by strcpy } closedir(dir); diff --git a/common/menu.c b/common/menu.c index 5e86a99..bb5da22 100644 --- a/common/menu.c +++ b/common/menu.c @@ -70,7 +70,7 @@ void launchApplyThemeTask(menuEntry_s* arg){ tmp_path[0] = '/'; #endif - strncat(tmp_path, "config/nx-hbmenu/themes/theme.cfg", sizeof(tmp_path)-2); + strncat(tmp_path, "config/nx-hbmenu/settings.cfg", sizeof(tmp_path)-2); if(!config_write_file(&cfg, tmp_path)){ menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!"); return; @@ -123,7 +123,7 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) { int border_start_x, border_end_x; int border_start_y, border_end_y; - color_t border_color = MakeColor(themeCurrent.borderColor.r, themeCurrent.borderColor.g, themeCurrent.borderColor.b, 255); + color_t border_color = themeCurrent.borderColor; int shadow_start_y, shadow_y; int shadow_inset; @@ -202,7 +202,7 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) { for (y=start_y; yname, 140 - 32, "...");//Add to theme + + DrawTextTruncate(interuiregular14, start_x + 4, start_y + 4 + 18, themeCurrent.borderTextColor, me->name, 140 - 32, "..."); if (is_active) { start_x = 1280 - 790; @@ -499,20 +500,20 @@ 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)); + 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)); } else if (active_entry->type != ENTRY_TYPE_FOLDER) { - //TODO: add minus button + //TODO: add minus button for theme menu //drawImage(1280 - 126 - 30 - 32, 720 - 48, 32, 32, themeCurrent.buttonAImage, IMAGE_MODE_RGBA32); DrawText(fontscale7, 1280 - 126 - 30 - 32, 720 - 47 + 24, themeCurrent.textColor, themeCurrent.buttonAText);//Display the 'A' button from SharedFont. DrawText(interuiregular18, 1280 - 90 - 30 - 32, 720 - 47 + 24, themeCurrent.textColor, textGetString(StrId_Actions_Launch)); } - else{ - //TODO: add minus button + else { + //TODO: add minus button for theme menu //drawImage(1280 - 126 - 30 - 32, 720 - 48, 32, 32, themeCurrent.buttonAImage, IMAGE_MODE_RGBA32); 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_Open)); @@ -523,4 +524,4 @@ void menuLoop() { } menuDrawMsgBox(); -} \ No newline at end of file +} diff --git a/common/menu.h b/common/menu.h index 79b62bc..7d47650 100644 --- a/common/menu.h +++ b/common/menu.h @@ -110,20 +110,3 @@ static inline char* getSlash(const char* str) for (p = str+strlen(str); p >= str && *p != '/'; p--); return (char*)p; } - -static inline char* removeExtension(const char* str){ - const char* p; - char* copy = calloc(strlen(str)+1,sizeof(char)); - 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++; - } - return copyHead; -} - -static inline void replaceCharacter(char* str, char orig, char repl){ - char* p; - for (p = str; p <= (str+strlen(str)); p++) if(*p==orig) *p=repl; -} - diff --git a/common/text.c b/common/text.c index 8ee3e42..638a8bb 100644 --- a/common/text.c +++ b/common/text.c @@ -42,49 +42,3 @@ 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 f27d844..b2c47db 100644 --- a/common/text.h +++ b/common/text.h @@ -6,5 +6,3 @@ 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 bd4159b..40a876a 100644 --- a/common/theme.c +++ b/common/theme.c @@ -15,19 +15,6 @@ 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)); - switch (preset) { - case THEME_PRESET_LIGHT: - default: - strcpy(buttonAText, "\uE0E0"); - strcpy(buttonBText, "\uE0E1"); - break; - case THEME_PRESET_DARK: - strcpy(buttonAText, "\uE0A0"); - strcpy(buttonBText, "\uE0A1"); - break; - } theme_t themeLight = (theme_t) { .textColor = MakeColor(0, 0, 0, 255), .frontWaveColor = MakeColor(100, 212, 250, 255), @@ -39,8 +26,8 @@ void themeStartup(ThemePreset preset) { .borderColor = MakeColor(255,255,255,255), .borderTextColor = MakeColor(64,64,64,255), .enableWaveBlending = 0, - .buttonAText = buttonAText, - .buttonBText = buttonBText, + .buttonAText = "\uE0E0", + .buttonBText = "\uE0E1", //.buttonAImage = button_a_light_bin, //.buttonBImage = button_b_light_bin, .hbmenuLogoImage = hbmenu_logo_light_bin @@ -57,8 +44,8 @@ void themeStartup(ThemePreset preset) { .borderColor = MakeColor(255,255,255,255), .borderTextColor = MakeColor(64,64,64,255), .enableWaveBlending = 0, - .buttonAText = buttonAText, - .buttonBText = buttonBText, + .buttonAText = "\uE0A0", + .buttonBText = "\uE0A1", //.buttonAImage = button_a_dark_bin, //.buttonBImage = button_b_dark_bin, .hbmenuLogoImage = hbmenu_logo_dark_bin @@ -70,7 +57,7 @@ void themeStartup(ThemePreset preset) { tmp_path[0] = '/'; #endif - strncat(tmp_path, "config/nx-hbmenu/themes/theme.cfg", sizeof(tmp_path)-2); + strncat(tmp_path, "config/nx-hbmenu/settings.cfg", sizeof(tmp_path)-2); theme_t *themeDefault; config_t cfg = {0}; @@ -131,12 +118,12 @@ void themeStartup(ThemePreset preset) { .borderColor = borderColor, .borderTextColor = borderTextColor, .enableWaveBlending = waveBlending, - .buttonAText = AText, - .buttonBText = BText, //.buttonAImage = button_a_dark_bin, //.buttonBImage = button_b_dark_bin, .hbmenuLogoImage = hbmenu_logo_dark_bin }; + strncpy(themeCurrent.buttonAText, AText, sizeof(themeCurrent.buttonAText)-1); + strncpy(themeCurrent.buttonBText, BText, sizeof(themeCurrent.buttonBText)-1); } else { themeCurrent = *themeDefault; } @@ -144,4 +131,4 @@ void themeStartup(ThemePreset preset) { themeCurrent = *themeDefault; } config_destroy(&cfg); -} \ No newline at end of file +} diff --git a/common/theme.h b/common/theme.h index 099b099..3931508 100644 --- a/common/theme.h +++ b/common/theme.h @@ -15,8 +15,8 @@ typedef struct color_t borderColor; color_t borderTextColor; bool enableWaveBlending; - const char *buttonAText; - const char *buttonBText; + char buttonAText[32]; + char buttonBText[32]; //const uint8_t *buttonAImage; //const uint8_t *buttonBImage; const uint8_t *hbmenuLogoImage; @@ -35,9 +35,3 @@ void themeStartup(ThemePreset preset); theme_t themeCurrent; ThemePreset globalPreset; - - -static inline void themeExit(){ - free(themeCurrent.buttonAText); - free(themeCurrent.buttonBText); -} diff --git a/nx_main/main.c b/nx_main/main.c index 5663193..7748579 100644 --- a/nx_main/main.c +++ b/nx_main/main.c @@ -18,7 +18,6 @@ void audio_initialize(void); void audio_exit(void); #endif - int main(int argc, char **argv) { Result lastret=0; @@ -33,8 +32,7 @@ int main(int argc, char **argv) appletSetScreenShotPermission(1); - ColorSetId theme; - + ColorSetId theme; rc = setsysInitialize(); if (R_FAILED(rc)) fatalSimple(-5); @@ -99,7 +97,6 @@ int main(int argc, char **argv) #endif fontExit(); - themeExit(); launchExit(); plExit(); setsysExit(); diff --git a/pc_main/main.cpp b/pc_main/main.cpp index a260422..e029485 100644 --- a/pc_main/main.cpp +++ b/pc_main/main.cpp @@ -52,7 +52,6 @@ int main() } fontExit(); - themeExit(); return 0; }