Files
tinyblocks/libraries/tinyblocks-api/include/tb_api.h
T
mguinhos 0143d3efd5 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.
2026-10-20 23:31:42 -03:00

97 lines
3.7 KiB
C

/*
* TinyBlocks - tb_api.h
* Library tinyblocks-api: gestor publico de modulos/libraries e "cola" entre
* plugins (.so), libraries registradas e o registro de tipos do runtime.
*
* Responsabilidades:
* - carregar/descarregar/recarregar plugins .so (dlopen + tb_library_register)
* - adotar libraries embutidas (registradas estaticamente no runtime)
* - hot reload por mtime
* - introspeccao: enumerar modulos e tipos de bloco disponiveis
*
* NAO desenha UI: quem desenha e o editor.
*/
#ifndef TINYBLOCKS_API_H
#define TINYBLOCKS_API_H
#include <stdbool.h>
#include <time.h>
#include <tinyblocks/tinyblocks.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TB_API_MAX_MODULES 64
#define TB_API_PATH_LEN 512
/* Um modulo/library conhecido pelo processo (embutido ou .so dinamico). */
typedef struct TbApiModule {
char name[64]; /* nome da library (desc->name) */
char version[32];
char path[TB_API_PATH_LEN]; /* .so de origem; "" se embutido */
void* handle; /* dlopen; NULL se embutido */
TinyBlocks_LibraryBlock* lib;
const TinyBlocks_Category* category; /* pode ser NULL */
unsigned block_count;
time_t mtime; /* mtime do .so (hot reload) */
} TbApiModule;
/* -- Ciclo de vida --- */
TB_API bool tb_api_init(TinyBlocks* rt);
TB_API void tb_api_shutdown(void);
TB_API TinyBlocks* tb_api_runtime(void);
TB_API const char* tb_api_last_error(void);
/* -- Registro de modulos --- */
/* Adota as libraries ja registradas no runtime (embutidas). Retorna o total. */
TB_API int tb_api_adopt_all(void);
TB_API int tb_api_module_count(void);
TB_API const TbApiModule* tb_api_module(int i);
TB_API const TbApiModule* tb_api_module_find(const char* name);
/* -- Carregamento dinamico --- */
/* Carrega um .so; retorna o indice (>=0) ou -1 (erro em tb_api_last_error). */
TB_API int tb_api_load(const char* path);
TB_API bool tb_api_unload(int idx);
TB_API bool tb_api_reload(int idx);
TB_API bool tb_api_is_loaded(const char* name);
/* -- Modulos de codigo (bundle de um app, ex: libraries privadas do editor)
* Nao registram libraries/blocos: sao so codigo (.so) carregado por dlopen.
* Usados para HOT RELOAD: recompile a parte que mudou e o app recarrega. --- */
#define TB_API_MAX_CODE 32
TB_API int tb_api_code_load(const char* name, const char* path); /* idx ou -1 */
TB_API bool tb_api_code_unload(const char* name);
TB_API void tb_api_code_unload_all(void);
TB_API int tb_api_code_count(void);
TB_API const char* tb_api_code_name(int i);
TB_API const char* tb_api_code_path(int i);
TB_API void* tb_api_code_handle(const char* name);
TB_API void* tb_api_code_symbol(const char* name, const char* symbol);
/* Recarrega TODOS os modulos de codigo na ordem de carga (unload inverso,
* load direto) - resolve dependencias entre eles. Retorna quantos voltaram. */
TB_API int tb_api_code_reload_all(void);
/* true se algum modulo de codigo mudou no disco (usa watcher/mtime). */
TB_API bool tb_api_code_changed(void);
/* -- Watcher de arquivos (inotify quando disponivel, senao mtime) --- */
TB_API bool tb_api_watch(const char* path);
TB_API int tb_api_poll_watch(void); /* eventos pendentes (0 = nada) */
/* Hot reload: true se algum .so mudou no disco desde o ultimo load. */
TB_API bool tb_api_any_changed(void);
/* Recarrega os .so que mudaram; retorna quantos. */
TB_API int tb_api_poll_reload(void);
/* -- Introspeccao de tipos de bloco (API publica) --- */
TB_API int tb_api_type_count(void);
TB_API const TinyBlocks_TypeBlock* tb_api_type(int i);
TB_API const TinyBlocks_TypeBlock* tb_api_type_find(const char* name);
#ifdef __cplusplus
}
#endif
#endif /* TINYBLOCKS_API_H */