CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
host_api_canvas.cpp
Go to the documentation of this file.
1
8
12#include "cdc_views/Fonts.h"
14#include "cdc_hal/IDisplay.h"
15#include "host_str_conv.h"
16#include <goodisplay/gdey029T94.h>
17#include <cstring>
18#include <string>
19
20namespace {
21
22cdc::ui::CanvasView* canvas()
23{
25}
26
27} // namespace
28
29extern "C" {
30
31int host_view_canvas_push(const char* title, uint32_t key_action_id,
32 uint32_t widget_action_id)
33{
35 .pushCanvas(title, key_action_id, widget_action_id);
36}
37
38int host_view_canvas_get_body_size(uint16_t* w, uint16_t* h)
39{
40 auto* c = canvas();
41 if (!c || !w || !h) return HOST_ERR_NOT_FOUND;
42 c->getBodySize(w, h);
43 return HOST_OK;
44}
45
50
52{
54}
55
57{
58 auto* c = canvas();
59 if (!c) return HOST_ERR_NOT_FOUND;
60 if (flags & ~static_cast<uint32_t>(HOST_CANVAS_CLEAR_KEEP_SPRITES)) {
62 }
63 c->clearBody((flags & HOST_CANVAS_CLEAR_KEEP_SPRITES) != 0);
64 return HOST_OK;
65}
66
68{
69 auto* c = canvas();
70 if (!c) return HOST_ERR_NOT_FOUND;
71 c->setTextSize(size);
72 return HOST_OK;
73}
74
76{
77 auto* c = canvas();
78 if (!c) return HOST_ERR_NOT_FOUND;
79 c->setTextInverted(inverted);
80 return HOST_OK;
81}
82
84{
85 auto* c = canvas();
86 if (!c) return HOST_ERR_NOT_FOUND;
87 c->setShade(shade);
88 return HOST_OK;
89}
90
91int host_view_canvas_set_font(uint8_t font_id)
92{
93 auto* c = canvas();
94 if (!c) return HOST_ERR_NOT_FOUND;
95 if (font_id >= HOST_FONT_COUNT) return HOST_ERR_INVALID_ARG;
96 c->setFontId(font_id);
97 return HOST_OK;
98}
99
100int host_text_pick_font_that_fits(const char* text, int16_t max_width_px,
101 const uint8_t* candidates, uint32_t count,
102 uint8_t* out_font_id)
103{
104 if (!text || !candidates || !out_font_id || count == 0) {
106 }
107 auto* display = cdc::hal::getDisplayInstance();
108 if (!display) return HOST_ERR_NOT_FOUND;
109 auto* gfx = static_cast<Gdey029T94*>(display->getNativeHandle());
110 if (!gfx) return HOST_ERR_NOT_FOUND;
111
112 std::string cp = cdc::plugin_manager::toDisplay(text);
113 const GFXfont* candFonts[HOST_FONT_COUNT];
114 if (count > HOST_FONT_COUNT) count = HOST_FONT_COUNT;
115 for (uint32_t i = 0; i < count; ++i) {
116 candFonts[i] = cdc::ui::getGfxFont(candidates[i]);
117 }
118 const GFXfont* picked = cdc::ui::render::pickFontThatFits(
119 gfx, cp.c_str(), max_width_px, candFonts, count, false);
120
121 uint8_t pickedId = candidates[count - 1];
122 for (uint32_t i = 0; i < count; ++i) {
123 if (candFonts[i] == picked) {
124 pickedId = candidates[i];
125 break;
126 }
127 }
128 *out_font_id = pickedId;
129 return HOST_OK;
130}
131
132int host_view_canvas_draw_text(int16_t x, int16_t y, const char* text)
133{
134 auto* c = canvas();
135 if (!c) return HOST_ERR_NOT_FOUND;
136 c->drawText(x, y, cdc::plugin_manager::toDisplay(text).c_str());
137 return HOST_OK;
138}
139
140int host_view_canvas_draw_text_aligned(int16_t x, int16_t y, int16_t w,
141 const char* text, uint8_t align)
142{
143 auto* c = canvas();
144 if (!c) return HOST_ERR_NOT_FOUND;
145 c->drawTextAligned(x, y, w, cdc::plugin_manager::toDisplay(text).c_str(), align);
146 return HOST_OK;
147}
148
149int host_view_canvas_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, bool filled)
150{
151 auto* c = canvas();
152 if (!c) return HOST_ERR_NOT_FOUND;
153 c->drawRect(x, y, w, h, filled);
154 return HOST_OK;
155}
156
157int host_view_canvas_draw_pixel(int16_t x, int16_t y)
158{
159 auto* c = canvas();
160 if (!c) return HOST_ERR_NOT_FOUND;
161 c->drawPixel(x, y);
162 return HOST_OK;
163}
164
165int host_view_canvas_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
166{
167 auto* c = canvas();
168 if (!c) return HOST_ERR_NOT_FOUND;
169 c->drawLine(x0, y0, x1, y1);
170 return HOST_OK;
171}
172
173int host_view_canvas_draw_circle(int16_t x, int16_t y, int16_t r, bool filled)
174{
175 auto* c = canvas();
176 if (!c) return HOST_ERR_NOT_FOUND;
177 c->drawCircle(x, y, r, filled);
178 return HOST_OK;
179}
180
181int host_view_canvas_draw_triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
182 int16_t x2, int16_t y2, bool filled)
183{
184 auto* c = canvas();
185 if (!c) return HOST_ERR_NOT_FOUND;
186 c->drawTriangle(x0, y0, x1, y1, x2, y2, filled);
187 return HOST_OK;
188}
189
190int host_view_canvas_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h,
191 int16_t r, bool filled)
192{
193 auto* c = canvas();
194 if (!c) return HOST_ERR_NOT_FOUND;
195 c->drawRoundRect(x, y, w, h, r, filled);
196 return HOST_OK;
197}
198
199int host_view_canvas_draw_bitmap(int16_t x, int16_t y, int16_t w, int16_t h,
200 const uint8_t* data, uint32_t len)
201{
202 auto* c = canvas();
203 if (!c) return HOST_ERR_NOT_FOUND;
204 if (!data) return HOST_ERR_INVALID_ARG;
205 c->drawBitmap(x, y, w, h, data, len);
206 return HOST_OK;
207}
208
209int host_view_canvas_hline(int16_t x, int16_t y, int16_t w)
210{
211 auto* c = canvas();
212 if (!c) return HOST_ERR_NOT_FOUND;
213 c->drawHLine(x, y, w);
214 return HOST_OK;
215}
216
217int host_view_canvas_vline(int16_t x, int16_t y, int16_t h)
218{
219 auto* c = canvas();
220 if (!c) return HOST_ERR_NOT_FOUND;
221 c->drawVLine(x, y, h);
222 return HOST_OK;
223}
224
225int host_view_canvas_commit(bool full_refresh)
226{
227 auto* c = canvas();
228 if (!c) return HOST_ERR_NOT_FOUND;
229 c->commit(full_refresh);
230 return HOST_OK;
231}
232
233int host_view_canvas_elem_begin(uint32_t elem_id)
234{
235 auto* c = canvas();
236 if (!c) return HOST_ERR_NOT_FOUND;
237 if (elem_id == 0) return HOST_ERR_INVALID_ARG;
238 return c->beginElem(elem_id) ? HOST_OK : HOST_ERR_NO_MEMORY;
239}
240
242{
243 auto* c = canvas();
244 if (!c) return HOST_ERR_NOT_FOUND;
245 c->endElem();
246 return HOST_OK;
247}
248
249int host_view_canvas_elem_set_offset(uint32_t elem_id, int16_t ox, int16_t oy)
250{
251 auto* c = canvas();
252 if (!c) return HOST_ERR_NOT_FOUND;
253 return c->elemSetOffset(elem_id, ox, oy) ? HOST_OK : HOST_ERR_NOT_FOUND;
254}
255
256int host_view_canvas_elem_move(uint32_t elem_id, int16_t dx, int16_t dy)
257{
258 auto* c = canvas();
259 if (!c) return HOST_ERR_NOT_FOUND;
260 return c->elemMove(elem_id, dx, dy) ? HOST_OK : HOST_ERR_NOT_FOUND;
261}
262
263int host_view_canvas_elem_show(uint32_t elem_id, bool visible)
264{
265 auto* c = canvas();
266 if (!c) return HOST_ERR_NOT_FOUND;
267 return c->elemShow(elem_id, visible) ? HOST_OK : HOST_ERR_NOT_FOUND;
268}
269
270int host_view_canvas_elem_remove(uint32_t elem_id)
271{
272 auto* c = canvas();
273 if (!c) return HOST_ERR_NOT_FOUND;
274 return c->elemRemove(elem_id) ? HOST_OK : HOST_ERR_NOT_FOUND;
275}
276
277int host_view_canvas_elem_clear(uint32_t elem_id)
278{
279 auto* c = canvas();
280 if (!c) return HOST_ERR_NOT_FOUND;
281 return c->elemClear(elem_id) ? HOST_OK : HOST_ERR_NOT_FOUND;
282}
283
284int host_view_canvas_elem_set_z(uint32_t elem_id, int8_t z)
285{
286 auto* c = canvas();
287 if (!c) return HOST_ERR_NOT_FOUND;
288 return c->elemSetZ(elem_id, z) ? HOST_OK : HOST_ERR_NOT_FOUND;
289}
290
291int host_view_canvas_elem_get_offset(uint32_t elem_id, int16_t* ox, int16_t* oy)
292{
293 auto* c = canvas();
294 if (!c) return HOST_ERR_NOT_FOUND;
295 return c->elemGetOffset(elem_id, ox, oy) ? HOST_OK : HOST_ERR_NOT_FOUND;
296}
297
298int host_view_canvas_elem_get_bounds(uint32_t elem_id, int16_t* x, int16_t* y,
299 uint16_t* w, uint16_t* h)
300{
301 auto* c = canvas();
302 if (!c) return HOST_ERR_NOT_FOUND;
303 return c->elemGetBounds(elem_id, x, y, w, h) ? HOST_OK : HOST_ERR_NOT_FOUND;
304}
305
306int host_view_canvas_set_anim_policy(uint8_t refresh_policy, uint8_t max_fps)
307{
308 auto* c = canvas();
309 if (!c) return HOST_ERR_NOT_FOUND;
310 return c->setAnimPolicy(refresh_policy, max_fps) ? HOST_OK : HOST_ERR_INVALID_ARG;
311}
312
313int host_view_canvas_draw_sprite(int16_t x, int16_t y, uint32_t sprite)
314{
315 auto* c = canvas();
316 if (!c) return HOST_ERR_NOT_FOUND;
318 if (!c->spriteFrameView(sprite, &fv)) return HOST_ERR_NOT_FOUND;
319 c->drawSprite(x, y, sprite);
320 return HOST_OK;
321}
322
324{
325 auto* c = canvas();
326 if (!c) return HOST_ERR_NOT_FOUND;
327 c->setInkWhite(white);
328 return HOST_OK;
329}
330
331int host_view_canvas_marquee(int16_t x, int16_t y, int16_t window_w,
332 const char* text, uint16_t step_px, uint16_t frame_ms)
333{
334 auto* c = canvas();
335 if (!c) return HOST_ERR_NOT_FOUND;
336 if (!text) return HOST_ERR_INVALID_ARG;
337 int32_t handle = c->marquee(x, y, window_w,
338 cdc::plugin_manager::toDisplay(text).c_str(),
339 step_px, frame_ms);
340 if (handle > 0) return static_cast<int>(handle);
341 return handle == 0 ? HOST_ERR_INVALID_ARG : HOST_ERR_NO_MEMORY;
342}
343
344// --- Sprites -----------------------------------------------------------------
345
346int host_sprite_create(uint16_t frame_w, uint16_t frame_h, uint16_t frame_count,
347 const uint8_t* frames, uint32_t len)
348{
349 auto* c = canvas();
350 if (!c) return HOST_ERR_NOT_FOUND;
351 int32_t handle = c->spriteCreate(frame_w, frame_h, frame_count, frames, len);
352 if (handle > 0) return static_cast<int>(handle);
353 return handle == 0 ? HOST_ERR_INVALID_ARG : HOST_ERR_NO_MEMORY;
354}
355
356int host_sprite_set_mask(uint32_t sprite, const uint8_t* mask, uint32_t len)
357{
358 auto* c = canvas();
359 if (!c) return HOST_ERR_NOT_FOUND;
360 if (!mask) return HOST_ERR_INVALID_ARG;
361 return c->spriteSetMask(sprite, mask, len) ? HOST_OK : HOST_ERR_INVALID_ARG;
362}
363
364int host_sprite_set_flags(uint32_t sprite, uint8_t flags)
365{
366 auto* c = canvas();
367 if (!c) return HOST_ERR_NOT_FOUND;
368 return c->spriteSetFlags(sprite, flags) ? HOST_OK : HOST_ERR_NOT_FOUND;
369}
370
371int host_sprite_set_scale(uint32_t sprite, uint8_t scale)
372{
373 auto* c = canvas();
374 if (!c) return HOST_ERR_NOT_FOUND;
375 if (scale == 0 || scale > 4) return HOST_ERR_INVALID_ARG;
376 return c->spriteSetScale(sprite, scale) ? HOST_OK : HOST_ERR_NOT_FOUND;
377}
378
379int host_sprite_create_from_image(const uint8_t* data, uint32_t len,
380 uint16_t target_w, uint16_t frame_h)
381{
382 auto* c = canvas();
383 if (!c) return HOST_ERR_NOT_FOUND;
384 if (!data || len == 0 || target_w == 0 || frame_h == 0) {
386 }
387
388 // Decode + dither through the image pipeline into a temporary strip,
389 // then hand the vertically stacked frames to the sprite store.
390 const uint16_t stride = static_cast<uint16_t>((target_w + 7) / 8);
391 const size_t cap = 65536; // sprite arena upper bound
392 auto strip = cdc::core::psramAlloc<uint8_t>(cap);
393 if (!strip) return HOST_ERR_NO_MEMORY;
394 uint16_t out_stride = 0, out_h = 0;
395 int rc = host_image_render(data, len, target_w, strip.get(), cap,
396 &out_stride, &out_h);
397 if (rc != HOST_OK) return rc;
398
399 uint16_t frames = out_h / frame_h; // partial last frame is dropped
400 if (frames == 0) return HOST_ERR_INVALID_ARG;
401 int32_t handle = c->spriteCreate(target_w, frame_h, frames, strip.get(),
402 static_cast<uint32_t>(stride) * frame_h * frames);
403 if (handle > 0) return static_cast<int>(handle);
404 return handle == 0 ? HOST_ERR_INVALID_ARG : HOST_ERR_NO_MEMORY;
405}
406
407int host_sprite_set_frame(uint32_t sprite, uint16_t frame)
408{
409 auto* c = canvas();
410 if (!c) return HOST_ERR_NOT_FOUND;
411 return c->spriteSetFrame(sprite, frame) ? HOST_OK : HOST_ERR_INVALID_ARG;
412}
413
414int host_sprite_get_frame(uint32_t sprite, uint16_t* out)
415{
416 auto* c = canvas();
417 if (!c || !out) return HOST_ERR_NOT_FOUND;
418 int32_t f = c->spriteGetFrame(sprite);
419 if (f < 0) return HOST_ERR_NOT_FOUND;
420 *out = static_cast<uint16_t>(f);
421 return HOST_OK;
422}
423
424int host_sprite_set_frame_durations(uint32_t sprite, const uint16_t* ms,
425 uint16_t count)
426{
427 auto* c = canvas();
428 if (!c) return HOST_ERR_NOT_FOUND;
429 return c->spriteSetFrameDurations(sprite, ms, count) ? HOST_OK
431}
432
433int host_sprite_play(uint32_t sprite, uint8_t mode, uint16_t frame_ms,
434 uint16_t repeat, uint32_t done_action_id)
435{
436 auto* c = canvas();
437 if (!c) return HOST_ERR_NOT_FOUND;
438 return c->spritePlay(sprite, mode, frame_ms, repeat, done_action_id)
440}
441
442int host_sprite_stop(uint32_t sprite)
443{
444 auto* c = canvas();
445 if (!c) return HOST_ERR_NOT_FOUND;
446 return c->spriteStop(sprite) ? HOST_OK : HOST_ERR_NOT_FOUND;
447}
448
449int host_sprite_destroy(uint32_t sprite)
450{
451 auto* c = canvas();
452 if (!c) return HOST_ERR_NOT_FOUND;
453 return c->spriteDestroy(sprite) ? HOST_OK : HOST_ERR_NOT_FOUND;
454}
455
456// --- Tweens ------------------------------------------------------------------
457
459{
460 auto* c = canvas();
461 if (!c) return HOST_ERR_NOT_FOUND;
462 if (!cfg) return HOST_ERR_INVALID_ARG;
463
465 tc.elemId = cfg->elem_id;
466 tc.fromX = cfg->from_x;
467 tc.fromY = cfg->from_y;
468 tc.toX = cfg->to_x;
469 tc.toY = cfg->to_y;
470 tc.durationMs = cfg->duration_ms;
471 tc.delayMs = cfg->delay_ms;
472 tc.repeat = cfg->repeat;
473 tc.easing = cfg->easing;
474 tc.flags = cfg->flags;
476 tc.startAfter = cfg->start_after;
477
478 uint32_t handle = c->animStart(tc);
479 if (handle != 0) return static_cast<int>(handle);
480 // Disambiguate: unknown element vs bad parameters vs full slots.
481 if (!c->elemGetOffset(cfg->elem_id, nullptr, nullptr)) return HOST_ERR_NOT_FOUND;
482 if (cfg->duration_ms == 0 || cfg->duration_ms > 60000
483 || cfg->delay_ms > 60000 || cfg->easing > HOST_EASE_STEP) {
485 }
486 return HOST_ERR_NO_MEMORY;
487}
488
489int host_anim_cancel(uint32_t handle)
490{
491 auto* c = canvas();
492 if (!c) return HOST_ERR_NOT_FOUND;
493 return c->animCancel(handle) ? HOST_OK : HOST_ERR_NOT_FOUND;
494}
495
496int host_anim_pause(uint32_t handle, bool paused)
497{
498 auto* c = canvas();
499 if (!c) return HOST_ERR_NOT_FOUND;
500 return c->animPause(handle, paused) ? HOST_OK : HOST_ERR_NOT_FOUND;
501}
502
503int host_anim_state(uint32_t handle)
504{
505 auto* c = canvas();
506 if (!c) return HOST_ERR_NOT_FOUND;
507 int8_t s = c->animState(handle);
508 return s < 0 ? HOST_ERR_NOT_FOUND : s;
509}
510
512{
513 auto* c = canvas();
514 if (!c) return HOST_ERR_NOT_FOUND;
515 return c->animActiveCount();
516}
517
518int host_anim_blink(uint32_t elem_id, uint16_t period_ms, uint16_t count,
519 uint32_t done_action_id)
520{
521 auto* c = canvas();
522 if (!c) return HOST_ERR_NOT_FOUND;
523 uint32_t handle = c->animBlink(elem_id, period_ms, count, done_action_id);
524 if (handle != 0) return static_cast<int>(handle);
525 if (!c->elemGetOffset(elem_id, nullptr, nullptr)) return HOST_ERR_NOT_FOUND;
526 if (period_ms == 0 || count == 0) return HOST_ERR_INVALID_ARG;
527 return HOST_ERR_NO_MEMORY;
528}
529
530int host_view_canvas_add_slider(uint32_t widget_id, int32_t min, int32_t max,
531 int32_t initial, int32_t step)
532{
533 auto* c = canvas();
534 if (!c) return HOST_ERR_NOT_FOUND;
535 return c->addSlider(widget_id, min, max, initial, step) ? HOST_OK : HOST_ERR_INVALID_ARG;
536}
537
538int host_view_canvas_add_text(uint32_t widget_id, uint16_t max_len, const char* initial)
539{
540 auto* c = canvas();
541 if (!c) return HOST_ERR_NOT_FOUND;
542 std::string cp = cdc::plugin_manager::toDisplay(initial);
543 return c->addText(widget_id, max_len, initial ? cp.c_str() : nullptr)
545}
546
547int host_view_canvas_add_button(uint32_t widget_id)
548{
549 auto* c = canvas();
550 if (!c) return HOST_ERR_NOT_FOUND;
551 return c->addButton(widget_id) ? HOST_OK : HOST_ERR_INVALID_ARG;
552}
553
554int host_view_canvas_remove_widget(uint32_t widget_id)
555{
556 auto* c = canvas();
557 if (!c) return HOST_ERR_NOT_FOUND;
558 return c->removeWidget(widget_id) ? HOST_OK : HOST_ERR_NOT_FOUND;
559}
560
561int host_view_canvas_set_value(uint32_t widget_id, int32_t value)
562{
563 auto* c = canvas();
564 if (!c) return HOST_ERR_NOT_FOUND;
565 return c->setValue(widget_id, value) ? HOST_OK : HOST_ERR_NOT_FOUND;
566}
567
568int host_view_canvas_get_value(uint32_t widget_id, int32_t* out)
569{
570 auto* c = canvas();
571 if (!c) return HOST_ERR_NOT_FOUND;
572 return c->getValue(widget_id, out) ? HOST_OK : HOST_ERR_NOT_FOUND;
573}
574
575int host_view_canvas_set_text(uint32_t widget_id, const char* text)
576{
577 auto* c = canvas();
578 if (!c) return HOST_ERR_NOT_FOUND;
579 return c->setText(widget_id, cdc::plugin_manager::toDisplay(text).c_str())
581}
582
583int host_view_canvas_get_text(uint32_t widget_id, char* out, size_t cap)
584{
585 auto* c = canvas();
586 if (!c) return HOST_ERR_NOT_FOUND;
587 if (!out || cap == 0) return HOST_ERR_INVALID_ARG;
588 std::string tmp;
589 tmp.resize(cap);
590 int n = c->getText(widget_id, &tmp[0], cap);
591 if (n < 0) return HOST_ERR_NOT_FOUND;
592 tmp.resize(std::strlen(tmp.c_str()));
593 return cdc::plugin_manager::copyUtf8(tmp.c_str(), out, cap);
594}
595
596int host_view_canvas_set_focus(uint32_t widget_id)
597{
598 auto* c = canvas();
599 if (!c) return HOST_ERR_NOT_FOUND;
600 return c->setFocus(widget_id) ? HOST_OK : HOST_ERR_NOT_FOUND;
601}
602
604{
605 auto* c = canvas();
606 if (!c || !out) return HOST_ERR_NOT_FOUND;
607 *out = c->getFocus();
608 return HOST_OK;
609}
610
611int host_view_canvas_set_key_repeat(uint16_t initial_ms, uint16_t repeat_ms)
612{
613 auto* c = canvas();
614 if (!c) return HOST_ERR_NOT_FOUND;
615 c->setKeyRepeat(initial_ms, repeat_ms);
616 return HOST_OK;
617}
618
624
625} // extern "C"
Singleton that owns plugin-pushed UI views (lists, confirms, inputs).
uint8_t flags
int setCanvasLongPressAction(uint32_t action_id)
int pushCanvas(const char *title, uint32_t key_action_id, uint32_t widget_action_id)
int setViewFooter(const char *hint)
cdc::ui::CanvasView * canvasView()
static PluginUiState & instance() noexcept
Generic canvas view exposed to WASM plugins for custom UIs.
Definition CanvasView.h:26
int host_anim_pause(uint32_t handle, bool paused)
Pause (paused != 0) or resume a tween; delay time freezes too.
int host_anim_blink(uint32_t elem_id, uint16_t period_ms, uint16_t count, uint32_t done_action_id)
Convenience: blink an element.
int host_anim_active_count(void)
Number of live tweens plus playing sprites (>= 0).
int host_anim_start(const host_anim_t *cfg)
Start (or queue, when start_after != 0) a tween on an element.
int host_anim_cancel(uint32_t handle)
Cancel a tween and its chained successors; handle 0 cancels all of the canvas's tweens....
int host_anim_state(uint32_t handle)
Query a tween's state.
#define HOST_EASE_STEP
Definition host_api.h:1490
int host_image_render(const uint8_t *data, size_t len, uint16_t target_w, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes, uint16_t *out_height_px)
Decode, scale to target_w (aspect preserved) and dither to 1-bpp.
int host_sprite_create(uint16_t frame_w, uint16_t frame_h, uint16_t frame_count, const uint8_t *frames, uint32_t len)
Create a sprite from a packed 1-bpp frame sheet in plugin memory.
int host_sprite_set_frame(uint32_t sprite, uint16_t frame)
Jump to a frame. A running playback continues from it.
int host_sprite_play(uint32_t sprite, uint8_t mode, uint16_t frame_ms, uint16_t repeat, uint32_t done_action_id)
Start host-driven playback from frame 0.
int host_sprite_create_from_image(const uint8_t *data, uint32_t len, uint16_t target_w, uint16_t frame_h)
Create a sprite straight from an encoded PNG/JPEG.
int host_sprite_destroy(uint32_t sprite)
Destroy a sprite and reclaim its arena bytes. Recorded draw-sprite commands referencing it are skippe...
int host_sprite_set_frame_durations(uint32_t sprite, const uint16_t *ms, uint16_t count)
Optional per-frame durations in milliseconds.
int host_sprite_set_scale(uint32_t sprite, uint8_t scale)
Integer upscale factor applied whenever the sprite is drawn.
int host_sprite_set_flags(uint32_t sprite, uint8_t flags)
Replace the sprite's flag set (HOST_SPRITE_FLAG_*).
int host_sprite_stop(uint32_t sprite)
Stop playback, keeping the current frame on screen.
int host_sprite_set_mask(uint32_t sprite, const uint8_t *mask, uint32_t len)
Attach a transparency mask plane (same sheet layout and size as the frame data). Mask bit set = pixel...
int host_sprite_get_frame(uint32_t sprite, uint16_t *out)
Read the currently displayed frame index.
int host_view_canvas_clear_ex(uint32_t flags)
Clear with options: like host_view_canvas_clear, but HOST_CANVAS_CLEAR_KEEP_SPRITES keeps the sprite ...
int host_view_canvas_get_value(uint32_t widget_id, int32_t *out)
Read the integer value of a slider widget.
int host_view_canvas_elem_show(uint32_t elem_id, bool visible)
Show or hide an element (hidden elements are skipped on replay).
int host_view_canvas_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, bool filled)
Draw a rounded rectangle outline or filled, corner radius r.
int host_view_canvas_elem_set_offset(uint32_t elem_id, int16_t ox, int16_t oy)
Set an element's replay offset relative to its recorded coordinates.
int host_view_canvas_elem_remove(uint32_t elem_id)
Remove an element and all draw commands recorded under it.
int host_view_canvas_push(const char *title, uint32_t key_action_id, uint32_t widget_action_id)
Push a new canvas view.
int host_view_canvas_get_focus(uint32_t *out)
Read the currently focused widget id, 0 if none.
int host_view_canvas_hline(int16_t x, int16_t y, int16_t w)
Draw a horizontal line.
int host_view_canvas_vline(int16_t x, int16_t y, int16_t h)
Draw a vertical line.
int host_view_canvas_clear(void)
Clear all draw state and widgets. Equals host_view_canvas_clear_ex(0).
int host_view_canvas_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, bool filled)
Draw a rectangle outline or filled rectangle.
#define HOST_FONT_COUNT
Number of defined font ids.
Definition host_api.h:1150
int host_view_canvas_set_ink(bool white)
Draw subsequent shapes in white instead of black.
int host_view_canvas_elem_move(uint32_t elem_id, int16_t dx, int16_t dy)
Shift an element's replay offset by a delta.
int host_view_canvas_elem_begin(uint32_t elem_id)
Start recording draw calls under element elem_id.
int host_view_canvas_set_text_color(bool inverted)
Switch between normal and inverted (white on black) text.
int host_view_canvas_set_font(uint8_t font_id)
Switch the canvas font to one of the canonical HOST_FONT_* ids.
int host_view_canvas_draw_bitmap(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *data, uint32_t len)
Draw a 1-bpp bitmap; set bits render black, unset bits are transparent.
int host_view_canvas_add_button(uint32_t widget_id)
Add a focusable button widget bound to widget_id.
int host_view_canvas_draw_pixel(int16_t x, int16_t y)
Draw a single pixel.
int host_view_canvas_draw_circle(int16_t x, int16_t y, int16_t r, bool filled)
Draw a circle outline or filled circle of radius r centred at (x, y).
int host_view_canvas_marquee(int16_t x, int16_t y, int16_t window_w, const char *text, uint16_t step_px, uint16_t frame_ms)
Record a host-driven text marquee (ticker).
int host_view_canvas_set_focus(uint32_t widget_id)
Move keyboard focus to the given widget.
int host_view_canvas_get_text(uint32_t widget_id, char *out, size_t cap)
Read the text of a text-input widget.
int host_view_canvas_set_text_size(uint8_t size)
Set text size multiplier (Adafruit-GFX semantics).
int host_view_canvas_elem_get_offset(uint32_t elem_id, int16_t *ox, int16_t *oy)
Read an element's current replay offset.
int host_view_canvas_set_key_repeat(uint16_t initial_ms, uint16_t repeat_ms)
Configure key auto-repeat timing for the canvas.
int host_view_canvas_elem_get_bounds(uint32_t elem_id, int16_t *x, int16_t *y, uint16_t *w, uint16_t *h)
Bounding box of an element's recorded commands, offset applied.
int host_view_canvas_elem_end(void)
Stop recording draw calls into an element.
int host_view_canvas_draw_text_aligned(int16_t x, int16_t y, int16_t w, const char *text, uint8_t align)
Draw text within a horizontal box.
int host_view_canvas_set_footer(const char *hint)
Override the footer hint of the canvas.
int host_view_canvas_draw_text(int16_t x, int16_t y, const char *text)
Draw text at (x, y) using the current text size/colour.
int host_view_canvas_set_shade(uint8_t shade)
Set the fill ink for subsequent filled shapes (rect, circle, triangle).
int host_view_canvas_remove_widget(uint32_t widget_id)
Remove a widget previously added to the canvas.
int host_text_pick_font_that_fits(const char *text, int16_t max_width_px, const uint8_t *candidates, uint32_t count, uint8_t *out_font_id)
Pick the largest HOST_FONT_* whose rendered text fits within max_width_px. Candidates are evaluated i...
int host_view_canvas_add_text(uint32_t widget_id, uint16_t max_len, const char *initial)
Add a T9 text input widget bound to widget_id.
int host_view_canvas_set_text(uint32_t widget_id, const char *text)
Set the text of a text-input widget.
int host_view_canvas_elem_set_z(uint32_t elem_id, int8_t z)
Set an element's replay layer (z-order).
int host_view_canvas_draw_triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool filled)
Draw a triangle outline or filled triangle through three points.
int host_view_canvas_set_anim_policy(uint8_t refresh_policy, uint8_t max_fps)
Configure host-driven animation pacing for the current canvas.
int host_view_canvas_set_long_press_action(uint32_t action_id)
Set the action id fired on a canvas long-press.
int host_view_canvas_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
Draw a line between two points.
int host_view_canvas_set_value(uint32_t widget_id, int32_t value)
Set the integer value of a slider widget.
int host_view_canvas_get_body_size(uint16_t *w, uint16_t *h)
Read the drawable body region (excluding header/footer).
int host_view_canvas_commit(bool full_refresh)
Flush draw state to the panel.
#define HOST_CANVAS_CLEAR_KEEP_SPRITES
Definition host_api.h:1124
int host_view_canvas_add_slider(uint32_t widget_id, int32_t min, int32_t max, int32_t initial, int32_t step)
Add an integer slider widget bound to widget_id.
int host_view_canvas_elem_clear(uint32_t elem_id)
Drop only an element's recorded draw commands, keeping the element.
int host_view_canvas_draw_sprite(int16_t x, int16_t y, uint32_t sprite)
Record a draw of a sprite's current frame at (x, y).
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_OK
Definition host_api.h:37
#define HOST_ERR_INVALID_ARG
Definition host_api.h:39
#define HOST_ERR_NO_MEMORY
Definition host_api.h:43
#define HOST_ERR_NOT_FOUND
Definition host_api.h:41
Internal UTF-8 <-> CP437 helpers for the plugin host API boundary.
PsramUniquePtr< T > psramAlloc(std::size_t count) noexcept
Allocate count elements of T in PSRAM (8-bit capable region).
Definition Raii.h:51
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
std::string toDisplay(const char *utf8)
Decode a UTF-8 (with optional HTML entities) string into CP437 bytes.
int copyUtf8(const char *cp437, char *out, size_t out_size)
Encode a CP437 string into a caller buffer as UTF-8.
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....
const GFXfont * getGfxFont(FontId id)
Resolves a FontId to its underlying GFX font pointer.
Definition Fonts.cpp:26
Replay accessors: geometry, flags and pixel pointers of a sprite.
Definition CanvasAnim.h:267
Tween start configuration (mirrors host_anim_t plus the blink shorthand).
Definition CanvasAnim.h:94
uint16_t repeat
Extra runs; REPEAT_FOREVER = endless.
Definition CanvasAnim.h:102
uint32_t startAfter
Predecessor tween handle; 0 = start now.
Definition CanvasAnim.h:106
Tween description for host_anim_start(); zero-init unused fields.
Definition host_api.h:1500
int16_t to_y
Definition host_api.h:1505
uint16_t delay_ms
Definition host_api.h:1507
int16_t from_x
Definition host_api.h:1502
uint32_t start_after
Definition host_api.h:1514
uint32_t done_action_id
Definition host_api.h:1512
uint8_t easing
Definition host_api.h:1510
int16_t from_y
Definition host_api.h:1503
uint8_t flags
Definition host_api.h:1511
uint16_t duration_ms
Definition host_api.h:1506
uint16_t repeat
Definition host_api.h:1508
uint32_t elem_id
Definition host_api.h:1501
int16_t to_x
Definition host_api.h:1504