|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Classes | |
| struct | BlitOpts |
| Options for drawBitmapMasked. Zero-init = plain transparent blit. More... | |
Enumerations | |
| enum class | DisplayTarget : uint8_t { Cp437 = 0 , Latin1 = 1 } |
| Display encoding targets for decodeWebText(). More... | |
Functions | |
| void | drawHeaderLeft (Gdey029T94 *gfx, const char *title, int x, int y, uint16_t width, int underlineOffset=18) |
| void | drawHeaderCentered (Gdey029T94 *gfx, const char *title, int y, uint16_t width) |
| Draws a centered header title. | |
| void | drawFooterBar (Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force) |
| Draws footer bar with optional prefix and hint text. | |
| void | drawScrollIndicator (Gdey029T94 *gfx, int x, int y, int listHeight, uint16_t totalItems, uint16_t visibleItems, uint16_t scrollPos) |
| Draws scroll arrows and scrollbar thumb. | |
| void | drawDialogFrame (Gdey029T94 *gfx, int x, int y, int w, int h) |
| Draws a framed dialog box with double border. | |
| void | printTruncated (Adafruit_GFX *gfx, const char *text, int maxWidthPx) |
| Print text at the current cursor, truncated with an ellipsis to fit maxWidthPx. Caller must have already called setCursor and setTextColor/setTextSize. Adafruit-GFX text wrap should be off. | |
| uint8_t | cp437ToLatin1 (uint8_t c) |
| Maps a CP437 byte to the equivalent Latin-1 byte for use with Unicode/Latin-1 indexed GFX fonts (e.g. FreeMonoBold*pt8b). | |
| void | utf8ToCp437Inplace (char *buf) |
| Decodes a UTF-8 string in place to CP437 single bytes. Truncates if the buffer is too small. Unmapped codepoints are dropped silently. | |
| void | decodeWebText (const char *in, char *out, size_t out_size, DisplayTarget target=DisplayTarget::Cp437) |
| Normalises a web payload for display: HTML named/numeric entities decode first, then UTF-8 multibyte sequences collapse into the single-byte layout expected by the target font. | |
| void | drawCp437Text (Adafruit_GFX *gfx, const char *text) |
| Prints a CP437 string by mapping each byte to Latin-1 before drawing. Use with TTF-derived GFX fonts (range 0x20..0xFF) that expect Latin-1 indices. | |
| void | drawText (Adafruit_GFX *gfx, const char *text, const GFXfont *font) |
Draws CP437-encoded text correctly for the given font: the built-in glcdfont (font == nullptr) is CP437-indexed and receives the bytes raw; TTF-derived GFX fonts are Latin-1-indexed and receive a per-byte CP437->Latin1 mapping. This is the single point where the in-memory CP437 canonical form is adapted to the active font's index space. The caller must have set font on gfx and positioned the cursor. | |
| void | printText (Adafruit_GFX *gfx, const char *text) |
| Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte. | |
| void | measureText (Adafruit_GFX *gfx, const char *text, const GFXfont *font, int16_t x0, int16_t y0, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) |
Measures CP437 text exactly as drawText would render it with font, so width-based layout (centering, fitting, truncation) matches the drawn glyphs. | |
| const GFXfont * | pickFontThatFits (Adafruit_GFX *gfx, const char *text, int maxWidthPx, const GFXfont *const *candidates, size_t count, bool cp437=false) |
Picks the largest font from candidates whose rendered width of text fits within maxWidthPx. Candidates are evaluated in array order; pass them sorted from largest to smallest so the first match is the biggest font that still fits. | |
| void | measureCp437Text (Adafruit_GFX *gfx, const char *text, int16_t x0, int16_t y0, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) |
| Measures a CP437 string using the current font (via Latin-1 mapping). | |
| bool | ditherOn (int16_t x, int16_t y, uint8_t shade) |
| True when the ordered-dither matrix inks pixel (x, y) for shade. | |
| void | fillRectDither (Adafruit_GFX *gfx, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t shade, uint16_t color) |
| Fills a rectangle with an ordered-dither fake-grey pattern. | |
| void | fillCircleDither (Adafruit_GFX *gfx, int16_t cx, int16_t cy, int16_t r, uint8_t shade, uint16_t color) |
| Dithered filled circle; see fillRectDither. | |
| void | fillTriangleDither (Adafruit_GFX *gfx, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t shade, uint16_t color) |
| Dithered filled triangle; see fillRectDither. | |
| void | drawBitmapMasked (Adafruit_GFX *gfx, int16_t x, int16_t y, const uint8_t *data, int16_t w, int16_t h, const BlitOpts &opts, uint16_t fg, uint16_t bg) |
| Blit a packed 1-bpp bitmap with optional mask plane, flipping, 90-degree rotation, integer scaling and a horizontal source window. | |
Variables | |
| constexpr int | FOOTER_HEIGHT = cdc::ui::layout::FOOTER_HEIGHT |
| constexpr int | SCROLL_INDICATOR_WIDTH = cdc::ui::layout::SCROLL_INDICATOR_WIDTH |
RenderHelpers
Shared rendering utilities for common UI chrome and dialogs.
|
strong |
Display encoding targets for decodeWebText().
| Enumerator | |
|---|---|
| Cp437 | GFX builtin glcdfont (default after setFont(nullptr)). |
| Latin1 | FreeMonoBold*pt8b fonts (Latin-1 indexed, 0x20..0xFF). |
Definition at line 59 of file RenderHelpers.h.
| uint8_t cdc::ui::render::cp437ToLatin1 | ( | uint8_t | c | ) |
Maps a CP437 byte to the equivalent Latin-1 byte for use with Unicode/Latin-1 indexed GFX fonts (e.g. FreeMonoBold*pt8b).
Maps a CP437 byte to the equivalent Latin-1 byte for use with Latin-1 indexed GFX fonts (TTF-derived range 0x20..0xFF). ASCII (<0x80) and untracked codes pass through unchanged.
| c | CP437 byte value. |
Definition at line 218 of file RenderHelpers.cpp.
Referenced by drawCp437Text(), and measureCp437Text().
| void cdc::ui::render::decodeWebText | ( | const char * | in, |
| char * | out, | ||
| size_t | out_size, | ||
| DisplayTarget | target = DisplayTarget::Cp437 ) |
Normalises a web payload for display: HTML named/numeric entities decode first, then UTF-8 multibyte sequences collapse into the single-byte layout expected by the target font.
target picks the output codepage:
Output is always NUL-terminated. Unmapped codepoints are dropped. in and out must not alias.
| in | Source string (UTF-8, optionally containing HTML entities). |
| out | Destination buffer. |
| out_size | Capacity of out in bytes (including the terminator). |
| target | Encoding target. Defaults to CP437. |
Definition at line 395 of file RenderHelpers.cpp.
References Latin1, and utf8ToCp437Inplace().
Referenced by host_str_to_display(), and cdc::plugin_manager::toDisplay().
| bool cdc::ui::render::ditherOn | ( | int16_t | x, |
| int16_t | y, | ||
| uint8_t | shade ) |
True when the ordered-dither matrix inks pixel (x, y) for shade.
| x | Pixel column. |
| y | Pixel row. |
| shade | Grey level 0 (white) .. 255 (black), quantised to 64 levels. |
Definition at line 532 of file RenderHelpers.cpp.
Referenced by fillCircleDither(), fillRectDither(), and fillTriangleDither().
| void cdc::ui::render::drawBitmapMasked | ( | Adafruit_GFX * | gfx, |
| int16_t | x, | ||
| int16_t | y, | ||
| const uint8_t * | data, | ||
| int16_t | w, | ||
| int16_t | h, | ||
| const BlitOpts & | opts, | ||
| uint16_t | fg, | ||
| uint16_t | bg ) |
Blit a packed 1-bpp bitmap with optional mask plane, flipping, 90-degree rotation, integer scaling and a horizontal source window.
Rows are byte-padded, MSB first (the surface/QR/image convention). Without a mask, set bits paint fg and unset bits are transparent unless opts.opaque, in which case they paint bg. With a mask, only pixels whose mask bit is set are painted (data bit picks fg / bg), which allows drawing white pixels without making the whole rectangle opaque.
Definition at line 546 of file RenderHelpers.cpp.
References cdc::ui::render::BlitOpts::flipH, cdc::ui::render::BlitOpts::flipV, cdc::ui::render::BlitOpts::mask, cdc::ui::render::BlitOpts::opaque, cdc::ui::render::BlitOpts::rot90, cdc::ui::render::BlitOpts::scale, cdc::ui::scale, cdc::ui::render::BlitOpts::srcSpan, cdc::ui::render::BlitOpts::srcW, and cdc::ui::render::BlitOpts::srcX.
Referenced by host_surface_draw_sprite().
| void cdc::ui::render::drawCp437Text | ( | Adafruit_GFX * | gfx, |
| const char * | text ) |
Prints a CP437 string by mapping each byte to Latin-1 before drawing. Use with TTF-derived GFX fonts (range 0x20..0xFF) that expect Latin-1 indices.
| gfx | Target display. |
| text | CP437-encoded null-terminated string. |
Definition at line 421 of file RenderHelpers.cpp.
References cp437ToLatin1().
Referenced by drawText().
| void cdc::ui::render::drawDialogFrame | ( | Gdey029T94 * | gfx, |
| int | x, | ||
| int | y, | ||
| int | w, | ||
| int | h ) |
Draws a framed dialog box with double border.
| gfx | Display drawing context. |
| x | Left position. |
| y | Top position. |
| w | Frame width. |
| h | Frame height. |
Definition at line 205 of file RenderHelpers.cpp.
Referenced by cdc::ui::BlePairingPromptView::render(), cdc::ui::ConfirmView::render(), cdc::ui::ContextMenuView::render(), cdc::ui::MessageBox::render(), and cdc::ui::ToastView::render().
| void cdc::ui::render::drawFooterBar | ( | Gdey029T94 * | gfx, |
| uint16_t | width, | ||
| uint16_t | height, | ||
| const char * | prefix, | ||
| const char * | hint, | ||
| bool | force ) |
Draws footer bar with optional prefix and hint text.
| gfx | Display drawing context. |
| width | Display width. |
| height | Display height. |
| prefix | Optional prefix text. |
| hint | Optional hint text. |
| force | Draw even if prefix/hint are empty. |
Definition at line 118 of file RenderHelpers.cpp.
References FOOTER_HEIGHT.
Referenced by cdc::ui::BlePairingView::render(), cdc::ui::CanvasView::render(), cdc::ui::ColorPickerView::render(), cdc::ui::DateInputView::render(), cdc::ui::ImageView::render(), cdc::ui::InfoView::render(), cdc::ui::ListView::render(), cdc::ui::MarkdownView::render(), cdc::ui::PasswordT9View::render(), cdc::ui::PinChangeView::render(), cdc::ui::PinEntryView::render(), cdc::ui::SliderView::render(), cdc::ui::T9InputView::render(), and cdc::ui::TimeInputView::render().
| void cdc::ui::render::drawHeaderCentered | ( | Gdey029T94 * | gfx, |
| const char * | title, | ||
| int | y, | ||
| uint16_t | width ) |
Draws a centered header title.
| gfx | Display drawing context. |
| title | Title text. |
| y | Header text Y position. |
| width | Total layout width. |
Definition at line 98 of file RenderHelpers.cpp.
Referenced by cdc::ui::BlePairingView::render(), cdc::ui::DateInputView::render(), cdc::ui::PinChangeView::render(), cdc::ui::PinEntryView::render(), cdc::ui::SliderView::render(), and cdc::ui::TimeInputView::render().
| void cdc::ui::render::drawHeaderLeft | ( | Gdey029T94 * | gfx, |
| const char * | title, | ||
| int | x, | ||
| int | y, | ||
| uint16_t | width, | ||
| int | underlineOffset = 18 ) |
Definition at line 79 of file RenderHelpers.cpp.
Referenced by cdc::ui::CanvasView::render(), cdc::ui::InfoView::render(), cdc::ui::ListView::render(), cdc::ui::MarkdownView::render(), cdc::ui::PasswordT9View::render(), and cdc::ui::T9InputView::render().
| void cdc::ui::render::drawScrollIndicator | ( | Gdey029T94 * | gfx, |
| int | x, | ||
| int | y, | ||
| int | listHeight, | ||
| uint16_t | totalItems, | ||
| uint16_t | visibleItems, | ||
| uint16_t | scrollPos ) |
Draws scroll arrows and scrollbar thumb.
| gfx | Display drawing context. |
| x | Indicator X position. |
| y | Indicator Y position. |
| listHeight | Height of the scrollable list area. |
| totalItems | Total item count. |
| visibleItems | Number of visible items. |
| scrollPos | Current scroll offset. |
Definition at line 148 of file RenderHelpers.cpp.
References SCROLL_INDICATOR_WIDTH.
Referenced by cdc::ui::InfoView::render(), cdc::ui::ListView::render(), and cdc::ui::MarkdownView::render().
| void cdc::ui::render::drawText | ( | Adafruit_GFX * | gfx, |
| const char * | text, | ||
| const GFXfont * | font ) |
Draws CP437-encoded text correctly for the given font: the built-in glcdfont (font == nullptr) is CP437-indexed and receives the bytes raw; TTF-derived GFX fonts are Latin-1-indexed and receive a per-byte CP437->Latin1 mapping. This is the single point where the in-memory CP437 canonical form is adapted to the active font's index space. The caller must have set font on gfx and positioned the cursor.
| gfx | Target display. |
| text | CP437-encoded null-terminated string. |
| font | Active font (nullptr for the built-in glcdfont). |
Definition at line 428 of file RenderHelpers.cpp.
References drawCp437Text().
Referenced by host_surface_draw_text(), host_surface_draw_text_aligned(), cdc::ui::CanvasView::marquee(), cdc::ui::LockScreenView::render(), and cdc::ui::MarkdownView::render().
| void cdc::ui::render::fillCircleDither | ( | Adafruit_GFX * | gfx, |
| int16_t | cx, | ||
| int16_t | cy, | ||
| int16_t | r, | ||
| uint8_t | shade, | ||
| uint16_t | color ) |
Dithered filled circle; see fillRectDither.
Definition at line 600 of file RenderHelpers.cpp.
References ditherOn().
Referenced by host_surface_draw_circle().
| void cdc::ui::render::fillRectDither | ( | Adafruit_GFX * | gfx, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | w, | ||
| int16_t | h, | ||
| uint8_t | shade, | ||
| uint16_t | color ) |
Fills a rectangle with an ordered-dither fake-grey pattern.
| gfx | Target drawing context. |
| color | Ink color for dithered-on pixels. |
Definition at line 537 of file RenderHelpers.cpp.
References ditherOn().
Referenced by host_surface_draw_rect().
| void cdc::ui::render::fillTriangleDither | ( | Adafruit_GFX * | gfx, |
| int16_t | x0, | ||
| int16_t | y0, | ||
| int16_t | x1, | ||
| int16_t | y1, | ||
| int16_t | x2, | ||
| int16_t | y2, | ||
| uint8_t | shade, | ||
| uint16_t | color ) |
Dithered filled triangle; see fillRectDither.
Definition at line 613 of file RenderHelpers.cpp.
References ditherOn().
Referenced by host_surface_draw_triangle().
| void cdc::ui::render::measureCp437Text | ( | Adafruit_GFX * | gfx, |
| const char * | text, | ||
| int16_t | x0, | ||
| int16_t | y0, | ||
| int16_t * | x1, | ||
| int16_t * | y1, | ||
| uint16_t * | w, | ||
| uint16_t * | h ) |
Measures a CP437 string using the current font (via Latin-1 mapping).
| gfx | Target display. |
| text | CP437-encoded null-terminated string. |
| x0 | Starting x position for measurement. |
| y0 | Starting y position for measurement. |
| x1 | Output: top-left x of the rendered bounds. |
| y1 | Output: top-left y of the rendered bounds. |
| w | Output: width of the rendered text. |
| h | Output: height of the rendered text. |
Definition at line 499 of file RenderHelpers.cpp.
References cp437ToLatin1().
Referenced by measureText(), and pickFontThatFits().
| void cdc::ui::render::measureText | ( | Adafruit_GFX * | gfx, |
| const char * | text, | ||
| const GFXfont * | font, | ||
| int16_t | x0, | ||
| int16_t | y0, | ||
| int16_t * | x1, | ||
| int16_t * | y1, | ||
| uint16_t * | w, | ||
| uint16_t * | h ) |
Measures CP437 text exactly as drawText would render it with font, so width-based layout (centering, fitting, truncation) matches the drawn glyphs.
| gfx | Target display. |
| text | CP437-encoded null-terminated string. |
| font | Active font (nullptr for the built-in glcdfont). |
| x0 | Starting x for measurement. |
| y0 | Starting y for measurement. |
| x1 | Output: top-left x of the rendered bounds. |
| y1 | Output: top-left y of the rendered bounds. |
| w | Output: rendered width. |
| h | Output: rendered height. |
Definition at line 448 of file RenderHelpers.cpp.
References measureCp437Text().
Referenced by host_surface_draw_text_aligned(), host_surface_measure_text(), cdc::ui::CanvasView::marquee(), and cdc::ui::LockScreenView::render().
| const GFXfont * cdc::ui::render::pickFontThatFits | ( | Adafruit_GFX * | gfx, |
| const char * | text, | ||
| int | maxWidthPx, | ||
| const GFXfont *const * | candidates, | ||
| size_t | count, | ||
| bool | cp437 = false ) |
Picks the largest font from candidates whose rendered width of text fits within maxWidthPx. Candidates are evaluated in array order; pass them sorted from largest to smallest so the first match is the biggest font that still fits.
| gfx | Target display. Its current font is overwritten while measuring and restored to the selected font on return. |
| text | Null-terminated text to measure. |
| maxWidthPx | Pixel budget that the rendered text must stay below. |
| candidates | Array of GFX font pointers. nullptr entries select the built-in 6x8 font. |
| count | Number of entries in candidates. |
| cp437 | If true, measure via measureCp437Text() (CP437->Latin1 mapping); otherwise use Adafruit-GFX getTextBounds() directly. |
Definition at line 466 of file RenderHelpers.cpp.
References measureCp437Text().
Referenced by host_text_pick_font_that_fits(), and cdc::ui::LockScreenView::render().
| void cdc::ui::render::printText | ( | Adafruit_GFX * | gfx, |
| const char * | text ) |
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
Use this instead of gfx->print(const char*) for any user/i18n string: the CalEPD Epd::print(const std::string&) overload assumes UTF-8 and adds 64 to bytes 0x84..0xBE, corrupting CP437 umlauts (ae 0x84 -> 0xC4 etc.). This forces the built-in font and writes each byte straight through, bypassing that.
| gfx | Display drawing context. |
| text | CP437-encoded null-terminated string. |
Definition at line 442 of file RenderHelpers.cpp.
Referenced by host_display_draw_text(), cdc::mod_2fa::OathCodeView::render(), cdc::ui::BlePairingView::render(), cdc::ui::ColorPickerView::render(), cdc::ui::ConfirmView::render(), cdc::ui::ContextMenuView::render(), cdc::ui::ImageView::render(), cdc::ui::ListView::render(), cdc::ui::LockScreenView::render(), cdc::ui::MessageBox::render(), cdc::ui::PasswordT9View::render(), cdc::ui::PinChangeView::render(), cdc::ui::PinEntryView::render(), cdc::ui::QRCodeView::render(), cdc::ui::T9InputView::render(), cdc::ui::renderBleRow(), and cdc::ui::renderWifiRow().
| void cdc::ui::render::printTruncated | ( | Adafruit_GFX * | gfx, |
| const char * | text, | ||
| int | maxWidthPx ) |
Print text at the current cursor, truncated with an ellipsis to fit maxWidthPx. Caller must have already called setCursor and setTextColor/setTextSize. Adafruit-GFX text wrap should be off.
Draws a left-aligned header with optional underline.
| gfx | Display drawing context. |
| text | Null-terminated text. |
| maxWidthPx | Maximum width in pixels. |
| gfx | Display drawing context. |
| title | Optional title text. |
| x | Header text X position. |
| y | Header text Y position. |
| width | Width used for underline. |
| underlineOffset | Vertical offset for underline. |
Definition at line 40 of file RenderHelpers.cpp.
Referenced by cdc::ui::BlePairingView::render(), and cdc::ui::ToastView::render().
| void cdc::ui::render::utf8ToCp437Inplace | ( | char * | buf | ) |
Decodes a UTF-8 string in place to CP437 single bytes. Truncates if the buffer is too small. Unmapped codepoints are dropped silently.
| buf | Mutable null-terminated UTF-8 buffer; written back as CP437. |
Definition at line 357 of file RenderHelpers.cpp.
References cdc::core::cp437::fromUtf8().
Referenced by decodeWebText().
|
constexpr |
Definition at line 17 of file RenderHelpers.h.
Referenced by drawFooterBar().
|
constexpr |
Definition at line 18 of file RenderHelpers.h.
Referenced by drawScrollIndicator().