Removed duplicate code and made missing settings better
I tried to remove as much duplicate code as I think I can Also missing settings in the hbtheme.cfg file will now be supplemented by the default values
This commit is contained in:
parent
43af1fc96f
commit
a3ee372649
186
common/theme.c
186
common/theme.c
@ -6,13 +6,44 @@
|
|||||||
#include "hbmenu_logo_light_bin.h"
|
#include "hbmenu_logo_light_bin.h"
|
||||||
#include "hbmenu_logo_dark_bin.h"
|
#include "hbmenu_logo_dark_bin.h"
|
||||||
|
|
||||||
color_t colorFromSetting(config_setting_t *rgba) {
|
bool colorFromSetting(config_setting_t *rgba, color_t *col) {
|
||||||
if(rgba==NULL)
|
if(rgba == NULL)
|
||||||
return MakeColor(128,0,128,255);
|
return false;
|
||||||
return MakeColor(config_setting_get_int_elem(rgba, 0), config_setting_get_int_elem(rgba, 1), config_setting_get_int_elem(rgba, 2), config_setting_get_int_elem(rgba, 3));
|
*col = MakeColor(config_setting_get_int_elem(rgba, 0), config_setting_get_int_elem(rgba, 1), config_setting_get_int_elem(rgba, 2), config_setting_get_int_elem(rgba, 3));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void themeStartup(ThemePreset preset) {
|
void themeStartup(ThemePreset preset) {
|
||||||
|
theme_t themeLight = (theme_t) {
|
||||||
|
.textColor = MakeColor(0, 0, 0, 255),
|
||||||
|
.frontWaveColor = MakeColor(100, 212, 250, 255),
|
||||||
|
.middleWaveColor = MakeColor(100, 153, 255, 255),
|
||||||
|
.backWaveColor = MakeColor(154, 171, 255, 255),
|
||||||
|
.backgroundColor = MakeColor(233, 236, 241, 255),
|
||||||
|
.highlightColor = MakeColor(91, 237, 224, 255),
|
||||||
|
.separatorColor = MakeColor(219, 218, 219, 255),
|
||||||
|
.enableWaveBlending = 0,
|
||||||
|
.buttonAText = "\uE0E0",
|
||||||
|
.buttonBText = "\uE0E1",
|
||||||
|
//.buttonAImage = button_a_light_bin,
|
||||||
|
//.buttonBImage = button_b_light_bin,
|
||||||
|
.hbmenuLogoImage = hbmenu_logo_light_bin
|
||||||
|
};
|
||||||
|
theme_t themeDark = (theme_t) {
|
||||||
|
.textColor = MakeColor(255, 255, 255, 255),
|
||||||
|
.frontWaveColor = MakeColor(96, 204, 204, 255),
|
||||||
|
.middleWaveColor = MakeColor(66, 154, 159, 255),
|
||||||
|
.backWaveColor = MakeColor(73, 103, 169, 255),
|
||||||
|
.backgroundColor = MakeColor(45, 45, 50, 255),
|
||||||
|
.highlightColor = MakeColor(91, 237, 224, 255),
|
||||||
|
.separatorColor = MakeColor(219, 218, 219, 255),
|
||||||
|
.enableWaveBlending = 0,
|
||||||
|
.buttonAText = "\uE0A0",
|
||||||
|
.buttonBText = "\uE0A1",
|
||||||
|
//.buttonAImage = button_a_dark_bin,
|
||||||
|
//.buttonBImage = button_b_dark_bin,
|
||||||
|
.hbmenuLogoImage = hbmenu_logo_dark_bin
|
||||||
|
};
|
||||||
config_t *cfg = NULL;
|
config_t *cfg = NULL;
|
||||||
cfg = (config_t *) malloc(sizeof(config_t));
|
cfg = (config_t *) malloc(sizeof(config_t));
|
||||||
config_init(cfg);
|
config_init(cfg);
|
||||||
@ -20,108 +51,81 @@ void themeStartup(ThemePreset preset) {
|
|||||||
color_t text, frontWave, middleWave, backWave, background, highlight, separator;
|
color_t text, frontWave, middleWave, backWave, background, highlight, separator;
|
||||||
int waveBlending;
|
int waveBlending;
|
||||||
const char *AText, *BText;
|
const char *AText, *BText;
|
||||||
bool good_cfg=false;
|
bool good_cfg=config_read_file(cfg, "/hbtheme.cfg");
|
||||||
switch (preset) {
|
switch (preset) {
|
||||||
case THEME_PRESET_LIGHT:
|
case THEME_PRESET_LIGHT:
|
||||||
if (config_read_file(cfg, "/hbtheme.cfg")) {
|
if (good_cfg) {
|
||||||
theme=config_lookup(cfg, "lightTheme");
|
theme=config_lookup(cfg, "lightTheme");
|
||||||
if (theme != NULL) {
|
if (theme != NULL) {
|
||||||
text = colorFromSetting(config_lookup(cfg, "lightTheme.textColor"));
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.textColor"), &text))
|
||||||
frontWave = colorFromSetting(config_lookup(cfg, "lightTheme.frontWaveColor"));
|
text = themeLight.textColor;
|
||||||
middleWave = colorFromSetting(config_lookup(cfg, "lightTheme.middleWaveColor"));
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.frontWaveColor"), &frontWave))
|
||||||
backWave = colorFromSetting(config_lookup(cfg, "lightTheme.backWaveColor"));
|
frontWave = themeLight.frontWaveColor;
|
||||||
background = colorFromSetting(config_lookup(cfg, "lightTheme.backgroundColor"));
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.middleWaveColor"), &middleWave))
|
||||||
highlight = colorFromSetting(config_lookup(cfg, "lightTheme.highlightColor"));
|
middleWave = themeLight.middleWaveColor;
|
||||||
separator = colorFromSetting(config_lookup(cfg, "lightTheme.separatorColor"));
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.backWaveColor"), &backWave))
|
||||||
good_cfg = config_setting_lookup_int(theme, "enableWaveBlending", &waveBlending);
|
backWave = themeLight.backWaveColor;
|
||||||
good_cfg = good_cfg && config_setting_lookup_string(theme, "buttonAText", &AText);
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.backgroundColor"), &background))
|
||||||
good_cfg = good_cfg && config_setting_lookup_string(theme, "buttonBText", &BText);
|
background = themeLight.backgroundColor;
|
||||||
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.highlightColor"), &highlight))
|
||||||
|
highlight = themeLight.highlightColor;
|
||||||
|
if (!colorFromSetting(config_lookup(cfg, "lightTheme.separatorColor"), &separator))
|
||||||
|
separator = themeLight.separatorColor;
|
||||||
|
} else {
|
||||||
|
themeCurrent=themeLight;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (good_cfg) {
|
|
||||||
themeCurrent = (theme_t) {
|
|
||||||
.textColor = text,
|
|
||||||
.frontWaveColor = frontWave,
|
|
||||||
.middleWaveColor = middleWave,
|
|
||||||
.backWaveColor = backWave,
|
|
||||||
.backgroundColor = background,
|
|
||||||
.highlightColor = highlight,
|
|
||||||
.separatorColor = separator,
|
|
||||||
.enableWaveBlending = waveBlending,
|
|
||||||
.buttonAText = AText,
|
|
||||||
.buttonBText = BText,
|
|
||||||
//.buttonAImage = button_a_light_bin,
|
|
||||||
//.buttonBImage = button_b_light_bin,
|
|
||||||
.hbmenuLogoImage = hbmenu_logo_light_bin
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
themeCurrent = (theme_t) {
|
themeCurrent=themeLight;
|
||||||
.textColor = MakeColor(0, 0, 0, 255),
|
|
||||||
.frontWaveColor = MakeColor(100, 212, 250, 255),
|
|
||||||
.middleWaveColor = MakeColor(100, 153, 255, 255),
|
|
||||||
.backWaveColor = MakeColor(154, 171, 255, 255),
|
|
||||||
.backgroundColor = MakeColor(233, 236, 241, 255),
|
|
||||||
.highlightColor = MakeColor(91, 237, 224, 255),
|
|
||||||
.separatorColor = MakeColor(219, 218, 219, 255),
|
|
||||||
.enableWaveBlending = 0,
|
|
||||||
.buttonAText = "\uE0E0",
|
|
||||||
.buttonBText = "\uE0E1",
|
|
||||||
//.buttonAImage = button_a_light_bin,
|
|
||||||
//.buttonBImage = button_b_light_bin,
|
|
||||||
.hbmenuLogoImage = hbmenu_logo_light_bin
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case THEME_PRESET_DARK:
|
case THEME_PRESET_DARK:
|
||||||
if (config_read_file(cfg, "/hbtheme.cfg")) {
|
if (good_cfg) {
|
||||||
theme=config_lookup(cfg, "darkTheme");
|
theme=config_lookup(cfg, "darkTheme");
|
||||||
if (theme != NULL) {
|
if (theme != NULL) {
|
||||||
text = colorFromSetting(config_lookup(cfg, "darkTheme.textColor"));
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.textColor"), &text))
|
||||||
frontWave = colorFromSetting(config_lookup(cfg, "darkTheme.frontWaveColor"));
|
text = themeDark.textColor;
|
||||||
middleWave = colorFromSetting(config_lookup(cfg, "darkTheme.middleWaveColor"));
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.frontWaveColor"), &frontWave))
|
||||||
backWave = colorFromSetting(config_lookup(cfg, "darkTheme.backWaveColor"));
|
frontWave = themeDark.frontWaveColor;
|
||||||
background = colorFromSetting(config_lookup(cfg, "darkTheme.backgroundColor"));
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.middleWaveColor"), &middleWave))
|
||||||
highlight = colorFromSetting(config_lookup(cfg, "darkTheme.highlightColor"));
|
middleWave = themeDark.middleWaveColor;
|
||||||
separator = colorFromSetting(config_lookup(cfg, "darkTheme.separatorColor"));
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.backWaveColor"), &backWave))
|
||||||
good_cfg = config_setting_lookup_int(theme, "enableWaveBlending", &waveBlending);
|
backWave = themeDark.backWaveColor;
|
||||||
good_cfg = good_cfg && config_setting_lookup_string(theme, "buttonAText", &AText);
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.backgroundColor"), &background))
|
||||||
good_cfg = good_cfg && config_setting_lookup_string(theme, "buttonBText", &BText);
|
background = themeDark.backgroundColor;
|
||||||
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.highlightColor"), &highlight))
|
||||||
|
highlight = themeDark.highlightColor;
|
||||||
|
if (!colorFromSetting(config_lookup(cfg, "darkTheme.separatorColor"), &separator))
|
||||||
|
separator = themeDark.separatorColor;
|
||||||
|
} else {
|
||||||
|
themeCurrent=themeDark;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (good_cfg) {
|
|
||||||
themeCurrent = (theme_t) {
|
|
||||||
.textColor = text,
|
|
||||||
.frontWaveColor = frontWave,
|
|
||||||
.middleWaveColor = middleWave,
|
|
||||||
.backWaveColor = backWave,
|
|
||||||
.backgroundColor = background,
|
|
||||||
.highlightColor = highlight,
|
|
||||||
.separatorColor = separator,
|
|
||||||
.enableWaveBlending = waveBlending,
|
|
||||||
.buttonAText = AText,
|
|
||||||
.buttonBText = BText,
|
|
||||||
//.buttonAImage = button_a_dark_bin,
|
|
||||||
//.buttonBImage = button_b_dark_bin,
|
|
||||||
.hbmenuLogoImage = hbmenu_logo_dark_bin
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
themeCurrent = (theme_t) {
|
themeCurrent=themeDark;
|
||||||
.textColor = MakeColor(255, 255, 255, 255),
|
|
||||||
.frontWaveColor = MakeColor(96, 204, 204, 255),
|
|
||||||
.middleWaveColor = MakeColor(66, 154, 159, 255),
|
|
||||||
.backWaveColor = MakeColor(73, 103, 169, 255),
|
|
||||||
.backgroundColor = MakeColor(45, 45, 50, 255),
|
|
||||||
.highlightColor = MakeColor(91, 237, 224, 255),
|
|
||||||
.separatorColor = MakeColor(219, 218, 219, 255),
|
|
||||||
.enableWaveBlending = 0,
|
|
||||||
.buttonAText = "\uE0A0",
|
|
||||||
.buttonBText = "\uE0A1",
|
|
||||||
//.buttonAImage = button_a_dark_bin,
|
|
||||||
//.buttonBImage = button_b_dark_bin,
|
|
||||||
.hbmenuLogoImage = hbmenu_logo_dark_bin
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (good_cfg){
|
||||||
|
if (!config_setting_lookup_int(theme, "enableWaveBlending", &waveBlending))
|
||||||
|
waveBlending = themeLight.enableWaveBlending;
|
||||||
|
if (!config_setting_lookup_string(theme, "buttonAText", &AText))
|
||||||
|
AText = themeLight.buttonAText;
|
||||||
|
if (!config_setting_lookup_string(theme, "buttonBText", &BText))
|
||||||
|
BText = themeDark.buttonBText;
|
||||||
|
themeCurrent = (theme_t) {
|
||||||
|
.textColor = text,
|
||||||
|
.frontWaveColor = frontWave,
|
||||||
|
.middleWaveColor = middleWave,
|
||||||
|
.backWaveColor = backWave,
|
||||||
|
.backgroundColor = background,
|
||||||
|
.highlightColor = highlight,
|
||||||
|
.separatorColor = separator,
|
||||||
|
.enableWaveBlending = waveBlending,
|
||||||
|
.buttonAText = AText,
|
||||||
|
.buttonBText = BText,
|
||||||
|
//.buttonAImage = button_a_dark_bin,
|
||||||
|
//.buttonBImage = button_b_dark_bin,
|
||||||
|
.hbmenuLogoImage = hbmenu_logo_dark_bin
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ typedef enum
|
|||||||
THEME_PRESET_DARK,
|
THEME_PRESET_DARK,
|
||||||
} ThemePreset;
|
} ThemePreset;
|
||||||
|
|
||||||
color_t colorFromSetting(config_setting_t *rgba);
|
bool colorFromSetting(config_setting_t *rgba, color_t *col);
|
||||||
|
|
||||||
void themeStartup(ThemePreset preset);
|
void themeStartup(ThemePreset preset);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user