Skip to content

Commit

Permalink
nyx: Refactor launch icon colorization
Browse files Browse the repository at this point in the history
The Switch and Payload icons will be colorized by default, because they are system icons.

Users can still replace them with icons named `icon_switch_custom.bmp` and `icon_payload_custom.bmp` that do not get colorized.
  • Loading branch information
CTCaer committed May 2, 2020
1 parent 54c36a7 commit 8edc997
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions nyx/README_RES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The background for Nyx, must be a 1280 x 720 32-bit BMP. Alpha blending is taken

The icons supported are 192 x 192 32-bit BMP. You can utilize transparency at will and make nice mixes with the button background.

Additionally, using the `icon={sd path}`, the icon will get colorized if the name ends in `_hue.bmp`. That only works nicely if the icon is a white layout with transparency.

The default system icons (`icon_switch.bmp` and `icon_payload.bmp`) can be replaced with white layouts that have transparency. They can also be replaced with normal icons if the following exist: `icon_switch_custom.bmp` or/and `icon_payload_custom.bmp`


## How to configure

Expand Down
38 changes: 30 additions & 8 deletions nyx/nyx_gui/frontend/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1503,13 +1503,23 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
launch_ctxt[btn_idx + 1] = boot_entry_label;
}

// Create colorized icon style based on its parrent style.
static lv_style_t img_style;
lv_style_copy(&img_style, &lv_style_plain);
img_style.image.color = lv_color_hsv_to_rgb(n_cfg.themecolor, 100, 100);
img_style.image.intense = LV_OPA_COVER;

// Parse ini boot entries and set buttons/icons.
char *tmp_path = malloc(1024);
u32 curr_btn_idx = 0; // Active buttons.
LIST_INIT(ini_sections);

if (sd_mount())
{
// Check if we use custom system icons.
bool icon_sw_custom = !f_stat("bootloader/res/icon_switch_custom.bmp", NULL);
bool icon_pl_custom = !f_stat("bootloader/res/icon_payload_custom.bmp", NULL);

// Choose what to parse.
bool ini_parse_success = false;
if (!more_cfg)
Expand Down Expand Up @@ -1539,6 +1549,7 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)

icon_path = NULL;
u32 payload = 0;
bool img_colorize = false;
lv_img_dsc_t *bmp = NULL;
lv_obj_t *img = NULL;

Expand Down Expand Up @@ -1568,32 +1579,43 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
if (!strcmp(ini_sec->name, "Lakka"))
bmp = icon_lakka;
else if (payload)
{
bmp = icon_payload;

if (!icon_pl_custom)
img_colorize = true;
}
}
}
else
{
bmp = bmp_to_lvimg_obj(icon_path);

// Check if colorization is enabled.
if (bmp && strlen(icon_path) > 8 && !memcmp(icon_path + strlen(icon_path) - 8, "_hue", 4))
img_colorize = true;
}

// Enable button.
lv_obj_set_opa_scale(launch_ctxt[curr_btn_idx], LV_OPA_COVER);

// Default to switch logo if no icon found at all.
if (!bmp)
{
bmp = icon_switch;

if (!icon_sw_custom)
img_colorize = true;
}

//Set icon.
if (bmp)
{
img = lv_img_create(launch_ctxt[curr_btn_idx], NULL);

if (icon_path && strlen(icon_path) > 13 && !memcmp(icon_path + strlen(icon_path) - 13, "_colorize", 9)) {
static lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.image.color = lv_color_hsv_to_rgb(n_cfg.themecolor, 100, 100);
style.image.intense = LV_OPA_COVER;
lv_img_set_style(img, &style);
}

if (img_colorize)
lv_img_set_style(img, &img_style);

lv_img_set_src(img, bmp);
}

Expand Down
14 changes: 12 additions & 2 deletions nyx/nyx_gui/nyx.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,18 @@ void nyx_init_load_res()
f_read(&fp, (void *)NYX_RES_ADDR, f_size(&fp), NULL);
f_close(&fp);

icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch.bmp");
icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload.bmp");
// If no custom switch icon exists, load normal.
if (f_stat("bootloader/res/icon_switch_custom.bmp", NULL))
icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch.bmp");
else
icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch_custom.bmp");

// If no custom payload icon exists, load normal.
if (f_stat("bootloader/res/icon_payload_custom.bmp", NULL))
icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload.bmp");
else
icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload_custom.bmp");

icon_lakka = bmp_to_lvimg_obj("bootloader/res/icon_lakka.bmp");
hekate_bg = bmp_to_lvimg_obj("bootloader/res/background.bmp");

Expand Down
Binary file modified nyx/resources/icon_payload.bmp
Binary file not shown.
Binary file removed nyx/resources/icon_payload_colorize.bmp
Binary file not shown.
Binary file modified nyx/resources/icon_switch.bmp
Binary file not shown.
Binary file removed nyx/resources/icon_switch_colorize.bmp
Binary file not shown.

0 comments on commit 8edc997

Please sign in to comment.