Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a theme switcher feature #62

Merged
merged 64 commits into from Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ed5c670
Implemented hbmenu Theme Switcher! Final changes will now be cosmetic
NightlyFox Sep 19, 2018
afe968f
Merge branch 'master' of https://github.com/switchbrew/nx-hbmenu
NightlyFox Sep 19, 2018
93ee023
saw a potential bug, where i was changing the size of something a whi…
NightlyFox Sep 19, 2018
2f887cc
added some minor touch ups to the Theme Switcher Menu
NightlyFox Sep 19, 2018
bd23932
got rid of TODO comments that are no longer needed, different impleme…
NightlyFox Sep 19, 2018
35a3c64
added proper deallocation in places of the code for pointers that i a…
NightlyFox Sep 19, 2018
8e2a79c
added two new theming attributes, borderColor, borderTextcolor, allow…
NightlyFox Sep 20, 2018
981a60a
Added themeExit to pc main.cpp
NightlyFox Sep 21, 2018
4369cbf
not sure how the highlight multiplier got removed, but i added it back
NightlyFox Sep 21, 2018
df53f5f
added config_destroy() after done applying theme.
NightlyFox Sep 21, 2018
af0278b
removed *bin.h files
NightlyFox Sep 21, 2018
c877b65
reverted make file
NightlyFox Sep 21, 2018
59ba53d
remmoved (old) files and got rid of extra whitespace
NightlyFox Sep 21, 2018
9c8c395
removed the free from the menu-entry file and put it in the function …
NightlyFox Sep 21, 2018
42df5cf
fixed bug that would take user from netloader screen to theme switche…
NightlyFox Sep 21, 2018
2f1e6ad
got rid of void* cast when freeing, got rid of comments asking questi…
NightlyFox Sep 22, 2018
22c2c5b
restored newline at eof of main.c
NightlyFox Sep 22, 2018
907b594
fixed indention
NightlyFox Sep 22, 2018
12761b1
got rid of stray whitespace, replaced with newline
NightlyFox Sep 22, 2018
7dbc5b2
got rid of void* in menu-list, didnt save the file last time
NightlyFox Sep 22, 2018
4d488b4
got rid of code modifying display name of theme config files, changed…
NightlyFox Sep 23, 2018
b0c5a82
user no longer needs to restart the application
NightlyFox Sep 23, 2018
2880429
added spaces to areas in code to have coding conformity
NightlyFox Sep 23, 2018
ea1d7dc
missed this extra newline
NightlyFox Sep 23, 2018
0f95009
added theme info to config file, users can now add theme author, and …
NightlyFox Sep 23, 2018
d79d501
cleaned up code with themeInfo config, now looks a lot better
NightlyFox Sep 23, 2018
350fbda
got rid of booleans, initialized pointers with default values
NightlyFox Sep 23, 2018
a9921cb
changed settings.cfg name back to theme.cfg name, but left it in the …
NightlyFox Sep 23, 2018
c542b19
added declaration of functions to get rid of implicit warnings
NightlyFox Sep 23, 2018
2a2128c
tested building on mac osx, added to .gitignore and make clean for fi…
NightlyFox Sep 23, 2018
3abb799
fixed spaces
NightlyFox Sep 23, 2018
f7d1f7a
added git ignore changes
NightlyFox Sep 24, 2018
59f2e4d
fixed aligment and added a newline after temp_path within launchApply…
NightlyFox Sep 24, 2018
f89e331
got rid of redundent code in menu-entry.c file
NightlyFox Sep 24, 2018
26acfdd
out newline before tmp_path in menu.c
NightlyFox Sep 24, 2018
3bc3217
made requested changes by yellows8
NightlyFox Sep 24, 2018
b928153
updated language for theme menu
NightlyFox Sep 24, 2018
1afb097
fixed capitalization of functions to match others
NightlyFox Sep 24, 2018
8f20c9a
made suggested changes
NightlyFox Sep 24, 2018
03503d8
updated changes
NightlyFox Sep 24, 2018
ce5470d
added GetThemePathConfig function
NightlyFox Sep 26, 2018
e60156c
Merge branch 'master' of https://github.com/NightlyFox/nx-hbmenu
NightlyFox Sep 26, 2018
5621fb4
NOT STABLE: attempting to write functions that copy themePath to and …
NightlyFox Sep 26, 2018
58f5a78
added removeDriveFromPath Function
NightlyFox Sep 26, 2018
3e7618a
added newline
NightlyFox Sep 26, 2018
63e71a4
NO IDEA WHY I REVERTED
NightlyFox Sep 26, 2018
19ea89c
newline to font.c at eof
NightlyFox Sep 26, 2018
1d9ef3b
added functions to create/modify settings config for hbmenu theme
NightlyFox Sep 26, 2018
624fbed
added check for empty themePath, added check for existing settings co…
NightlyFox Sep 28, 2018
cd8698c
added null checks to theme.c, removed and added newline in language.c
NightlyFox Sep 28, 2018
1c15605
i swear if this adds two newlines!
NightlyFox Sep 28, 2018
a776768
added newline
NightlyFox Sep 28, 2018
56f495f
final changed to make and gitignore file
NightlyFox Sep 28, 2018
3c548f6
changed hbmenuConfig to settings
NightlyFox Sep 28, 2018
a5279c8
passed in size
NightlyFox Sep 28, 2018
3b40097
made some final changes, cleaned up code
NightlyFox Sep 28, 2018
0cfaa79
added Default theme entry that will always insert itself at the front…
NightlyFox Sep 28, 2018
8f01f59
added correct punctuation to the end of StrId_ThemeNotApplied languages
NightlyFox Sep 28, 2018
dab82dc
added code for + and - button, using - button for theme menu now, cor…
NightlyFox Sep 29, 2018
253ef7c
took repeated code out of if/else statements
NightlyFox Sep 29, 2018
de42849
added correct unicode for switch characters + and - for light theme
NightlyFox Sep 29, 2018
3c4f483
commented out prompt to press - button to open theme menu
NightlyFox Sep 29, 2018
c6716a0
got rid of newline
NightlyFox Sep 29, 2018
096b283
got rid of extra newline before themeMenuScan
NightlyFox Sep 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,5 @@ build
*.pfs0
*.nacp
*.nro
test.*
switch
12 changes: 11 additions & 1 deletion Makefile.pc
Expand Up @@ -25,6 +25,7 @@ test : pc_main/main.cpp pc_main/pc_launch.c \
common/netloader.c \
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/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
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 $@

Expand Down Expand Up @@ -78,7 +79,16 @@ build_pc/hbmenu_logo_dark.bin.o : data/hbmenu_logo_dark.bin
@echo $(notdir $<)
@$(bin2o)

build_pc/theme_icon_light.bin.o : data/theme_icon_light.bin
mkdir -p $(dir $@)
@echo $(notdir $<)
@$(bin2o)

build_pc/theme_icon_dark.bin.o : data/theme_icon_dark.bin
mkdir -p $(dir $@)
@echo $(notdir $<)
@$(bin2o)


clean:
rm -rf build_pc/ test
rm -rf build_pc/ test test.*
3 changes: 3 additions & 0 deletions common/common.h
Expand Up @@ -60,6 +60,7 @@ typedef union {
#include "message-box.h"

void menuStartup();
void themeMenuStartup();
void menuLoop();

static inline uint8_t BlendColor(uint32_t src, uint32_t dst, uint8_t alpha)
Expand Down Expand Up @@ -152,6 +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 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 GetTextXCoordinate(u32 font, uint32_t rX, const char* text, const char align);
uint32_t GetTextYCoordinate(u32 font, uint32_t rY, const char* text, const char align);

bool fontInitialize(void);
void fontExit();
48 changes: 48 additions & 0 deletions common/font.c
Expand Up @@ -376,3 +376,51 @@ 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 alignment
*rY=reference point... where to align around
*align='t','b','c' translates to (top,bottom,center)
*'t' aligned, top of text aligns with rY,
*you get the rest....
*/
uint32_t GetTextYCoordinate(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){
NightlyFox marked this conversation as resolved.
Show resolved Hide resolved
case 't':
default:
return rY;
case 'c':
return (rY+(height>>1));//>>1 is a bitwise shift for dividing by 2
case 'b':
if(fC<=0) return 0;
else return fC;
}
}

/*Automatically gives you the desired x-coordinate
NightlyFox marked this conversation as resolved.
Show resolved Hide resolved
*based on the string length and desired alignment
*rX=reference point... where to align around
*text=string you want to display
*align='r','l','c' translates to (right,left,center)
*'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 height,width_o;
GetTextDimensions(font,text,&width_o,&height);
uint32_t fC = (rX-width_o);

switch(align){
case 'r':
if(fC<0) return 0;
else return fC;
case 'c':
return (rX+(width_o>>1));//>>1 is a bitwise shift for dividing by 2
case 'l':
default:
return rX;
}
}
27 changes: 27 additions & 0 deletions common/language.c
Expand Up @@ -310,6 +310,33 @@ const char* const g_strings[StrId_Max][16] =
STR_TW("確認"),
},

[StrId_Actions_Apply] =
{
STR_EN("Apply"),
STR_ES("Aplicar"),
STR_JP("適用"),
STR_KO("대다"),
STR_TW("应用"),
},

[StrId_ThemeMenu] =
{
STR_EN("Theme Menu"),
STR_ES("Menú temático"),
STR_JP("テーマメニュー"),
STR_KO("테마 메뉴"),
STR_TW("主题菜单"),
},

[StrId_ThemeNotApplied] =
{
STR_EN("Theme cannot be applied because an error occurred."),
STR_ES("El tema no se pudo aplicar porque se ha producido un error."),
STR_JP("エラーが発生したため、テーマを適用できませんでした。"),
STR_KO("오류가 발생 했기 때문에 테마를 적용할 수 없습니다."),
STR_TW("由于发生错误, 无法应用主题。"),
},

/*[StrId_Reboot] =
NightlyFox marked this conversation as resolved.
Show resolved Hide resolved
{
STR_EN(
Expand Down
4 changes: 4 additions & 0 deletions common/language.h
Expand Up @@ -21,6 +21,7 @@ typedef enum
StrId_Actions_Launch,
StrId_Actions_Open,
StrId_Actions_Back,
StrId_Actions_Apply,

StrId_MsgBox_OK,

Expand All @@ -42,6 +43,9 @@ typedef enum
StrId_NetLoaderActive,
StrId_NetLoaderTransferring,

StrId_ThemeMenu,
StrId_ThemeNotApplied,

StrId_Max,
} StrId;

Expand Down
26 changes: 25 additions & 1 deletion common/menu-entry.c
Expand Up @@ -137,6 +137,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {

tempbuf[PATH_MAX] = 0;
strcpy(me->name, name);

if (me->type == ENTRY_TYPE_FOLDER)
{
//Check for <dirpath>/<dirname>.nro
Expand Down Expand Up @@ -182,7 +183,7 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {

if (me->type == ENTRY_TYPE_FILE)
{
strcpy(me->name, name);
//strcpy(me->name, name);//This is already done before both if statements
strcpy(me->author, textGetString(StrId_DefaultPublisher));
strcpy(me->version, "1.0.0");

Expand Down Expand Up @@ -293,6 +294,29 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
/*if (shortcut)
shortcutFree(&sc);*/
}

if (me->type == ENTRY_TYPE_THEME) {
config_t cfg = {0};
NightlyFox marked this conversation as resolved.
Show resolved Hide resolved
config_init(&cfg);
config_setting_t *themeInfo;
const char *name,
*author = textGetString(StrId_DefaultPublisher),
*version = "1.0.0";

if(config_read_file(&cfg, me->path)) {
themeInfo = config_lookup(&cfg, "themeInfo");
if (themeInfo != NULL) {
if(config_setting_lookup_string(themeInfo, "name", &name))
strncpy(me->name, name, sizeof(me->name)-1);
config_setting_lookup_string(themeInfo, "author", &author);
config_setting_lookup_string(themeInfo, "version", &version);
}
}

strncpy(me->author, author, sizeof(me->author)-1);
strncpy(me->version, version, sizeof(me->version)-1);
config_destroy(&cfg);
}

return true;
}
Expand Down
68 changes: 68 additions & 0 deletions common/menu-list.c
Expand Up @@ -34,6 +34,22 @@ static void menuAddEntry(menuEntry_s* me) {
m->nEntries ++;
}

static void menuAddEntryToFront(menuEntry_s* me) {
menu_s* m = &s_menu[!s_curMenu];
me->menu = m;
if (m->lastEntry)
{
me->next = m->firstEntry;
m->firstEntry = me;
} else
{
m->firstEntry = me;
m->lastEntry = me;
}
m->xPos = 0;
m->nEntries ++;
}

static void menuClear(void) {
menu_s* m = &s_menu[!s_curMenu];
menuEntry_s *cur, *next;
Expand Down Expand Up @@ -150,3 +166,55 @@ int menuScan(const char* target) {
return 0;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code using config_setting_lookup_string was wrong. In theme.h theme_t can you change buttonAText/buttonBText to char {name}[32];, and update code setting those fields to use this? strncpy({dest}, {input}, sizeof({dest})-1);

got it, fixed! no longer useds calloc :), got rid of themeExit functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got rid of the extra newline

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still has an extra newline here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yeah remove it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping^

int themeMenuScan(const char* target) {
menuClear();
if (chdir(target) < 0) return 1;
if (getcwd(s_menu[!s_curMenu].dirname, PATH_MAX+1) == NULL)
return 1;
DIR* dir;
struct dirent* dp;
char tmp_path[PATH_MAX+1];
dir = opendir(s_menu[!s_curMenu].dirname);
if (!dir) return 2;

while ((dp = readdir(dir)))
{
menuEntry_s* me = NULL;

bool shortcut = false;
if (dp->d_name[0]=='.')
continue;

memset(tmp_path, 0, sizeof(tmp_path));
snprintf(tmp_path, sizeof(tmp_path)-1, "%s/%s", s_menu[!s_curMenu].dirname, dp->d_name);

const char* ext = getExtension(dp->d_name);
if (strcasecmp(ext, ".cfg")==0)
me = menuCreateEntry(ENTRY_TYPE_THEME);

if (!me)
continue;

strncpy(me->path, tmp_path, sizeof(me->path)-1);
me->path[sizeof(me->path)-1] = 0;
if (menuEntryLoad(me, dp->d_name, shortcut))
menuAddEntry(me);
else
menuDeleteEntry(me);
}

closedir(dir);
menuSort();

menuEntry_s* me = menuCreateEntry(ENTRY_TYPE_THEME);

if(me) {
if(menuEntryLoad(me, "Default Theme", false));//Create Default theme Menu Entry
menuAddEntryToFront(me);
}
// Swap the menu and clear the previous menu
s_curMenu = !s_curMenu;
menuClear();
return 0;
}