Editor: diálogo "Criar um Bloco" estilo Scratch e nomes de parâmetros no bloco
- Diálogo modal (novo/editar) com protótipo ao vivo: campo de nome, cards para adicionar entrada numérica/texto, booleana e rótulo, controles <lixeira> de reordenar/apagar a parte selecionada, paleta de cores e Cancelar/OK (atalhos Esc/Enter). - UserBlockDef guarda o protótipo em parts[] (NUM/BOOL/LABEL); build_parts monta o rótulo do bloco com os nomes dos parâmetros, blk_defaults usa o nome como valor inicial e slot_is_bool consulta as parts. Renomear o bloco atualiza as referências User.*. - A aba de definição é criada com os Port.In sincronizados (comp_sync_inputs) e os Port.Out definem a saída; a barra do bloco composto ganhou "Editar bloco" + "Salvar" e perdeu os swatches. - tests/editor_harness.c portado do scratchpad para o repositório, com o cenário do diálogo; alvo "make test-editor" (ASan/UBSan). Os 18 cenários passam. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
4950ad6006
commit
278d3f4473
3 files changed
+848
-73
No files matched your search
@@ -27,7 +27,7 @@ OBJS := $(patsubst src/%.c,$(BUILD)/%.o,$(SRCS))
|
||||
OBJS_DBG := $(patsubst src/%.c,$(BUILD)/%-dbg.o,$(SRCS))
|
||||
|
||||
.PHONY: all help debug release static shared example sdl2 clean run python-lib mcp-lib json \
|
||||
editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend
|
||||
editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend test-editor
|
||||
|
||||
all: static example ## Compila a biblioteca estática e o exemplo hello (padrão)
|
||||
|
||||
@@ -239,6 +239,22 @@ mcp-lib: static $(BUILD)/libtinyblocks-python.so $(BUILD)/libtinyblocks-mcp.so $
|
||||
@echo "Build mcp OK: $(BUILD)/mcp.so"
|
||||
|
||||
# ── Limpeza ───────────────────────────────────────────────────────────────
|
||||
# ── Testes (harness headless com ASan/UBSan) ────────────────────────────
|
||||
$(BUILD)/editor_harness: tests/editor_harness.c $(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage.c \
|
||||
libraries/tinyblocks-graphics/src/tb_graphics.c
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_DBG) \
|
||||
-Ilibraries/tinyblocks-editor/include -Ilibraries/tinyblocks-editor/src \
|
||||
-I$(GFX_INC) \
|
||||
$(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage.c \
|
||||
libraries/tinyblocks-graphics/src/tb_graphics.c \
|
||||
tests/editor_harness.c -o $@ -ldl -lm
|
||||
|
||||
test-editor: $(BUILD)/editor_harness ## Roda o harness headless do editor (ASan/UBSan)
|
||||
./$(BUILD)/editor_harness
|
||||
|
||||
clean: ## Remove o diretório build/
|
||||
$(RM) -r $(BUILD)
|
||||
$(MAKE) -C libraries/tinyblocks-sdl2 clean 2>/dev/null || true
|
||||
@@ -122,6 +122,7 @@ TB_API void tb_editor_preload(const char* path) {
|
||||
#define MAX_HOT_TYPES 64
|
||||
#define MAX_USER_BLOCKS 16
|
||||
#define MAX_UBLK_SLOTS 8
|
||||
#define MAX_UBLK_PARTS 16
|
||||
|
||||
/* ══════════════════════════════════════════════════════════════════════════
|
||||
* Cores (paleta do Scratch 3) — componentes 0..1
|
||||
@@ -280,11 +281,16 @@ typedef struct {
|
||||
int color_idx;
|
||||
} Tab;
|
||||
|
||||
typedef enum { PARAM_NUM, PARAM_BOOL, PARAM_LABEL } ParamKind;
|
||||
typedef struct { ParamKind kind; char name[32]; } UserParam;
|
||||
|
||||
typedef struct {
|
||||
char name[48];
|
||||
int input_count, output_count;
|
||||
char input_names[MAX_UBLK_SLOTS][32];
|
||||
char output_names[MAX_UBLK_SLOTS][32];
|
||||
UserParam parts[MAX_UBLK_PARTS]; /* protótipo: entradas, booleanas e rótulos */
|
||||
int part_n;
|
||||
Tab* snap; /* cópia da aba no momento do "Salvar" */
|
||||
TinyBlocks_TypeBlock* reg_type;
|
||||
int tab_idx;
|
||||
@@ -332,7 +338,19 @@ typedef struct {
|
||||
|
||||
char comp_name_buf[48];
|
||||
int comp_name_len;
|
||||
bool comp_name_active;
|
||||
|
||||
/* Diálogo modal "Criar um Bloco" (estilo Scratch) */
|
||||
bool comp_dialog_open;
|
||||
int comp_dialog_def; /* -1 = novo; senão índice em user_blocks */
|
||||
bool comp_dialog_editing; /* true = edição de nome/rótulo em andamento */
|
||||
int comp_dialog_edit_part; /* índice da parte em edição, -1 = nome do bloco */
|
||||
char comp_dialog_name[48];
|
||||
UserParam comp_dialog_parts[MAX_UBLK_PARTS];
|
||||
int comp_dialog_part_n;
|
||||
int comp_dialog_sel; /* parte selecionada (-1 = nenhuma) */
|
||||
int comp_dialog_color;
|
||||
float comp_dialog_geom[MAX_UBLK_PARTS][2]; /* x,w desenhados (para hit test) */
|
||||
float comp_dialog_name_x, comp_dialog_name_w;
|
||||
|
||||
bool ctx_menu_open;
|
||||
int ctx_menu_bi;
|
||||
@@ -404,6 +422,13 @@ typedef struct {
|
||||
static Ed* g_active_ed = NULL;
|
||||
|
||||
static void palette_rebuild(Ed* ed);
|
||||
static void utf8_pop(char* s);
|
||||
static void append_text(char* dst, size_t cap, const char* add);
|
||||
static void dlg_open(Ed* ed, int def_idx);
|
||||
static void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb);
|
||||
static bool dlg_click(Ed* ed, float mx, float my);
|
||||
static void dlg_key(Ed* ed, int sc);
|
||||
static void dlg_text(Ed* ed, const char* typed);
|
||||
|
||||
/* ══════════════════════════════════════════════════════════════════════════
|
||||
* Helpers de desenho — emitem TinyBlocks_DrawCmd em um RenderableBlock
|
||||
@@ -585,9 +610,28 @@ static Shape shape_of(const TinyBlocks_TypeBlock* t) {
|
||||
|
||||
static bool shape_is_value(Shape s) { return s == SH_REPORTER || s == SH_BOOL; }
|
||||
|
||||
static UserBlockDef* user_def_find(Ed* ed, const char* name);
|
||||
|
||||
/* idx-ésima entrada (NUM/BOOL) do protótipo; NULL se fora do intervalo */
|
||||
static const UserParam* user_param_at(const UserBlockDef* def, int idx) {
|
||||
if (!def || idx < 0) return NULL;
|
||||
int k = 0;
|
||||
for (int i = 0; i < def->part_n; i++) {
|
||||
if (def->parts[i].kind == PARAM_LABEL) continue;
|
||||
if (k == idx) return &def->parts[i];
|
||||
k++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool slot_is_bool(const TinyBlocks_TypeBlock* t, int i) {
|
||||
if (!t || !t->type_name) return false;
|
||||
const char* n = t->type_name;
|
||||
if (strncmp(n, "User.", 5) == 0) {
|
||||
UserBlockDef* def = g_active_ed ? user_def_find(g_active_ed, n + 5) : NULL;
|
||||
const UserParam* p = user_param_at(def, i);
|
||||
return p && p->kind == PARAM_BOOL;
|
||||
}
|
||||
if (i == 0 && (strcmp(n,"Control.If") == 0 || strcmp(n,"Control.IfElse") == 0 ||
|
||||
strcmp(n,"Control.RepeatUntil") == 0)) return true;
|
||||
return strcmp(n,"Operators.And") == 0 || strcmp(n,"Operators.Or") == 0 ||
|
||||
@@ -660,6 +704,21 @@ static void blk_defaults(EdBlock* b) {
|
||||
if ((k == TB_VALUE_INTEGER || k == TB_VALUE_REAL) && !slot_is_bool(t, i))
|
||||
strcpy(b->in_text[i], "0");
|
||||
}
|
||||
/* Blocos compostos mostram o nome do parâmetro como valor inicial */
|
||||
if (t && t->type_name && strncmp(t->type_name, "User.", 5) == 0 && g_active_ed) {
|
||||
UserBlockDef* def = user_def_find(g_active_ed, t->type_name + 5);
|
||||
if (def) {
|
||||
int k = 0;
|
||||
for (int i = 0; i < def->part_n && k < n; i++) {
|
||||
if (def->parts[i].kind == PARAM_LABEL) continue;
|
||||
if (def->parts[i].kind == PARAM_NUM)
|
||||
snprintf(b->in_text[k], sizeof(b->in_text[k]), "%s", def->parts[i].name);
|
||||
else
|
||||
b->in_text[k][0] = 0;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
const BlockSpec* sp = t ? spec_of(t->type_name) : NULL;
|
||||
const char* p = sp ? sp->defs : NULL;
|
||||
for (int i = 0; i < n && p; i++) {
|
||||
@@ -930,9 +989,26 @@ static void build_parts(EdBlock* b) {
|
||||
} else p++;
|
||||
}
|
||||
add_part(b, -1, seg, (int)(p - seg));
|
||||
} else if (t->type_name && strncmp(t->type_name, "User.", 5) == 0) {
|
||||
UserBlockDef* def = g_active_ed ? user_def_find(g_active_ed, t->type_name + 5) : NULL;
|
||||
if (!def) {
|
||||
add_part(b, -1, t->type_name + 5, (int)strlen(t->type_name + 5));
|
||||
} else {
|
||||
const char* nm = strncmp(t->type_name, "User.", 5) == 0 ? t->type_name + 5
|
||||
: display_name(t->type_name);
|
||||
add_part(b, -1, def->name, (int)strlen(def->name));
|
||||
int ii = 0;
|
||||
for (int k = 0; k < def->part_n; k++) {
|
||||
UserParam* pp = &def->parts[k];
|
||||
if (pp->kind == PARAM_LABEL) {
|
||||
add_part(b, -1, pp->name, (int)strlen(pp->name));
|
||||
} else if (ii < n) {
|
||||
add_part(b, ii, NULL, 0);
|
||||
used[ii] = true;
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const char* nm = display_name(t->type_name);
|
||||
add_part(b, -1, nm, (int)strlen(nm));
|
||||
}
|
||||
/* Campos que o rótulo não cita: "nome [campo]" ao final */
|
||||
@@ -1766,7 +1842,6 @@ static void tab_select(Ed* ed, int i) {
|
||||
if (i < 0 || i >= ed->tab_n) return;
|
||||
ed->cur_tab = i;
|
||||
ed->editing = false;
|
||||
ed->comp_name_active = false;
|
||||
ed->bubble_bi = -1;
|
||||
if (CT.is_composite) {
|
||||
const char* nm = CT.comp_id >= 0 ? ed->user_blocks[CT.comp_id].name : "";
|
||||
@@ -1808,13 +1883,7 @@ static void tab_close(Ed* ed, int ti) {
|
||||
}
|
||||
|
||||
static void new_composite_tab(Ed* ed) {
|
||||
if (!tab_new(ed, "Novo bloco", true)) return;
|
||||
ed->comp_name_buf[0] = 0;
|
||||
ed->comp_name_len = 0;
|
||||
ed->comp_name_active = true;
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status),
|
||||
"Monte o bloco com \"parâmetro\" e \"devolva\" (Meus Blocos) e clique em Salvar");
|
||||
ed->hot_status_ok = true;
|
||||
dlg_open(ed, -1);
|
||||
}
|
||||
|
||||
static void open_def(Ed* ed, const char* uname) {
|
||||
@@ -1848,39 +1917,63 @@ static void collect_labels(Tab* T, const char* type_name, char names[][32], int*
|
||||
}
|
||||
}
|
||||
|
||||
static void save_composite_from_tab(Ed* ed) {
|
||||
if (!ed->comp_name_buf[0]) {
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Digite um nome para o bloco antes de salvar.");
|
||||
ed->hot_status_ok = false;
|
||||
ed->comp_name_active = true;
|
||||
return;
|
||||
/* 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++) {
|
||||
EdBlock* b = &T->ws[i];
|
||||
if (b->used && strcmp(b->type_name, "Port.In") == 0) ids[n++] = i;
|
||||
}
|
||||
UserBlockDef* def = user_def_find(ed, ed->comp_name_buf);
|
||||
if (!def) {
|
||||
if (ed->user_block_n >= MAX_USER_BLOCKS) {
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Limite de blocos compostos atingido.");
|
||||
ed->hot_status_ok = false;
|
||||
return;
|
||||
TinyBlocks_TypeBlock* t_in = tb_type_block_find(ed->rt, "Port.In");
|
||||
for (int k = 0; k < def->input_count; k++) {
|
||||
int bi = k < n ? ids[k] : (t_in ? blk_new(T, t_in) : -1);
|
||||
if (bi < 0) break;
|
||||
snprintf(T->ws[bi].in_text[0], sizeof(T->ws[bi].in_text[0]), "%s", def->input_names[k]);
|
||||
if (k >= n) {
|
||||
T->ws[bi].x = 40;
|
||||
T->ws[bi].y = 70 + (k - n) * 52;
|
||||
top_add(T, bi);
|
||||
}
|
||||
def = &ed->user_blocks[ed->user_block_n++];
|
||||
memset(def, 0, sizeof(*def));
|
||||
snprintf(def->name, sizeof(def->name), "%s", ed->comp_name_buf);
|
||||
}
|
||||
int def_idx = (int)(def - ed->user_blocks);
|
||||
snprintf(CT.name, sizeof(CT.name), "%s", def->name);
|
||||
CT.comp_id = def_idx;
|
||||
def->tab_idx = ed->cur_tab;
|
||||
def->color_idx = CT.color_idx;
|
||||
for (int k = def->input_count; k < n; k++) free_tree(ed, T, ids[k]);
|
||||
}
|
||||
|
||||
collect_labels(&CT, "Port.In", def->input_names, &def->input_count, "in%d");
|
||||
collect_labels(&CT, "Port.Out", def->output_names, &def->output_count, "out%d");
|
||||
/* Deriva os nomes das entradas a partir das partes do protótipo */
|
||||
static void comp_build_input_names(UserBlockDef* def) {
|
||||
def->input_count = 0;
|
||||
for (int i = 0; i < def->part_n && def->input_count < MAX_UBLK_SLOTS; i++) {
|
||||
if (def->parts[i].kind == PARAM_LABEL) continue;
|
||||
char nm[64];
|
||||
if (def->parts[i].name[0]) snprintf(nm, sizeof(nm), "%s", def->parts[i].name);
|
||||
else snprintf(nm, sizeof(nm), "entrada %d", def->input_count + 1);
|
||||
char base[40]; snprintf(base, sizeof(base), "%.31s", nm);
|
||||
for (int suffix = 1; ; suffix++) {
|
||||
bool dup = false;
|
||||
for (int j = 0; j < def->input_count; j++)
|
||||
if (strcmp(def->input_names[j], nm) == 0) { dup = true; break; }
|
||||
if (!dup) break;
|
||||
snprintf(nm, sizeof(nm), "%.24s %d", base, suffix + 1);
|
||||
}
|
||||
snprintf(def->input_names[def->input_count], 32, "%.31s", nm);
|
||||
def->input_count++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Salva corpo da aba e re-registra o tipo do bloco composto */
|
||||
static void comp_register(Ed* ed, UserBlockDef* def, Tab* T) {
|
||||
snprintf(T->name, sizeof(T->name), "%s", def->name);
|
||||
T->is_composite = true;
|
||||
T->comp_id = (int)(def - ed->user_blocks);
|
||||
T->color_idx = def->color_idx;
|
||||
comp_sync_inputs(ed, def, T);
|
||||
collect_labels(T, "Port.Out", def->output_names, &def->output_count, "out%d");
|
||||
|
||||
/* Instâncias e referências ao tipo antigo precisam sumir antes de destruí-lo */
|
||||
invalidate_types(ed);
|
||||
if (def->reg_type) { tb_block_destroy(&def->reg_type->base, ed->rt); def->reg_type = NULL; }
|
||||
|
||||
if (!def->snap) def->snap = (Tab*)malloc(sizeof(Tab));
|
||||
if (def->snap) *def->snap = CT;
|
||||
if (def->snap) *def->snap = *T;
|
||||
|
||||
TinyBlocks_SlotDesc in_s[MAX_UBLK_SLOTS], out_s[MAX_UBLK_SLOTS];
|
||||
for (int i = 0; i < def->input_count; i++) in_s[i] = (TinyBlocks_SlotDesc){def->input_names[i], TB_VALUE_NONE};
|
||||
@@ -1892,11 +1985,384 @@ static void save_composite_from_tab(Ed* ed) {
|
||||
def->output_count ? out_s : NULL, (uint32_t)def->output_count,
|
||||
eval_composite);
|
||||
|
||||
def->tab_idx = (int)(T - ed->tabs);
|
||||
retype_all(ed);
|
||||
}
|
||||
|
||||
static void save_composite_from_tab(Ed* ed) {
|
||||
if (!ed->comp_name_buf[0]) {
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Digite um nome para o bloco antes de salvar.");
|
||||
ed->hot_status_ok = false;
|
||||
return;
|
||||
}
|
||||
UserBlockDef* def = user_def_find(ed, ed->comp_name_buf);
|
||||
if (!def) {
|
||||
if (ed->user_block_n >= MAX_USER_BLOCKS) {
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Limite de blocos compostos atingido.");
|
||||
ed->hot_status_ok = false;
|
||||
return;
|
||||
}
|
||||
def = &ed->user_blocks[ed->user_block_n++];
|
||||
memset(def, 0, sizeof(*def));
|
||||
def->tab_idx = ed->cur_tab;
|
||||
def->color_idx = CT.color_idx;
|
||||
snprintf(def->name, sizeof(def->name), "%s", ed->comp_name_buf);
|
||||
collect_labels(&CT, "Port.In", def->input_names, &def->input_count, "in%d");
|
||||
}
|
||||
comp_register(ed, def, &CT);
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Bloco \"%s\" salvo em Meus Blocos", def->name);
|
||||
ed->hot_status_ok = true;
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════════════════════════════════
|
||||
* Diálogo modal "Criar um Bloco" (estilo Scratch)
|
||||
* ══════════════════════════════════════════════════════════════════════════ */
|
||||
#define DLG_W 580
|
||||
#define DLG_H 380
|
||||
#define DLG_HEAD_H 50
|
||||
|
||||
/* Geometria do protótipo: preenche comp_dialog_geom e devolve o retângulo */
|
||||
static void dlg_geom(Ed* ed, float* bx, float* by, float* bw, float* bh) {
|
||||
const float pad = 14.f, gap = 8.f;
|
||||
float x = pad;
|
||||
ed->comp_dialog_name_x = x;
|
||||
ed->comp_dialog_name_w = fmaxf(96.f,
|
||||
tw(ed->comp_dialog_name[0] ? ed->comp_dialog_name : "nome do bloco", FS) + 26.f);
|
||||
x += ed->comp_dialog_name_w + gap;
|
||||
for (int i = 0; i < ed->comp_dialog_part_n; i++) {
|
||||
UserParam* p = &ed->comp_dialog_parts[i];
|
||||
const char* label = p->name[0] ? p->name : (p->kind == PARAM_LABEL ? "rótulo" : "entrada");
|
||||
float w;
|
||||
if (p->kind == PARAM_LABEL) w = tw(label, FS) + 4.f;
|
||||
else w = fmaxf(p->kind == PARAM_BOOL ? 36.f : 48.f, tw(label, FS) + 24.f);
|
||||
ed->comp_dialog_geom[i][0] = x;
|
||||
ed->comp_dialog_geom[i][1] = w;
|
||||
x += w + gap;
|
||||
}
|
||||
float w = x - gap + pad;
|
||||
float dx = (WIN_W - DLG_W) * 0.5f, dy = (WIN_H - DLG_H) * 0.5f;
|
||||
*bw = w; *bh = 40.f;
|
||||
*bx = dx + (DLG_W - w) * 0.5f;
|
||||
*by = dy + DLG_HEAD_H + 46.f;
|
||||
}
|
||||
|
||||
/* Dimensões de um card "Adicionar…" */
|
||||
static void dlg_card_rect(float* w, float* h) {
|
||||
*w = (DLG_W - 56.f - 32.f) / 3.f;
|
||||
*h = 88.f;
|
||||
}
|
||||
|
||||
static void dlg_open(Ed* ed, int def_idx) {
|
||||
ed->comp_dialog_open = true;
|
||||
ed->comp_dialog_def = def_idx;
|
||||
ed->comp_dialog_editing = false;
|
||||
ed->comp_dialog_edit_part = -1;
|
||||
ed->comp_dialog_sel = -1;
|
||||
ed->comp_dialog_name[0] = 0;
|
||||
ed->comp_dialog_part_n = 0;
|
||||
ed->comp_dialog_color = 0;
|
||||
if (def_idx >= 0 && def_idx < ed->user_block_n) {
|
||||
UserBlockDef* def = &ed->user_blocks[def_idx];
|
||||
snprintf(ed->comp_dialog_name, sizeof(ed->comp_dialog_name), "%s", def->name);
|
||||
ed->comp_dialog_color = def->color_idx;
|
||||
ed->comp_dialog_part_n = def->part_n;
|
||||
memcpy(ed->comp_dialog_parts, def->parts, sizeof(UserParam) * def->part_n);
|
||||
} else {
|
||||
ed->comp_dialog_part_n = 0;
|
||||
}
|
||||
ed->comp_dialog_editing = true;
|
||||
ed->comp_dialog_edit_part = -1;
|
||||
}
|
||||
|
||||
static char* dlg_edit_target(Ed* ed, size_t* cap) {
|
||||
if (ed->comp_dialog_edit_part < 0) {
|
||||
*cap = sizeof(ed->comp_dialog_name);
|
||||
return ed->comp_dialog_name;
|
||||
}
|
||||
*cap = sizeof(ed->comp_dialog_parts[0].name);
|
||||
return ed->comp_dialog_parts[ed->comp_dialog_edit_part].name;
|
||||
}
|
||||
|
||||
static void dlg_add_part(Ed* ed, ParamKind kind) {
|
||||
if (ed->comp_dialog_part_n >= MAX_UBLK_PARTS) return;
|
||||
int i = ed->comp_dialog_part_n++;
|
||||
ed->comp_dialog_parts[i].kind = kind;
|
||||
ed->comp_dialog_parts[i].name[0] = 0;
|
||||
ed->comp_dialog_sel = i;
|
||||
ed->comp_dialog_editing = true;
|
||||
ed->comp_dialog_edit_part = i;
|
||||
}
|
||||
|
||||
static void dlg_delete_part(Ed* ed, int i) {
|
||||
if (i < 0 || i >= ed->comp_dialog_part_n) return;
|
||||
for (int k = i; k < ed->comp_dialog_part_n - 1; k++)
|
||||
ed->comp_dialog_parts[k] = ed->comp_dialog_parts[k + 1];
|
||||
ed->comp_dialog_part_n--;
|
||||
ed->comp_dialog_sel = -1;
|
||||
ed->comp_dialog_editing = false;
|
||||
ed->comp_dialog_edit_part = -1;
|
||||
}
|
||||
|
||||
static void dlg_move_part(Ed* ed, int dir) {
|
||||
int i = ed->comp_dialog_sel, j = i + dir;
|
||||
if (i < 0 || j < 0 || j >= ed->comp_dialog_part_n) return;
|
||||
UserParam tmp = ed->comp_dialog_parts[i];
|
||||
ed->comp_dialog_parts[i] = ed->comp_dialog_parts[j];
|
||||
ed->comp_dialog_parts[j] = tmp;
|
||||
ed->comp_dialog_sel = j;
|
||||
if (ed->comp_dialog_edit_part == i) ed->comp_dialog_edit_part = j;
|
||||
else if (ed->comp_dialog_edit_part == j) ed->comp_dialog_edit_part = i;
|
||||
}
|
||||
|
||||
static void dlg_ok(Ed* ed) {
|
||||
char nm[48];
|
||||
snprintf(nm, sizeof(nm), "%s", ed->comp_dialog_name);
|
||||
if (!nm[0]) snprintf(nm, sizeof(nm), "meu bloco");
|
||||
|
||||
UserBlockDef* def;
|
||||
if (ed->comp_dialog_def >= 0 && ed->comp_dialog_def < ed->user_block_n)
|
||||
def = &ed->user_blocks[ed->comp_dialog_def];
|
||||
else {
|
||||
if (ed->user_block_n >= MAX_USER_BLOCKS) {
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Limite de blocos compostos atingido.");
|
||||
ed->hot_status_ok = false;
|
||||
return;
|
||||
}
|
||||
def = &ed->user_blocks[ed->user_block_n++];
|
||||
memset(def, 0, sizeof(*def));
|
||||
def->tab_idx = -1;
|
||||
}
|
||||
|
||||
char old_name[48];
|
||||
snprintf(old_name, sizeof(old_name), "%s", def->name);
|
||||
bool rename = old_name[0] && strcmp(old_name, nm) != 0;
|
||||
|
||||
snprintf(def->name, sizeof(def->name), "%s", nm);
|
||||
def->color_idx = ed->comp_dialog_color;
|
||||
def->part_n = ed->comp_dialog_part_n;
|
||||
memcpy(def->parts, ed->comp_dialog_parts, sizeof(UserParam) * def->part_n);
|
||||
comp_build_input_names(def);
|
||||
|
||||
if (rename) {
|
||||
if (def->reg_type) {
|
||||
invalidate_types(ed);
|
||||
tb_block_destroy(&def->reg_type->base, ed->rt);
|
||||
def->reg_type = NULL;
|
||||
}
|
||||
char old_type[64], new_type[64];
|
||||
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++) {
|
||||
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);
|
||||
}
|
||||
if (def->snap) snprintf(def->snap->name, sizeof(def->snap->name), "%s", def->name);
|
||||
}
|
||||
|
||||
/* Aba de definição: reusa a existente, ou restaura/cria */
|
||||
if (def->tab_idx >= 0 && def->tab_idx < ed->tab_n) {
|
||||
tab_select(ed, def->tab_idx);
|
||||
} else {
|
||||
if (!tab_new(ed, def->name, true)) return;
|
||||
def->tab_idx = ed->cur_tab;
|
||||
if (def->snap) { CT = *def->snap; clear_live(&CT); }
|
||||
}
|
||||
CT.is_composite = true;
|
||||
CT.color_idx = def->color_idx;
|
||||
comp_register(ed, def, &CT);
|
||||
|
||||
ed->comp_dialog_open = false;
|
||||
ed->comp_dialog_editing = false;
|
||||
snprintf(ed->comp_name_buf, sizeof(ed->comp_name_buf), "%s", def->name);
|
||||
ed->comp_name_len = (int)strlen(ed->comp_name_buf);
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Bloco \"%s\" salvo em Meus Blocos", def->name);
|
||||
ed->hot_status_ok = true;
|
||||
}
|
||||
|
||||
static void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
if (!ed->comp_dialog_open) return;
|
||||
rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COLA(0, 0, 0, 120));
|
||||
|
||||
float dx = (WIN_W - DLG_W) * 0.5f, dy = (WIN_H - DLG_H) * 0.5f;
|
||||
Col accent = s_user_colors[ed->comp_dialog_color];
|
||||
Col dark = col_mul(accent, 0.78f);
|
||||
|
||||
rb_fill_rrect(rb, dx + 3, dy + 4, DLG_W, DLG_H, 12, COLA(0, 0, 0, 70));
|
||||
rb_fill_rrect(rb, dx, dy, DLG_W, DLG_H, 12, COL_PANEL);
|
||||
|
||||
/* Cabeçalho */
|
||||
rb_fill_rrect(rb, dx, dy, DLG_W, DLG_HEAD_H, 12, accent);
|
||||
rb_fill_rect(rb, dx, dy + DLG_HEAD_H - 12, DLG_W, 12, accent);
|
||||
const char* title = ed->comp_dialog_def >= 0 ? "Editar Bloco" : "Criar um Bloco";
|
||||
rb_text_c(rb, dx + (DLG_W - tw(title, 18)) * 0.5f, dy + DLG_HEAD_H * 0.5f, title, COL_WHITE, 18);
|
||||
rb_fill_circle(rb, dx + DLG_W - 26, dy + DLG_HEAD_H * 0.5f, 12, COLA(255, 255, 255, 60));
|
||||
rb_text_c(rb, dx + DLG_W - 30, dy + DLG_HEAD_H * 0.5f, "×", COL_WHITE, 18);
|
||||
|
||||
/* Protótipo do bloco */
|
||||
float bx, by, bw, bh;
|
||||
dlg_geom(ed, &bx, &by, &bw, &bh);
|
||||
rb_fill_rrect(rb, bx, by, bw, bh, 4, dark);
|
||||
rb_fill_rrect(rb, bx + 1, by + 1, bw - 2, bh - 2, 3, accent);
|
||||
draw_bump(rb, bx, by + bh, accent, dark);
|
||||
|
||||
/* Campo do nome do bloco */
|
||||
{
|
||||
float nfx = bx + ed->comp_dialog_name_x, nfy = by + 7, nfw = ed->comp_dialog_name_w, nfh = bh - 14;
|
||||
rb_fill_rrect(rb, nfx, nfy, nfw, nfh, nfh * 0.5f, COLA(0, 0, 0, 40));
|
||||
rb_fill_rrect(rb, nfx + 1, nfy + 1, nfw - 2, nfh - 2, nfh * 0.5f - 1, COL_WHITE);
|
||||
const char* nm = ed->comp_dialog_name[0] ? ed->comp_dialog_name : "nome do bloco";
|
||||
float lw = tw(nm, FS);
|
||||
rb_text_c(rb, nfx + (nfw - lw) * 0.5f, nfy + nfh * 0.5f, nm,
|
||||
ed->comp_dialog_name[0] ? COL_TEXT : COL_TEXT_DIM, FS);
|
||||
if (ed->comp_dialog_editing && ed->comp_dialog_edit_part < 0)
|
||||
rb_fill_rect(rb, nfx + (nfw + lw) * 0.5f + 2, nfy + 4, 1.5f, nfh - 8, COL_TEXT);
|
||||
}
|
||||
|
||||
/* Partes do protótipo */
|
||||
for (int i = 0; i < ed->comp_dialog_part_n; i++) {
|
||||
UserParam* p = &ed->comp_dialog_parts[i];
|
||||
const char* label = p->name[0] ? p->name : (p->kind == PARAM_LABEL ? "rótulo" : "entrada");
|
||||
float px = bx + ed->comp_dialog_geom[i][0], pw = ed->comp_dialog_geom[i][1];
|
||||
float py = by + 7, ph = bh - 14;
|
||||
bool sel = ed->comp_dialog_sel == i;
|
||||
if (p->kind == PARAM_LABEL) {
|
||||
rb_text_c(rb, px, by + bh * 0.5f, label,
|
||||
p->name[0] ? COL_WHITE : COLA(255, 255, 255, 150), FS);
|
||||
} else if (p->kind == PARAM_BOOL) {
|
||||
draw_hex(rb, px, py, pw, ph, sel ? COL_WHITE : COLA(0, 0, 0, 40));
|
||||
rb_text_c(rb, px + (pw - tw(label, FS)) * 0.5f, py + ph * 0.5f, label,
|
||||
p->name[0] ? COL_TEXT : COL_TEXT_DIM, FS);
|
||||
} else {
|
||||
rb_fill_rrect(rb, px, py, pw, ph, ph * 0.5f, sel ? COL_MENU : COLA(0, 0, 0, 40));
|
||||
rb_fill_rrect(rb, px + 1, py + 1, pw - 2, ph - 2, ph * 0.5f - 1, COL_WHITE);
|
||||
rb_text_c(rb, px + (pw - tw(label, FS)) * 0.5f, py + ph * 0.5f, label,
|
||||
p->name[0] ? COL_TEXT : COL_TEXT_DIM, FS);
|
||||
}
|
||||
if (sel) rb_stroke_rect(rb, px - 2, py - 2, pw + 4, ph + 4, 2, COL_TEXT);
|
||||
if (ed->comp_dialog_editing && ed->comp_dialog_edit_part == i && p->kind != PARAM_LABEL) {
|
||||
float lw = tw(label, FS);
|
||||
rb_fill_rect(rb, px + (pw + lw) * 0.5f + 2, py + 5, 1.5f, ph - 10, COL_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
/* Controles ‹ 🗑 › da parte selecionada */
|
||||
if (ed->comp_dialog_sel >= 0) {
|
||||
float ctr = bx + bw * 0.5f, cty = by - 26;
|
||||
rb_text_c(rb, ctr - 44, cty, "‹", COL_TEXT, 22);
|
||||
rb_text_c(rb, ctr + 40, cty, "›", COL_TEXT, 22);
|
||||
rb_fill_rect(rb, ctr - 7, cty - 8, 14, 3, COL_TEXT);
|
||||
rb_fill_rect(rb, ctr - 4, cty - 12, 8, 4, COL_TEXT);
|
||||
rb_fill_rect(rb, ctr - 6, cty - 4, 12, 12, COL_TEXT);
|
||||
}
|
||||
|
||||
/* Cards de adicionar */
|
||||
float cw, ch; dlg_card_rect(&cw, &ch);
|
||||
float cx0 = dx + 28.f;
|
||||
float cy0 = by + bh + 34.f;
|
||||
const char* lines[3][3] = {
|
||||
{"Adicionar uma", "entrada", "numérica ou texto"},
|
||||
{"Adicionar uma", "entrada", "booleana"},
|
||||
{"Adicionar um", "rótulo", ""},
|
||||
};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float cx = cx0 + i * (cw + 16.f);
|
||||
bool hover = in_rect(ed->mouse_x, ed->mouse_y, cx, cy0, cw, ch);
|
||||
rb_fill_rrect(rb, cx, cy0, cw, ch, 8, hover ? COL_HOVER : COL_PANEL);
|
||||
rb_stroke_rect(rb, cx + 0.5f, cy0 + 0.5f, cw - 1, ch - 1, 1, hover ? COL_MENU : COL_BORDER);
|
||||
float iy = cy0 + 16.f;
|
||||
if (i == 0) {
|
||||
rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 11, accent);
|
||||
rb_text_c(rb, cx + cw * 0.5f - 14, iy + 11, "· · ·", COL_WHITE, FS);
|
||||
} else if (i == 1) {
|
||||
draw_hex(rb, cx + cw * 0.5f - 20, iy, 40, 22, accent);
|
||||
} else {
|
||||
rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 4, accent);
|
||||
rb_text_c(rb, cx + cw * 0.5f - 11, iy + 11, "text", COL_WHITE, FS);
|
||||
}
|
||||
float ty = cy0 + 46.f;
|
||||
for (int l = 0; l < 3 && lines[i][l][0]; l++) {
|
||||
rb_text_c(rb, cx + (cw - tw(lines[i][l], FS)) * 0.5f, ty, lines[i][l], COL_TEXT, FS);
|
||||
ty += 16.f;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cores + Cancelar/OK */
|
||||
float fy = dy + DLG_H - 40.f;
|
||||
for (int ci = 0; ci < USER_COLOR_COUNT; ci++) {
|
||||
float sx = dx + 28.f + ci * 30.f;
|
||||
if (ed->comp_dialog_color == ci) rb_fill_rrect(rb, sx - 2, fy - 2, 26, 26, 6, COL_TEXT);
|
||||
rb_fill_rrect(rb, sx, fy, 22, 22, 5, s_user_colors[ci]);
|
||||
}
|
||||
float okx = dx + DLG_W - 28.f - 84.f, cax = okx - 96.f;
|
||||
rb_fill_rrect(rb, cax, fy - 8, 84, 36, 8, COL_BORDER);
|
||||
rb_text_c(rb, cax + (84 - tw("Cancelar", FS_UI)) * 0.5f, fy + 10, "Cancelar", COL_TEXT, FS_UI);
|
||||
rb_fill_rrect(rb, okx, fy - 8, 84, 36, 8, accent);
|
||||
rb_text_c(rb, okx + (84 - tw("OK", FS_UI)) * 0.5f, fy + 10, "OK", COL_WHITE, FS_UI);
|
||||
}
|
||||
|
||||
static bool dlg_click(Ed* ed, float mx, float my) {
|
||||
if (!ed->comp_dialog_open) return false;
|
||||
float dx = (WIN_W - DLG_W) * 0.5f, dy = (WIN_H - DLG_H) * 0.5f;
|
||||
if (!in_rect(mx, my, dx, dy, DLG_W, DLG_H)) { ed->comp_dialog_open = false; return true; }
|
||||
if (in_rect(mx, my, dx + DLG_W - 44, dy, 44, DLG_HEAD_H)) { ed->comp_dialog_open = false; return true; }
|
||||
|
||||
float bx, by, bw, bh;
|
||||
dlg_geom(ed, &bx, &by, &bw, &bh);
|
||||
if (in_rect(mx, my, bx + ed->comp_dialog_name_x, by + 7, ed->comp_dialog_name_w, bh - 14)) {
|
||||
ed->comp_dialog_editing = true; ed->comp_dialog_edit_part = -1; ed->comp_dialog_sel = -1;
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < ed->comp_dialog_part_n; i++) {
|
||||
if (in_rect(mx, my, bx + ed->comp_dialog_geom[i][0], by + 7, ed->comp_dialog_geom[i][1], bh - 14)) {
|
||||
ed->comp_dialog_sel = i; ed->comp_dialog_editing = true; ed->comp_dialog_edit_part = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ed->comp_dialog_sel >= 0) {
|
||||
float ctr = bx + bw * 0.5f, cty = by - 26;
|
||||
if (in_rect(mx, my, ctr - 60, cty - 16, 34, 32)) { dlg_move_part(ed, -1); return true; }
|
||||
if (in_rect(mx, my, ctr - 16, cty - 16, 32, 32)) { dlg_delete_part(ed, ed->comp_dialog_sel); return true; }
|
||||
if (in_rect(mx, my, ctr + 26, cty - 16, 34, 32)) { dlg_move_part(ed, 1); return true; }
|
||||
}
|
||||
|
||||
float cw, ch; dlg_card_rect(&cw, &ch);
|
||||
float cx0 = dx + 28.f, cy0 = by + bh + 34.f;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float cx = cx0 + i * (cw + 16.f);
|
||||
if (in_rect(mx, my, cx, cy0, cw, ch)) {
|
||||
dlg_add_part(ed, i == 0 ? PARAM_NUM : i == 1 ? PARAM_BOOL : PARAM_LABEL);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
float fy = dy + DLG_H - 40.f;
|
||||
for (int ci = 0; ci < USER_COLOR_COUNT; ci++)
|
||||
if (in_rect(mx, my, dx + 28.f + ci * 30.f, fy, 22, 22)) { ed->comp_dialog_color = ci; return true; }
|
||||
float okx = dx + DLG_W - 28.f - 84.f, cax = okx - 96.f;
|
||||
if (in_rect(mx, my, okx, fy - 8, 84, 36)) { dlg_ok(ed); return true; }
|
||||
if (in_rect(mx, my, cax, fy - 8, 84, 36)) { ed->comp_dialog_open = false; return true; }
|
||||
|
||||
ed->comp_dialog_editing = false;
|
||||
ed->comp_dialog_edit_part = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dlg_key(Ed* ed, int sc) {
|
||||
if (sc == TB_KEY_ESCAPE) { ed->comp_dialog_open = false; return; }
|
||||
if (sc == TB_KEY_RETURN) { dlg_ok(ed); return; }
|
||||
if (ed->comp_dialog_editing && sc == TB_KEY_BACKSPACE) {
|
||||
size_t cap; char* t = dlg_edit_target(ed, &cap); (void)cap; utf8_pop(t);
|
||||
}
|
||||
}
|
||||
|
||||
static void dlg_text(Ed* ed, const char* typed) {
|
||||
if (!ed->comp_dialog_editing) return;
|
||||
size_t cap; char* t = dlg_edit_target(ed, &cap);
|
||||
append_text(t, cap, typed);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════════════════════════════════
|
||||
* Hot reload de libraries .so
|
||||
* ══════════════════════════════════════════════════════════════════════════ */
|
||||
@@ -2136,9 +2602,9 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
clip_clear(ed, rb);
|
||||
}
|
||||
|
||||
/* ── Painel de bloco composto (canto superior direito do workspace) ───── */
|
||||
/* ── Barra do bloco composto (canto superior direito do workspace) ───── */
|
||||
#define CP_W 440
|
||||
#define CP_H 40
|
||||
#define CP_H 44
|
||||
static void comp_panel_pos(Ed* ed, float* px, float* py) {
|
||||
*px = WS_X + WS_W - CP_W - 10;
|
||||
*py = WS_Y + 10;
|
||||
@@ -2149,24 +2615,20 @@ static void render_comp_panel(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
float px, py; comp_panel_pos(ed, &px, &py);
|
||||
rb_fill_rrect(rb, px, py, CP_W, CP_H, 8, COL_BORDER);
|
||||
rb_fill_rrect(rb, px+1, py+1, CP_W-2, CP_H-2, 7, COL_PANEL);
|
||||
rb_text_c(rb, px+10, py+CP_H*0.5f, "Nome:", COL_TEXT, FS_UI);
|
||||
|
||||
rb_fill_rrect(rb, px+56, py+6, 140, 28, 5, ed->comp_name_active ? COL_MENU : COL_BORDER);
|
||||
rb_fill_rrect(rb, px+57, py+7, 138, 26, 4, COL_WHITE);
|
||||
bool empty = !ed->comp_name_buf[0];
|
||||
rb_text_c(rb, px+64, py+CP_H*0.5f, empty ? "nome do bloco" : ed->comp_name_buf,
|
||||
empty ? COL_TEXT_DIM : COL_TEXT, FS_UI);
|
||||
if (ed->comp_name_active)
|
||||
rb_fill_rect(rb, px+65 + tw(ed->comp_name_buf, FS_UI), py+12, 1.5f, 16, COL_TEXT);
|
||||
Col c = s_user_colors[CT.color_idx];
|
||||
rb_fill_rrect(rb, px+10, py+10, 24, 24, 6, col_mul(c, 0.8f));
|
||||
rb_fill_rrect(rb, px+11, py+11, 22, 22, 5, c);
|
||||
const char* nm = ed->comp_name_buf[0] ? ed->comp_name_buf : "Novo bloco";
|
||||
rb_text_c(rb, px+44, py+CP_H*0.5f, nm, COL_TEXT, FS_UI);
|
||||
|
||||
for (int ci = 0; ci < USER_COLOR_COUNT; ci++) {
|
||||
float sx = px + 206 + ci*20;
|
||||
if (CT.color_idx == ci) rb_fill_rrect(rb, sx-2, py+10, 20, 20, 5, COL_TEXT);
|
||||
rb_fill_rrect(rb, sx, py+12, 16, 16, 4, s_user_colors[ci]);
|
||||
}
|
||||
float bx = px + 206 + USER_COLOR_COUNT*20 + 4;
|
||||
rb_fill_rrect(rb, bx, py+6, 64, 28, 6, s_user_colors[CT.color_idx]);
|
||||
rb_text_c(rb, bx + (64 - tw("Salvar", FS_UI))*0.5f, py+CP_H*0.5f, "Salvar", COL_WHITE, FS_UI);
|
||||
float bx = px + CP_W - 10;
|
||||
bx -= 78;
|
||||
rb_fill_rrect(rb, bx, py+8, 78, 28, 6, c);
|
||||
rb_text_c(rb, bx + (78 - tw("Salvar", FS_UI))*0.5f, py+CP_H*0.5f, "Salvar", COL_WHITE, FS_UI);
|
||||
bx -= 96;
|
||||
rb_fill_rrect(rb, bx, py+8, 88, 28, 6, COL_BORDER);
|
||||
rb_text_c(rb, bx + (88 - tw("Editar bloco", FS_UI))*0.5f, py+CP_H*0.5f, "Editar bloco", COL_TEXT, FS_UI);
|
||||
}
|
||||
|
||||
/* Altura da área do palco no painel (4:3 embutido; faixa curta se destacado) */
|
||||
@@ -2532,6 +2994,7 @@ static void ctx_exec(Ed* ed, int id) {
|
||||
}
|
||||
|
||||
static void on_lmb_down(Ed* ed, float mx, float my) {
|
||||
if (ed->comp_dialog_open) { dlg_click(ed, mx, my); return; }
|
||||
if (ed->ctx_menu_open) {
|
||||
int it = ctx_hit(ed, mx, my);
|
||||
ed->ctx_menu_open = false;
|
||||
@@ -2540,8 +3003,6 @@ static void on_lmb_down(Ed* ed, float mx, float my) {
|
||||
}
|
||||
ed->editing = false;
|
||||
ed->bubble_bi = -1;
|
||||
bool was_naming = ed->comp_name_active;
|
||||
ed->comp_name_active = false;
|
||||
|
||||
/* Barra de menu */
|
||||
if (my < MENU_H) {
|
||||
@@ -2577,15 +3038,18 @@ static void on_lmb_down(Ed* ed, float mx, float my) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Painel do bloco composto */
|
||||
/* Barra do bloco composto */
|
||||
if (CT.is_composite) {
|
||||
float px, py; comp_panel_pos(ed, &px, &py);
|
||||
if (in_rect(mx, my, px, py, CP_W, CP_H)) {
|
||||
if (in_rect(mx, my, px+56, py+6, 140, 28)) { ed->comp_name_active = true; return; }
|
||||
for (int ci = 0; ci < USER_COLOR_COUNT; ci++)
|
||||
if (in_rect(mx, my, px+206+ci*20, py+10, 18, 20)) { CT.color_idx = ci; return; }
|
||||
if (in_rect(mx, my, px+206+USER_COLOR_COUNT*20+4, py+6, 64, 28)) save_composite_from_tab(ed);
|
||||
ed->comp_name_active = was_naming;
|
||||
float bx = px + CP_W - 10;
|
||||
bx -= 78;
|
||||
if (in_rect(mx, my, bx, py+8, 78, 28)) { save_composite_from_tab(ed); return; }
|
||||
bx -= 96;
|
||||
if (in_rect(mx, my, bx, py+8, 88, 28)) {
|
||||
if (CT.comp_id >= 0) dlg_open(ed, CT.comp_id);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2632,6 +3096,7 @@ static void on_lmb_down(Ed* ed, float mx, float my) {
|
||||
|
||||
static void on_lmb_up(Ed* ed, float mx, float my) {
|
||||
(void)my;
|
||||
if (ed->comp_dialog_open) return;
|
||||
if (ed->state == ES_DRAG && ed->drag_bi >= 0) {
|
||||
mark_drag(&CT, ed->drag_bi, false);
|
||||
if (mx < PALETTE_W) free_tree(ed, &CT, ed->drag_bi); /* solto na paleta = apagar */
|
||||
@@ -2668,6 +3133,7 @@ static void on_rmb_down(Ed* ed, float mx, float my) {
|
||||
|
||||
static void on_key(Ed* ed, int sc, bool ctrl) {
|
||||
bool enter = sc == TB_KEY_RETURN;
|
||||
if (ed->comp_dialog_open) { dlg_key(ed, sc); return; }
|
||||
if (ed->ctx_menu_open) { if (sc == TB_KEY_ESCAPE) ed->ctx_menu_open = false; return; }
|
||||
|
||||
if (ed->path_input_active) {
|
||||
@@ -2681,15 +3147,6 @@ static void on_key(Ed* ed, int sc, bool ctrl) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ed->comp_name_active) {
|
||||
if (sc == TB_KEY_ESCAPE) ed->comp_name_active = false;
|
||||
else if (enter) { ed->comp_name_active = false; save_composite_from_tab(ed); }
|
||||
else if (sc == TB_KEY_BACKSPACE) {
|
||||
utf8_pop(ed->comp_name_buf);
|
||||
ed->comp_name_len = (int)strlen(ed->comp_name_buf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ed->editing) {
|
||||
size_t cap; char* t = edit_target(ed, &cap);
|
||||
bool multi = is_lit_text(CT.ws[ed->edit_bi].type);
|
||||
@@ -2715,12 +3172,10 @@ static void on_key(Ed* ed, int sc, bool ctrl) {
|
||||
}
|
||||
|
||||
static void on_text(Ed* ed, const char* typed) {
|
||||
if (ed->comp_dialog_open) { dlg_text(ed, typed); return; }
|
||||
if (ed->path_input_active) {
|
||||
append_text(ed->path_input_buf, sizeof(ed->path_input_buf), typed);
|
||||
ed->path_input_len = (int)strlen(ed->path_input_buf);
|
||||
} else if (ed->comp_name_active) {
|
||||
append_text(ed->comp_name_buf, sizeof(ed->comp_name_buf), typed);
|
||||
ed->comp_name_len = (int)strlen(ed->comp_name_buf);
|
||||
} else if (ed->editing) {
|
||||
size_t cap; char* t = edit_target(ed, &cap);
|
||||
append_text(t, cap, typed);
|
||||
@@ -2839,6 +3294,7 @@ static bool editor_on_draw(TinyBlocks_Block* self, TinyBlocks* rt,
|
||||
render_chain(ed, rb, &CT, ed->drag_bi, WS_X - CT.ws_sx, WS_Y - CT.ws_sy);
|
||||
|
||||
render_ctx_menu(ed, rb);
|
||||
dlg_render(ed, rb);
|
||||
|
||||
*dst = rb;
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
/* Harness headless do editor: dirige Editor.Scene com um bloco de eventos
|
||||
* falso e inspeciona os comandos de desenho produzidos por on_draw. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_renderable_block.h>
|
||||
#include <tb_editor.h>
|
||||
#include <tb_graphics.h>
|
||||
|
||||
static TinyBlocks* rt;
|
||||
static TinyBlocks_Block *ev, *scene;
|
||||
static TinyBlocks_DrawCmd cmds[TB_DRAW_CMD_CAP];
|
||||
static uint32_t ncmd;
|
||||
static int fails = 0;
|
||||
|
||||
static void eval_print(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value l = tb_block_get_input(self, rt, 0), v = tb_block_get_input(self, rt, 1);
|
||||
const char* lbl = l.kind==TB_VALUE_TEXT ? l.as.text : "resultado";
|
||||
if (v.kind==TB_VALUE_INTEGER) printf("%s = %lld\n", lbl, (long long)v.as.integer);
|
||||
else if (v.kind==TB_VALUE_REAL) printf("%s = %g\n", lbl, v.as.real);
|
||||
else if (v.kind==TB_VALUE_TEXT) printf("%s = %s\n", lbl, v.as.text);
|
||||
else printf("%s\n", lbl);
|
||||
}
|
||||
static void eval_add(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value a = tb_block_get_input(self, rt, 0), b = tb_block_get_input(self, rt, 1);
|
||||
long long x = a.kind==TB_VALUE_INTEGER ? a.as.integer : 0, y = b.kind==TB_VALUE_INTEGER ? b.as.integer : 0;
|
||||
tb_block_set_output(self, 0, tb_value_integer(x + y));
|
||||
}
|
||||
static void eval_ev(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; self->dirty = false; }
|
||||
|
||||
static void draw(void) {
|
||||
TinyBlocks_RenderableBlock* rb = NULL;
|
||||
if (scene->type->on_draw(scene, rt, &rb) && rb) {
|
||||
ncmd = rb->count;
|
||||
memcpy(cmds, rb->cmds, ncmd * sizeof(cmds[0]));
|
||||
}
|
||||
tb_renderable_release_all();
|
||||
}
|
||||
|
||||
static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char* text) {
|
||||
tb_block_set_output(ev, GFX_IN_MOUSE_X, tb_value_real(mx));
|
||||
tb_block_set_output(ev, GFX_IN_MOUSE_Y, tb_value_real(my));
|
||||
tb_block_set_output(ev, GFX_IN_MOUSE_L_DOWN, tb_value_integer(ld));
|
||||
tb_block_set_output(ev, GFX_IN_MOUSE_L_UP, tb_value_integer(lu));
|
||||
tb_block_set_output(ev, GFX_IN_MOUSE_R_DOWN, tb_value_integer(rd));
|
||||
tb_block_set_output(ev, GFX_IN_KEY, tb_value_integer(sc));
|
||||
tb_block_set_output(ev, GFX_IN_KEY_MOD, tb_value_integer(0));
|
||||
tb_block_set_output(ev, GFX_IN_MOD_STATE, tb_value_integer(0));
|
||||
tb_block_set_output(ev, GFX_IN_TEXT, tb_value_text(text ? text : ""));
|
||||
tb_block_set_output(ev, GFX_IN_DROP_FILE, tb_value_text(""));
|
||||
tb_block_set_output(ev, GFX_IN_SCROLL_DX, tb_value_real(0));
|
||||
tb_block_set_output(ev, GFX_IN_SCROLL_DY, tb_value_real(0));
|
||||
tb_block_set_output(ev, GFX_IN_WIN_W, tb_value_integer(1280));
|
||||
tb_block_set_output(ev, GFX_IN_WIN_H, tb_value_integer(720));
|
||||
tb_block_eval(scene, rt);
|
||||
draw();
|
||||
}
|
||||
|
||||
enum { R_ANY, R_CAT, R_FLY, R_WS, R_STAGE };
|
||||
static bool in_region(float x, int r) {
|
||||
switch (r) {
|
||||
case R_CAT: return x < 68;
|
||||
case R_FLY: return x >= 68 && x < 318;
|
||||
case R_WS: return x >= 318 && x < 920;
|
||||
case R_STAGE: return x >= 920;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Centro (aprox.) do n-ésimo texto igual a s na região */
|
||||
static bool find(const char* s, int region, int nth, float* x, float* y) {
|
||||
for (uint32_t i = 0; i < ncmd; i++) {
|
||||
TinyBlocks_DrawCmd* c = &cmds[i];
|
||||
if (c->kind != TB_DRAW_TEXT || strcmp(c->text, s) != 0 || !in_region(c->x, region)) continue;
|
||||
if (nth-- > 0) continue;
|
||||
*x = c->x + 3; *y = c->y - c->font_size*0.36f;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool stage_has(const char* s) {
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, s)) return true;
|
||||
return false;
|
||||
}
|
||||
static bool any_has(const char* s) {
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, s)) return true;
|
||||
return false;
|
||||
}
|
||||
static bool ws_has(const char* s) {
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strcmp(cmds[i].text, s) == 0) return true;
|
||||
return false;
|
||||
}
|
||||
static void dump_stage(void) {
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && cmds[i].y > 130) printf(" | %s\n", cmds[i].text);
|
||||
}
|
||||
|
||||
#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; dump_stage(); } } while (0)
|
||||
|
||||
static void click(float x, float y) { frame(x, y, 1, 0, 0, 0, NULL); frame(x, y, 0, 1, 0, 0, NULL); }
|
||||
static void drag(float x0, float y0, float x1, float y1) {
|
||||
frame(x0, y0, 1, 0, 0, 0, NULL);
|
||||
frame(x0 + 8, y0 + 8, 0, 0, 0, 0, NULL);
|
||||
frame(x1, y1, 0, 0, 0, 0, NULL);
|
||||
frame(x1, y1, 0, 1, 0, 0, NULL);
|
||||
}
|
||||
static void type(const char* s) { frame(0, 0, 0, 0, 0, 0, s); }
|
||||
static void key(int sc, float x, float y) { frame(x, y, 0, 0, 0, sc, NULL); }
|
||||
static void flag(void) { click(920 + 30, 44 + 22); }
|
||||
|
||||
static bool need(const char* s, int region, int nth, float* x, float* y) {
|
||||
if (find(s, region, nth, x, y)) return true;
|
||||
printf("FAIL não achei \"%s\"\n", s); fails++;
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
tinyblocks_init(&rt, NULL);
|
||||
static const TinyBlocks_SlotDesc print_in[] = {{"label", TB_VALUE_TEXT}, {"value", TB_VALUE_NONE}};
|
||||
static const TinyBlocks_SlotDesc two_int[] = {{"a", TB_VALUE_INTEGER}, {"b", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc int_out[] = {{"result", TB_VALUE_INTEGER}};
|
||||
tb_type_block_create(rt, "Math.Add", two_int, 2, int_out, 1, eval_add);
|
||||
tb_type_block_create(rt, "IO.Print", print_in, 2, NULL, 0, eval_print);
|
||||
tb_graphics_set_backend(tb_graphics_null_backend());
|
||||
tb_library_register(rt, tb_graphics_get_library());
|
||||
tb_library_register(rt, tb_editor_get_library());
|
||||
(void)eval_ev;
|
||||
ev = tb_block_create(rt, tb_type_block_find(rt, "Graphics.Input"));
|
||||
scene = tb_block_create(rt, tb_type_block_find(rt, "Editor.Scene"));
|
||||
tb_block_set_default(scene, 0, tb_value_block(ev));
|
||||
|
||||
float x, y, x2, y2;
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
printf("comandos de desenho no 1º frame: %u (cap %d)\n", ncmd, TB_DRAW_CMD_CAP);
|
||||
CHECK(ncmd > 100 && ncmd < TB_DRAW_CMD_CAP, "frame inicial cabe no RenderableBlock");
|
||||
|
||||
/* 1. Script de exemplo */
|
||||
flag();
|
||||
CHECK(stage_has("x vale = 1") && stage_has("x vale = 5") && !stage_has("x vale = 6"),
|
||||
"bandeira roda o script de exemplo (x vale = 1..5)");
|
||||
|
||||
/* 2. Arrastar "escreva" do flyout para uma área livre e clicar nele */
|
||||
if (need("Aparência", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("escreva", R_FLY, 0, &x, &y)) drag(x, y, 600, 560);
|
||||
CHECK(find("escreva", R_WS, 1, &x, &y), "bloco do flyout aparece no workspace");
|
||||
if (need("escreva", R_WS, 1, &x, &y)) click(x, y);
|
||||
CHECK(stage_has("Olá!"), "clique no bloco solto executa (Olá!)");
|
||||
|
||||
/* 3. Encaixar o "escreva Olá!" logo abaixo do chapéu */
|
||||
float hx, hy;
|
||||
if (need("quando ⚑ for clicado", R_WS, 0, &hx, &hy) && need("escreva", R_WS, 1, &x, &y)) {
|
||||
/* hat: rótulo em (bx+10, by+18+18); fundo em by+54 → alvo: topo do bloco em by+54 */
|
||||
float bx = hx - 3 - 10, by = hy - 18 - 18;
|
||||
float gx = x - 3 - 10, gy = y - 18; /* canto do bloco arrastado */
|
||||
drag(x, y, x + (bx - gx), y + (by + 54 - gy) + 6);
|
||||
}
|
||||
flag();
|
||||
CHECK(stage_has("Olá!") && stage_has("x vale = 5"), "encaixe sob o chapéu: script roda os dois");
|
||||
float oy1 = 0, oy2 = 0;
|
||||
for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920) {
|
||||
if (!strcmp(cmds[i].text, "Olá!") && !oy1) oy1 = cmds[i].y;
|
||||
if (!strcmp(cmds[i].text, "x vale = 1") && !oy2) oy2 = cmds[i].y;
|
||||
}
|
||||
CHECK(oy1 > 0 && oy2 > oy1, "ordem de execução: Olá! antes de x vale");
|
||||
|
||||
/* 4. Repórter "+": solto, editar campos, clicar → balão */
|
||||
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("+", R_FLY, 0, &x, &y)) drag(x, y, 640, 470);
|
||||
if (need("+", R_WS, 0, &x, &y)) {
|
||||
click(x - 22, y); type("2"); key(TB_KEY_RETURN, 0, 0);
|
||||
if (need("+", R_WS, 0, &x, &y)) { click(x + 22, y); type("3"); key(TB_KEY_RETURN, 0, 0); }
|
||||
if (need("+", R_WS, 0, &x, &y)) click(x, y);
|
||||
}
|
||||
CHECK(ws_has("5"), "repórter clicado mostra balão com 5 (2+3)");
|
||||
|
||||
/* 5. Encaixar o repórter (2+3) no campo de "mude x para (0)" */
|
||||
if (need("para", R_WS, 0, &x2, &y2) && need("+", R_WS, 0, &x, &y)) {
|
||||
float zx, zy; int k = 0;
|
||||
while (find("0", R_WS, k, &zx, &zy) && !(zx > x2 && zy > y2 - 4 && zy < y2 + 4)) k++;
|
||||
float tgt_left = zx - 3 - 10, rep_left = x - 3 - 43;
|
||||
drag(x, y, x + (tgt_left - rep_left), y + (zy - y));
|
||||
}
|
||||
flag();
|
||||
CHECK(stage_has("x vale = 10") && stage_has("x vale = 6") && !stage_has("x vale = 5"),
|
||||
"repórter encaixado: x começa em 5 (x vale = 6..10)");
|
||||
|
||||
/* 6. Delete sobre o "escreva Olá!" apaga só ele; o resto sobe */
|
||||
if (need("escreva", R_WS, 0, &x, &y)) {
|
||||
float ox, oy; find("Olá!", R_WS, 0, &ox, &oy);
|
||||
if (oy < y) find("escreva", R_WS, 1, &x, &y); /* o do "Olá!" é o primeiro de cima */
|
||||
key(TB_KEY_DELETE, x, y);
|
||||
}
|
||||
flag();
|
||||
CHECK(!stage_has("Olá!") && stage_has("x vale = 10"), "Delete remove o bloco e mantém o resto do script");
|
||||
|
||||
/* 7. Arrastar de volta para a paleta apaga */
|
||||
if (need("Aparência", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("escreva", R_FLY, 0, &x, &y)) drag(x, y, 700, 600);
|
||||
int before = 0; while (find("escreva", R_WS, before, &x2, &y2)) before++;
|
||||
float lx = 0, ly = 0; for (int k = 0; find("escreva", R_WS, k, &x2, &y2); k++) if (y2 > ly) { lx = x2; ly = y2; }
|
||||
drag(lx, ly, 150, 400);
|
||||
int after = 0; while (find("escreva", R_WS, after, &x2, &y2)) after++;
|
||||
CHECK(after == before - 1, "soltar bloco sobre a paleta apaga");
|
||||
|
||||
/* 8. Bloco composto "dobro(n)" criado pelo diálogo; corpo: devolva n + 1 */
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("Criar um Bloco", R_FLY, 0, &x, &y)) click(x, y);
|
||||
if (need("nome do bloco", R_WS, 0, &x, &y)) click(x, y);
|
||||
type("dobro");
|
||||
if (need("numérica ou texto", R_WS, 0, &x, &y)) click(x, y);
|
||||
type("n");
|
||||
key(TB_KEY_RETURN, 0, 0); /* OK no diálogo */
|
||||
CHECK(ws_has("parâmetro"), "diálogo cria o bloco composto e o corpo com o parâmetro");
|
||||
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("devolva", R_FLY, 0, &x, &y)) drag(x, y, 450, 300);
|
||||
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("+", R_FLY, 0, &x, &y)) drag(x, y, 470, 450);
|
||||
/* encaixa o parâmetro n no slot esquerdo do "+" */
|
||||
{
|
||||
float px, py, zx, zy;
|
||||
if (need("parâmetro", R_WS, 0, &px, &py) && need("+", R_WS, 0, &x, &y)) {
|
||||
int k = 0; bool got = false;
|
||||
while (find("0", R_WS, k++, &zx, &zy))
|
||||
if (zy > y - 4 && zy < y + 4 && zx < x) { got = true; break; }
|
||||
if (!got) { printf("FAIL slot esquerdo do +\n"); fails++; }
|
||||
else drag(px, py, px + ((zx - 3 - 10) - (px - 3 - 10)), zy);
|
||||
}
|
||||
}
|
||||
/* digita 1 no slot direito do "+" */
|
||||
if (need("+", R_WS, 0, &x, &y)) {
|
||||
float zx, zy; int k = 0;
|
||||
while (find("0", R_WS, k++, &zx, &zy))
|
||||
if (zy > y - 4 && zy < y + 4 && zx > x) {
|
||||
click(zx, zy); type("1"); key(TB_KEY_RETURN, 0, 0); break;
|
||||
}
|
||||
}
|
||||
if (need("+", R_WS, 0, &x, &y) && need("=", R_WS, 0, &x2, &y2)) {
|
||||
float rep_left = x - 3 - 10;
|
||||
{ float px, py; if (find("parâmetro", R_WS, 0, &px, &py)) rep_left = px - 3 - 10 - 10; }
|
||||
drag(x, y, x + ((x2 + 12) - rep_left), y + (y2 - y));
|
||||
}
|
||||
if (need("Salvar", R_WS, 0, &x, &y)) click(x, y);
|
||||
CHECK(find("dobro", R_ANY, 0, &x, &y), "bloco composto salvo");
|
||||
if (need("Código", R_ANY, 0, &x, &y)) click(x, y);
|
||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("dobro", R_FLY, 0, &x, &y)) drag(x, y, 650, 640);
|
||||
{
|
||||
float sx, sy;
|
||||
if (find("n", R_WS, 0, &sx, &sy)) {
|
||||
click(sx, sy);
|
||||
key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type("21"); key(TB_KEY_RETURN, 0, 0);
|
||||
}
|
||||
}
|
||||
if (need("dobro", R_WS, 0, &x, &y)) click(x, y);
|
||||
CHECK(ws_has("22"), "bloco composto dobro(21) = 22");
|
||||
if (!ws_has("22")) { for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind==TB_DRAW_TEXT && in_region(cmds[i].x,R_WS)) printf(" ws: %s (%.0f,%.0f)\n", cmds[i].text, cmds[i].x, cmds[i].y); }
|
||||
|
||||
/* 9. Laço infinito é interrompido */
|
||||
if (need("Controle", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("repita até que", R_FLY, 0, &x, &y)) drag(x, y, 700, 300);
|
||||
if (need("repita até que", R_WS, 0, &x, &y)) click(x, y);
|
||||
CHECK(stage_has("limite de passos"), "laço infinito é abortado com aviso");
|
||||
|
||||
/* 10. Caneta: desenhar no palco embutido */
|
||||
int circles_before = 0;
|
||||
for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmds[i].x >= 920 && cmds[i].y > 90 && cmds[i].y < 340) circles_before++;
|
||||
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("desenhe círculo em x", R_FLY, 0, &x, &y)) drag(x, y, 600, 650);
|
||||
if (need("desenhe círculo em x", R_WS, 0, &x, &y)) click(x, y);
|
||||
int circles = 0; float cx = 0, cy = 0, cr = 0;
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmds[i].x >= 920 && cmds[i].y > 90 && cmds[i].y < 340) {
|
||||
circles++; cx = cmds[i].x; cy = cmds[i].y; cr = cmds[i].param;
|
||||
}
|
||||
printf(" círculo no palco: (%.1f, %.1f) r=%.1f\n", cx, cy, cr);
|
||||
CHECK(circles == circles_before + 1 && fabsf(cx - (928 + 172)) < 2 && fabsf(cy - (44 + 44 + 1 + 128)) < 2,
|
||||
"bloco da caneta desenha círculo centrado no palco embutido");
|
||||
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
|
||||
if (need("apague tudo", R_FLY, 0, &x, &y)) drag(x, y, 600, 700);
|
||||
if (need("apague tudo", R_WS, 0, &x, &y)) click(x, y);
|
||||
circles = 0;
|
||||
for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmds[i].x >= 920 && cmds[i].y > 90 && cmds[i].y < 340) circles++;
|
||||
CHECK(circles == circles_before, "\"apague tudo\" limpa o palco");
|
||||
|
||||
/* 11. Destacar o palco numa janela própria e recolher de volta */
|
||||
click(1280 - 50 + 20, 44 + 22);
|
||||
CHECK(any_has("Palco aberto em outra janela"), "palco destacado abre janela própria");
|
||||
click(1280 - 50 + 20, 44 + 22);
|
||||
CHECK(!any_has("Palco aberto em outra janela"), "palco recolhido volta ao painel");
|
||||
|
||||
printf("comandos de desenho no último frame: %u\n", ncmd);
|
||||
tinyblocks_deinit(&rt);
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
return fails != 0;
|
||||
}
|
||||
Reference in new issue
Block a user