editor: bundle com libraries privadas + hot reload (tinyblocks-api) e aba de imagem estilo Krita

- tinyblocks-editor agora e um bundle: libraries privadas em
  libraries/tinyblocks-editor-{widgets,image} (.a + .so), com library.toml
  (bundle = tinyblocks-editor, private = true -> nao aparecem no libman).
- O editor carrega os modulos por dlopen via tinyblocks-api e chama tudo por
  tabelas de ponteiros (tb_ed_w, tb_ed_img): da para recompilar so a parte que
  mudou e o editor recarrega ao vivo (make ed-modules), sem reiniciar.
- tinyblocks-api ganhou modulos de codigo (tb_api_code_*) e watcher de
  arquivos (inotify, com mtime como reserva).
- libman: entradas com bundle/private nao sao listadas como extensao.
- Aba de imagem: layout estilo Krita - ferramentas na esquerda, tela no meio,
  roda de cores + paleta + camadas na coluna da direita; miniatura por camada
  (como as fantasias do Scratch); rodape enxuto (Desfazer/Limpar/zoom).
- Ferramenta selecionar (mover/redimensionar/excluir pixels) e consertada a
  geometria da folha (doc = area de desenho, zoom puro).
- Makefile: alvo ed-modules; AppImage empacota os .so do bundle.
- harness: testes de imagem atualizados + testes de cores na lateral.
This commit is contained in:
mguinhos committed 2026-10-20 23:31:42 -03:00
1 parent 036162280d
commit 0143d3efd5
21 files changed
+3775 -557

No files matched your search

+191 -2
View File
@@ -23,6 +23,8 @@ static TinyBlocks_Block *ev, *scene;
static TinyBlocks_DrawCmd cmds[TB_DRAW_CMD_CAP];
static uint32_t ncmd;
static int fails = 0;
static int g_mods = 0;
static void mods(int m) { g_mods = m; }
static void eval_ev(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; self->dirty = false; }
@@ -42,8 +44,8 @@ static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char
tb_block_set_output(ev, GFX_IN_MOUSE_L_UP, tb_value_integer(lu));
tb_block_set_output(ev, GFX_IN_MOUSE_R_DOWN, tb_value_integer(rd));
tb_block_set_output(ev, GFX_IN_KEY, tb_value_integer(sc));
tb_block_set_output(ev, GFX_IN_KEY_MOD, tb_value_integer(0));
tb_block_set_output(ev, GFX_IN_MOD_STATE, tb_value_integer(0));
tb_block_set_output(ev, GFX_IN_KEY_MOD, tb_value_integer(g_mods));
tb_block_set_output(ev, GFX_IN_MOD_STATE, tb_value_integer(g_mods));
tb_block_set_output(ev, GFX_IN_TEXT, tb_value_text(text ? text : ""));
tb_block_set_output(ev, GFX_IN_DROP_FILE, tb_value_text(""));
tb_block_set_output(ev, GFX_IN_SCROLL_DX, tb_value_real(0));
@@ -92,6 +94,60 @@ static bool ws_has(const char* s) {
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strcmp(cmds[i].text, s) == 0) return true;
return false;
}
static bool find_tabbar(const char* s, float* x, float* y) {
for (uint32_t i = 0; i < ncmd; i++) {
TinyBlocks_DrawCmd* c = &cmds[i];
if (c->kind != TB_DRAW_TEXT || strcmp(c->text, s) != 0) continue;
if (c->y < 40 || c->y > 86) continue;
*x = c->x + 3; *y = c->y - c->font_size*0.36f;
return true;
}
return false;
}
static bool find_sub(const char* sub, float* x, float* y) {
for (uint32_t i = 0; i < ncmd; i++) {
TinyBlocks_DrawCmd* c = &cmds[i];
if (c->kind != TB_DRAW_TEXT || !strstr(c->text, sub)) continue;
*x = c->x + 3; *y = c->y - c->font_size*0.36f;
return true;
}
return false;
}
/* Conta pixels nao-brancos da ultima imagem desenhada no workspace */
static int img_nonwhite(void) {
/* A folha de desenho e a MAIOR imagem do workspace (miniaturas sao pequenas) */
const TinyBlocks_Image* im = NULL;
float best = 0;
for (uint32_t i = 0; i < ncmd; i++) {
if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image || !in_region(cmds[i].x, R_WS)) continue;
float a = cmds[i].w * cmds[i].h;
if (a < 20000.f) continue; /* ignora miniaturas */
if (a > best) { best = a; im = cmds[i].image; }
}
if (!im) return -1;
int W = tb_image_width(im), H = tb_image_height(im), n = 0;
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++) {
uint8_t r, g, b, a;
if (tb_image_get_pixel(im, x, y, &r, &g, &b, &a) && a > 0 &&
(r < 240 || g < 240 || b < 240)) n++;
}
return n;
}
static bool any_substr(const char* s) {
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, s)) return true;
return false;
}
static bool ws_substr(const char* s) {
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strstr(cmds[i].text, s)) return true;
return false;
}
static void dump_ws(void) {
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS)) printf(" ws| %s (%.0f,%.0f)\n", cmds[i].text, cmds[i].x, cmds[i].y);
}
static void dump_stage(void) {
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && cmds[i].y > 130) printf(" | %s\n", cmds[i].text);
@@ -455,6 +511,139 @@ int main(void) {
}
CHECK(ws_has("32x32"), "balão mostra as dimensões da imagem");
/* 21. Tooltip de metadados: Alt + hover sobre um bloco (Stage.Clear) */
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
frame(0, 0, 0, 0, 0, 0, NULL);
if (need("apague tudo", R_FLY, 0, &x, &y)) drag(x, y, 520, 430);
frame(0, 0, 0, 0, 0, 0, NULL);
{
float bx = 0, by = 0;
if (find("apague tudo", R_WS, 0, &bx, &by)) {
mods(TB_MOD_ALT);
frame(bx, by, 0, 0, 0, 0, NULL);
CHECK(any_substr("eval_clear"), "Alt+hover mostra o tooltip com a funcao C");
CHECK(any_substr("tb_pen.c"), "tooltip mostra o arquivo-fonte");
CHECK(any_substr("Limpa o palco"), "tooltip mostra a descricao (doc)");
/* clica na previa do codigo -> abre aba de codigo na linha */
float px = 0, py = 0;
if (find_sub("tb_stage_clear", &px, &py)) {
mods(0);
click(px, py);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(any_substr("tb_pen.c"), "clique na previa abre aba de codigo do arquivo");
CHECK(ws_substr("eval_clear"), "aba de codigo mostra o codigo na linha da funcao");
} else { mods(0); CHECK(false, "achei a previa do codigo no tooltip"); }
} else { CHECK(false, "achei o bloco 'apague tudo' no workspace"); }
}
/* 22. Botao "+" -> nova aba: Editor de Codigo */
key(TB_KEY_ESCAPE, 0, 0);
frame(0, 0, 0, 0, 0, 0, NULL);
{
float px = 0, py = 0;
if (find_tabbar("+", &px, &py)) click(px, py); else { CHECK(false, "achei o botao +"); }
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(find("Editor de Codigo", R_ANY, 0, &x, &y), "menu '+' lista as opcoes de nova aba");
CHECK(find("Edicao de Imagem", R_ANY, 0, &x, &y), "menu '+' oferece Edicao de Imagem");
if (need("Editor de Codigo", R_ANY, 0, &x, &y)) click(x, y);
frame(0, 0, 0, 0, 0, 0, NULL);
type("int x = 42;");
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(ws_has("int"), "aba de codigo realca 'int' (palavra-chave)");
CHECK(ws_has("42"), "aba de codigo realca o numero 42");
CHECK(ws_has(";"), "aba de codigo realca a pontuacao");
}
/* 23. Botao "+" -> nova aba: Edicao de Imagem */
key(TB_KEY_ESCAPE, 0, 0);
frame(0, 0, 0, 0, 0, 0, NULL);
{
float px = 0, py = 0;
if (find_tabbar("+", &px, &py)) click(px, py); else { CHECK(false, "achei o botao +"); }
frame(0, 0, 0, 0, 0, 0, NULL);
if (need("Edicao de Imagem", R_ANY, 0, &x, &y)) click(x, y);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(find("Camadas", R_WS, 0, &x, &y), "aba de imagem mostra a lista de camadas");
CHECK(find("Salvar", R_WS, 0, &x, &y), "aba de imagem mostra o botao Salvar");
CHECK(find("Desfazer", R_WS, 0, &x, &y), "aba de imagem mostra o botao Desfazer");
CHECK(find("Cores", R_WS, 0, &x, &y), "aba de imagem mostra a coluna de cores");
CHECK(find("Paleta", R_WS, 0, &x, &y), "aba de imagem mostra a paleta rapida");
CHECK(x > 700, "cores ficam na lateral direita");
{
int imgs = 0;
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_IMAGE && in_region(cmds[i].x, R_WS)) imgs++;
CHECK(imgs >= 1, "aba de imagem desenha a folha de desenho");
}
}
/* 24. Pintar na aba de imagem (ferramenta pincel) */
{
int before = img_nonwhite();
CHECK(before == 0, "folha de desenho comeca em branco");
click(345, 192); /* botao da ferramenta pincel */
frame(0, 0, 0, 0, 0, 0, NULL);
drag(500, 300, 560, 400); /* pinta um traco no canvas */
frame(0, 0, 0, 0, 0, 0, NULL);
int after = img_nonwhite();
CHECK(after > 0, "pincel pinta pixels na folha de desenho");
click(421, 703); /* botao Desfazer */
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(img_nonwhite() == 0, "Desfazer volta a folha em branco");
click(345, 292); /* ferramenta retangulo */
frame(0, 0, 0, 0, 0, 0, NULL);
drag(560, 280, 680, 360);
frame(0, 0, 0, 0, 0, 0, NULL);
int rect_px = img_nonwhite();
CHECK(rect_px > 100, "ferramenta retangulo desenha o contorno");
click(345, 342); /* ferramenta elipse */
frame(0, 0, 0, 0, 0, 0, NULL);
drag(620, 290, 690, 390);
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(img_nonwhite() > rect_px, "ferramenta elipse desenha o contorno");
click(345, 392); /* ferramenta preencher */
frame(0, 0, 0, 0, 0, 0, NULL);
click(620, 320); /* dentro do retangulo */
frame(0, 0, 0, 0, 0, 0, NULL);
click(520, 400); /* fora das formas */
frame(0, 0, 0, 0, 0, 0, NULL);
int fill_px = img_nonwhite();
CHECK(fill_px > rect_px * 3, "ferramenta preencher alaga a area branca");
click(345, 492); /* conta-gotas */
frame(0, 0, 0, 0, 0, 0, NULL);
click(520, 400);
frame(0, 0, 0, 0, 0, 0, NULL);
{
bool found = false;
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "Cor do pixel")) found = true;
CHECK(found, "conta-gotas informa a cor capturada");
}
/* 24b. Escolher uma cor na paleta lateral e desenhar com ela */
{
click(803, 277); /* segundo quadradinho da paleta (branco) */
frame(0, 0, 0, 0, 0, 0, NULL);
bool dark = false;
for (uint32_t i = 0; i < ncmd; i++)
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "#FFFFFF")) dark = true;
CHECK(dark, "paleta lateral troca a cor da ferramenta");
click(345, 142); /* selecionar */
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(find("Desfazer", R_WS, 0, &x, &y), "ferramenta selecionar continua disponivel");
}
CHECK(find("Fundo", R_WS, 0, &x, &y), "lista de camadas mostra a camada Fundo");
CHECK(find("+ Raster", R_WS, 0, &x, &y), "botao de nova camada raster");
CHECK(find("+ Vetor", R_WS, 0, &x, &y), "botao de nova camada vetorial");
CHECK(find("Fundo", R_WS, 0, &x, &y), "achei a camada Fundo");
click(x - 29, y + 6); /* olho da camada Fundo: esconde */
frame(0, 0, 0, 0, 0, 0, NULL);
/* sem camada visivel nao ha imagem nenhuma na folha (=-1) */
CHECK(img_nonwhite() <= 0, "camada pode ser escondida");
click(x - 29, y + 6); /* olho: mostra de novo */
frame(0, 0, 0, 0, 0, 0, NULL);
CHECK(img_nonwhite() > 0, "camada pode ser mostrada de novo");
}
printf("comandos de desenho no último frame: %u\n", ncmd);
tinyblocks_deinit(&rt);
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);