Linha de comando: pasta é ignorada com aviso, projeto é aberto
Todo argumento ia para o dlopen como library: abrir o editor com uma pasta (./TinyBlocks.AppDir) dava "dlopen: ... Is a directory". Agora .so é library, pasta é ignorada com um aviso claro e qualquer outro arquivo é aberto como projeto (.json, ou .txt em scratchblocks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2a2d22a64a
commit
bfa17eecea
15 files changed
+9784
-124
No files matched your search
@@ -329,18 +329,67 @@ static void blk_defaults(EdBlock* b) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Zera um slot para o estado "vazio" (sem pai, sem proximo, campos -1) */
|
||||
static void blk_slot_clear(Tab* T, int i) {
|
||||
EdBlock* b = &T->ws[i];
|
||||
memset(b, 0, sizeof(*b));
|
||||
b->used = false;
|
||||
b->parent = -1; b->prel = REL_NONE; b->next = -1;
|
||||
b->sub[0] = b->sub[1] = b->sub[2] = -1;
|
||||
for (int s = 0; s < MAX_INPUTS; s++) b->args[s] = -1;
|
||||
}
|
||||
|
||||
/* Garante que o slot i existe (crescendo o vetor por dobragem) */
|
||||
bool blk_reserve(Tab* T, int i) {
|
||||
if (!T || i < 0) return false;
|
||||
if (i >= MAX_WS) return false;
|
||||
if (i >= T->ws_cap) {
|
||||
int nc = T->ws_cap ? T->ws_cap : 64;
|
||||
while (nc <= i) nc *= 2;
|
||||
EdBlock* p = (EdBlock*)realloc(T->ws, (size_t)nc * sizeof(*p));
|
||||
if (!p) return false;
|
||||
T->ws = p;
|
||||
for (int k = T->ws_cap; k < nc; k++) blk_slot_clear(T, k);
|
||||
T->ws_cap = nc;
|
||||
}
|
||||
if (i >= T->ws_n) T->ws_n = i + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Zera o pool da aba (mantem a memoria alocada, para reuso) */
|
||||
void tab_ws_clear(Tab* T) {
|
||||
if (!T) return;
|
||||
for (int i = 0; i < T->ws_cap; i++) blk_slot_clear(T, i);
|
||||
T->ws_n = 0;
|
||||
T->free_n = 0;
|
||||
T->top_n = 0;
|
||||
}
|
||||
|
||||
/* Devolve o slot para reuso (o bloco ja saiu da arvore) */
|
||||
void blk_release(Tab* T, int i) {
|
||||
if (!T || i < 0 || i >= T->ws_cap) return;
|
||||
if (T->free_n >= T->free_cap) {
|
||||
int nc = T->free_cap ? T->free_cap * 2 : 64;
|
||||
int* p = (int*)realloc(T->free_ids, (size_t)nc * sizeof(*p));
|
||||
if (!p) return; /* sem memoria: o slot so nao e reusado */
|
||||
T->free_ids = p; T->free_cap = nc;
|
||||
}
|
||||
T->free_ids[T->free_n++] = i;
|
||||
}
|
||||
|
||||
static int blk_alloc(Tab* T) {
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
if (T->ws[i].used) continue;
|
||||
EdBlock* b = &T->ws[i];
|
||||
memset(b, 0, sizeof(*b));
|
||||
b->used = true;
|
||||
b->parent = -1; b->prel = REL_NONE; b->next = -1;
|
||||
b->sub[0] = b->sub[1] = b->sub[2] = -1;
|
||||
for (int s = 0; s < MAX_INPUTS; s++) b->args[s] = -1;
|
||||
if (T->free_n > 0) {
|
||||
int i = T->free_ids[--T->free_n];
|
||||
blk_slot_clear(T, i);
|
||||
T->ws[i].used = true;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
if (T->ws_n >= MAX_WS) return -1;
|
||||
int i = T->ws_n;
|
||||
if (!blk_reserve(T, i)) return -1;
|
||||
blk_slot_clear(T, i);
|
||||
T->ws[i].used = true;
|
||||
return i;
|
||||
}
|
||||
|
||||
int blk_new(Tab* T, TinyBlocks_TypeBlock* type) {
|
||||
@@ -365,7 +414,13 @@ void top_remove(Tab* T, int bi) {
|
||||
/* Adiciona (ou traz para a frente) uma pilha de topo */
|
||||
void top_add(Tab* T, int bi) {
|
||||
top_remove(T, bi);
|
||||
if (T->top_n < MAX_WS) T->top[T->top_n++] = bi;
|
||||
if (T->top_n >= T->top_cap) {
|
||||
int nc = T->top_cap ? T->top_cap * 2 : 32;
|
||||
int* p = (int*)realloc(T->top, (size_t)nc * sizeof(*p));
|
||||
if (!p) return;
|
||||
T->top = p; T->top_cap = nc;
|
||||
}
|
||||
T->top[T->top_n++] = bi;
|
||||
}
|
||||
|
||||
/* Liga child ao pai na relação rel (child - -1 desliga) */
|
||||
@@ -491,6 +546,7 @@ void free_tree(Ed* ed, Tab* T, int bi) {
|
||||
}
|
||||
b->used = false;
|
||||
b->live_rt = NULL;
|
||||
blk_release(T, bi);
|
||||
bi = nx;
|
||||
}
|
||||
}
|
||||
@@ -1035,8 +1091,25 @@ static void ax_chain(Ed* ed, Tab* T, int head, float ox, float oy, uint32_t acts
|
||||
|
||||
static void render_chain(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int head, float ox, float oy);
|
||||
|
||||
/* Retangulo visivel (coordenadas de tela) do painel que esta sendo desenhado.
|
||||
* O palco e a saida sao desenhados depois da area de scripts, e os comandos de
|
||||
* desenho tem um teto (TB_DRAW_CMD_CAP): sem culling, uma aba com milhares de
|
||||
* blocos consome o teto e o palco some da tela. */
|
||||
void ed_cull_pane(Ed* ed, bool on, float x, float y, float w, float h) {
|
||||
ed->cull_on = on; ed->cull_x = x; ed->cull_y = y; ed->cull_w = w; ed->cull_h = h;
|
||||
}
|
||||
|
||||
static bool culled(const Ed* ed, const EdBlock* b, float ox, float oy) {
|
||||
if (!ed->cull_on) return false;
|
||||
const float M = 80.f; /* folga: valores encaixados passam do corpo */
|
||||
float x = b->ax + ox, y = b->ay + oy;
|
||||
return x + b->w < ed->cull_x - M || x > ed->cull_x + ed->cull_w + M ||
|
||||
y + b->h < ed->cull_y - M || y > ed->cull_y + ed->cull_h + M;
|
||||
}
|
||||
|
||||
static void render_block(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int bi, float ox, float oy) {
|
||||
EdBlock* b = &T->ws[bi];
|
||||
if (culled(ed, b, ox, oy)) return;
|
||||
Shape sh = shape_of(b->type);
|
||||
Col c, d; block_cols(ed, b, &c, &d);
|
||||
float x = b->ax + ox, y = b->ay + oy, w = b->w, h = b->h;
|
||||
@@ -1142,9 +1215,11 @@ static void render_block(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int bi,
|
||||
|
||||
/* Desenha de baixo para cima, para cada encaixe cobrir o bloco seguinte */
|
||||
static void render_chain(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int head, float ox, float oy) {
|
||||
int ids[MAX_WS], n = 0;
|
||||
for (int c = head; c >= 0 && n < MAX_WS; c = T->ws[c].next) ids[n++] = c;
|
||||
int* ids = T->ws_n > 0 ? (int*)malloc((size_t)T->ws_n * sizeof(int)) : NULL;
|
||||
int n = 0;
|
||||
for (int c = head; ids && c >= 0 && n < T->ws_n; c = T->ws[c].next) ids[n++] = c;
|
||||
for (int i = n - 1; i >= 0; i--) render_block(ed, rb, T, ids[i], ox, oy);
|
||||
free(ids);
|
||||
}
|
||||
|
||||
/* ===
|
||||
@@ -1169,7 +1244,7 @@ static void run_abort(Ed* ed, const char* msg) {
|
||||
}
|
||||
|
||||
static void clear_live(Tab* T) {
|
||||
for (int i = 0; i < MAX_WS; i++) T->ws[i].live_rt = NULL;
|
||||
for (int i = 0; i < T->ws_n; i++) T->ws[i].live_rt = NULL;
|
||||
}
|
||||
|
||||
/* Destrói as instâncias do runtime da execução anterior (e para os scripts) */
|
||||
@@ -1523,8 +1598,9 @@ void vm_stop(Ed* ed) {
|
||||
void run_flag(Ed* ed) {
|
||||
run_begin(ed, true);
|
||||
tb_input_timer_reset(); /* como no Scratch: a bandeira zera o cronometro */
|
||||
int heads[MAX_WS], n = 0;
|
||||
for (int i = 0; i < CT.top_n; i++) heads[n++] = CT.top[i];
|
||||
int* heads = CT.top_n > 0 ? (int*)malloc((size_t)CT.top_n * sizeof(int)) : NULL;
|
||||
int n = 0;
|
||||
for (int i = 0; heads && i < CT.top_n; i++) heads[n++] = CT.top[i];
|
||||
for (int i = 1; i < n; i++)
|
||||
for (int j = i; j > 0 && CT.ws[heads[j]].y < CT.ws[heads[j-1]].y; j--) {
|
||||
int tmp = heads[j]; heads[j] = heads[j-1]; heads[j-1] = tmp;
|
||||
@@ -1538,6 +1614,7 @@ void run_flag(Ed* ed) {
|
||||
started++;
|
||||
}
|
||||
}
|
||||
free(heads);
|
||||
if (!started) {
|
||||
run_end(ed);
|
||||
stage_append(ed, "Nenhum script começa com \"quando a bandeira for clicado\".\n");
|
||||
@@ -1823,8 +1900,9 @@ static void eval_composite(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
}
|
||||
/* Aba so do bloco: roda os scripts da definição de cima para baixo */
|
||||
Tab* S = def->snap;
|
||||
int heads[MAX_WS], n = 0;
|
||||
for (int i = 0; i < S->top_n; i++) heads[n++] = S->top[i];
|
||||
int* heads = S->top_n > 0 ? (int*)malloc((size_t)S->top_n * sizeof(int)) : NULL;
|
||||
int n = 0;
|
||||
for (int i = 0; heads && i < S->top_n; i++) heads[n++] = S->top[i];
|
||||
for (int i = 1; i < n; i++)
|
||||
for (int j = i; j > 0 && S->ws[heads[j]].y < S->ws[heads[j-1]].y; j--) {
|
||||
int tmp = heads[j]; heads[j] = heads[j-1]; heads[j-1] = tmp;
|
||||
@@ -1832,6 +1910,7 @@ static void eval_composite(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
for (int i = 0; i < n && !ed->abort; i++)
|
||||
if (!shape_is_value(shape_of(blk_type(ed, &S->ws[heads[i]]))))
|
||||
run_chain(ed, S, heads[i]);
|
||||
free(heads);
|
||||
|
||||
done:
|
||||
for (int i = 0; i < def->output_count; i++) {
|
||||
@@ -1848,7 +1927,7 @@ done:
|
||||
* Tipos: invalidação/re-resolução (hot reload e redefinição de compostos)
|
||||
* === */
|
||||
static void invalidate_tab(Tab* T) {
|
||||
for (int i = 0; i < MAX_WS; i++) { T->ws[i].type = NULL; T->ws[i].live_rt = NULL; }
|
||||
for (int i = 0; i < T->ws_n; i++) { T->ws[i].type = NULL; T->ws[i].live_rt = NULL; }
|
||||
}
|
||||
|
||||
static void invalidate_types(Ed* ed) {
|
||||
@@ -1860,7 +1939,7 @@ static void invalidate_types(Ed* ed) {
|
||||
}
|
||||
|
||||
static void retype_tab(Ed* ed, Tab* T) {
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
for (int i = 0; i < T->ws_n; i++) {
|
||||
EdBlock* b = &T->ws[i];
|
||||
if (!b->used) continue;
|
||||
b->type = b->type_name[0] ? tb_type_block_find(ed->rt, b->type_name) : NULL;
|
||||
@@ -1945,7 +2024,15 @@ static void fly_add_block(Ed* ed, int cat, TinyBlocks_TypeBlock* t, const char*
|
||||
|
||||
void palette_rebuild(Ed* ed) {
|
||||
cats_rebuild(ed);
|
||||
/* Zera a paleta sem jogar fora o pool de blocos (ele seria realocado do
|
||||
zero a cada troca de categoria) */
|
||||
EdBlock* fws = ed->fly.ws; int fcap = ed->fly.ws_cap;
|
||||
int* fids = ed->fly.free_ids; int fidscap = ed->fly.free_cap;
|
||||
int* ftop = ed->fly.top; int ftopcap = ed->fly.top_cap;
|
||||
memset(&ed->fly, 0, sizeof(ed->fly));
|
||||
ed->fly.ws = fws; ed->fly.ws_cap = fcap;
|
||||
ed->fly.free_ids = fids; ed->fly.free_cap = fidscap;
|
||||
ed->fly.top = ftop; ed->fly.top_cap = ftopcap;
|
||||
ed->fly_n = 0;
|
||||
float y = 8;
|
||||
TinyBlocks_TypeBlock* var_get = tb_type_block_find(ed->rt, "Variables.Get");
|
||||
@@ -2495,6 +2582,7 @@ bool tab_new_kind(Ed* ed, const char* name, bool is_composite, int kind) {
|
||||
}
|
||||
int idx = ed->tab_n++;
|
||||
Tab* T = &ed->tabs[idx];
|
||||
tab_doc_free(T); /* slot reaproveitado: solta o pool */
|
||||
memset(T, 0, sizeof(*T));
|
||||
if (name && name[0]) strncpy(T->name, name, sizeof(T->name) - 1);
|
||||
else snprintf(T->name, sizeof(T->name), "Código %d", idx + 1);
|
||||
@@ -2535,6 +2623,10 @@ void tab_doc_free(Tab* T) {
|
||||
T->img_layer_n = 0;
|
||||
if (T->img_prev) { tb_image_release(T->img_prev); T->img_prev = NULL; }
|
||||
img_sel_reset(T);
|
||||
/* pool de blocos e pilhas de topo (dinamicos desde o limite de 65536) */
|
||||
free(T->ws); T->ws = NULL; T->ws_cap = T->ws_n = 0;
|
||||
free(T->free_ids); T->free_ids = NULL; T->free_n = T->free_cap = 0;
|
||||
free(T->top); T->top = NULL; T->top_cap = T->top_n = 0;
|
||||
}
|
||||
|
||||
/* Novo indice de uma aba depois de mover `from` para `to` */
|
||||
@@ -2626,7 +2718,7 @@ static void open_def(Ed* ed, const char* uname) {
|
||||
|
||||
static void collect_labels(Tab* T, const char* type_name, char names[][32], int* count, const char* fallback) {
|
||||
*count = 0;
|
||||
for (int i = 0; i < MAX_WS && *count < MAX_UBLK_SLOTS; i++) {
|
||||
for (int i = 0; i < T->ws_n && *count < MAX_UBLK_SLOTS; i++) {
|
||||
EdBlock* b = &T->ws[i];
|
||||
if (!b->used || strcmp(b->type_name, type_name) != 0) continue;
|
||||
char lbl[32];
|
||||
@@ -2640,8 +2732,9 @@ static void collect_labels(Tab* T, const char* type_name, char names[][32], int*
|
||||
|
||||
/* Reconcilia os blocos Port.In do corpo com as entradas do protótipo */
|
||||
static void comp_sync_inputs(Ed* ed, UserBlockDef* def, Tab* T) {
|
||||
int ids[MAX_WS], n = 0;
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
int* ids = T->ws_n > 0 ? (int*)malloc((size_t)T->ws_n * sizeof(int)) : NULL;
|
||||
int n = 0;
|
||||
for (int i = 0; ids && i < T->ws_n; i++) {
|
||||
EdBlock* b = &T->ws[i];
|
||||
if (b->used && strcmp(b->type_name, "Port.In") == 0) ids[n++] = i;
|
||||
}
|
||||
@@ -2657,6 +2750,7 @@ static void comp_sync_inputs(Ed* ed, UserBlockDef* def, Tab* T) {
|
||||
}
|
||||
}
|
||||
for (int k = def->input_count; k < n; k++) free_tree(ed, T, ids[k]);
|
||||
free(ids);
|
||||
}
|
||||
|
||||
/* Deriva os nomes das entradas a partir das partes do protótipo */
|
||||
@@ -2750,18 +2844,19 @@ static void tab_to_bp(const Tab* T, TbBpTab* B) {
|
||||
B->comp_id = T->comp_id;
|
||||
B->color_idx = T->color_idx;
|
||||
B->ws_sx = T->ws_sx; B->ws_sy = T->ws_sy;
|
||||
B->top_n = T->top_n;
|
||||
for (int i = 0; i < T->top_n; i++) B->top[i] = T->top[i];
|
||||
B->top_n = 0;
|
||||
for (int i = 0; i < T->top_n; i++) tb_blueprint_top_add(B, T->top[i]);
|
||||
B->group_n = T->group_n < TB_BP_MAX_GROUPS ? T->group_n : TB_BP_MAX_GROUPS;
|
||||
for (int g = 0; g < B->group_n; g++) {
|
||||
const WsGroup* G = &T->groups[g];
|
||||
B->groups[g] = (TbBpGroup){ G->x, G->y, G->w, G->h, G->color, "" };
|
||||
snprintf(B->groups[g].title, sizeof(B->groups[g].title), "%s", G->title);
|
||||
}
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
for (int i = 0; i < T->ws_n; i++) {
|
||||
const EdBlock* b = &T->ws[i];
|
||||
if (!b->used) continue;
|
||||
TbBpBlock* o = &B->blocks[i];
|
||||
TbBpBlock* o = tb_blueprint_tab_slot(B, i);
|
||||
if (!o) break;
|
||||
o->used = true;
|
||||
snprintf(o->type, sizeof(o->type), "%s", b->type_name);
|
||||
o->x = b->x; o->y = b->y;
|
||||
@@ -2821,15 +2916,11 @@ static TbBlueprint* ed_to_blueprint(Ed* ed) {
|
||||
|
||||
/* Blocos de uma aba da blueprint -> aba do editor (os mesmos indices) */
|
||||
static void bp_tab_load(Ed* ed, const TbBpTab* B, Tab* T) {
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
memset(&T->ws[i], 0, sizeof(T->ws[i]));
|
||||
T->ws[i].parent = -1; T->ws[i].prel = REL_NONE; T->ws[i].next = -1;
|
||||
T->ws[i].sub[0] = T->ws[i].sub[1] = T->ws[i].sub[2] = -1;
|
||||
for (int s = 0; s < MAX_INPUTS; s++) T->ws[i].args[s] = -1;
|
||||
}
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
tab_ws_clear(T); /* zera o pool da aba */
|
||||
for (int i = 0; i < B->blocks_n; i++) {
|
||||
const TbBpBlock* o = &B->blocks[i];
|
||||
if (!o->used) continue;
|
||||
if (!blk_reserve(T, i)) break;
|
||||
EdBlock* b = &T->ws[i];
|
||||
b->used = true;
|
||||
snprintf(b->type_name, sizeof(b->type_name), "%s", o->type);
|
||||
@@ -2843,8 +2934,8 @@ static void bp_tab_load(Ed* ed, const TbBpTab* B, Tab* T) {
|
||||
}
|
||||
snprintf(b->lit_text, sizeof(b->lit_text), "%s", o->lit);
|
||||
}
|
||||
T->top_n = B->top_n < MAX_WS ? B->top_n : MAX_WS;
|
||||
for (int i = 0; i < T->top_n; i++) T->top[i] = B->top[i];
|
||||
T->top_n = 0;
|
||||
for (int i = 0; i < B->top_n; i++) top_add(T, B->top[i]);
|
||||
}
|
||||
|
||||
/* Descarta tudo do editor e reconstroi a partir da blueprint. */
|
||||
@@ -2885,6 +2976,7 @@ static void blueprint_apply(Ed* ed, const TbBlueprint* bp) {
|
||||
for (int ti = 0; ti < bp->tab_count && ed->tab_n < MAX_TABS; ti++) {
|
||||
const TbBpTab* B = &bp->tabs[ti];
|
||||
Tab* T = &ed->tabs[ed->tab_n++];
|
||||
tab_doc_free(T); /* slot reaproveitado: solta o pool */
|
||||
memset(T, 0, sizeof(*T));
|
||||
snprintf(T->name, sizeof(T->name), "%s", B->name);
|
||||
T->is_composite = B->composite;
|
||||
@@ -3047,6 +3139,13 @@ static TbSbContext sb_context(Ed* ed, TbSbLabel** labels_out) {
|
||||
return cx;
|
||||
}
|
||||
|
||||
/* Solta uma aba de blueprint isolada (pool de blocos + struct) */
|
||||
static void bp_tab_dispose(TbBpTab* B) {
|
||||
if (!B) return;
|
||||
tb_blueprint_tab_free(B);
|
||||
free(B);
|
||||
}
|
||||
|
||||
/* Pilha `head` da aba T (ou a aba inteira, head < 0) em scratchblocks. malloc */
|
||||
char* ed_scratchblocks_export(Ed* ed, const Tab* T, int head) {
|
||||
TbBpTab* B = calloc(1, sizeof(TbBpTab));
|
||||
@@ -3057,7 +3156,7 @@ char* ed_scratchblocks_export(Ed* ed, const Tab* T, int head) {
|
||||
TbSbContext cx = sb_context(ed, &labels);
|
||||
char* txt = tb_scratchblocks_export(B, &cx);
|
||||
free(labels);
|
||||
free(B);
|
||||
bp_tab_dispose(B);
|
||||
return txt;
|
||||
}
|
||||
|
||||
@@ -3072,21 +3171,23 @@ int ed_scratchblocks_import(Ed* ed, Tab* T, const char* text, float x, float y,
|
||||
TbSbContext cx = sb_context(ed, &labels);
|
||||
int n = tb_scratchblocks_import(text, B, &cx, warn, warn_cap);
|
||||
free(labels);
|
||||
if (n <= 0) { free(B); return -1; }
|
||||
int map[TB_BP_MAX_WS];
|
||||
for (int i = 0; i < TB_BP_MAX_WS; i++) {
|
||||
if (n <= 0) { bp_tab_dispose(B); return -1; }
|
||||
int* map = (int*)malloc((size_t)(B->blocks_n > 0 ? B->blocks_n : 1) * sizeof(int));
|
||||
if (!map) { bp_tab_dispose(B); return -1; }
|
||||
for (int i = 0; i < B->blocks_n; i++) {
|
||||
map[i] = -1;
|
||||
if (!B->blocks[i].used) continue;
|
||||
map[i] = blk_alloc(T);
|
||||
if (map[i] < 0) { /* aba cheia: desfaz */
|
||||
for (int j = 0; j < i; j++) if (map[j] >= 0) T->ws[map[j]].used = false;
|
||||
if (warn && warn_cap) snprintf(warn, warn_cap, "a aba esta cheia (%d blocos)", MAX_WS);
|
||||
free(B);
|
||||
if (map[i] < 0) { /* limite da aba: desfaz */
|
||||
for (int j = 0; j < i; j++) if (map[j] >= 0) { T->ws[map[j]].used = false; blk_release(T, map[j]); }
|
||||
if (warn && warn_cap) snprintf(warn, warn_cap, "limite de %d blocos por aba", MAX_WS);
|
||||
free(map);
|
||||
bp_tab_dispose(B);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#define MAP(i) ((i) >= 0 && (i) < TB_BP_MAX_WS ? map[i] : -1)
|
||||
for (int i = 0; i < TB_BP_MAX_WS; i++) {
|
||||
#define MAP(i) ((i) >= 0 && (i) < B->blocks_n ? map[i] : -1)
|
||||
for (int i = 0; i < B->blocks_n; i++) {
|
||||
const TbBpBlock* o = &B->blocks[i];
|
||||
if (!o->used) continue;
|
||||
EdBlock* b = &T->ws[map[i]];
|
||||
@@ -3104,14 +3205,15 @@ int ed_scratchblocks_import(Ed* ed, Tab* T, const char* text, float x, float y,
|
||||
#undef MAP
|
||||
int made = 0;
|
||||
for (int t = 0; t < B->top_n; t++) {
|
||||
int h = B->top[t] >= 0 && B->top[t] < TB_BP_MAX_WS ? map[B->top[t]] : -1;
|
||||
int h = B->top[t] >= 0 && B->top[t] < B->blocks_n ? map[B->top[t]] : -1;
|
||||
if (h < 0) continue;
|
||||
T->ws[h].x = x; T->ws[h].y = y;
|
||||
top_add(T, h);
|
||||
if (made < max && heads) heads[made] = h;
|
||||
made++;
|
||||
}
|
||||
free(B);
|
||||
free(map);
|
||||
bp_tab_dispose(B);
|
||||
layout_tab(T); /* empilha uma embaixo da outra */
|
||||
for (int k = 1; k < made && k < max && heads; k++) {
|
||||
float x0, y0, x1, y1;
|
||||
@@ -3176,11 +3278,11 @@ static bool sb_import_text(Ed* ed, const char* text, const char* name) {
|
||||
if (n <= 0) snprintf(ed->hot_status, sizeof(ed->hot_status), "Nenhum script em %.200s", name);
|
||||
else snprintf(ed->hot_status, sizeof(ed->hot_status), "Limite de abas atingido");
|
||||
ed->hot_status_ok = false;
|
||||
free(B);
|
||||
bp_tab_dispose(B);
|
||||
return false;
|
||||
}
|
||||
bp_tab_load(ed, B, &CT);
|
||||
free(B);
|
||||
bp_tab_dispose(B);
|
||||
layout_tab(&CT);
|
||||
cleanup_ws(ed); /* arruma as pilhas uma embaixo da outra */
|
||||
palette_rebuild(ed);
|
||||
@@ -3488,7 +3590,7 @@ static void dlg_ok(Ed* ed) {
|
||||
snprintf(old_type, sizeof(old_type), "User.%s", old_name);
|
||||
snprintf(new_type, sizeof(new_type), "User.%s", def->name);
|
||||
for (int t = 0; t < ed->tab_n; t++)
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
for (int i = 0; i < ed->tabs[t].ws_n; i++) {
|
||||
EdBlock* b = &ed->tabs[t].ws[i];
|
||||
if (b->used && strcmp(b->type_name, old_type) == 0)
|
||||
snprintf(b->type_name, sizeof(b->type_name), "%s", new_type);
|
||||
@@ -4837,7 +4939,7 @@ static void groups_render(Ed* ed, TinyBlocks_RenderableBlock* rb, float ox, floa
|
||||
/* Limites de uma pilha (todos os blocos dela, ja com layout) */
|
||||
void stack_bounds(Tab* T, int root, float* x0, float* y0, float* x1, float* y1) {
|
||||
*x0 = *y0 = 1e9f; *x1 = *y1 = -1e9f;
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
for (int i = 0; i < T->ws_n; i++) {
|
||||
EdBlock* b = &T->ws[i];
|
||||
if (!b->used || stack_root(T, i) != root) continue;
|
||||
if (b->ax < *x0) *x0 = b->ax;
|
||||
@@ -4871,6 +4973,21 @@ static void group_delete(Tab* T, int g) {
|
||||
T->group_n--;
|
||||
}
|
||||
|
||||
/* Garante espaco para n pilhas no arrasto de grupo */
|
||||
static bool grp_mem_reserve(Ed* ed, int n) {
|
||||
if (n <= ed->grp_mem_cap) return true;
|
||||
int nc = ed->grp_mem_cap ? ed->grp_mem_cap * 2 : 64;
|
||||
while (nc < n) nc *= 2;
|
||||
int* ids = (int*)realloc(ed->grp_mem, (size_t)nc * sizeof(*ids));
|
||||
if (!ids) return false;
|
||||
ed->grp_mem = ids;
|
||||
float (*pos)[2] = (float(*)[2])realloc(ed->grp_mem_pos, (size_t)nc * sizeof(*pos));
|
||||
if (!pos) return false;
|
||||
ed->grp_mem_pos = pos;
|
||||
ed->grp_mem_cap = nc;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Comeca a mover o grupo g: guarda as pilhas e grupos que estao dentro */
|
||||
static void group_press(Ed* ed, int g, float mx, float my, int mode) {
|
||||
Tab* T = &CT;
|
||||
@@ -4883,6 +5000,7 @@ static void group_press(Ed* ed, int g, float mx, float my, int mode) {
|
||||
for (int i = 0; i < T->top_n; i++) {
|
||||
EdBlock* b = &T->ws[T->top[i]];
|
||||
if (!in_rect(b->x, b->y, G->x, G->y, G->w, G->h)) continue;
|
||||
if (!grp_mem_reserve(ed, ed->grp_mem_n + 1)) break;
|
||||
ed->grp_mem[ed->grp_mem_n] = T->top[i];
|
||||
ed->grp_mem_pos[ed->grp_mem_n][0] = b->x;
|
||||
ed->grp_mem_pos[ed->grp_mem_n][1] = b->y;
|
||||
@@ -4952,10 +5070,16 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_text_c(rb, WS_X + (WS_W - tw(hint, FS_UI))*0.5f, WS_Y + WS_H*0.45f, hint, COL_TEXT_DIM, FS_UI);
|
||||
}
|
||||
|
||||
ed_cull_pane(ed, true, WS_X, WS_Y, WS_W, WS_H);
|
||||
for (int i = 0; i < CT.top_n; i++) {
|
||||
if (ed->state == ES_DRAG && CT.top[i] == ed->drag_bi) continue;
|
||||
/* pilha inteira fora da vista: nem comeca a desenhar */
|
||||
float x0, y0, x1, y1;
|
||||
stack_bounds(&CT, CT.top[i], &x0, &y0, &x1, &y1);
|
||||
if (x1 + ox < WS_X || x0 + ox > WS_X + WS_W || y1 + oy < WS_Y || y0 + oy > WS_Y + WS_H) continue;
|
||||
render_chain(ed, rb, &CT, CT.top[i], ox, oy);
|
||||
}
|
||||
ed_cull_pane(ed, false, 0, 0, 0, 0);
|
||||
render_snap(ed, rb, ox, oy);
|
||||
ax_workspace(ed, ox, oy);
|
||||
if (ed->bubble_bi >= 0 && CT.ws[ed->bubble_bi].used) { /* balao com o valor do reporter */
|
||||
@@ -5848,7 +5972,7 @@ static void compute_snap(Ed* ed) {
|
||||
if (shape_is_value(ds)) {
|
||||
/* Repórter: o lado esquerdo procura um campo de entrada */
|
||||
float px = d->x, py = d->y + d->h*0.5f;
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
for (int i = 0; i < T->ws_n; i++) {
|
||||
EdBlock* B = &T->ws[i];
|
||||
if (!B->used || B->dragging || !B->type) continue;
|
||||
for (int s = 0; s < input_count(B->type); s++) {
|
||||
@@ -5865,7 +5989,7 @@ static void compute_snap(Ed* ed) {
|
||||
int last = ed->drag_bi;
|
||||
while (T->ws[last].next >= 0) last = T->ws[last].next;
|
||||
bool drag_cap = is_cap(T->ws[last].type);
|
||||
for (int i = 0; i < MAX_WS; i++) {
|
||||
for (int i = 0; i < T->ws_n; i++) {
|
||||
EdBlock* B = &T->ws[i];
|
||||
if (!B->used || B->dragging) continue;
|
||||
Shape bs = shape_of(B->type);
|
||||
@@ -6830,7 +6954,7 @@ static void update_tooltip(Ed* ed, bool alt) {
|
||||
/* mantem aberto enquanto o mouse estiver sobre o tooltip ... */
|
||||
if (in_rect(ed->mouse_x, ed->mouse_y, ed->tip_x, ed->tip_y, ed->tip_w, ed->tip_h)) return;
|
||||
/* ... ou sobre o proprio bloco de origem (permite soltar o Alt e clicar) */
|
||||
if (tab_class(&CT)->blocks && ed->tip_bi >= 0 && ed->tip_bi < MAX_WS && CT.ws[ed->tip_bi].used) {
|
||||
if (tab_class(&CT)->blocks && ed->tip_bi >= 0 && ed->tip_bi < CT.ws_n && CT.ws[ed->tip_bi].used) {
|
||||
int hb = hit_ws(&CT, ed->mouse_x - WS_X + CT.ws_sx, ed->mouse_y - WS_Y + CT.ws_sy);
|
||||
if (hb == ed->tip_bi) return;
|
||||
}
|
||||
@@ -7499,9 +7623,24 @@ static bool editor_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
palette_rebuild(ed);
|
||||
tb_libman_init(rt); /* liga tinyblocks-api e adota as libs embutidas */
|
||||
tb_libman_scan_defaults(); /* procura library.toml em libraries/ e ~/.tinyblocks */
|
||||
for (int i = 0; i < s_preload_n; i++) hotlib_load(ed, s_preload[i]);
|
||||
s_preload_n = 0;
|
||||
/* Argumentos da linha de comando: .so = library; projeto (.json, .txt...) =
|
||||
abre; pasta = ignora com aviso (antes ia para o dlopen) */
|
||||
const char* open_path = NULL;
|
||||
for (int i = 0; i < s_preload_n; i++) {
|
||||
const char* a = s_preload[i];
|
||||
struct stat st;
|
||||
if (stat(a, &st) == 0 && S_ISDIR(st.st_mode)) {
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Ignorado: %.120s é uma pasta, não um projeto nem uma library", a);
|
||||
ed->hot_status_ok = false;
|
||||
} else if (has_ext(a, ".so")) {
|
||||
hotlib_load(ed, a);
|
||||
} else {
|
||||
open_path = a; /* o ultimo projeto da linha de comando */
|
||||
}
|
||||
}
|
||||
seed_example(ed);
|
||||
if (open_path) project_load(ed, open_path);
|
||||
s_preload_n = 0;
|
||||
|
||||
/* Configuracoes iniciais (store da tinyblocks-environ) */
|
||||
if (tb_environ_count() == 0) {
|
||||
@@ -7523,9 +7662,12 @@ static void editor_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
* aqui só soltamos o que é do editor. */
|
||||
bubble_clear(ed);
|
||||
for (int i = 0; i < ed->tab_n; i++) tab_doc_free(&ed->tabs[i]);
|
||||
tab_doc_free(&ed->fly); /* pool da paleta */
|
||||
free(ed->fdlg.ents);
|
||||
free(ed->sbp_text);
|
||||
free(ed->run_blocks);
|
||||
free(ed->grp_mem);
|
||||
free(ed->grp_mem_pos);
|
||||
for (int u = 0; u < ed->user_block_n; u++) free(ed->user_blocks[u].snap);
|
||||
tb_libman_shutdown();
|
||||
tb_a11y_tree_free(ed->ax_tree);
|
||||
|
||||
Reference in new issue
Block a user