From 29a36c865893798f8e61fe9936834a8c3cd5f64f Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Wed, 11 Oct 2023 00:43:56 -0500 Subject: [PATCH] Revived Fonts Viewer as an External app (in Utilities menu) (#1484) * Add files via upload * Moved Font Viewer to external app --- firmware/application/apps/ui_debug.cpp | 36 -------- firmware/application/apps/ui_debug.hpp | 11 --- firmware/application/external/external.cmake | 5 ++ firmware/application/external/external.ld | 7 ++ .../application/external/font_viewer/main.cpp | 82 ++++++++++++++++++ .../external/font_viewer/ui_font_viewer.cpp | 69 +++++++++++++++ .../external/font_viewer/ui_font_viewer.hpp | 51 +++++++++++ firmware/graphics/icon_font_viewer.png | Bin 0 -> 166 bytes 8 files changed, 214 insertions(+), 47 deletions(-) create mode 100644 firmware/application/external/font_viewer/main.cpp create mode 100644 firmware/application/external/font_viewer/ui_font_viewer.cpp create mode 100644 firmware/application/external/font_viewer/ui_font_viewer.hpp create mode 100644 firmware/graphics/icon_font_viewer.png diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index 0a45e15b..90869c5f 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -400,7 +400,6 @@ DebugMenuView::DebugMenuView(NavigationView& nav) { add_items({ {"Buttons Test", ui::Color::dark_cyan(), &bitmap_icon_controls, [&nav]() { nav.push(); }}, {"Debug Dump", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { portapack::persistent_memory::debug_dump(); }}, - //{"Fonts Viewer", ui::Color::dark_cyan(), &bitmap_icon_notepad, [&nav]() { nav.push(); }}, // temporarily disabled to conserve ROM space {"M0 Stack Dump", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { stack_dump(); }}, {"Memory", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push(); }}, {"P.Memory", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push(); }}, @@ -469,41 +468,6 @@ uint32_t DebugPmemView::registers_widget_feed(const size_t register_number) { return data.regfile[(page_size * page + register_number) / 4] >> (register_number % 4 * 8); } -/* DebugFontsView *******************************************************/ - -uint16_t DebugFontsView::display_font(Painter& painter, uint16_t y_offset, const Style* font_style, std::string_view font_name) { - auto char_width{font_style->font.char_width()}; - auto char_height{font_style->font.line_height()}; - auto cpl{((screen_width / char_width) - 6) & 0xF8}; // Display a multiple of 8 characters per line - uint16_t line_pos{y_offset}; - - painter.draw_string({0, y_offset}, *font_style, font_name); - - // Displaying ASCII+extended characters from 0x20 to 0xFF - for (uint8_t c = 0; c <= 0xDF; c++) { - line_pos = y_offset + ((c / cpl) + 2) * char_height; - - if ((c % cpl) == 0) - painter.draw_string({0, line_pos}, *font_style, "Ox" + to_string_hex(c + 0x20, 2)); - - painter.draw_char({((c % cpl) + 5) * char_width, line_pos}, *font_style, (char)(c + 0x20)); - } - - return line_pos + char_height; -} - -void DebugFontsView::paint(Painter& painter) { - int16_t line_pos; - - line_pos = display_font(painter, 32, &Styles::white, "Fixed 8x16"); - display_font(painter, line_pos + 16, &Styles::white_small, "Fixed 5x8"); -} - -DebugFontsView::DebugFontsView(NavigationView& nav) - : nav_{nav} { - set_focusable(true); -} - /* DebugScreenTest ****************************************************/ DebugScreenTest::DebugScreenTest(NavigationView& nav) diff --git a/firmware/application/apps/ui_debug.hpp b/firmware/application/apps/ui_debug.hpp index ed2b909a..e76f6808 100644 --- a/firmware/application/apps/ui_debug.hpp +++ b/firmware/application/apps/ui_debug.hpp @@ -310,17 +310,6 @@ class DebugPmemView : public View { uint32_t registers_widget_feed(const size_t register_number); }; -class DebugFontsView : public View { - public: - DebugFontsView(NavigationView& nav); - void paint(Painter& painter) override; - std::string title() const override { return "Fonts"; }; - - private: - uint16_t display_font(Painter& painter, uint16_t y_offset, const Style* font_style, std::string_view font_name); - NavigationView& nav_; -}; - class DebugScreenTest : public View { public: DebugScreenTest(NavigationView& nav); diff --git a/firmware/application/external/external.cmake b/firmware/application/external/external.cmake index 1dd3d696..795a0443 100644 --- a/firmware/application/external/external.cmake +++ b/firmware/application/external/external.cmake @@ -11,10 +11,15 @@ set(EXTCPPSRC #calculator external/calculator/main.cpp external/calculator/ui_calculator.cpp + + #font_viewer + external/font_viewer/main.cpp + external/font_viewer/ui_font_viewer.cpp ) set(EXTAPPLIST pacman afsk_rx calculator + font_viewer ) diff --git a/firmware/application/external/external.ld b/firmware/application/external/external.ld index 0e129d72..5d020f29 100644 --- a/firmware/application/external/external.ld +++ b/firmware/application/external/external.ld @@ -20,6 +20,7 @@ MEMORY ram_external_app_pacman (rwx) : org = 0xEEE90000, len = 32k ram_external_app_afsk_rx (rwx) : org = 0xEEEA0000, len = 32k ram_external_app_calculator (rwx) : org = 0xEEEB0000, len = 32k + ram_external_app_font_viewer(rwx) : org = 0xEEEC0000, len = 32k } SECTIONS @@ -41,4 +42,10 @@ SECTIONS KEEP(*(.external_app.app_calculator.application_information)); *(*ui*external_app*calculator*); } > ram_external_app_calculator + + .external_app_font_viewer : ALIGN(4) SUBALIGN(4) + { + KEEP(*(.external_app.app_font_viewer.application_information)); + *(*ui*external_app*font_viewer*); + } > ram_external_app_font_viewer } diff --git a/firmware/application/external/font_viewer/main.cpp b/firmware/application/external/font_viewer/main.cpp new file mode 100644 index 00000000..a275649b --- /dev/null +++ b/firmware/application/external/font_viewer/main.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2023 Mark Thompson + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "ui.hpp" +#include "ui_font_viewer.hpp" +#include "ui_navigation.hpp" +#include "external_app.hpp" + +namespace ui::external_app::font_viewer { +void initialize_app(ui::NavigationView& nav) { + nav.push(); +} +} // namespace ui::external_app::font_viewer + +extern "C" { + +__attribute__((section(".external_app.app_font_viewer.application_information"), used)) application_information_t _application_information_font_viewer = { + /*.memory_location = */ (uint8_t*)0x00000000, + /*.externalAppEntry = */ ui::external_app::font_viewer::initialize_app, + /*.header_version = */ CURRENT_HEADER_VERSION, + /*.app_version = */ VERSION_MD5, + + /*.app_name = */ "Font Viewer", + /*.bitmap_data = */ { + 0x00, + 0x00, + 0x10, + 0x08, + 0x10, + 0x08, + 0x38, + 0x08, + 0x28, + 0x08, + 0x6C, + 0x08, + 0x44, + 0x08, + 0xFE, + 0x78, + 0x82, + 0x88, + 0x83, + 0x89, + 0x01, + 0x89, + 0x01, + 0x79, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + }, + /*.icon_color = */ ui::Color::yellow().v, + /*.menu_location = */ app_location_t::UTILITIES, + + /*.m4_app_tag = portapack::spi_flash::image_tag_noop */ {'\0', '\0', '\0', '\0'}, + /*.m4_app_offset = */ 0x00000000, // will be filled at compile time +}; +} diff --git a/firmware/application/external/font_viewer/ui_font_viewer.cpp b/firmware/application/external/font_viewer/ui_font_viewer.cpp new file mode 100644 index 00000000..64be431e --- /dev/null +++ b/firmware/application/external/font_viewer/ui_font_viewer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 Mark Thompson + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "ui_font_viewer.hpp" + +#include "ui_font_fixed_8x16.hpp" +#include "ui_styles.hpp" +#include "ui_painter.hpp" + +#include "portapack.hpp" +using namespace portapack; +using namespace ui; + +namespace ui::external_app::font_viewer { + +/* DebugFontsView *******************************************************/ + +uint16_t DebugFontsView::display_font(Painter& painter, uint16_t y_offset, const Style* font_style, std::string_view font_name) { + auto char_width{font_style->font.char_width()}; + auto char_height{font_style->font.line_height()}; + auto cpl{((screen_width / char_width) - 6) & 0xF8}; // Display a multiple of 8 characters per line + uint16_t line_pos{y_offset}; + + painter.draw_string({0, y_offset}, *font_style, font_name); + + // Displaying ASCII+extended characters from 0x20 to 0xFF + for (uint8_t c = 0; c <= 0xDF; c++) { + line_pos = y_offset + ((c / cpl) + 2) * char_height; + + if ((c % cpl) == 0) + painter.draw_string({0, line_pos}, *font_style, "Ox" + to_string_hex(c + 0x20, 2)); + + painter.draw_char({((c % cpl) + 5) * char_width, line_pos}, *font_style, (char)(c + 0x20)); + } + + return line_pos + char_height; +} + +void DebugFontsView::paint(Painter& painter) { + int16_t line_pos; + + line_pos = display_font(painter, 32, &Styles::white, "Fixed 8x16"); + display_font(painter, line_pos + 16, &Styles::white_small, "Fixed 5x8"); +} + +DebugFontsView::DebugFontsView(NavigationView& nav) + : nav_{nav} { + set_focusable(true); +} + +} /* namespace ui::external_app::font_viewer */ diff --git a/firmware/application/external/font_viewer/ui_font_viewer.hpp b/firmware/application/external/font_viewer/ui_font_viewer.hpp new file mode 100644 index 00000000..72afcb58 --- /dev/null +++ b/firmware/application/external/font_viewer/ui_font_viewer.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 Mark Thompson + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __UI_DEBUG_H__ +#define __UI_DEBUG_H__ + +#include "ui.hpp" +#include "ui_widget.hpp" +#include "ui_painter.hpp" +#include "ui_menu.hpp" +#include "ui_navigation.hpp" + +#include +#include + +using namespace ui; + +namespace ui::external_app::font_viewer { + +class DebugFontsView : public View { + public: + DebugFontsView(NavigationView& nav); + void paint(Painter& painter) override; + std::string title() const override { return "Fonts"; }; + + private: + uint16_t display_font(Painter& painter, uint16_t y_offset, const Style* font_style, std::string_view font_name); + NavigationView& nav_; +}; + +} /* namespace ui::external_app::font_viewer */ + +#endif /*__UI_FONT_VIEWER_H__*/ diff --git a/firmware/graphics/icon_font_viewer.png b/firmware/graphics/icon_font_viewer.png new file mode 100644 index 0000000000000000000000000000000000000000..62eb3e119a696e92bb81f3a96c3e8a84e1a9e87b GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5M?jcysy3fAP%y&N z#WBR9_wK}ldoh#w;<Df90?O^b9 L^>bP0l+XkKE$%vt literal 0 HcmV?d00001