Moved path init code from menuStartup() into new func menuStartupPath(), which now creates the config dirs if needed. Added menuGetRootBasePath(), which is now used for config paths and pc-build fonts. Changed some funcs from () to (void). Fixed broken button handling in pc_main for theme-menu. This fixes pc-build support for config/theme-menu.

This commit is contained in:
yellows8 2018-10-01 12:53:08 -04:00
parent 6e11672e20
commit e01ca3150e
7 changed files with 46 additions and 26 deletions

View File

@ -59,9 +59,10 @@ typedef union {
#include "theme.h" #include "theme.h"
#include "message-box.h" #include "message-box.h"
void menuStartup(); void menuStartupPath(void);
void themeMenuStartup(); void menuStartup(void);
void menuLoop(); void themeMenuStartup(void);
void menuLoop(void);
static inline uint8_t BlendColor(uint32_t src, uint32_t dst, uint8_t alpha) static inline uint8_t BlendColor(uint32_t src, uint32_t dst, uint8_t alpha)
{ {

View File

@ -349,7 +349,7 @@ bool fontInitialize(void)
for (i=0; i<FONT_FACES_MAX; i++) { for (i=0; i<FONT_FACES_MAX; i++) {
memset(fontpath, 0, sizeof(fontpath)); memset(fontpath, 0, sizeof(fontpath));
snprintf(fontpath, sizeof(fontpath)-1, "fonts%s%u.ttf", DIRECTORY_SEPARATOR, i); snprintf(fontpath, sizeof(fontpath)-1, "%s%sfonts%s%u.ttf", menuGetRootBasePath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, i);
ret = FT_New_Face( s_font_library, ret = FT_New_Face( s_font_library,
fontpath, fontpath,

View File

@ -7,13 +7,18 @@
#include "theme_icon_dark_bin.h" #include "theme_icon_dark_bin.h"
#include "theme_icon_light_bin.h" #include "theme_icon_light_bin.h"
char rootPathBase[PATH_MAX];
char rootPath[PATH_MAX+8]; char rootPath[PATH_MAX+8];
void computeFrontGradient(color_t baseColor, int height); void computeFrontGradient(color_t baseColor, int height);
char *menuGetRootPath() { char *menuGetRootPath(void) {
return rootPath; return rootPath;
} }
char *menuGetRootBasePath(void) {
return rootPathBase;
}
void launchMenuEntryTask(menuEntry_s* arg) { void launchMenuEntryTask(menuEntry_s* arg) {
menuEntry_s* me = arg; menuEntry_s* me = arg;
if (me->type == ENTRY_TYPE_FOLDER) if (me->type == ENTRY_TYPE_FOLDER)
@ -286,15 +291,15 @@ void computeFrontGradient(color_t baseColor, int height) {
} }
} }
void menuStartup() { void menuStartupPath(void) {
char tmp_path[PATH_MAX]; char tmp_path[PATH_MAX+25];
#ifdef __SWITCH__ #ifdef __SWITCH__
strcpy(tmp_path,"sdmc:"); strncpy(rootPathBase, "sdmc:", sizeof(rootPathBase)-1);
#else #else
getcwd(tmp_path, PATH_MAX); getcwd(rootPathBase, sizeof(rootPathBase));
#endif #endif
snprintf(rootPath, sizeof(rootPath)-1, "%s%s%s", tmp_path, DIRECTORY_SEPARATOR, "switch"); snprintf(rootPath, sizeof(rootPath)-1, "%s%s%s", rootPathBase, DIRECTORY_SEPARATOR, "switch");
struct stat st = {0}; struct stat st = {0};
@ -302,6 +307,20 @@ void menuStartup() {
mkdir(rootPath, 0755); mkdir(rootPath, 0755);
} }
snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu/themes", rootPathBase);
if (stat(tmp_path, &st) == -1) {
snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config", rootPathBase);
mkdir(tmp_path, 0755);
snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu", rootPathBase);
mkdir(tmp_path, 0755);
snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu/themes", rootPathBase);
mkdir(tmp_path, 0755);
}
}
void menuStartup(void) {
menuScan(rootPath); menuScan(rootPath);
folder_icon_small = downscaleImg(folder_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24); folder_icon_small = downscaleImg(folder_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
@ -314,12 +333,12 @@ void menuStartup() {
//menuCreateMsgBox(780, 300, "This is a test"); //menuCreateMsgBox(780, 300, "This is a test");
} }
void themeMenuStartup() { void themeMenuStartup(void) {
if(hbmenu_state != HBMENU_DEFAULT) return; if(hbmenu_state != HBMENU_DEFAULT) return;
hbmenu_state = HBMENU_THEME_MENU; hbmenu_state = HBMENU_THEME_MENU;
char tmp_path[PATH_MAX]; char tmp_path[PATH_MAX+25];
snprintf(tmp_path, sizeof(tmp_path)-1, "%s%s%s%s%s%s",DIRECTORY_SEPARATOR, "config", DIRECTORY_SEPARATOR, "nx-hbmenu" , DIRECTORY_SEPARATOR, "themes"); snprintf(tmp_path, sizeof(tmp_path)-1, "%s%s%s%s%s%s%s", rootPathBase, DIRECTORY_SEPARATOR, "config", DIRECTORY_SEPARATOR, "nx-hbmenu" , DIRECTORY_SEPARATOR, "themes");
themeMenuScan(tmp_path); themeMenuScan(tmp_path);
} }
@ -406,7 +425,7 @@ void drawBackBtn(menu_s* menu, bool emptyDir) {
} }
} }
void menuLoop() { void menuLoop(void) {
menuEntry_s* me; menuEntry_s* me;
menu_s* menu = menuGetCurrent(); menu_s* menu = menuGetCurrent();
int i; int i;

View File

@ -91,7 +91,8 @@ void launchMenuEntryTask(menuEntry_s* arg);
void launchApplyThemeTask(menuEntry_s* arg); void launchApplyThemeTask(menuEntry_s* arg);
void launchMenuBackTask(); void launchMenuBackTask();
void launchMenuNetloaderTask(); void launchMenuNetloaderTask();
char *menuGetRootPath(); char *menuGetRootPath(void);
char *menuGetRootBasePath(void);
void menuHandleAButton(void); void menuHandleAButton(void);

View File

@ -144,16 +144,11 @@ void GetThemePathFromConfig(char* themePath, size_t size) {
const char* tmpThemePath = ""; const char* tmpThemePath = "";
config_t cfg = {0}; config_t cfg = {0};
config_setting_t *settings = NULL; config_setting_t *settings = NULL;
char tmp_path[PATH_MAX] = {0}; char tmp_path[PATH_MAX+1] = {0};
char tmp_path_theme[PATH_MAX] = {0}; char tmp_path_theme[PATH_MAX+1] = {0};
#ifdef __SWITCH__ snprintf(tmp_path, sizeof(tmp_path)-1, "%s/config/nx-hbmenu/settings.cfg", menuGetRootBasePath());
tmp_path[0] = '/'; snprintf(tmp_path_theme, sizeof(tmp_path_theme)-1, "%s/config/nx-hbmenu/themes/", menuGetRootBasePath());
tmp_path_theme[0] = '/';
#endif
strncat(tmp_path, "config/nx-hbmenu/settings.cfg", sizeof(tmp_path)-2);
strncat(tmp_path_theme, "config/nx-hbmenu/themes/", sizeof(tmp_path_theme)-2);
bool good_cfg = config_read_file(&cfg, tmp_path); bool good_cfg = config_read_file(&cfg, tmp_path);
if(good_cfg) { if(good_cfg) {
@ -183,7 +178,7 @@ void SetThemePathToConfig(const char* themePath) {
settingPath[0] = '/'; settingPath[0] = '/';
#endif #endif
strncat(settingPath, "config/nx-hbmenu/settings.cfg", sizeof(settingPath)-2); snprintf(settingPath, sizeof(settingPath)-1, "%s/config/nx-hbmenu/settings.cfg", menuGetRootBasePath());
bool good_cfg = config_read_file(&cfg, settingPath); bool good_cfg = config_read_file(&cfg, settingPath);
if(good_cfg) { if(good_cfg) {

View File

@ -41,6 +41,8 @@ int main(int argc, char **argv)
rc = plInitialize(); rc = plInitialize();
if (R_FAILED(rc)) fatalSimple(-6); if (R_FAILED(rc)) fatalSimple(-6);
menuStartupPath();
themeStartup((ThemePreset)theme); themeStartup((ThemePreset)theme);
textInit(); textInit();
menuStartup(); menuStartup();

View File

@ -15,9 +15,10 @@ int main()
sf::RenderWindow window(sf::VideoMode(1280, 720), "Test"); sf::RenderWindow window(sf::VideoMode(1280, 720), "Test");
window.setFramerateLimit(60); window.setFramerateLimit(60);
menuStartupPath();
themeStartup(THEME_PRESET_LIGHT); themeStartup(THEME_PRESET_LIGHT);
textInit(); textInit();
fontInitialize();//Must be called before menuStartup() due to cwd. fontInitialize();
menuStartup(); menuStartup();
while (window.isOpen()) while (window.isOpen())
@ -111,6 +112,7 @@ extern "C" bool menuUpdate(void) {
esc_state = new_esc_state; esc_state = new_esc_state;
return_state = new_return_state; return_state = new_return_state;
y_state = new_y_state; y_state = new_y_state;
t_state = new_t_state;
return 0; return 0;
} }