Estado atual do TinyBlocks: editor estilo Scratch + graphics como interface

Snapshot do projeto antes de implementar o diálogo "Criar um Bloco":
- runtime C block-based (src/, include/)
- libraries: graphics (interface), sdl2 (backend), editor (estilo Scratch),
  python, mcp
- exemplos (hello, sdl2, editor, vector, json, customappearance, python, mcp)
- Makefile com alvo help e build do editor

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude committed 2026-10-20 19:10:43 -03:00
commit 4950ad6006
49 files changed
+10596

No files matched your search

+116
View File
@@ -0,0 +1,116 @@
/*
* TinyBlocks — tb_defs.h
* Forward declarations, enums e tipos primitivos compartilhados por todo o runtime.
*/
#ifndef TINYBLOCKS_DEFS_H
#define TINYBLOCKS_DEFS_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/* ── Visibilidade de API ─────────────────────────────────────────────────── */
#ifdef _WIN32
# define TB_API __declspec(dllexport)
#else
# define TB_API __attribute__((visibility("default")))
#endif
/* ── Forward declarations ────────────────────────────────────────────────── */
typedef struct TinyBlocks TinyBlocks;
typedef struct TinyBlocks_Block TinyBlocks_Block;
typedef struct TinyBlocks_TypeBlock TinyBlocks_TypeBlock;
typedef struct TinyBlocks_LibraryBlock TinyBlocks_LibraryBlock;
typedef struct TinyBlocks_TextBlock TinyBlocks_TextBlock;
typedef struct TinyBlocks_IntegerBlock TinyBlocks_IntegerBlock;
typedef struct TinyBlocks_RealBlock TinyBlocks_RealBlock;
typedef struct TinyBlocks_VectorBlock TinyBlocks_VectorBlock;
typedef struct TinyBlocks_VectorData TinyBlocks_VectorData;
typedef struct TinyBlocks_RenderableBlock TinyBlocks_RenderableBlock;
typedef struct TinyBlocks_JsonValue TinyBlocks_JsonValue;
/* ── Kinds de bloco ──────────────────────────────────────────────────────── */
typedef enum TinyBlocks_BlockKind {
TB_KIND_BLOCK = 0, /* bloco genérico / definido pelo usuário */
TB_KIND_TYPE = 1, /* TinyBlocks_TypeBlock */
TB_KIND_LIBRARY = 2, /* TinyBlocks_LibraryBlock */
TB_KIND_TEXT = 3, /* TinyBlocks_TextBlock */
TB_KIND_INTEGER = 4, /* TinyBlocks_IntegerBlock */
TB_KIND_REAL = 5, /* TinyBlocks_RealBlock */
TB_KIND_VECTOR = 6, /* TinyBlocks_VectorBlock */
} TinyBlocks_BlockKind;
/* ── Kinds de valor (para slots) ─────────────────────────────────────────── */
typedef enum TinyBlocks_ValueKind {
TB_VALUE_NONE = 0,
TB_VALUE_INTEGER = 1,
TB_VALUE_REAL = 2,
TB_VALUE_TEXT = 3,
TB_VALUE_BLOCK = 4, /* referência a qualquer bloco (handle opaco) */
TB_VALUE_VECTOR = 5, /* dados de vetor 2D (ref-counted) */
TB_VALUE_JSON = 6, /* valor JSON (ref-counted) */
} TinyBlocks_ValueKind;
/* ── Valor com tag (flui entre slots) ────────────────────────────────────── */
typedef struct TinyBlocks_Value {
TinyBlocks_ValueKind kind;
union {
int64_t integer;
double real;
char* text; /* heap-owned (tb_value_free) */
TinyBlocks_Block* block; /* ponteiro não-owning */
TinyBlocks_VectorData* vector; /* ref-counted (retain/release) */
TinyBlocks_JsonValue* json; /* ref-counted (retain/release) */
} as;
} TinyBlocks_Value;
/* ══════════════════════════════════════════════════════════════════════════
* Dados de vetor 2D (fluxo de comandos de desenho, ref-counted)
* ══════════════════════════════════════════════════════════════════════════ */
typedef enum TinyBlocks_VCmdKind {
TB_VCMD_BEGIN_PATH = 0, /* nenhum arg */
TB_VCMD_MOVE_TO, /* args[0]=x, args[1]=y */
TB_VCMD_LINE_TO, /* args[0]=x, args[1]=y */
TB_VCMD_CLOSE_PATH, /* nenhum arg */
TB_VCMD_STROKE, /* args[0..3]=r,g,b,a args[4]=width */
TB_VCMD_FILL, /* args[0..3]=r,g,b,a */
TB_VCMD_RECT, /* args[0..3]=x,y,w,h */
TB_VCMD_CIRCLE, /* args[0..2]=cx,cy,raio */
} TinyBlocks_VCmdKind;
typedef struct { TinyBlocks_VCmdKind kind; float args[5]; } TinyBlocks_VCmd;
struct TinyBlocks_VectorData {
TinyBlocks_VCmd* cmds;
uint32_t count, capacity;
int32_t ref;
};
/* ── Descritor de slot (em TypeBlock — descreve a forma dos inputs/outputs) ─ */
typedef struct TinyBlocks_SlotDesc {
const char* name;
TinyBlocks_ValueKind expected_kind; /* TB_VALUE_NONE = aceita qualquer tipo */
} TinyBlocks_SlotDesc;
/* ── Conexão de entrada (de qual bloco/slot este input lê) ───────────────── */
typedef struct TinyBlocks_Connection {
TinyBlocks_Block* source; /* bloco de origem (NULL se não conectado) */
uint32_t output_idx; /* qual output slot da origem */
TinyBlocks_Value default_value; /* valor quando não há conexão */
} TinyBlocks_Connection;
/* ── Alocador customizável ───────────────────────────────────────────────── */
typedef void* (*TinyBlocks_AllocFn)(size_t size, void* userdata);
typedef void (*TinyBlocks_FreeFn) (void* ptr, void* userdata);
/* ── Helpers para TinyBlocks_Value ──────────────────────────────────────── */
TB_API TinyBlocks_Value tb_value_none(void);
TB_API TinyBlocks_Value tb_value_integer(int64_t v);
TB_API TinyBlocks_Value tb_value_real(double v);
TB_API TinyBlocks_Value tb_value_text(const char* v); /* copia a string */
TB_API TinyBlocks_Value tb_value_block(TinyBlocks_Block* v);
TB_API TinyBlocks_Value tb_value_clone(TinyBlocks_Value v); /* deep copy */
TB_API void tb_value_free(TinyBlocks_Value* v); /* libera text */
#endif /* TINYBLOCKS_DEFS_H */