Editor: animacoes M3, compartilhar/receber blocos por QR e ver codigo-fonte

- Animacoes (curvas do M3): blocos criados por codigo surgem em cascata,
  apagados saem de cena (fantasma que encolhe), os de baixo deslizam ao
  mudar de lugar na pilha; rolagem e zoom suaves. TINYBLOCKS_REDUCE_MOTION=1
  desliga (o harness usa). Texto respeita a opacidade no backend SDL2.
- Botao direito: "Ver codigo-fonte" (funcao C do bloco na aba de codigo),
  "Compartilhar pilha/blueprint (QR)" (scratchblocks em partes de 220 bytes,
  "TB1|id|parte|total|", em loop de 1 s) e "Receber blocos (QR)" (camera,
  partes em qualquer ordem, importa onde clicou).
- tinyblocks-qr: qrcodegen (MIT) + quirc (ISC) e camera em cinza: V4L2 no
  Linux, Camera2 do NDK no Android (sem Java), nada no Windows.
- Captura de desenvolvimento: TINYBLOCKS_SHOT_COUNT/STEP salvam sequencias.
- Testes: test-qr (ida e volta) e harness cenario 35.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-28 23:28:18 -03:00
1 parent 70c819393c
commit 4f6a68c22c
31 files changed
+5789 -49

No files matched your search

+58
View File
@@ -305,6 +305,7 @@ int main(void) {
/* configurações isoladas: o harness não lê nem grava o ~/.config real */
setenv("XDG_CONFIG_HOME", "/tmp/tb_harness_cfg", 1);
setenv("TINYBLOCKS_MCP_PORT", "0", 1); /* o servidor MCP atende sem rede (cenario 29) */
setenv("TINYBLOCKS_REDUCE_MOTION", "1", 1); /* sem animacoes: cada quadro ja e o estado final */
unsetenv("TINYBLOCKS_SETTINGS");
remove("/tmp/tb_harness_cfg/tinyblocks/settings.csv");
tinyblocks_init(&rt, NULL);
@@ -1704,6 +1705,63 @@ int main(void) {
ax_do(ax_need(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_BUTTON, "Cancelar"), TB_A11Y_ACT_ACTIVATE);
}
/* 35. Botão direito: ver o código-fonte do bloco; compartilhar a pilha por
* QR (partes em loop) e receber blocos por QR (partes fora de ordem) */
{
frame(0, 0, 0, 0, 0, 0, NULL);
int hat = ws_block("quando a bandeira for clicado", 0);
CHECK(hat >= 0, "qr: há uma pilha para compartilhar");
ax_do(hat, TB_A11Y_ACT_MENU);
int menu = ax_in(0, TB_A11Y_MENU, "Menu de contexto");
ax_do(ax_need(menu, TB_A11Y_MENU_ITEM, "Compartilhar pilha (QR)"), TB_A11Y_ACT_ACTIVATE);
frame(0, 0, 0, 0, 0, 0, NULL);
int dlg = ax_in(0, TB_A11Y_DIALOG, "Compartilhar pilha");
CHECK(dlg >= 0 && !strncmp(ax_value(ax_in(dlg, TB_A11Y_LABEL, "Parte")), "Parte 1 de ", 11),
"compartilhar: painel com o QR (Parte 1 de N)");
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Fechar"), TB_A11Y_ACT_ACTIVATE);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(ax_in(0, TB_A11Y_DIALOG, "Compartilhar pilha") < 0, "compartilhar: Fechar fecha");
/* ver o código-fonte: abre a aba de código no arquivo do bloco */
cat("Caneta");
ax_drop_at(pal_block("Caneta", "apague tudo"), ws(), 60, 60);
frame(0, 0, 0, 0, 0, 0, NULL);
ax_do(ws_block("apague tudo", 0), TB_A11Y_ACT_MENU);
menu = ax_in(0, TB_A11Y_MENU, "Menu de contexto");
CHECK(ax_in(menu, TB_A11Y_MENU_ITEM, "Ver código-fonte") >= 0, "menu do bloco: Ver código-fonte");
ax_do(ax_need(menu, TB_A11Y_MENU_ITEM, "Ver código-fonte"), TB_A11Y_ACT_ACTIVATE);
frame(0, 0, 0, 0, 0, 0, NULL);
int code = ax_in(0, TB_A11Y_TEXT_FIELD, "Código");
CHECK(code >= 0 && strstr(N(code)->description, "tb_pen.c"), "Ver código-fonte abre o arquivo do bloco");
/* receber: numa folha em branco, botão direito no fundo da área */
ax_do(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_BUTTON, "Nova aba"), TB_A11Y_ACT_ACTIVATE);
ax_do(ax_in(ax_in(0, TB_A11Y_MENU, "Nova aba"), TB_A11Y_MENU_ITEM, "Blueprint"), TB_A11Y_ACT_ACTIVATE);
frame(0, 0, 0, 0, 0, 0, NULL);
int w = ws();
float rx = N(w)->x + N(w)->w - 60, ry = N(w)->y + N(w)->h - 60;
frame(rx, ry, 0, 0, 1, 0, NULL);
frame(rx, ry, 0, 0, 0, 0, NULL);
menu = ax_in(0, TB_A11Y_MENU, "Menu de contexto");
ax_do(ax_need(menu, TB_A11Y_MENU_ITEM, "Receber blocos (QR)"), TB_A11Y_ACT_ACTIVATE);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(ax_in(0, TB_A11Y_DIALOG, "Receber blocos") >= 0, "receber: abre o leitor");
int before = ws_count("via qr");
tb_editor_qr_feed(scene, "TB1|beef|2|2|[via qr]\n");
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(!strcmp(ax_value(ax_in(ax_in(0, TB_A11Y_DIALOG, "Receber blocos"), TB_A11Y_STATUS, "Recebimento")),
"Recebidas 1 de 2 partes"), "receber: conta as partes (1 de 2)");
tb_editor_qr_feed(scene, "TB1|beef|1|2|when flag clicked\nsay ");
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(ax_in(0, TB_A11Y_DIALOG, "Receber blocos") < 0 && ws_count("via qr") == before + 1,
"receber: com todas as partes (fora de ordem), os blocos entram");
frame(rx - 300, ry, 0, 0, 1, 0, NULL);
frame(rx - 300, ry, 0, 0, 0, 0, NULL);
CHECK(ax_in(ax_in(0, TB_A11Y_MENU, "Menu de contexto"), TB_A11Y_MENU_ITEM, "Compartilhar blueprint (QR)") >= 0,
"menu do fundo: Compartilhar blueprint (com blocos na aba)");
key(TB_KEY_ESCAPE, 0, 0);
}
tinyblocks_deinit(&rt);
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
return fails != 0;
+47
View File
@@ -0,0 +1,47 @@
/* Teste da tinyblocks-qr: gerar um QR, desenhar numa imagem cinza e ler */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tb_qr.h>
static int fails = 0;
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
static char got[4096];
static void found(const char* t, int n, void* u) { (void)u; snprintf(got, sizeof(got), "%.*s", n, t); }
/* QR -> imagem cinza: s pixels por modulo, margem de 4 modulos, fundo claro */
static int roundtrip(const char* text, int s) {
static unsigned char mods[TB_QR_MAX_SIDE * TB_QR_MAX_SIDE];
int side = tb_qr_encode(text, mods, (int)sizeof(mods));
if (!side) return 0;
int W = (side + 8) * s, H = W;
unsigned char* img = malloc((size_t)W * H);
memset(img, 230, (size_t)W * H);
for (int y = 0; y < side; y++)
for (int x = 0; x < side; x++)
if (mods[y * side + x])
for (int dy = 0; dy < s; dy++)
memset(img + (size_t)((y + 4) * s + dy) * W + (x + 4) * s, 25, (size_t)s);
TbQrReader* r = tb_qr_reader_new();
got[0] = 0;
int n = tb_qr_reader_scan(r, img, W, H, found, NULL);
tb_qr_reader_free(r);
free(img);
return n;
}
int main(void) {
const char* small = "TB1|a1b2|1|1|when flag clicked\nsay [olá]\n";
CHECK(roundtrip(small, 4) == 1 && !strcmp(got, small), "QR pequeno (com acento) vai e volta");
char big[300];
for (int i = 0; i < 299; i++) big[i] = (char)('a' + i % 26);
big[299] = 0;
CHECK(roundtrip(big, 3) == 1 && !strcmp(got, big), "QR de 299 bytes vai e volta");
static unsigned char mods[TB_QR_MAX_SIDE * TB_QR_MAX_SIDE];
char huge[4000];
memset(huge, 'x', sizeof(huge) - 1); huge[sizeof(huge) - 1] = 0;
CHECK(tb_qr_encode(huge, mods, (int)sizeof(mods)) == 0, "texto grande demais: nao gera");
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
return fails != 0;
}