added removeDriveFromPath Function

This commit is contained in:
NightlyFox 2018-09-26 01:08:50 -05:00
parent 5621fb460b
commit 58f5a78ceb
5 changed files with 33 additions and 25 deletions

View File

@ -377,50 +377,48 @@ void fontExit()
} }
/*Automatically gives you the desired x-coordinate /*Automatically gives you the desired x-coordinate
*based on the string length and desired alignment *based on the string length and desired alignmenr
*rY=reference point... where to align around *rY=reference point... where to align around
*align='t','b','c' translates to (top,bottom,center) *align='t','b','c' translates too (top,bottom,center)
*'t' aligned, top of text aligns with rY, *'t' aligned, top of text aligns with rY,
*you get the rest.... *you get the rest....
*/ */
uint32_t GetTextYCoordinate(u32 font, uint32_t rY, const char* text, const char align) { uint32_t getYCoordinate(u32 font,uint32_t rY,const char* text, const char align){
uint32_t height_o,width; uint32_t height_o,width;
GetTextDimensions(font,text,&width,&height_o); GetTextDimensions(font,text,&width,&height_o);
uint32_t height = (uint32_t)height_o; uint32_t height = (uint32_t)height_o;
uint32_t fC = (rY-height); uint32_t fC = (rY-height);
switch(align){ switch(align){
case 't': case 't':
default: default:
return rY; return rY;
case 'c': case 'c':
return (rY+(height>>1));//>>1 is a bitwise shift for dividing by 2 return (rY+(height/2U));
case 'b': case 'b':
if(fC<=0) return 0; if(fC<=0U) return 0U;
else return fC; else return fC;
} }
} }
/*Automatically gives you the desired x-coordinate /*Automatically gives you the desired x-coordinate
*based on the string length and desired alignment *based on the string length and desired alignmenr
*rX=reference point... where to align around *rX=reference point... where to align around
*text=string you want to display *text=string you want to display
*align='r','l','c' translates to (right,left,center) *align='r','l','c' translates too (right,left,center)
*'r' aligned, rX location = end of string, you get the rest... *'r' aligned, rX location = end of string, you get the rest...
*/ */
uint32_t GetTextXCoordinate(u32 font, uint32_t rX, const char* text, const char align) { uint32_t getXCoordinate(u32 font,uint32_t rX, const char* text ,const char align){
uint32_t height,width_o; uint32_t height,width_o;
GetTextDimensions(font,text,&width_o,&height); GetTextDimensions(font,text,&width_o,&height);
uint32_t fC = (rX-width_o); uint32_t fC = (rX-width_o);
switch(align){ switch(align){
case 'r': case 'r':
if(fC<0) return 0; if(fC<0U) return 0U;
else return fC; else return fC;
case 'c': case 'c':
return (rX+(width_o>>1));//>>1 is a bitwise shift for dividing by 2 return (rX+(width_o/2U));
case 'l': case 'l':
default: default:
return rX; return rX;
} }
} }

View File

@ -55,7 +55,8 @@ void launchMenuBackTask() {
} }
void launchApplyThemeTask(menuEntry_s* arg) { void launchApplyThemeTask(menuEntry_s* arg) {
//SetThemePathToConfig(arg->path); const char* themePath = removeDriveFromPath(arg->path);
//SetThemePathToConfig(themePath);
themeStartup(themeGlobalPreset); themeStartup(themeGlobalPreset);
computeFrontGradient(themeCurrent.frontWaveColor, 280); computeFrontGradient(themeCurrent.frontWaveColor, 280);
} }

View File

@ -111,3 +111,10 @@ static inline char* getSlash(const char* str)
for (p = str+strlen(str); p >= str && *p != '/'; p--); for (p = str+strlen(str); p >= str && *p != '/'; p--);
return (char*)p; return (char*)p;
} }
static inline char* removeDriveFromPath(const char* str) {
const char* p;
for (p = str; p <= (str+strlen(str)) && *p != ':'; p++);
p++;//iterate one more time past ':'
return (char*)p;
}

View File

@ -54,11 +54,9 @@ void themeStartup(ThemePreset preset) {
.hbmenuLogoImage = hbmenu_logo_dark_bin .hbmenuLogoImage = hbmenu_logo_dark_bin
}; };
config_t themeCfg = {0};
config_setting_t *setting;
config_init(&themeCfg);
const char* themePath = ""; const char* themePath = "";
//GetThemePathFromConfig(themeCfg, setting, themePath); GetThemePathFromConfig(themePath);
theme_t *themeDefault; theme_t *themeDefault;
@ -69,7 +67,6 @@ void themeStartup(ThemePreset preset) {
int waveBlending; int waveBlending;
const char *AText, *BText; const char *AText, *BText;
bool good_cfg = config_read_file(&cfg, themePath); bool good_cfg = config_read_file(&cfg, themePath);
config_destroy(&themeCfg);
switch (preset) { switch (preset) {
case THEME_PRESET_LIGHT: case THEME_PRESET_LIGHT:
@ -138,7 +135,11 @@ void themeStartup(ThemePreset preset) {
config_destroy(&cfg); config_destroy(&cfg);
} }
void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath) { void GetThemePathFromConfig(const char* themePath) {
config_t cfg = {0};
config_setting_t *setting;
config_init(&cfg);
char tmp_path[PATH_MAX] = {0}; char tmp_path[PATH_MAX] = {0};
#ifdef __SWITCH__ #ifdef __SWITCH__
@ -152,26 +153,27 @@ void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char
setting = config_lookup(&cfg, "themePath"); setting = config_lookup(&cfg, "themePath");
config_setting_lookup_string(setting, "themePath", &themePath); config_setting_lookup_string(setting, "themePath", &themePath);
} }
config_destroy(&cfg);
} }
void SetThemePathToConfig(const char* themePath) { void SetThemePathToConfig(const char* themePath) {
config_t cfg = {0}; config_t cfg = {0};
config_init(&cfg); config_init(&cfg);
char tmp_path[PATH_MAX] = {0}; char settingPath[PATH_MAX] = {0};
config_setting_t *root,*group, *setting; config_setting_t *root,*group, *setting;
#ifdef __SWITCH__ #ifdef __SWITCH__
tmp_path[0] = '/'; settingPath[0] = '/';
#endif #endif
strncat(tmp_path, "config/nx-hbmenu/setting.cfg", sizeof(tmp_path)-2); strncat(settingPath, "config/nx-hbmenu/setting.cfg", sizeof(settingPath)-2);
root = config_root_setting(&cfg); root = config_root_setting(&cfg);
group = config_setting_add(root, "hbmenuConfig", CONFIG_TYPE_GROUP); group = config_setting_add(root, "hbmenuConfig", CONFIG_TYPE_GROUP);
setting = config_setting_add(group, "themePath", CONFIG_TYPE_STRING); setting = config_setting_add(group, "themePath", CONFIG_TYPE_STRING);
config_setting_set_string(setting, themePath); config_setting_set_string(setting, themePath);
if(!config_write_file(&cfg, tmp_path)) { if(!config_write_file(&cfg, settingPath)) {
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!"); menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!");
} }

View File

@ -30,7 +30,7 @@ typedef enum
bool colorFromSetting(config_setting_t *rgba, color_t *col); bool colorFromSetting(config_setting_t *rgba, color_t *col);
void themeStartup(ThemePreset preset); void themeStartup(ThemePreset preset);
void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath); void GetThemePathFromConfig(const char* themePath);
void SetThemePathToConfig(const char* themePath); void SetThemePathToConfig(const char* themePath);
extern theme_t themeCurrent; extern theme_t themeCurrent;