got rid of code modifying display name of theme config files, changed directory of saved/applied theme. Changed theme_t pointers to char[32]
This commit is contained in:
parent
7dbc5b24f7
commit
4d488b48d8
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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; y<end_y; y++) {
|
||||
for (x=start_x; x<end_x; x+=4) {
|
||||
Draw4PixelsRaw(x, y, MakeColor(themeCurrent.borderColor.r, themeCurrent.borderColor.g, themeCurrent.borderColor.b, 255));//add to theme
|
||||
Draw4PixelsRaw(x, y, themeCurrent.borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,7 +247,8 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) {
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawTextTruncate(interuiregular14, start_x + 4, start_y + 4 + 18, MakeColor(themeCurrent.borderTextColor.r, themeCurrent.borderTextColor.g, themeCurrent.borderTextColor.b, 255), me->name, 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));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ void audio_initialize(void);
|
||||
void audio_exit(void);
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Result lastret=0;
|
||||
@ -34,7 +33,6 @@ int main(int argc, char **argv)
|
||||
appletSetScreenShotPermission(1);
|
||||
|
||||
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();
|
||||
|
@ -52,7 +52,6 @@ int main()
|
||||
}
|
||||
|
||||
fontExit();
|
||||
themeExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user