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

+23 -6
View File
@@ -490,6 +490,8 @@ static void sdl2_execute(SDL_Renderer* ren,
SDL_Surface* surf = TTF_RenderUTF8_Blended(font, cmd->text, col);
if (surf) {
SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, surf);
if (tex && cmd->a < 1.f) /* o Blended nao usa o alfa da cor */
SDL_SetTextureAlphaMod(tex, (Uint8)(fmaxf(0.f, cmd->a) * 255.f + 0.5f));
if (tex) {
/* cmd->x,cmd->y é baseline-left; converte para o
topo do retângulo usando o ascent real da fonte. */
@@ -755,6 +757,10 @@ static bool be_apply(SDL_Event* ev) {
break;
case SDL_MOUSEMOTION:
if ((w = win_by_id(ev->motion.windowID))) {
/* depois de apertar/soltar neste quadro, o movimento fica para o
proximo: o editor precisa ver onde o dedo apertou e onde soltou
(um deslize rapido, como a roda no emulador, cabe num quadro) */
if (w->in.l_down || w->in.l_up) return false;
w->in.mouse_x = (float)ev->motion.x / S;
w->in.mouse_y = (float)ev->motion.y / S;
w->pos_fresh = 1;
@@ -767,8 +773,9 @@ static bool be_apply(SDL_Event* ev) {
w->in.mouse_x = (float)ev->button.x / S;
w->in.mouse_y = (float)ev->button.y / S;
w->pos_fresh = 1;
/* clique repetido no mesmo quadro: espera o proximo */
if (ev->button.button == SDL_BUTTON_LEFT && (down ? w->in.l_down : w->in.l_up)) return false;
/* uma mudanca do botao esquerdo por quadro: apertar e soltar no
mesmo quadro viram dois (senao o deslize parece toque parado) */
if (ev->button.button == SDL_BUTTON_LEFT && (w->in.l_down || w->in.l_up)) return false;
if (ev->button.button == SDL_BUTTON_LEFT) { if (down) w->in.l_down = 1; else w->in.l_up = 1; }
if (ev->button.button == SDL_BUTTON_RIGHT) { if (down) w->in.r_down = 1; else w->in.r_up = 1; }
}
@@ -920,7 +927,8 @@ static char* be_clipboard_get(void) {
/* Captura para conferir o visual sem olhar a tela de ninguem:
TINYBLOCKS_SHOT=arquivo.bmp salva a 1a janela depois de
TINYBLOCKS_SHOT_FRAMES quadros (padrao 30) e sai. */
TINYBLOCKS_SHOT_FRAMES quadros (padrao 30) e sai. Com TINYBLOCKS_SHOT_COUNT=n
(e o caminho com %d), salva n quadros, um a cada TINYBLOCKS_SHOT_STEP. */
static void shot_check(SdlWin* w) {
static int frames = 0;
static bool done = false;
@@ -930,14 +938,23 @@ static void shot_check(SdlWin* w) {
while (first && first->next) first = first->next; /* a lista e LIFO */
if (w != first) return;
const char* fe = getenv("TINYBLOCKS_SHOT_FRAMES");
if (++frames < (fe && atoi(fe) > 0 ? atoi(fe) : 30)) return;
done = true;
const char* fc = getenv("TINYBLOCKS_SHOT_COUNT"); /* >1: sequencia (path com %d) */
const char* fs = getenv("TINYBLOCKS_SHOT_STEP");
int start = fe && atoi(fe) > 0 ? atoi(fe) : 30, count = fc && atoi(fc) > 1 ? atoi(fc) : 1;
int step = fs && atoi(fs) > 0 ? atoi(fs) : 1;
++frames;
if (frames < start || (frames - start) % step) return;
int idx = (frames - start) / step;
char name[1200];
if (count > 1) snprintf(name, sizeof(name), path, idx); else snprintf(name, sizeof(name), "%s", path);
int pw = 0, ph = 0;
SDL_GetRendererOutputSize(w->ren, &pw, &ph);
SDL_Surface* s = SDL_CreateRGBSurfaceWithFormat(0, pw, ph, 32, SDL_PIXELFORMAT_ARGB8888);
if (s && SDL_RenderReadPixels(w->ren, NULL, SDL_PIXELFORMAT_ARGB8888, s->pixels, s->pitch) == 0)
SDL_SaveBMP(s, path);
SDL_SaveBMP(s, name);
if (s) SDL_FreeSurface(s);
if (idx + 1 < count) return;
done = true;
exit(0); /* so para conferir: sai em seguida */
}