diff --git a/application.fam b/application.fam index 0df73cd7fc6..4d9fe46345a 100644 --- a/application.fam +++ b/application.fam @@ -15,7 +15,7 @@ App( ], stack_size=2 * 1024, order=20, - fap_version="2.23", + fap_version="2.3", fap_author="Alexander Kopachov (@akopachov)", fap_description="Software-based TOTP authenticator for Flipper Zero device", fap_weburl="https://github.com/akopachov/flipper-zero_authenticator", @@ -38,5 +38,8 @@ App( Lib( name="roll_value", ), + Lib( + name="fonts", + ), ], ) diff --git a/features_config.h b/features_config.h index c51a2b01ed6..1f1e77d8c76 100644 --- a/features_config.h +++ b/features_config.h @@ -34,22 +34,3 @@ #ifndef TOTP_TARGET_FIRMWARE #define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_OFFICIAL_STABLE #endif - -// List of available font for TOTP code -#define TOTP_FONT_MODENINE (1) -#define TOTP_FONT_REDHATMONO (2) -#define TOTP_FONT_BEDSTEAD (3) -#define TOTP_FONT_ZECTOR (4) -#define TOTP_FONT_712SERIF (5) -#define TOTP_FONT_GRAPH35PIX (6) -#define TOTP_FONT_KARMAFUTURE (7) -#define TOTP_FONT_FUNCLIMBING (8) -#define TOTP_FONT_DPCOMIC (9) -#define TOTP_FONT_PIXELFLAG (10) - -// End of list - -// Active font for TOTP codes -#ifndef TOTP_FONT -#define TOTP_FONT TOTP_FONT_MODENINE -#endif diff --git a/ui/fonts/712serif/712serif.c b/lib/fonts/712serif/712serif.c similarity index 99% rename from ui/fonts/712serif/712serif.c rename to lib/fonts/712serif/712serif.c index 0fe73378ce7..7d0b9f1e96e 100644 --- a/ui/fonts/712serif/712serif.c +++ b/lib/fonts/712serif/712serif.c @@ -931,6 +931,7 @@ const FONT_CHAR_INFO _712Serif_24ptDescriptors[] = { /* Font information for 7:12 Serif 24pt */ const FONT_INFO _712Serif_24ptFontInfo = { + "712 Serif", 14, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/712serif/712serif.h b/lib/fonts/712serif/712serif.h similarity index 100% rename from ui/fonts/712serif/712serif.h rename to lib/fonts/712serif/712serif.h diff --git a/lib/fonts/available_fonts.c b/lib/fonts/available_fonts.c new file mode 100644 index 00000000000..dd019a75881 --- /dev/null +++ b/lib/fonts/available_fonts.c @@ -0,0 +1,23 @@ +#include "available_fonts.h" +#include "712serif/712serif.h" +#include "bedstead/bedstead.h" +#include "dpcomic/dpcomic.h" +#include "funclimbing/funclimbing.h" +#include "graph35pix/graph35pix.h" +#include "karma_future/karma_future.h" +#include "mode_nine/mode_nine.h" +#include "pixelflag/pixelflag.h" +#include "redhat_mono/redhat_mono.h" +#include "zector/zector.h" + +const FONT_INFO* const available_fonts[AVAILABLE_FONTS_COUNT] = { + &modeNine_15ptFontInfo, + &_712Serif_24ptFontInfo, + &bedstead_17ptFontInfo, + &dPComic_18ptFontInfo, + &funclimbingDemo_18ptFontInfo, + &graph35pix_12ptFontInfo, + &karmaFuture_14ptFontInfo, + &pixelFlag_18ptFontInfo, + &redHatMono_16ptFontInfo, + &zector_18ptFontInfo}; diff --git a/lib/fonts/available_fonts.h b/lib/fonts/available_fonts.h new file mode 100644 index 00000000000..fd4b0c1da17 --- /dev/null +++ b/lib/fonts/available_fonts.h @@ -0,0 +1,7 @@ +#pragma once + +#include "font_info.h" + +#define AVAILABLE_FONTS_COUNT (10) + +extern const FONT_INFO* const available_fonts[AVAILABLE_FONTS_COUNT]; diff --git a/ui/fonts/bedstead/bedstead.c b/lib/fonts/bedstead/bedstead.c similarity index 99% rename from ui/fonts/bedstead/bedstead.c rename to lib/fonts/bedstead/bedstead.c index ec6680fabb7..6b23a39d479 100644 --- a/ui/fonts/bedstead/bedstead.c +++ b/lib/fonts/bedstead/bedstead.c @@ -1047,6 +1047,7 @@ const FONT_CHAR_INFO bedstead_17ptDescriptors[] = { /* Font information for Bedstead 17pt */ const FONT_INFO bedstead_17ptFontInfo = { + "Bedstead", 16, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/bedstead/bedstead.h b/lib/fonts/bedstead/bedstead.h similarity index 100% rename from ui/fonts/bedstead/bedstead.h rename to lib/fonts/bedstead/bedstead.h diff --git a/ui/fonts/dpcomic/dpcomic.c b/lib/fonts/dpcomic/dpcomic.c similarity index 99% rename from ui/fonts/dpcomic/dpcomic.c rename to lib/fonts/dpcomic/dpcomic.c index e9c5ea1deeb..7d215c273ef 100644 --- a/ui/fonts/dpcomic/dpcomic.c +++ b/lib/fonts/dpcomic/dpcomic.c @@ -1105,6 +1105,7 @@ const FONT_CHAR_INFO dPComic_18ptDescriptors[] = { /* Font information for DPComic 18pt */ const FONT_INFO dPComic_18ptFontInfo = { + "DP Comic", 17, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/dpcomic/dpcomic.h b/lib/fonts/dpcomic/dpcomic.h similarity index 100% rename from ui/fonts/dpcomic/dpcomic.h rename to lib/fonts/dpcomic/dpcomic.h diff --git a/ui/fonts/font_info.h b/lib/fonts/font_info.h similarity index 96% rename from ui/fonts/font_info.h rename to lib/fonts/font_info.h index 86c131ec9b8..b7bf6a045aa 100644 --- a/ui/fonts/font_info.h +++ b/lib/fonts/font_info.h @@ -14,11 +14,11 @@ typedef struct { // Describes a single font typedef struct { + const char* name; // Font name const uint8_t height; // height, in pages (8 pixels), of the font's characters const uint8_t startChar; // the first character in the font (e.g. in charInfo and data) const uint8_t endChar; // the last character in the font const uint8_t spacePixels; // number of pixels that a space character takes up const FONT_CHAR_INFO* charInfo; // pointer to array of char information const uint8_t* data; // pointer to generated array of character visual representation - } FONT_INFO; \ No newline at end of file diff --git a/ui/fonts/funclimbing/funclimbing.c b/lib/fonts/funclimbing/funclimbing.c similarity index 99% rename from ui/fonts/funclimbing/funclimbing.c rename to lib/fonts/funclimbing/funclimbing.c index d6b1a0c974a..4176e1f373e 100644 --- a/ui/fonts/funclimbing/funclimbing.c +++ b/lib/fonts/funclimbing/funclimbing.c @@ -1163,6 +1163,7 @@ const FONT_CHAR_INFO funclimbingDemo_18ptDescriptors[] = { /* Font information for fun climbing (Demo) 18pt */ const FONT_INFO funclimbingDemo_18ptFontInfo = { + "Fun Climbing", 18, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/funclimbing/funclimbing.h b/lib/fonts/funclimbing/funclimbing.h similarity index 100% rename from ui/fonts/funclimbing/funclimbing.h rename to lib/fonts/funclimbing/funclimbing.h diff --git a/ui/fonts/graph35pix/graph35pix.c b/lib/fonts/graph35pix/graph35pix.c similarity index 99% rename from ui/fonts/graph35pix/graph35pix.c rename to lib/fonts/graph35pix/graph35pix.c index fd93d4de9be..d4edf52e2dd 100644 --- a/ui/fonts/graph35pix/graph35pix.c +++ b/lib/fonts/graph35pix/graph35pix.c @@ -931,6 +931,7 @@ const FONT_CHAR_INFO graph35pix_12ptDescriptors[] = { /* Font information for Graph 35+ pix 12pt */ const FONT_INFO graph35pix_12ptFontInfo = { + "Graph 35pix", 14, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/graph35pix/graph35pix.h b/lib/fonts/graph35pix/graph35pix.h similarity index 100% rename from ui/fonts/graph35pix/graph35pix.h rename to lib/fonts/graph35pix/graph35pix.h diff --git a/ui/fonts/karma_future/karma_future.c b/lib/fonts/karma_future/karma_future.c similarity index 99% rename from ui/fonts/karma_future/karma_future.c rename to lib/fonts/karma_future/karma_future.c index ed620144148..23bebbc010f 100644 --- a/ui/fonts/karma_future/karma_future.c +++ b/lib/fonts/karma_future/karma_future.c @@ -1163,6 +1163,7 @@ const FONT_CHAR_INFO karmaFuture_14ptDescriptors[] = { /* Font information for Karma Future 14pt */ const FONT_INFO karmaFuture_14ptFontInfo = { + "Karma Future", 18, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/karma_future/karma_future.h b/lib/fonts/karma_future/karma_future.h similarity index 100% rename from ui/fonts/karma_future/karma_future.h rename to lib/fonts/karma_future/karma_future.h diff --git a/ui/fonts/mode_nine/mode_nine.c b/lib/fonts/mode_nine/mode_nine.c similarity index 99% rename from ui/fonts/mode_nine/mode_nine.c rename to lib/fonts/mode_nine/mode_nine.c index ca2191789fc..5d19f59aa9e 100644 --- a/ui/fonts/mode_nine/mode_nine.c +++ b/lib/fonts/mode_nine/mode_nine.c @@ -932,6 +932,7 @@ const FONT_CHAR_INFO modeNine_15ptDescriptors[] = { /* Font information for ModeNine 15pt */ const FONT_INFO modeNine_15ptFontInfo = { + "Mode Nine", 14, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/mode_nine/mode_nine.h b/lib/fonts/mode_nine/mode_nine.h similarity index 100% rename from ui/fonts/mode_nine/mode_nine.h rename to lib/fonts/mode_nine/mode_nine.h diff --git a/ui/fonts/pixelflag/pixelflag.c b/lib/fonts/pixelflag/pixelflag.c similarity index 99% rename from ui/fonts/pixelflag/pixelflag.c rename to lib/fonts/pixelflag/pixelflag.c index 2b7be9eb885..eacf36b2827 100644 --- a/ui/fonts/pixelflag/pixelflag.c +++ b/lib/fonts/pixelflag/pixelflag.c @@ -1105,6 +1105,7 @@ const FONT_CHAR_INFO pixelFlag_18ptDescriptors[] = { /* Font information for {PixelFlag} 18pt */ const FONT_INFO pixelFlag_18ptFontInfo = { + "Pixel Flag", 17, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/pixelflag/pixelflag.h b/lib/fonts/pixelflag/pixelflag.h similarity index 100% rename from ui/fonts/pixelflag/pixelflag.h rename to lib/fonts/pixelflag/pixelflag.h diff --git a/ui/fonts/redhat_mono/redhat_mono.c b/lib/fonts/redhat_mono/redhat_mono.c similarity index 99% rename from ui/fonts/redhat_mono/redhat_mono.c rename to lib/fonts/redhat_mono/redhat_mono.c index 77f639d4aa1..e39b6c81c3a 100644 --- a/ui/fonts/redhat_mono/redhat_mono.c +++ b/lib/fonts/redhat_mono/redhat_mono.c @@ -1048,6 +1048,7 @@ const FONT_CHAR_INFO redHatMono_16ptDescriptors[] = { /* Font information for Red Hat Mono 16pt */ const FONT_INFO redHatMono_16ptFontInfo = { + "RedHat Mono", 16, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/redhat_mono/redhat_mono.h b/lib/fonts/redhat_mono/redhat_mono.h similarity index 100% rename from ui/fonts/redhat_mono/redhat_mono.h rename to lib/fonts/redhat_mono/redhat_mono.h diff --git a/ui/fonts/zector/zector.c b/lib/fonts/zector/zector.c similarity index 99% rename from ui/fonts/zector/zector.c rename to lib/fonts/zector/zector.c index f49d8b30649..c94e455e44c 100644 --- a/ui/fonts/zector/zector.c +++ b/lib/fonts/zector/zector.c @@ -1047,6 +1047,7 @@ const FONT_CHAR_INFO zector_18ptDescriptors[] = { /* Font information for Zector 18pt */ const FONT_INFO zector_18ptFontInfo = { + "Zector", 16, /* Character height */ '-', /* Start character */ 'Y', /* End character */ diff --git a/ui/fonts/zector/zector.h b/lib/fonts/zector/zector.h similarity index 100% rename from ui/fonts/zector/zector.h rename to lib/fonts/zector/zector.h diff --git a/services/config/config.c b/services/config/config.c index fae6f3fd03a..5b7cd936eab 100644 --- a/services/config/config.c +++ b/services/config/config.c @@ -154,6 +154,9 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) { flipper_format_write_uint32( fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_METHOD, &tmp_uint32, 1); + tmp_uint32 = 0; + flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1); + if(!flipper_format_rewind(fff_data_file)) { totp_close_config_file(fff_data_file); FURI_LOG_E(LOGGING_TAG, "Rewind error"); @@ -257,6 +260,11 @@ bool totp_config_file_update_user_settings(const PluginState* plugin_state) { break; } + tmp_uint32 = plugin_state->active_font_index; + if(!flipper_format_insert_or_update_uint32(file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) { + break; + } + update_result = true; } while(false); @@ -405,6 +413,12 @@ bool totp_config_file_load(PluginState* const plugin_state) { plugin_state->automation_method = tmp_uint32; + if(!flipper_format_read_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) { + tmp_uint32 = 0; + } + + plugin_state->active_font_index = tmp_uint32; + plugin_state->config_file_context = malloc(sizeof(ConfigFileContext)); furi_check(plugin_state->config_file_context != NULL); plugin_state->config_file_context->storage = storage; diff --git a/services/config/constants.h b/services/config/constants.h index 3a33c80b393..ba6658fb5b0 100644 --- a/services/config/constants.h +++ b/services/config/constants.h @@ -4,7 +4,7 @@ #define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator") #define CONFIG_FILE_HEADER "Flipper TOTP plugin config file" -#define CONFIG_FILE_ACTUAL_VERSION (5) +#define CONFIG_FILE_ACTUAL_VERSION (6) #define TOTP_CONFIG_KEY_TIMEZONE "Timezone" #define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName" @@ -18,3 +18,4 @@ #define TOTP_CONFIG_KEY_PINSET "PinIsSet" #define TOTP_CONFIG_KEY_NOTIFICATION_METHOD "NotificationMethod" #define TOTP_CONFIG_KEY_AUTOMATION_METHOD "AutomationMethod" +#define TOTP_CONFIG_KEY_FONT "Font" diff --git a/services/config/migrations/common_migration.c b/services/config/migrations/common_migration.c index 8c7c6267366..e8537da0b1b 100644 --- a/services/config/migrations/common_migration.c +++ b/services/config/migrations/common_migration.c @@ -58,6 +58,16 @@ bool totp_config_migrate_to_latest( flipper_format_rewind(fff_backup_data_file); + if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_FONT, temp_str)) { + flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_FONT, temp_str); + } else { + uint32_t default_font_index = 0; + flipper_format_write_uint32( + fff_data_file, TOTP_CONFIG_KEY_FONT, &default_font_index, 1); + } + + flipper_format_rewind(fff_backup_data_file); + while(true) { if(!flipper_format_read_string( fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) { diff --git a/types/plugin_state.h b/types/plugin_state.h index 19ea72a4b74..87ed51abd5a 100644 --- a/types/plugin_state.h +++ b/types/plugin_state.h @@ -105,4 +105,9 @@ typedef struct { * @brief IDLE timeout context */ IdleTimeoutContext* idle_timeout_context; + + /** + * @brief Font index to be used to draw TOTP token + */ + uint8_t active_font_index; } PluginState; diff --git a/ui/canvas_extensions.c b/ui/canvas_extensions.c new file mode 100644 index 00000000000..d3f044b7753 --- /dev/null +++ b/ui/canvas_extensions.c @@ -0,0 +1,33 @@ +#include "canvas_extensions.h" + +void canvas_draw_str_ex( + Canvas* canvas, + uint8_t x, + uint8_t y, + const char* text, + size_t text_length, + const FONT_INFO* const font) { + const char* p_ch = text; + char ch; + size_t i = 0; + uint8_t offset_x = x; + uint8_t char_width = font->charInfo[0].width; + uint8_t offset_x_inc = char_width + font->spacePixels; + while(i < text_length && (ch = *p_ch) != 0) { + if(ch >= font->startChar && ch <= font->endChar) { + uint8_t char_index = ch - font->startChar; + canvas_draw_xbm( + canvas, + offset_x, + y, + char_width, + font->height, + &font->data[font->charInfo[char_index].offset]); + } + + offset_x += offset_x_inc; + + p_ch++; + i++; + } +} \ No newline at end of file diff --git a/ui/canvas_extensions.h b/ui/canvas_extensions.h new file mode 100644 index 00000000000..ab55191400c --- /dev/null +++ b/ui/canvas_extensions.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include + +void canvas_draw_str_ex( + Canvas* canvas, + uint8_t x, + uint8_t y, + const char* text, + size_t text_length, + const FONT_INFO* const font); \ No newline at end of file diff --git a/ui/fonts/active_font.h b/ui/fonts/active_font.h deleted file mode 100644 index 82baae5ab24..00000000000 --- a/ui/fonts/active_font.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include "../../features_config.h" -#include "font_info.h" - -#if TOTP_FONT == TOTP_FONT_MODENINE -#include "mode_nine/mode_nine.h" -#define TOTP_CODE_FONT_INFO modeNine_15ptFontInfo -#elif TOTP_FONT == TOTP_FONT_REDHATMONO -#include "redhat_mono/redhat_mono.h" -#define TOTP_CODE_FONT_INFO redHatMono_16ptFontInfo -#elif TOTP_FONT == TOTP_FONT_BEDSTEAD -#include "bedstead/bedstead.h" -#define TOTP_CODE_FONT_INFO bedstead_17ptFontInfo -#elif TOTP_FONT == TOTP_FONT_ZECTOR -#include "zector/zector.h" -#define TOTP_CODE_FONT_INFO zector_18ptFontInfo -#elif TOTP_FONT == TOTP_FONT_712SERIF -#include "712serif/712serif.h" -#define TOTP_CODE_FONT_INFO _712Serif_24ptFontInfo -#elif TOTP_FONT == TOTP_FONT_GRAPH35PIX -#include "graph35pix/graph35pix.h" -#define TOTP_CODE_FONT_INFO graph35pix_12ptFontInfo -#elif TOTP_FONT == TOTP_FONT_KARMAFUTURE -#include "karma_future/karma_future.h" -#define TOTP_CODE_FONT_INFO karmaFuture_14ptFontInfo -#elif TOTP_FONT == TOTP_FONT_FUNCLIMBING -#include "funclimbing/funclimbing.h" -#define TOTP_CODE_FONT_INFO funclimbingDemo_18ptFontInfo -#elif TOTP_FONT == TOTP_FONT_DPCOMIC -#include "dpcomic/dpcomic.h" -#define TOTP_CODE_FONT_INFO dPComic_18ptFontInfo -#elif TOTP_FONT == TOTP_FONT_PIXELFLAG -#include "pixelflag/pixelflag.h" -#define TOTP_CODE_FONT_INFO pixelFlag_18ptFontInfo -#else -#error TOTP Font is not set or unknown -#endif \ No newline at end of file diff --git a/ui/scenes/app_settings/totp_app_settings.c b/ui/scenes/app_settings/totp_app_settings.c index 54659946d24..7575d0f2df9 100644 --- a/ui/scenes/app_settings/totp_app_settings.c +++ b/ui/scenes/app_settings/totp_app_settings.c @@ -1,6 +1,8 @@ #include "totp_app_settings.h" #include #include +#include +#include "../../canvas_extensions.h" #include "../../ui_controls.h" #include "../../common_dialogs.h" #include "../../scene_director.h" @@ -14,17 +16,20 @@ #include "../../../workers/bt_type_code/bt_type_code.h" #endif -char* YES_NO_LIST[] = {"NO", "YES"}; -char* ON_OFF_LIST[] = {"OFF", "ON"}; +static const char* YES_NO_LIST[] = {"NO", "YES"}; +static const char* ON_OFF_LIST[] = {"OFF", "ON"}; +static const char* FONT_TEST_STR = "0123BCD"; +static const uint8_t FONT_TEST_STR_LENGTH = 7; typedef enum { HoursInput, MinutesInput, - Sound, - Vibro, - BadUsb, + FontSelect, + SoundSwitch, + VibroSwitch, + BadUsbSwitch, #ifdef TOTP_BADBT_TYPE_ENABLED - BadBt, + BadBtSwitch, #endif ConfirmButton } Control; @@ -40,6 +45,7 @@ typedef struct { #endif uint8_t y_offset; Control selected_control; + uint8_t active_font; } SceneState; void totp_scene_app_settings_activate(PluginState* plugin_state) { @@ -57,6 +63,7 @@ void totp_scene_app_settings_activate(PluginState* plugin_state) { #ifdef TOTP_BADBT_TYPE_ENABLED scene_state->badbt_enabled = plugin_state->automation_method & AutomationMethodBadBt; #endif + scene_state->active_font = plugin_state->active_font_index; } static void two_digit_to_str(int8_t num, char* str) { @@ -109,65 +116,88 @@ void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plu SCREEN_HEIGHT - 5 - scene_state->y_offset, &I_totp_arrow_bottom_10x5); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Font"); + canvas_set_font(canvas, FontSecondary); + + const FONT_INFO* const font = available_fonts[scene_state->active_font]; + ui_control_select_render( + canvas, + 0, + 74 - scene_state->y_offset, + SCREEN_WIDTH, + font->name, + scene_state->selected_control == FontSelect); + + uint8_t font_x_offset = + SCREEN_WIDTH_CENTER - + (((font->charInfo[0].width + font->spacePixels) * FONT_TEST_STR_LENGTH) >> 1); + uint8_t font_y_offset = 108 - scene_state->y_offset - (font->height >> 1); + canvas_draw_str_ex( + canvas, font_x_offset, font_y_offset, FONT_TEST_STR, FONT_TEST_STR_LENGTH, font); + + canvas_draw_icon( + canvas, SCREEN_WIDTH_CENTER - 5, 123 - scene_state->y_offset, &I_totp_arrow_bottom_10x5); + canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned( - canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications"); + canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications"); canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 0, 81 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:"); + canvas_draw_str_aligned(canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:"); ui_control_select_render( canvas, 36, - 74 - scene_state->y_offset, + 138 - scene_state->y_offset, SCREEN_WIDTH - 36, YES_NO_LIST[scene_state->notification_sound], - scene_state->selected_control == Sound); + scene_state->selected_control == SoundSwitch); - canvas_draw_str_aligned(canvas, 0, 99 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:"); + canvas_draw_str_aligned(canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:"); ui_control_select_render( canvas, 36, - 92 - scene_state->y_offset, + 156 - scene_state->y_offset, SCREEN_WIDTH - 36, YES_NO_LIST[scene_state->notification_vibro], - scene_state->selected_control == Vibro); + scene_state->selected_control == VibroSwitch); canvas_draw_icon( - canvas, SCREEN_WIDTH_CENTER - 5, 123 - scene_state->y_offset, &I_totp_arrow_bottom_10x5); + canvas, SCREEN_WIDTH_CENTER - 5, 187 - scene_state->y_offset, &I_totp_arrow_bottom_10x5); canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned( - canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Automation"); + canvas, 0, 192 - scene_state->y_offset, AlignLeft, AlignTop, "Automation"); canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "BadUSB:"); + canvas, 0, 209 - scene_state->y_offset, AlignLeft, AlignTop, "BadUSB:"); ui_control_select_render( canvas, 36, - 138 - scene_state->y_offset, + 202 - scene_state->y_offset, SCREEN_WIDTH - 36, ON_OFF_LIST[scene_state->badusb_enabled], - scene_state->selected_control == BadUsb); + scene_state->selected_control == BadUsbSwitch); #ifdef TOTP_BADBT_TYPE_ENABLED - canvas_draw_str_aligned(canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "BadBT:"); + canvas_draw_str_aligned(canvas, 0, 227 - scene_state->y_offset, AlignLeft, AlignTop, "BadBT:"); ui_control_select_render( canvas, 36, - 156 - scene_state->y_offset, + 220 - scene_state->y_offset, SCREEN_WIDTH - 36, ON_OFF_LIST[scene_state->badbt_enabled], - scene_state->selected_control == BadBt); + scene_state->selected_control == BadBtSwitch); #endif ui_control_button_render( canvas, SCREEN_WIDTH_CENTER - 24, #ifdef TOTP_BADBT_TYPE_ENABLED - 178 - scene_state->y_offset, + 242 - scene_state->y_offset, #else - 165 - scene_state->y_offset, + 229 - scene_state->y_offset, #endif 48, 13, @@ -192,10 +222,12 @@ bool totp_scene_app_settings_handle_event( HoursInput, ConfirmButton, RollOverflowBehaviorStop); - if(scene_state->selected_control > Vibro) { - scene_state->y_offset = 128; + if(scene_state->selected_control > VibroSwitch) { + scene_state->y_offset = SCREEN_HEIGHT * 3; + } else if(scene_state->selected_control > FontSelect) { + scene_state->y_offset = SCREEN_HEIGHT * 2; } else if(scene_state->selected_control > MinutesInput) { - scene_state->y_offset = 64; + scene_state->y_offset = SCREEN_HEIGHT; } else { scene_state->y_offset = 0; } @@ -207,10 +239,12 @@ bool totp_scene_app_settings_handle_event( HoursInput, ConfirmButton, RollOverflowBehaviorStop); - if(scene_state->selected_control > Vibro) { - scene_state->y_offset = 128; + if(scene_state->selected_control > VibroSwitch) { + scene_state->y_offset = SCREEN_HEIGHT * 3; + } else if(scene_state->selected_control > FontSelect) { + scene_state->y_offset = SCREEN_HEIGHT * 2; } else if(scene_state->selected_control > MinutesInput) { - scene_state->y_offset = 64; + scene_state->y_offset = SCREEN_HEIGHT; } else { scene_state->y_offset = 0; } @@ -222,15 +256,22 @@ bool totp_scene_app_settings_handle_event( } else if(scene_state->selected_control == MinutesInput) { totp_roll_value_uint8_t( &scene_state->tz_offset_minutes, 15, 0, 45, RollOverflowBehaviorRoll); - } else if(scene_state->selected_control == Sound) { + } else if(scene_state->selected_control == FontSelect) { + totp_roll_value_uint8_t( + &scene_state->active_font, + 1, + 0, + AVAILABLE_FONTS_COUNT - 1, + RollOverflowBehaviorRoll); + } else if(scene_state->selected_control == SoundSwitch) { scene_state->notification_sound = !scene_state->notification_sound; - } else if(scene_state->selected_control == Vibro) { + } else if(scene_state->selected_control == VibroSwitch) { scene_state->notification_vibro = !scene_state->notification_vibro; - } else if(scene_state->selected_control == BadUsb) { + } else if(scene_state->selected_control == BadUsbSwitch) { scene_state->badusb_enabled = !scene_state->badusb_enabled; } #ifdef TOTP_BADBT_TYPE_ENABLED - else if(scene_state->selected_control == BadBt) { + else if(scene_state->selected_control == BadBtSwitch) { scene_state->badbt_enabled = !scene_state->badbt_enabled; } #endif @@ -242,15 +283,22 @@ bool totp_scene_app_settings_handle_event( } else if(scene_state->selected_control == MinutesInput) { totp_roll_value_uint8_t( &scene_state->tz_offset_minutes, -15, 0, 45, RollOverflowBehaviorRoll); - } else if(scene_state->selected_control == Sound) { + } else if(scene_state->selected_control == FontSelect) { + totp_roll_value_uint8_t( + &scene_state->active_font, + -1, + 0, + AVAILABLE_FONTS_COUNT - 1, + RollOverflowBehaviorRoll); + } else if(scene_state->selected_control == SoundSwitch) { scene_state->notification_sound = !scene_state->notification_sound; - } else if(scene_state->selected_control == Vibro) { + } else if(scene_state->selected_control == VibroSwitch) { scene_state->notification_vibro = !scene_state->notification_vibro; - } else if(scene_state->selected_control == BadUsb) { + } else if(scene_state->selected_control == BadUsbSwitch) { scene_state->badusb_enabled = !scene_state->badusb_enabled; } #ifdef TOTP_BADBT_TYPE_ENABLED - else if(scene_state->selected_control == BadBt) { + else if(scene_state->selected_control == BadBtSwitch) { scene_state->badbt_enabled = !scene_state->badbt_enabled; } #endif @@ -281,6 +329,8 @@ bool totp_scene_app_settings_handle_event( AutomationMethodNone; #endif + plugin_state->active_font_index = scene_state->active_font; + if(!totp_config_file_update_user_settings(plugin_state)) { totp_dialogs_config_updating_error(plugin_state); return false; diff --git a/ui/scenes/generate_token/totp_scene_generate_token.c b/ui/scenes/generate_token/totp_scene_generate_token.c index 51779c1754e..0a0c8373a58 100644 --- a/ui/scenes/generate_token/totp_scene_generate_token.c +++ b/ui/scenes/generate_token/totp_scene_generate_token.c @@ -3,7 +3,9 @@ #include #include #include +#include #include "totp_scene_generate_token.h" +#include "../../canvas_extensions.h" #include "../../../types/token_info.h" #include "../../../types/common.h" #include "../../constants.h" @@ -16,7 +18,6 @@ #ifdef TOTP_BADBT_TYPE_ENABLED #include "../../../workers/bt_type_code/bt_type_code.h" #endif -#include "../../fonts/active_font.h" #define PROGRESS_BAR_MARGIN (3) #define PROGRESS_BAR_HEIGHT (4) @@ -26,7 +27,6 @@ typedef struct { uint8_t progress_bar_width; uint8_t code_total_length; uint8_t code_offset_x; - uint8_t code_offset_x_inc; uint8_t code_offset_y; } UiPrecalculatedDimensions; @@ -38,6 +38,7 @@ typedef struct { FuriMutex* last_code_update_sync; TotpGenerateCodeWorkerContext* generate_code_worker_context; UiPrecalculatedDimensions ui_precalculated_dimensions; + const FONT_INFO* active_font; } SceneState; static const NotificationSequence* @@ -141,24 +142,14 @@ static void draw_totp_code(Canvas* const canvas, const PluginState* const plugin const TokenInfoIteratorContext* iterator_context = totp_config_get_token_iterator_context(plugin_state); uint8_t code_length = totp_token_info_iterator_get_current_token(iterator_context)->digits; - uint8_t offset_x = scene_state->ui_precalculated_dimensions.code_offset_x; - uint8_t char_width = TOTP_CODE_FONT_INFO.charInfo[0].width; - uint8_t offset_x_inc = scene_state->ui_precalculated_dimensions.code_offset_x_inc; - for(uint8_t i = 0; i < code_length; i++) { - char ch = scene_state->last_code[i]; - if(ch >= TOTP_CODE_FONT_INFO.startChar && ch <= TOTP_CODE_FONT_INFO.endChar) { - uint8_t char_index = ch - TOTP_CODE_FONT_INFO.startChar; - canvas_draw_xbm( - canvas, - offset_x, - scene_state->ui_precalculated_dimensions.code_offset_y, - char_width, - TOTP_CODE_FONT_INFO.height, - &TOTP_CODE_FONT_INFO.data[TOTP_CODE_FONT_INFO.charInfo[char_index].offset]); - } - offset_x += offset_x_inc; - } + canvas_draw_str_ex( + canvas, + scene_state->ui_precalculated_dimensions.code_offset_x, + scene_state->ui_precalculated_dimensions.code_offset_y, + scene_state->last_code, + code_length, + scene_state->active_font); } static void on_new_token_code_generated(bool time_left, void* context) { @@ -171,16 +162,15 @@ static void on_new_token_code_generated(bool time_left, void* context) { SceneState* scene_state = plugin_state->current_scene_state; const TokenInfo* current_token = totp_token_info_iterator_get_current_token(iterator_context); + const FONT_INFO* const font = scene_state->active_font; - uint8_t char_width = TOTP_CODE_FONT_INFO.charInfo[0].width; + uint8_t char_width = font->charInfo[0].width; scene_state->ui_precalculated_dimensions.code_total_length = - current_token->digits * (char_width + TOTP_CODE_FONT_INFO.spacePixels); + current_token->digits * (char_width + font->spacePixels); scene_state->ui_precalculated_dimensions.code_offset_x = (SCREEN_WIDTH - scene_state->ui_precalculated_dimensions.code_total_length) >> 1; - scene_state->ui_precalculated_dimensions.code_offset_x_inc = - char_width + TOTP_CODE_FONT_INFO.spacePixels; scene_state->ui_precalculated_dimensions.code_offset_y = - SCREEN_HEIGHT_CENTER - (TOTP_CODE_FONT_INFO.height >> 1); + SCREEN_HEIGHT_CENTER - (font->height >> 1); if(time_left) { notification_message( @@ -213,6 +203,8 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) { scene_state->last_code, TokenDigitsCountMax + 1, scene_state->last_code_update_sync); } + scene_state->active_font = available_fonts[plugin_state->active_font_index]; + #ifdef TOTP_BADBT_TYPE_ENABLED if(plugin_state->automation_method & AutomationMethodBadBt) {