- tinyblocks-blueprint: dona do estado de edicao (abas, pool de blocos, vinculos parent/prel/next/sub/args, blocos compostos e variaveis) e da serializacao. JSON nativo (to/from) usando a AST JSON do core e export JSON/XML/CSV. Testado com round-trip (test-blueprint). - tinyblocks-json: lexer + parser + emissor JSON independentes. - tinyblocks-xml: lexer + parser de XML -> AST JSON do core + emissor. - tinyblocks-csv: divisor de linhas/campos + parser/emissor sobre a AST JSON. - Editor: botoes Abrir / Salvar / Exportar JSON XML CSV no menu; converte Ed <-> TbBlueprint; barra de caminho com modo; .json pode ser arrastado. - Variaveis: tb_variables_clear e tb_variables_set_text. - Harness: teste de salvar/abrir projeto; tests/blueprint_test.c.
95 lines
3.5 KiB
C
95 lines
3.5 KiB
C
/*
|
|
* TinyBlocks - exemplo editor
|
|
*
|
|
* Abre o editor visual com as libraries de categoria registradas:
|
|
* Eventos, Controle, Operadores, Variáveis, Aparência, Caneta, Meus Blocos.
|
|
*
|
|
* A janela vem da interface tinyblocks-graphics; o backend padrão é SDL2 e
|
|
* pode ser trocado por outro .so:
|
|
*
|
|
* ./editor [--backend libbackend.so] [library.so ...]
|
|
*
|
|
* O editor não conhece essas libraries: elas apenas registram seus blocos e
|
|
* declaram uma categoria, e o editor monta a paleta a partir disso.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <tinyblocks/tinyblocks.h>
|
|
#include <tb_editor.h>
|
|
#include <tb_graphics.h>
|
|
#include <tb_events.h>
|
|
#include <tb_control.h>
|
|
#include <tb_operators.h>
|
|
#include <tb_variables.h>
|
|
#include <tb_appearance.h>
|
|
#include <tb_pen.h>
|
|
#include <tb_fs.h>
|
|
#include <tb_toml.h>
|
|
#include <tb_json.h>
|
|
#include <tb_xml.h>
|
|
#include <tb_csv.h>
|
|
#include <tb_blueprint.h>
|
|
|
|
int main(int argc, char** argv) {
|
|
TinyBlocks* rt = NULL;
|
|
if (!tinyblocks_init(&rt, NULL)) return 1;
|
|
|
|
/* --backend troca o backend gráfico; os demais .so são pré-carregados */
|
|
for (int i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "--backend") == 0 && i + 1 < argc) {
|
|
if (!tb_graphics_load_backend(argv[++i])) return 1;
|
|
} else {
|
|
tb_editor_preload(argv[i]);
|
|
}
|
|
}
|
|
|
|
/* Libraries de categoria, na ordem em que aparecem na paleta */
|
|
tb_library_register(rt, tb_events_get_library());
|
|
tb_library_register(rt, tb_control_get_library());
|
|
tb_library_register(rt, tb_operators_get_library());
|
|
tb_library_register(rt, tb_variables_get_library());
|
|
tb_library_register(rt, tb_appearance_get_library());
|
|
tb_library_register(rt, tb_pen_get_library());
|
|
tb_library_register(rt, tb_fs_get_library());
|
|
tb_library_register(rt, tb_toml_get_library());
|
|
tb_library_register(rt, tb_json_get_library());
|
|
tb_library_register(rt, tb_xml_get_library());
|
|
tb_library_register(rt, tb_csv_get_library());
|
|
tb_library_register(rt, tb_blueprint_get_library());
|
|
|
|
/* Interface gráfica: o editor mede texto e cria o palco ao nascer */
|
|
tb_library_register(rt, tb_graphics_get_library());
|
|
tb_library_register(rt, tb_editor_get_library());
|
|
|
|
/* Graphics.Input - Editor.Scene - Graphics.Window */
|
|
TinyBlocks_TypeBlock* t_input = tb_type_block_find(rt, "Graphics.Input");
|
|
TinyBlocks_TypeBlock* t_scene = tb_type_block_find(rt, "Editor.Scene");
|
|
TinyBlocks_TypeBlock* t_win = tb_type_block_find(rt, "Graphics.Window");
|
|
if (!t_input || !t_scene || !t_win) {
|
|
fprintf(stderr, "blocos Graphics.Input / Editor.Scene / Graphics.Window não encontrados\n");
|
|
return 1;
|
|
}
|
|
|
|
TinyBlocks_Block* input = tb_block_create(rt, t_input);
|
|
TinyBlocks_Block* scene = tb_block_create(rt, t_scene);
|
|
TinyBlocks_Block* win = tb_block_create(rt, t_win);
|
|
|
|
tb_block_set_default(scene, 0, tb_value_block(input));
|
|
|
|
TinyBlocks_Value title = tb_value_text("TinyBlocks Editor");
|
|
tb_block_set_default(win, 0, title); /* set_default clona */
|
|
tb_value_free(&title);
|
|
tb_block_set_default(win, 1, tb_value_integer(1280));
|
|
tb_block_set_default(win, 2, tb_value_integer(800));
|
|
tb_block_set_default(win, 3, tb_value_block(scene));
|
|
tb_block_set_default(win, 4, tb_value_block(input));
|
|
|
|
tb_block_eval(win, rt); /* abre a janela */
|
|
printf("Backend gráfico: %s\n", tb_graphics_backend()->name);
|
|
tb_graphics_run(rt); /* loop até a janela principal fechar */
|
|
|
|
tinyblocks_deinit(&rt);
|
|
return 0;
|
|
}
|