CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
RenderHelpers.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include <gfxfont.h>
7
9
10class Adafruit_GFX;
11class Gdey029T94;
12
13namespace cdc::ui::render {
14
15// Backwards-compatible aliases for the shared layout constants.
16// Prefer the canonical names in cdc::ui::layout for new code.
19
20void drawHeaderLeft(Gdey029T94* gfx, const char* title, int x, int y,
21 uint16_t width, int underlineOffset = 18);
22void drawHeaderCentered(Gdey029T94* gfx, const char* title, int y, uint16_t width);
23
24void drawFooterBar(Gdey029T94* gfx, uint16_t width, uint16_t height,
25 const char* prefix, const char* hint, bool force = false);
26
27void drawScrollIndicator(Gdey029T94* gfx, int x, int y, int listHeight,
28 uint16_t totalItems, uint16_t visibleItems,
29 uint16_t scrollPos);
30
31void drawDialogFrame(Gdey029T94* gfx, int x, int y, int w, int h);
32
41void printTruncated(Adafruit_GFX* gfx, const char* text, int maxWidthPx);
42
49uint8_t cp437ToLatin1(uint8_t c);
50
56void utf8ToCp437Inplace(char* buf);
57
59enum class DisplayTarget : uint8_t {
60 Cp437 = 0,
61 Latin1 = 1,
62};
63
81void decodeWebText(const char* in, char* out, size_t out_size,
83
90void drawCp437Text(Adafruit_GFX* gfx, const char* text);
91
103void drawText(Adafruit_GFX* gfx, const char* text, const GFXfont* font);
104
115void printText(Adafruit_GFX* gfx, const char* text);
116
131void measureText(Adafruit_GFX* gfx, const char* text, const GFXfont* font,
132 int16_t x0, int16_t y0, int16_t* x1, int16_t* y1,
133 uint16_t* w, uint16_t* h);
134
152const GFXfont* pickFontThatFits(Adafruit_GFX* gfx,
153 const char* text,
154 int maxWidthPx,
155 const GFXfont* const* candidates,
156 size_t count,
157 bool cp437 = false);
158
170void measureCp437Text(Adafruit_GFX* gfx, const char* text, int16_t x0, int16_t y0,
171 int16_t* x1, int16_t* y1, uint16_t* w, uint16_t* h);
172
179bool ditherOn(int16_t x, int16_t y, uint8_t shade);
180
186void fillRectDither(Adafruit_GFX* gfx, int16_t x, int16_t y, int16_t w, int16_t h,
187 uint8_t shade, uint16_t color);
188
190void fillCircleDither(Adafruit_GFX* gfx, int16_t cx, int16_t cy, int16_t r,
191 uint8_t shade, uint16_t color);
192
194void fillTriangleDither(Adafruit_GFX* gfx, int16_t x0, int16_t y0, int16_t x1, int16_t y1,
195 int16_t x2, int16_t y2, uint8_t shade, uint16_t color);
196
198struct BlitOpts {
199 const uint8_t* mask = nullptr;
200 bool opaque = false;
201 bool flipH = false;
202 bool flipV = false;
203 bool rot90 = false;
205 uint8_t scale = 1;
206 uint16_t srcX = 0;
207 uint16_t srcW = 0;
209 uint16_t srcSpan = 0;
211};
212
223void drawBitmapMasked(Adafruit_GFX* gfx, int16_t x, int16_t y,
224 const uint8_t* data, int16_t w, int16_t h,
225 const BlitOpts& opts, uint16_t fg, uint16_t bg);
226
227} // namespace cdc::ui::render
constexpr int SCROLL_INDICATOR_WIDTH
Scroll indicator column width in pixels.
constexpr int FOOTER_HEIGHT
Footer bar height in pixels (used by drawFooterBar).
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 CP4...
void drawFooterBar(Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force=false)
Draws footer bar with optional prefix and hint text.
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,...
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 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 drawDialogFrame(Gdey029T94 *gfx, int x, int y, int w, int h)
Draws a framed dialog box with double border.
void drawHeaderCentered(Gdey029T94 *gfx, const char *title, int y, uint16_t width)
Draws a centered header title.
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,...
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....
void utf8ToCp437Inplace(char *buf)
Decodes a UTF-8 string in place to CP437 single bytes. Truncates if the buffer is too small....
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 ...
void drawHeaderLeft(Gdey029T94 *gfx, const char *title, int x, int y, uint16_t width, int underlineOffset=18)
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....
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 ...
constexpr int SCROLL_INDICATOR_WIDTH
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 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 alre...
void printText(Adafruit_GFX *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
DisplayTarget
Display encoding targets for decodeWebText().
@ Cp437
GFX builtin glcdfont (default after setFont(nullptr)).
@ Latin1
FreeMonoBold*pt8b fonts (Latin-1 indexed, 0x20..0xFF).
constexpr int FOOTER_HEIGHT
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 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.
Options for drawBitmapMasked. Zero-init = plain transparent blit.
uint8_t scale
Integer upscale 1..4.
const uint8_t * mask
Mask plane (same layout) or null.
uint16_t srcX
Horizontal source window start.
bool opaque
Without a mask: unset bits paint bg.