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

@@ -0,0 +1,96 @@
/*
* TinyBlocks - tb_editor_modules.h
* Carga dinamica das libraries privadas do editor (bundle) para permitir
* HOT RELOAD: recompile so a parte que mudou (make -C libraries/... ) e o
* editor em execucao recarrega o .so sem reiniciar.
*
* O estado da interface vive em Ed/Tab (no editor), por isso trocar o modulo
* nao perde nada: so os codigos das funcoes sao substituidos.
*/
#ifndef TB_EDITOR_MODULES_H
#define TB_EDITOR_MODULES_H
#include <stdbool.h>
#include <stdint.h>
#include <tinyblocks/tb_renderable_block.h>
#include <tb_editor_widgets.h>
#ifdef __cplusplus
extern "C" {
#endif
struct Ed;
struct Tab;
typedef struct Ed Ed;
typedef struct Tab Tab;
/* Visibilidade dos simbolos do editor usados pelos modulos */
#define TB_ED_API __attribute__((visibility("default")))
#define TB_ED_MODULE_MAX 8
/* API da library privada tinyblocks-editor-widgets */
typedef struct {
TbEwColor (*col_mul) (TbEwColor, float);
void (*fill_rect) (TinyBlocks_RenderableBlock*, float, float, float, float, TbEwColor);
void (*fill_rrect) (TinyBlocks_RenderableBlock*, float, float, float, float, float, TbEwColor);
void (*fill_circle) (TinyBlocks_RenderableBlock*, float, float, float, TbEwColor);
void (*stroke_rect) (TinyBlocks_RenderableBlock*, float, float, float, float, float, TbEwColor);
void (*stroke_circle)(TinyBlocks_RenderableBlock*, float, float, float, float, TbEwColor);
void (*line) (TinyBlocks_RenderableBlock*, float, float, float, float, float, TbEwColor);
void (*text_c) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float);
float (*text_width) (const char*, float);
bool (*in_rect) (float, float, float, float, float, float);
} TbEdWidgetsApi;
/* API da library privada tinyblocks-editor-image */
typedef struct {
void (*view) (Ed*, TinyBlocks_RenderableBlock*);
bool (*click) (Ed*, float, float);
void (*drag) (Ed*, float, float);
void (*release) (Ed*, float, float);
void (*load_file) (Ed*, const char*, int);
void (*save) (Ed*, const char*);
void (*ensure) (Ed*, Tab*);
void (*sel_reset) (Tab*);
void (*sel_commit)(Tab*);
} TbEdImageApi;
typedef struct {
const char* name; /* tinyblocks-editor-image */
const char* file; /* libtinyblocks-editor-image.so */
void* handle;
int64_t mtime;
int ok;
} TbEdModule;
typedef struct {
TbEdModule list[TB_ED_MODULE_MAX];
TbEdWidgetsApi widgets;
int n;
TbEdImageApi image;
bool loaded;
int reloads;
char dir[512]; /* pasta dos modulos */
char info[160]; /* ultimo evento (status bar) */
} TbEdModules;
/* Tabelas vivas: o editor chama por aqui, entao a troca e instantanea */
TB_ED_API extern TbEdImageApi tb_ed_img;
TB_ED_API extern TbEdWidgetsApi tb_ed_w;
/* Carrega (ou recarrega) os modulos. Sempre que um .so muda de mtime
recarrega todos os modulos, na ordem. Retorna true se algo foi carregado. */
bool tb_ed_modules_load(Ed* ed);
/* Verificacao barata (inotify/mtime): recarrega se algum .so mudou. */
bool tb_ed_modules_check(Ed* ed);
/* Esquece os modulos carregados (nao mexe no state do editor) */
void tb_ed_modules_clear(void);
/* Caminho de origem dos modulos (para mensagens/uso no Makefile) */
const char* tb_ed_modules_dir(void);
#ifdef __cplusplus
}
#endif
#endif /* TB_EDITOR_MODULES_H */