mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-20 00:48:11 -07:00
Add asset packs font support
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
#define TAG "XtremeAssets"
|
||||
|
||||
#define ICONS_FMT XTREME_ASSETS_PATH "/%s/Icons/%s"
|
||||
#define FONTS_FMT XTREME_ASSETS_PATH "/%s/Fonts/%s.u8f"
|
||||
|
||||
XtremeAssets xtreme_assets = {
|
||||
.is_nsfw = false,
|
||||
.fonts = {NULL},
|
||||
};
|
||||
|
||||
void load_icon_animated(const Icon* replace, const char* name, FuriString* path, File* file) {
|
||||
@@ -105,6 +107,29 @@ void free_icon(const Icon* icon) {
|
||||
free(frames);
|
||||
}
|
||||
|
||||
void load_font(FontSwap font, const char* name, FuriString* path, File* file) {
|
||||
furi_string_printf(path, FONTS_FMT, xtreme_settings.asset_pack, name);
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
uint64_t size = storage_file_size(file);
|
||||
uint8_t* swap = malloc(size);
|
||||
|
||||
if(storage_file_read(file, swap, size) == size) {
|
||||
xtreme_assets.fonts[font] = swap;
|
||||
} else {
|
||||
free(swap);
|
||||
}
|
||||
}
|
||||
storage_file_close(file);
|
||||
}
|
||||
|
||||
static const char* font_names[] = {
|
||||
[FontSwapPrimary] = "Primary",
|
||||
[FontSwapSecondary] = "Secondary",
|
||||
[FontSwapKeyboard] = "Keyboard",
|
||||
[FontSwapBigNumbers] = "BigNumbers",
|
||||
[FontSwapBatteryPercent] = "BatteryPercent",
|
||||
};
|
||||
|
||||
void XTREME_ASSETS_LOAD() {
|
||||
const char* pack = xtreme_settings.asset_pack;
|
||||
xtreme_assets.is_nsfw = !strncmp(pack, "NSFW", strlen("NSFW"));
|
||||
@@ -128,6 +153,10 @@ void XTREME_ASSETS_LOAD() {
|
||||
}
|
||||
}
|
||||
|
||||
for(FontSwap font = 0; font < FontSwapCount; font++) {
|
||||
load_font(font, font_names[font], p, f);
|
||||
}
|
||||
|
||||
storage_file_free(f);
|
||||
}
|
||||
furi_string_free(p);
|
||||
@@ -140,4 +169,11 @@ void XTREME_ASSETS_FREE() {
|
||||
free_icon(ICON_PATHS[i].icon);
|
||||
}
|
||||
}
|
||||
|
||||
for(FontSwap font = 0; font < FontSwapCount; font++) {
|
||||
if(xtreme_assets.fonts[font] != NULL) {
|
||||
free(xtreme_assets.fonts[font]);
|
||||
xtreme_assets.fonts[font] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +89,18 @@ typedef struct {
|
||||
UARTChannel uart_general_channel;
|
||||
} XtremeSettings;
|
||||
|
||||
typedef enum {
|
||||
FontSwapPrimary,
|
||||
FontSwapSecondary,
|
||||
FontSwapKeyboard,
|
||||
FontSwapBigNumbers,
|
||||
FontSwapBatteryPercent,
|
||||
FontSwapCount,
|
||||
} FontSwap;
|
||||
|
||||
typedef struct {
|
||||
bool is_nsfw; // TODO: replace with packs text support
|
||||
uint8_t* fonts[FontSwapCount];
|
||||
} XtremeAssets;
|
||||
|
||||
void XTREME_SETTINGS_LOAD();
|
||||
|
||||
Reference in New Issue
Block a user