This commit is contained in:
NightlyFox 2018-09-25 22:27:03 -05:00
commit e60156c34f
11 changed files with 59 additions and 49 deletions

3
.gitignore vendored
View File

@ -11,3 +11,6 @@ build
*.pfs0 *.pfs0
*.nacp *.nacp
*.nro *.nro
test.*
*_bin.h
switch

View File

@ -25,6 +25,7 @@ test : pc_main/main.cpp pc_main/pc_launch.c \
common/netloader.c \ common/netloader.c \
build_pc/invalid_icon.bin.o build_pc/folder_icon.bin.o \ build_pc/invalid_icon.bin.o build_pc/folder_icon.bin.o \
build_pc/hbmenu_logo_light.bin.o build_pc/hbmenu_logo_dark.bin.o \ build_pc/hbmenu_logo_light.bin.o build_pc/hbmenu_logo_dark.bin.o \
build_pc/theme_icon_dark.bin.o build_pc/theme_icon_light.bin.o \
#build_pc/tahoma24.o build_pc/tahoma12.o build_pc/interuimedium20.o build_pc/interuimedium30.o build_pc/interuiregular14.o build_pc/interuiregular18.o #build_pc/tahoma24.o build_pc/tahoma12.o build_pc/interuimedium20.o build_pc/interuimedium30.o build_pc/interuiregular14.o build_pc/interuiregular18.o
gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ `pkg-config freetype2 --libs` -lm -lz -lconfig $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@ gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ `pkg-config freetype2 --libs` -lm -lz -lconfig $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@
@ -78,16 +79,16 @@ build_pc/hbmenu_logo_dark.bin.o : data/hbmenu_logo_dark.bin
@echo $(notdir $<) @echo $(notdir $<)
@$(bin2o) @$(bin2o)
build_pc/hbmenu_logo_light.bin.o : data/theme_icon_light.bin build_pc/theme_icon_light.bin.o : data/theme_icon_light.bin
mkdir -p $(dir $@) mkdir -p $(dir $@)
@echo $(notdir $<) @echo $(notdir $<)
@$(bin2o) @$(bin2o)
build_pc/hbmenu_logo_dark.bin.o : data/theme_icon_dark.bin build_pc/theme_icon_dark.bin.o : data/theme_icon_dark.bin
mkdir -p $(dir $@) mkdir -p $(dir $@)
@echo $(notdir $<) @echo $(notdir $<)
@$(bin2o) @$(bin2o)
clean: clean:
rm -rf build_pc/ test rm -rf build_pc/ test *_bin.h test.*

View File

@ -153,8 +153,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 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 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); 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 GetTextXCoordinate(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); uint32_t GetTextYCoordinate(u32 font, uint32_t rY, const char* text, const char align);
bool fontInitialize(void); bool fontInitialize(void);
void fontExit(); void fontExit();

View File

@ -377,46 +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 alignmenr *based on the string length and desired alignment
*rY=reference point... where to align around *rY=reference point... where to align around
*align='t','b','c' translates too (top,bottom,center) *align='t','b','c' translates to (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 getYCoordinate(u32 font,uint32_t rY,const char* text, const char align){ uint32_t GetTextYCoordinate(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/2U)); return (rY+(height>>1));//>>1 is a bitwise shift for dividing by 2
case 'b': case 'b':
if(fC<=0U) return 0U; if(fC<=0) return 0;
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 alignmenr *based on the string length and desired alignment
*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 too (right,left,center) *align='r','l','c' translates to (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 getXCoordinate(u32 font,uint32_t rX, const char* text ,const char align){ uint32_t GetTextXCoordinate(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<0U) return 0U; if(fC<0) return 0;
else return fC; else return fC;
case 'c': case 'c':
return (rX+(width_o/2U)); return (rX+(width_o>>1));//>>1 is a bitwise shift for dividing by 2
case 'l': case 'l':
default: default:
return rX; return rX;

View File

@ -322,11 +322,11 @@ const char* const g_strings[StrId_Max][16] =
[StrId_Actions_Theme_Menu] = [StrId_Actions_Theme_Menu] =
{ {
STR_EN("Theme Switcher V1.0"), STR_EN("Theme Menu"),
STR_ES("Versión 1,0 del cambiador de tema"), STR_ES("Menú temático"),
STR_JP("テーマスイッチャー版1.0"), STR_JP("テーマメニュー"),
STR_KO("테마 스위처 에디션 1.0"), STR_KO("테마 메뉴"),
STR_TW("主题切换器版本1。0"), STR_TW("主题菜单"),
}, },
/*[StrId_Reboot] = /*[StrId_Reboot] =
{ {

View File

@ -294,6 +294,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
/*if (shortcut) /*if (shortcut)
shortcutFree(&sc);*/ shortcutFree(&sc);*/
} }
if (me->type == ENTRY_TYPE_THEME) { if (me->type == ENTRY_TYPE_THEME) {
config_t cfg = {0}; config_t cfg = {0};
config_init(&cfg); config_init(&cfg);
@ -307,10 +308,8 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
if (themeInfo != NULL) { if (themeInfo != NULL) {
if(config_setting_lookup_string(themeInfo, "name", &name)) if(config_setting_lookup_string(themeInfo, "name", &name))
strncpy(me->name, name, sizeof(me->name)-1); strncpy(me->name, name, sizeof(me->name)-1);
if(!config_setting_lookup_string(themeInfo, "author", &author)) config_setting_lookup_string(themeInfo, "author", &author);
author = textGetString(StrId_DefaultPublisher); config_setting_lookup_string(themeInfo, "version", &version);
if(!config_setting_lookup_string(themeInfo, "version", &version))\
version = "1.0.0";
} }
} }

View File

@ -181,7 +181,7 @@ int themeMenuScan(const char* target) {
strncpy(me->path, tmp_path, sizeof(me->path)-1); strncpy(me->path, tmp_path, sizeof(me->path)-1);
me->path[sizeof(me->path)-1] = 0; me->path[sizeof(me->path)-1] = 0;
if (menuEntryLoad(me,dp->d_name, shortcut)) if (menuEntryLoad(me, dp->d_name, shortcut))
menuAddEntry(me); menuAddEntry(me);
else else
menuDeleteEntry(me); menuDeleteEntry(me);

View File

@ -14,8 +14,7 @@ char *menuGetRootPath() {
return rootPath; return rootPath;
} }
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)
menuScan(me->path); menuScan(me->path);
@ -40,39 +39,42 @@ void launchMenuNetloaderTask() {
if(netloader_activate() == 0) hbmenu_state = HBMENU_NETLOADER_ACTIVE; if(netloader_activate() == 0) hbmenu_state = HBMENU_NETLOADER_ACTIVE;
} }
void launchMenuBackTask() void launchMenuBackTask() {
{
if(hbmenu_state == HBMENU_NETLOADER_ACTIVE) { if(hbmenu_state == HBMENU_NETLOADER_ACTIVE) {
netloader_deactivate(); netloader_deactivate();
hbmenu_state = HBMENU_DEFAULT; hbmenu_state = HBMENU_DEFAULT;
}else if(hbmenu_state == HBMENU_THEME_MENU){ }
else if(hbmenu_state == HBMENU_THEME_MENU) {
hbmenu_state = HBMENU_DEFAULT; hbmenu_state = HBMENU_DEFAULT;
menuScan(rootPath); menuScan(rootPath);
} }
else { else {
menuScan(".."); menuScan("..");
} }
} }
void launchApplyThemeTask(menuEntry_s* arg){
void launchApplyThemeTask(menuEntry_s* arg) {
config_t cfg = {0}; config_t cfg = {0};
config_init(&cfg); config_init(&cfg);
if(!config_read_file(&cfg, arg->path)){
if(!config_read_file(&cfg, arg->path)) {
menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be loaded!"); menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be loaded!");
return; return;
} }
char tmp_path[PATH_MAX] = {0};
char tmp_path[PATH_MAX] = {0};
#ifdef __SWITCH__ #ifdef __SWITCH__
tmp_path[0] = '/'; tmp_path[0] = '/';
#endif #endif
strncat(tmp_path, "config/nx-hbmenu/theme.cfg", sizeof(tmp_path)-2); strncat(tmp_path, "config/nx-hbmenu/theme.cfg", sizeof(tmp_path)-2);
if(!config_write_file(&cfg, tmp_path)){ if(!config_write_file(&cfg, tmp_path)) {
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!");
return; return;
} }
config_destroy(&cfg); config_destroy(&cfg);
themeStartup(globalPreset); themeStartup(themeGlobalPreset);
computeFrontGradient(themeCurrent.frontWaveColor, 280); computeFrontGradient(themeCurrent.frontWaveColor, 280);
} }
@ -212,7 +214,7 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) {
} }
else if (me->type == ENTRY_TYPE_THEME){ else if (me->type == ENTRY_TYPE_THEME){
smallimg = theme_icon_small; smallimg = theme_icon_small;
if(globalPreset == THEME_PRESET_DARK) if(themeGlobalPreset == THEME_PRESET_DARK)
largeimg = theme_icon_dark_bin; largeimg = theme_icon_dark_bin;
else largeimg = theme_icon_light_bin; else largeimg = theme_icon_light_bin;
} }
@ -305,6 +307,10 @@ void menuStartup() {
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);
invalid_icon_small = downscaleImg(invalid_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24); invalid_icon_small = downscaleImg(invalid_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
if(themeGlobalPreset == THEME_PRESET_DARK)
theme_icon_small = downscaleImg(theme_icon_dark_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
else
theme_icon_small = downscaleImg(theme_icon_light_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
computeFrontGradient(themeCurrent.frontWaveColor, 280); computeFrontGradient(themeCurrent.frontWaveColor, 280);
//menuCreateMsgBox(780, 300, "This is a test"); //menuCreateMsgBox(780, 300, "This is a test");
} }
@ -317,13 +323,6 @@ void themeMenuStartup() {
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",DIRECTORY_SEPARATOR, "config", DIRECTORY_SEPARATOR, "nx-hbmenu" , DIRECTORY_SEPARATOR, "themes");
themeMenuScan(tmp_path); themeMenuScan(tmp_path);
if(globalPreset == THEME_PRESET_DARK)
theme_icon_small = downscaleImg(theme_icon_dark_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
else
theme_icon_small = downscaleImg(theme_icon_light_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
computeFrontGradient(themeCurrent.frontWaveColor, 280);
//menuCreateMsgBox(780, 300, "This is a test");
} }
color_t waveBlendAdd(color_t a, color_t b, float alpha) { color_t waveBlendAdd(color_t a, color_t b, float alpha) {
@ -497,7 +496,7 @@ void menuLoop() {
if(active_entry != NULL) { if(active_entry != NULL) {
if (active_entry->type == ENTRY_TYPE_THEME) { if (active_entry->type == ENTRY_TYPE_THEME) {
int getX = getXCoordinate(interuiregular18, 1180, textGetString(StrId_Actions_Theme_Menu), 'r'); int getX = GetTextXCoordinate(interuiregular18, 1180, textGetString(StrId_Actions_Theme_Menu), 'r');
DrawText(interuiregular18, getX, 0 + 47, themeCurrent.textColor, textGetString(StrId_Actions_Theme_Menu)); 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(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)); DrawText(interuiregular18, 1280 - 90 - 30 - 32, 720 - 47 + 24, themeCurrent.textColor, textGetString(StrId_Actions_Apply));

View File

@ -6,6 +6,9 @@
#include "hbmenu_logo_light_bin.h" #include "hbmenu_logo_light_bin.h"
#include "hbmenu_logo_dark_bin.h" #include "hbmenu_logo_dark_bin.h"
theme_t themeCurrent;
ThemePreset themeGlobalPreset;
bool colorFromSetting(config_setting_t *rgba, color_t *col) { bool colorFromSetting(config_setting_t *rgba, color_t *col) {
if(rgba == NULL) if(rgba == NULL)
return false; return false;
@ -14,7 +17,7 @@ bool colorFromSetting(config_setting_t *rgba, color_t *col) {
} }
void themeStartup(ThemePreset preset) { void themeStartup(ThemePreset preset) {
globalPreset = preset; themeGlobalPreset = preset;
theme_t themeLight = (theme_t) { theme_t themeLight = (theme_t) {
.textColor = MakeColor(0, 0, 0, 255), .textColor = MakeColor(0, 0, 0, 255),
.frontWaveColor = MakeColor(100, 212, 250, 255), .frontWaveColor = MakeColor(100, 212, 250, 255),
@ -70,6 +73,7 @@ void themeStartup(ThemePreset preset) {
int waveBlending; int waveBlending;
const char *AText, *BText; const char *AText, *BText;
bool good_cfg = config_read_file(&cfg, tmp_path); bool good_cfg = config_read_file(&cfg, tmp_path);
switch (preset) { switch (preset) {
case THEME_PRESET_LIGHT: case THEME_PRESET_LIGHT:
default: default:
@ -84,6 +88,7 @@ void themeStartup(ThemePreset preset) {
theme = config_lookup(&cfg, "darkTheme"); theme = config_lookup(&cfg, "darkTheme");
break; break;
} }
if (good_cfg) { if (good_cfg) {
if (theme != NULL) { if (theme != NULL) {
if (!colorFromSetting(config_setting_lookup(theme, "textColor"), &text)) if (!colorFromSetting(config_setting_lookup(theme, "textColor"), &text))

View File

@ -32,6 +32,6 @@ bool colorFromSetting(config_setting_t *rgba, color_t *col);
void themeStartup(ThemePreset preset); void themeStartup(ThemePreset preset);
theme_t themeCurrent; extern theme_t themeCurrent;
ThemePreset globalPreset; extern ThemePreset themeGlobalPreset;

View File

@ -32,7 +32,7 @@ int main(int argc, char **argv)
appletSetScreenShotPermission(1); appletSetScreenShotPermission(1);
ColorSetId theme; ColorSetId theme;
rc = setsysInitialize(); rc = setsysInitialize();
if (R_FAILED(rc)) fatalSimple(-5); if (R_FAILED(rc)) fatalSimple(-5);
@ -40,6 +40,7 @@ int main(int argc, char **argv)
rc = plInitialize(); rc = plInitialize();
if (R_FAILED(rc)) fatalSimple(-6); if (R_FAILED(rc)) fatalSimple(-6);
themeStartup((ThemePreset)theme); themeStartup((ThemePreset)theme);
textInit(); textInit();
menuStartup(); menuStartup();