/* * 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 /* API PRIVADA do editor: so o editor, os modulos do bundle dele (libraries/tinyblocks-editor-*) e o harness de testes compilam com TB_EDITOR_PRIVATE_API. Para usar o editor, inclua tb_editor.h. */ #ifndef TB_EDITOR_PRIVATE_API # error "API privada do editor: inclua tb_editor.h (ou compile com -DTB_EDITOR_PRIVATE_API)" #endif #include #include #include #include #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*); void (*zoom) (Ed*, float, float, int); /* roda do mouse = zoom */ } TbEdImageApi; /* API da library privada tinyblocks-editor-files (explorador de arquivos) */ typedef struct { void (*open) (Ed*, int, const char*); void (*close) (Ed*); void (*view) (Ed*, TinyBlocks_RenderableBlock*); bool (*click) (Ed*, float, float); void (*key) (Ed*, int, bool); void (*text) (Ed*, const char*); void (*scroll)(Ed*, float); } TbEdFilesApi; 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; TB_ED_API extern TbEdFilesApi tb_ed_files; /* 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 */