mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-10 05:59:08 -07:00
Asset Packs: Optimize icon loader (#164)
* Original pointer can be const * Back to const icons * Missed this one * Simpler string alloc * Single allocation and header struct for static icons * Shared allocation and meta struct for animated icons * Only try to load if dir exists * Restructure momentum lib * Use some internal headers * Swap icons at draw * Properly init and free, no more original in icon struct
This commit is contained in:
@@ -1,35 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <applications.h>
|
||||
#include <assets_icons.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <dolphin/dolphin_i.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <dolphin/helpers/dolphin_state.h>
|
||||
#include <expansion/expansion.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <assets_icons.h>
|
||||
#include <applications.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <lib/toolbox/value_index.h>
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
#include "scenes/momentum_app_scene.h"
|
||||
#include "dolphin/helpers/dolphin_state.h"
|
||||
#include "dolphin/dolphin.h"
|
||||
#include "dolphin/dolphin_i.h"
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/view.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include <lib/subghz/subghz_setting.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/value_index.h>
|
||||
#include <loader/loader_menu.h>
|
||||
#include <m-array.h>
|
||||
#include <momentum/asset_packs.h>
|
||||
#include <momentum/namespoof.h>
|
||||
#include <momentum/settings.h>
|
||||
#include <notification/notification_app.h>
|
||||
#include <power/power_service/power.h>
|
||||
#include <expansion/expansion.h>
|
||||
#include <rgb_backlight.h>
|
||||
#include <m-array.h>
|
||||
#include <momentum/namespoof.h>
|
||||
#include <momentum/momentum.h>
|
||||
#include <scenes/momentum_app_scene.h>
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
|
||||
ARRAY_DEF(CharList, char*)
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#include <furi_hal.h>
|
||||
#include <stdint.h>
|
||||
#include <u8g2_glue.h>
|
||||
#include <momentum/momentum.h>
|
||||
#include <momentum/asset_packs_i.h>
|
||||
#include <momentum/settings.h>
|
||||
|
||||
const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
|
||||
[FontPrimary] = {.leading_default = 12, .leading_min = 11, .height = 8, .descender = 2},
|
||||
@@ -137,8 +138,8 @@ size_t canvas_current_font_width(const Canvas* canvas) {
|
||||
const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font font) {
|
||||
furi_check(canvas);
|
||||
furi_check(font < FontTotalNumber);
|
||||
if(asset_packs.font_params[font]) {
|
||||
return asset_packs.font_params[font];
|
||||
if(asset_packs && asset_packs->font_params[font]) {
|
||||
return asset_packs->font_params[font];
|
||||
}
|
||||
return &canvas_font_params[font];
|
||||
}
|
||||
@@ -176,8 +177,8 @@ void canvas_invert_color(Canvas* canvas) {
|
||||
void canvas_set_font(Canvas* canvas, Font font) {
|
||||
furi_check(canvas);
|
||||
u8g2_SetFontMode(&canvas->fb, 1);
|
||||
if(asset_packs.fonts[font]) {
|
||||
u8g2_SetFont(&canvas->fb, asset_packs.fonts[font]);
|
||||
if(asset_packs && asset_packs->fonts[font]) {
|
||||
u8g2_SetFont(&canvas->fb, asset_packs->fonts[font]);
|
||||
return;
|
||||
}
|
||||
switch(font) {
|
||||
@@ -424,6 +425,7 @@ void canvas_draw_icon_ex(
|
||||
x += canvas->offset_x;
|
||||
y += canvas->offset_y;
|
||||
uint8_t* icon_data = NULL;
|
||||
icon = asset_packs_swap_icon(icon);
|
||||
compress_icon_decode(canvas->compress_icon, icon_get_frame_data(icon, 0), &icon_data);
|
||||
canvas_draw_u8g2_bitmap(
|
||||
&canvas->fb, x, y, icon_get_width(icon), icon_get_height(icon), icon_data, rotation);
|
||||
@@ -436,6 +438,7 @@ void canvas_draw_icon(Canvas* canvas, int32_t x, int32_t y, const Icon* icon) {
|
||||
x += canvas->offset_x;
|
||||
y += canvas->offset_y;
|
||||
uint8_t* icon_data = NULL;
|
||||
icon = asset_packs_swap_icon(icon);
|
||||
compress_icon_decode(canvas->compress_icon, icon_get_frame_data(icon, 0), &icon_data);
|
||||
canvas_draw_u8g2_bitmap(
|
||||
&canvas->fb, x, y, icon_get_width(icon), icon_get_height(icon), icon_data, IconRotation0);
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
#include "icon_i.h" // IWYU pragma: keep
|
||||
|
||||
#include <furi.h>
|
||||
#include <momentum/asset_packs_i.h>
|
||||
|
||||
IconAnimation* icon_animation_alloc(const Icon* icon) {
|
||||
furi_check(icon);
|
||||
|
||||
IconAnimation* instance = malloc(sizeof(IconAnimation));
|
||||
icon = asset_packs_swap_icon(icon);
|
||||
instance->icon = icon;
|
||||
instance->timer =
|
||||
furi_timer_alloc(icon_animation_timer_callback, FuriTimerTypePeriodic, instance);
|
||||
|
||||
@@ -14,6 +14,4 @@ struct Icon {
|
||||
const uint8_t frame_count;
|
||||
const uint8_t frame_rate;
|
||||
const uint8_t* const* frames;
|
||||
|
||||
Icon* original;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAINMENU_APPS_PATH CFG_PATH("mainmenu_apps.txt")
|
||||
|
||||
typedef struct LoaderMenu LoaderMenu;
|
||||
|
||||
LoaderMenu* loader_menu_alloc(void (*closed_cb)(void*), void* context, bool settings_only);
|
||||
|
||||
Reference in New Issue
Block a user