Files
mguinhosandClaude Opus 5.5 adf5d2cd12 Imagens no palco por nome/número, paleta recarregável e slider de zoom
- Core: armazém de imagens nomeadas (tb_image_store_*) e tb_stage_image*
  para desenhar imagens no palco pelo nome ou pelo número.
- Caneta: blocos "desenhe imagem nome/número".
- tinyblocks-api: tb_api_load_named/tb_api_find_library e mtime em ns;
  o editor carrega as libraries de categoria como .so quando existem,
  para a paleta recarregar ao vivo.
- Aba de imagem: slider de zoom no rodapé no lugar dos botões -/+.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:03:01 -03:00

103 lines
4.1 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 <stdint.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;
int64_t mtime; /* mtime do .so (ns; 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);
/* Procura "lib<name>.so" nos diretorios usuais (repo, ao lado do executavel,
* AppImage, $TINYBLOCKS_LIBS) e carrega. Serve para o app abrir as libraries
* de categoria como .so (e entao poder recarrega-las ao vivo). */
TB_API bool tb_api_find_library(const char* name, char* out, size_t cap);
TB_API int tb_api_load_named(const char* name); /* indice ou -1 */
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 */