From 8f046833e7a2df5017d4e20a3fb8dfa267e5d414 Mon Sep 17 00:00:00 2001 From: mguinhos Date: Fri, 23 Oct 2026 07:41:12 -0300 Subject: [PATCH] =?UTF-8?q?Acessibilidade:=20arrastar=20e=20soltar=20como?= =?UTF-8?q?=20a=C3=A7=C3=A3o;=20harness=20inteiro=20pela=20=C3=A1rvore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tb_a11y_drop(origem, destino) e tb_a11y_drop_at(origem, destino, x, y): o editor encaixa pelo papel do destino (campo, embaixo de um bloco, dentro de uma boca, sobre a paleta para apagar, aba sobre aba, área sobre área) pelo mesmo caminho do mouse (pointer_motion, extraído do tratamento de entrada); origem ou destino fora da vista rolam antes. A árvore passa a cobrir o explorador de arquivos (trilha, locais, arquivos, nome, opções, confirmação de substituir), a aba de imagem (ferramentas, folha, rodapé, cores, paleta, camadas), a dica (Alt), as bordas entre áreas, as alças e os botões de destacar. O retângulo do palco é a vista dele; avisos repetidos dizem quantas vezes no valor. O harness não acha mais nada por texto desenhado nem por coordenada fixa: categorias, blocos, campos, menus, diálogos, saída e avisos vêm da árvore. Só pintar na folha e soltar em lugar livre usam posição, e relativa a um componente. Co-Authored-By: Claude Opus 5.5 --- libraries/tinyblocks-a11y/include/tb_a11y.h | 22 +- libraries/tinyblocks-a11y/src/tb_a11y.c | 21 +- .../include/tb_editor_internal.h | 5 +- .../tinyblocks-editor-files/Makefile | 4 +- .../src/tb_editor_files.c | 81 ++ .../tinyblocks-editor-image/Makefile | 4 +- .../src/tb_editor_image.c | 119 ++ libraries/tinyblocks-editor/src/tb_editor.c | 279 ++-- tests/a11y_test.c | 14 +- tests/editor_harness.c | 1151 +++++++---------- 10 files changed, 953 insertions(+), 747 deletions(-) diff --git a/libraries/tinyblocks-a11y/include/tb_a11y.h b/libraries/tinyblocks-a11y/include/tb_a11y.h index 9e2ebad..5aab6e2 100644 --- a/libraries/tinyblocks-a11y/include/tb_a11y.h +++ b/libraries/tinyblocks-a11y/include/tb_a11y.h @@ -55,6 +55,8 @@ typedef enum TinyBlocks_A11yRole { TB_A11Y_STATUS, /* aviso / mensagem (regiao "viva") */ TB_A11Y_BLOCK, /* um bloco de programacao */ TB_A11Y_SLOT, /* encaixe vazio de um bloco (ex.: booleano) */ + TB_A11Y_SEPARATOR, /* borda arrastavel entre areas */ + TB_A11Y_TOOLTIP, /* dica flutuante */ TB_A11Y_ROLE_COUNT } TinyBlocks_A11yRole; @@ -78,10 +80,19 @@ typedef enum TinyBlocks_A11yAction { TB_A11Y_ACT_ACTIVATE = 1u << 0, /* clicar / pressionar */ TB_A11Y_ACT_MENU = 1u << 1, /* abrir o menu de contexto */ TB_A11Y_ACT_EDIT = 1u << 2, /* comecar a editar o texto */ - TB_A11Y_ACT_DRAG = 1u << 3, /* pode ser arrastado */ + TB_A11Y_ACT_DRAG = 1u << 3, /* pode ser arrastado (tb_a11y_drop) */ TB_A11Y_ACT_DROP = 1u << 4, /* aceita algo solto em cima */ } TinyBlocks_A11yAction; +/* Pedido de acao entregue a quem desenha a interface */ +typedef struct TinyBlocks_A11yRequest { + TinyBlocks_A11yAction action; + int target; /* DRAG: no de destino (-1 = nenhum) */ + bool at; /* DRAG: o canto da origem vai para destino + (x, y) */ + float x, y; /* (sem `at`, quem desenha escolhe pelo papel do * + * destino: encaixar no campo, embaixo do bloco...) */ +} TinyBlocks_A11yRequest; + #define TB_A11Y_NAME_MAX 128 #define TB_A11Y_DESC_MAX 192 #define TB_A11Y_VALUE_MAX 128 @@ -134,9 +145,9 @@ typedef struct TinyBlocks_A11yBridge { void* user; } TinyBlocks_A11yBridge; -/* == Quem desenha a interface executa as acoes (ex.: clicar no centro) */ +/* == Quem desenha a interface executa as acoes (ex.: clicar no ponto) */ typedef bool (*TinyBlocks_A11yPerform)(void* user, const TinyBlocks_A11yTree* tree, - int node, TinyBlocks_A11yAction action); + int node, const TinyBlocks_A11yRequest* req); /* -- Ciclo de vida --- */ TB_API TinyBlocks_A11yTree* tb_a11y_tree_new(void); @@ -191,6 +202,11 @@ TB_API void tb_a11y_dump(const TinyBlocks_A11yTree* tree, int from, FILE* out); /* -- Acoes e eventos --- */ TB_API bool tb_a11y_do_action(TinyBlocks_A11yTree* tree, int node, TinyBlocks_A11yAction action); +/* Arrasta `node` (acao DRAG) e solta sobre `target` (acao DROP). Quem desenha + * decide onde pelo papel do destino (ex.: um bloco solto num campo encaixa). */ +TB_API bool tb_a11y_drop(TinyBlocks_A11yTree* tree, int node, int target); +/* Idem, levando o canto de `node` para (x, y) relativo ao canto de `target` */ +TB_API bool tb_a11y_drop_at(TinyBlocks_A11yTree* tree, int node, int target, float x, float y); /* Eventos do ultimo tb_a11y_end (tambem enviados a ponte) */ TB_API int tb_a11y_event_count(const TinyBlocks_A11yTree* tree); TB_API const TinyBlocks_A11yEvent* tb_a11y_event(const TinyBlocks_A11yTree* tree, int i); diff --git a/libraries/tinyblocks-a11y/src/tb_a11y.c b/libraries/tinyblocks-a11y/src/tb_a11y.c index 9d35ed8..682900a 100644 --- a/libraries/tinyblocks-a11y/src/tb_a11y.c +++ b/libraries/tinyblocks-a11y/src/tb_a11y.c @@ -390,6 +390,8 @@ const char* tb_a11y_role_name(TinyBlocks_A11yRole r) { [TB_A11Y_STATUS] = "aviso", [TB_A11Y_BLOCK] = "bloco", [TB_A11Y_SLOT] = "encaixe", + [TB_A11Y_SEPARATOR] = "divisória", + [TB_A11Y_TOOLTIP] = "dica", }; return r >= 0 && r < TB_A11Y_ROLE_COUNT ? names[r] : ""; } @@ -434,7 +436,24 @@ void tb_a11y_dump(const TinyBlocks_A11yTree* t, int from, FILE* out) { /* -- Acoes --- */ bool tb_a11y_do_action(TinyBlocks_A11yTree* t, int node, TinyBlocks_A11yAction a) { if (!valid(t, node) || !t->perform || !(t->nodes[node].actions & (uint32_t)a)) return false; - return t->perform(t->perform_user, t, node, a); + TinyBlocks_A11yRequest req = { a, -1, false, 0, 0 }; + return t->perform(t->perform_user, t, node, &req); +} + +static bool drop_impl(TinyBlocks_A11yTree* t, int node, int target, bool at, float x, float y) { + if (!valid(t, node) || !valid(t, target) || !t->perform) return false; + if (!(t->nodes[node].actions & TB_A11Y_ACT_DRAG) || !(t->nodes[target].actions & TB_A11Y_ACT_DROP)) + return false; + TinyBlocks_A11yRequest req = { TB_A11Y_ACT_DRAG, target, at, x, y }; + return t->perform(t->perform_user, t, node, &req); +} + +bool tb_a11y_drop(TinyBlocks_A11yTree* t, int node, int target) { + return drop_impl(t, node, target, false, 0, 0); +} + +bool tb_a11y_drop_at(TinyBlocks_A11yTree* t, int node, int target, float x, float y) { + return drop_impl(t, node, target, true, x, y); } /* -- Ponte de texto --- */ diff --git a/libraries/tinyblocks-editor/include/tb_editor_internal.h b/libraries/tinyblocks-editor/include/tb_editor_internal.h index 9caf9de..85062ee 100644 --- a/libraries/tinyblocks-editor/include/tb_editor_internal.h +++ b/libraries/tinyblocks-editor/include/tb_editor_internal.h @@ -39,7 +39,8 @@ #include #include "tb_editor_modules.h" -/* Arvore acessivel (tb_a11y.h, da tinyblocks-a11y); so o tb_editor.c usa */ +/* Arvore acessivel (tb_a11y.h, da tinyblocks-a11y). Quem desenha uma parte + * da tela a descreve em ed_ax(ed) (NULL fora do desenho da janela principal). */ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree; #ifndef TB_EW_UNUSED @@ -974,6 +975,8 @@ typedef struct Ed { bool ax_on; /* montando a arvore neste desenho */ } Ed; +static inline TinyBlocks_A11yTree* ed_ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; } + #define CT (ed->tabs[ed->cur_tab]) /* Ponteiro global para o editor ativo - os eval_fn dos blocos do editor diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/Makefile b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/Makefile index eabeb60..a34da80 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/Makefile +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/Makefile @@ -16,7 +16,8 @@ CFLAGS := -std=c11 -Wall -Wextra -pedantic \ -I../../../tinyblocks-environ/include \ -I../../../tinyblocks-api/include \ -I../../../tinyblocks-libman/include \ - -I../../../tinyblocks-syntax/include + -I../../../tinyblocks-syntax/include \ + -I../../../tinyblocks-a11y/include OBJS := $(BUILD)/tb_editor_files.o LIB_A := $(BUILD)/libtinyblocks-editor-files.a @@ -29,6 +30,7 @@ shared: $(LIB_SO) $(BUILD)/tb_editor_files.o: src/tb_editor_files.c include/tb_editor_files.h \ ../../include/tb_editor_internal.h \ + ../../../tinyblocks-a11y/include/tb_a11y.h \ ../tinyblocks-editor-widgets/include/tb_editor_widgets.h @mkdir -p $(BUILD) $(CC) $(CFLAGS) -fPIC -c $< -o $@ diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c index 72bd5d1..6450b51 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/src/tb_editor_files.c @@ -17,6 +17,7 @@ #include #include +#include #include "tb_editor_files.h" /* -- Geometria --- */ @@ -609,11 +610,91 @@ static void fd_confirm_geom(const FdL* L, float* bx, float* by, float* bw, float *by = L->y + (L->h - *bh) * 0.5f; } +/* Componente que se ativa com um clique (acessibilidade) */ +static int fd_ax_click(TinyBlocks_A11yTree* t, TinyBlocks_A11yRole r, const char* name, + float x, float y, float w, float h) { + int n = tb_a11y_add(t, r, name, x, y, w, h); + tb_a11y_set_actions(t, n, TB_A11Y_ACT_ACTIVATE); + return n; +} + +/* O explorador na arvore acessivel: dialogo com trilha, locais, arquivos, + * campo do nome, opcoes, botoes e a confirmacao de substituir */ +static void fd_ax(Ed* ed, const FdL* L) { + TinyBlocks_A11yTree* t = ed_ax(ed); + if (!t) return; + FileDlg* F = &ed->fdlg; + char buf[512]; + tb_a11y_set_states(t, tb_a11y_push(t, TB_A11Y_DIALOG, F->title, L->x, L->y, L->w, L->h), TB_A11Y_MODAL); + fd_ax_click(t, TB_A11Y_BUTTON, "Fechar", L->close_cx - 14, L->close_cy - 14, 28, 28); + tb_a11y_set_states(t, fd_ax_click(t, TB_A11Y_BUTTON, "Pasta acima", L->up_x, L->bar_y, 32, 30), + strcmp(F->dir, "/") != 0 ? 0 : TB_A11Y_DISABLED); + { + FdCrumbs K; + fd_crumbs(ed, L, &K); + int tr = tb_a11y_push(t, TB_A11Y_TOOLBAR, "Caminho", L->crumb_x, L->bar_y, L->crumb_w, 30); + tb_a11y_set_value(t, tr, F->dir); + for (int k = K.first; k < K.n; k++) { + fd_crumb_label(F, &K, k, buf, sizeof(buf)); + fd_ax_click(t, TB_A11Y_BUTTON, buf, K.x[k], L->bar_y + 3, K.w[k], 24); + } + tb_a11y_pop(t); + } + tb_a11y_push(t, TB_A11Y_LIST, "Locais", L->side_x, L->side_y, FD_SIDE_W, L->side_h); + for (int i = 0; i < F->place_n; i++) { + int n = fd_ax_click(t, TB_A11Y_LIST_ITEM, F->place_label[i], L->side_x + 6, L->side_y + 30 + i * 32, + FD_SIDE_W - 12, 30); + tb_a11y_set_value(t, n, F->place_path[i]); + tb_a11y_set_states(t, n, strcmp(F->dir, F->place_path[i]) == 0 ? TB_A11Y_SELECTED : 0); + } + tb_a11y_pop(t); + tb_a11y_push(t, TB_A11Y_LIST, "Arquivos", L->list_x, L->list_y, L->list_w, L->list_h); + int end = F->scroll + L->rows; + if (end > F->n) end = F->n; + for (int i = F->scroll; i < end; i++) { /* as linhas visiveis */ + FileEnt* e = &F->ents[i]; + float ry = L->list_y + (float)(i - F->scroll) * FD_ROW_H; + int n = fd_ax_click(t, TB_A11Y_LIST_ITEM, e->is_dir == 2 ? ".." : e->name, + L->list_x + 4, ry + 1, L->list_w - 18, FD_ROW_H - 2); + if (e->is_dir) tb_a11y_set_value(t, n, e->is_dir == 2 ? "pasta acima" : "pasta"); + else { fd_size_str(buf, sizeof(buf), e->size); tb_a11y_set_value(t, n, buf); } + tb_a11y_set_states(t, n, i == F->sel ? TB_A11Y_SELECTED : 0); + } + tb_a11y_pop(t); + if (F->err[0]) tb_a11y_add(t, TB_A11Y_STATUS, F->err, L->list_x + 8, L->list_y + L->list_h - 30, L->list_w - 24, 24); + int nm = tb_a11y_add(t, TB_A11Y_TEXT_FIELD, "Nome", L->name_x, L->name_y, L->name_w, 30); + tb_a11y_set_value(t, nm, F->name); + tb_a11y_set_states(t, nm, TB_A11Y_EDITABLE | (F->confirm ? 0 : TB_A11Y_FOCUSED | TB_A11Y_EDITING)); + float r2 = L->row2_y; + if (F->filter[0]) + tb_a11y_set_states(t, fd_ax_click(t, TB_A11Y_CHECKBOX, "Todos os arquivos", L->chk_all_x, r2, 180, FD_BTN_H), + F->all_files ? TB_A11Y_CHECKED : 0); + tb_a11y_set_states(t, fd_ax_click(t, TB_A11Y_CHECKBOX, "Mostrar ocultos", L->chk_hid_x, r2, 170, FD_BTN_H), + F->show_hidden ? TB_A11Y_CHECKED : 0); + fd_ax_click(t, TB_A11Y_BUTTON, "Cancelar", L->cancel_x, L->row2_y, FD_BTN_W, FD_BTN_H); + fd_ax_click(t, TB_A11Y_BUTTON, F->ok_label, L->ok_x, L->row2_y, FD_BTN_W, FD_BTN_H); + if (F->confirm) { + float bx, by, bw, bh; + fd_confirm_geom(L, &bx, &by, &bw, &bh); + tb_a11y_set_states(t, tb_a11y_push(t, TB_A11Y_DIALOG, "Substituir arquivo", bx, by, bw, bh), TB_A11Y_MODAL); + const char* b = strrchr(F->name, '/'); + snprintf(buf, sizeof(buf), "\"%s\" já existe. Deseja substituir o arquivo?", b ? b + 1 : F->name); + tb_a11y_add(t, TB_A11Y_LABEL, buf, bx + 20, by + 20, bw - 40, 50); + float yb = by + bh - FD_BTN_H - 16; + float xo = bx + bw - 20 - FD_BTN_W, xc = xo - 10 - FD_BTN_W; + fd_ax_click(t, TB_A11Y_BUTTON, "Cancelar", xc, yb, FD_BTN_W, FD_BTN_H); + fd_ax_click(t, TB_A11Y_BUTTON, "Substituir", xo, yb, FD_BTN_W, FD_BTN_H); + tb_a11y_pop(t); + } + tb_a11y_pop(t); +} + void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { FileDlg* F = &ed->fdlg; if (!F->open) return; FdL L; fd_layout(ed, &L); + fd_ax(ed, &L); float mx = ed->mouse_x, my = ed->mouse_y; bool modal_free = !F->confirm; char buf[512]; diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/Makefile b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/Makefile index 2777656..e860ad1 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/Makefile +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/Makefile @@ -16,7 +16,8 @@ CFLAGS := -std=c11 -Wall -Wextra -pedantic \ -I../../../tinyblocks-environ/include \ -I../../../tinyblocks-api/include \ -I../../../tinyblocks-libman/include \ - -I../../../tinyblocks-syntax/include + -I../../../tinyblocks-syntax/include \ + -I../../../tinyblocks-a11y/include OBJS := $(BUILD)/tb_editor_image.o LIB_A := $(BUILD)/libtinyblocks-editor-image.a @@ -29,6 +30,7 @@ shared: $(LIB_SO) $(BUILD)/tb_editor_image.o: src/tb_editor_image.c include/tb_editor_image.h \ ../../include/tb_editor_internal.h \ + ../../../tinyblocks-a11y/include/tb_a11y.h \ ../tinyblocks-editor-widgets/include/tb_editor_widgets.h @mkdir -p $(BUILD) $(CC) $(CFLAGS) -fPIC -c $< -o $@ diff --git a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c index 385ff1b..69102ff 100644 --- a/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c +++ b/libraries/tinyblocks-editor/libraries/tinyblocks-editor-image/src/tb_editor_image.c @@ -10,6 +10,7 @@ * editor ficam pendentes e sao resolvidos na carga. */ #include +#include #include "tb_editor_image.h" /* Helpers internos desta library (definidos mais abaixo) */ @@ -673,9 +674,127 @@ static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, fl } /* Render --- */ +/* Nomes das cores da paleta rapida (para o narrador) */ +static const char* IMG_PALETTE_NAME[12] = { + "Preto", "Branco", "Vermelho", "Laranja", "Amarelo", "Verde", + "Azul-claro", "Azul", "Roxo", "Rosa", "Marrom", "Cinza" +}; + +static int img_ax_click(TinyBlocks_A11yTree* t, TinyBlocks_A11yRole r, const char* name, + float x, float y, float w, float h) { + int n = tb_a11y_add(t, r, name, x, y, w, h); + tb_a11y_set_actions(t, n, TB_A11Y_ACT_ACTIVATE); + return n; +} + +/* A aba de imagem na arvore acessivel: ferramentas, arquivo, folha, rodape, + * cores e camadas. A folha aceita arrastar (pintar) sobre ela mesma. */ +static void img_ax(Ed* ed, Tab* T) { + TinyBlocks_A11yTree* t = ed_ax(ed); + if (!t) return; + char buf[160]; + tb_a11y_push(t, TB_A11Y_TOOLBAR, "Ferramentas", WS_X, WS_Y, IMG_TOOL_W, WS_H); + for (int i = 0; i < IT_N; i++) { + float bx, by; + img_tool_rect(ed, i, &bx, &by); + tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_RADIO, img_tool_tip(i), bx, by, IMG_TH, IMG_TH), + T->img_tool == i ? TB_A11Y_CHECKED : 0); + } + tb_a11y_pop(t); + { + float bx = WS_X + IMG_TOOL_W + 10; + tb_a11y_push(t, TB_A11Y_TOOLBAR, "Arquivo", WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H); + img_ax_click(t, TB_A11Y_BUTTON, "Abrir", bx, WS_Y + 5, 62, 24); + img_ax_click(t, TB_A11Y_BUTTON, "Salvar", bx + 70, WS_Y + 5, 62, 24); + tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_LABEL, "Arquivo", bx + 144, WS_Y + 5, 200, 24), + T->img_path[0] ? T->img_path : "sem arquivo"); + tb_a11y_pop(t); + } + { + float dx, dy, dw, dh; + img_view(ed, T, &dx, &dy, &dw, &dh); + int f = tb_a11y_push(t, TB_A11Y_CANVAS, "Folha", dx, dy, dw, dh); + snprintf(buf, sizeof(buf), "%d x %d, %s", T->img_w, T->img_h, img_tool_tip(T->img_tool)); + tb_a11y_set_value(t, f, buf); + tb_a11y_set_actions(t, f, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_DRAG | TB_A11Y_ACT_DROP); + if (T->img_sel.on) { + ImgSel* S = &T->img_sel; + float sx = dx + S->x * T->img_zoom, sy = dy + S->y * T->img_zoom; + tb_a11y_add(t, TB_A11Y_GROUP, "Seleção", sx, sy, S->w * T->img_zoom, S->h * T->img_zoom); + img_ax_click(t, TB_A11Y_BUTTON, "Excluir seleção", sx + S->w * T->img_zoom - 20.f, sy + 2.f, 18, 18); + } + tb_a11y_pop(t); + } + { + static const char* labels[2] = { "Desfazer", "Limpar" }; + for (int i = 0; i < 2; i++) { + float bx, by, bw, bh; + img_foot_btn(ed, i, &bx, &by, &bw, &bh); + tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_BUTTON, labels[i], bx, by, bw, bh), + i == 0 && T->img_undo_n == 0 ? TB_A11Y_DISABLED : 0); + } + float sx, sy, sw, sh; + img_zoom_slider(ed, &sx, &sy, &sw, &sh); + snprintf(buf, sizeof(buf), "%d%%", (int)(T->img_zoom * 100.f + 0.5f)); + tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_LABEL, "Zoom", sx, sy - 10, sw, sh + 20), buf); + } + { + float px = img_color_x(ed); + tb_a11y_push(t, TB_A11Y_GROUP, "Cores", px, WS_Y, IMG_RIGHT_W, img_layers_title_y(ed) - 14 - WS_Y); + snprintf(buf, sizeof(buf), "#%02X%02X%02X", T->img_rgb[0], T->img_rgb[1], T->img_rgb[2]); + tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_LABEL, "Cor atual", px + IMG_RIGHT_W - 44, WS_Y + 5, 30, 30), buf); + float cx, cy, ro, ri; + img_wheel_rect(ed, &cx, &cy, &ro, &ri); + snprintf(buf, sizeof(buf), "%.0f graus", T->img_hue); + int wh = tb_a11y_add(t, TB_A11Y_CANVAS, "Matiz", cx - ro, cy - ro, 2 * ro, 2 * ro); + tb_a11y_set_value(t, wh, buf); + tb_a11y_set_point(t, wh, cx + (ri + ro) * 0.5f, cy); + float qx, qy, qw, qh; + img_sv_rect(ed, &qx, &qy, &qw, &qh); + snprintf(buf, sizeof(buf), "saturação %.0f%%, valor %.0f%%", T->img_sat * 100.f, T->img_val * 100.f); + tb_a11y_set_value(t, tb_a11y_add(t, TB_A11Y_CANVAS, "Saturação e valor", qx, qy, qw, qh), buf); + tb_a11y_push(t, TB_A11Y_LIST, "Paleta de cores", px, img_pal_y(ed), IMG_RIGHT_W, 4 * 30); + for (int i = 0; i < 12; i++) { + float sx, sy; + img_swatch_rect(ed, i, &sx, &sy); + tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_RADIO, IMG_PALETTE_NAME[i], sx, sy, 34, 22), + i == T->img_swatch ? TB_A11Y_CHECKED : 0); + } + tb_a11y_pop(t); + tb_a11y_pop(t); + } + { + float px = img_color_x(ed); + tb_a11y_push(t, TB_A11Y_LIST, "Camadas", px, img_layers_title_y(ed), IMG_RIGHT_W, + WS_Y + WS_H - img_layers_title_y(ed)); + for (int i = 0; i < T->img_layer_n; i++) { + float rx, ry, rw, rh; + img_layer_row(ed, i, &rx, &ry, &rw, &rh); + int it = tb_a11y_push(t, TB_A11Y_LIST_ITEM, T->img_layers[i].name[0] ? T->img_layers[i].name : "camada", + rx, ry, rw, rh); + tb_a11y_set_point(t, it, rx + rw * 0.6f, ry + rh * 0.5f); + tb_a11y_set_actions(t, it, TB_A11Y_ACT_ACTIVATE); + tb_a11y_set_value(t, it, T->img_layers[i].kind == IMG_L_VECTOR ? "vetor" : "raster"); + tb_a11y_set_states(t, it, i == T->img_layer_cur ? TB_A11Y_SELECTED : 0); + tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_CHECKBOX, "Visível", rx + 5, ry + rh * 0.5f - 6, 12, 12), + T->img_layers[i].visible ? TB_A11Y_CHECKED : 0); + tb_a11y_pop(t); + } + static const char* labels[3] = { "Excluir camada", "Nova camada raster", "Nova camada vetorial" }; + for (int i = 0; i < 3; i++) { + float bx2, by2, bw2, bh2; + img_side_btn(ed, i, &bx2, &by2, &bw2, &bh2); + tb_a11y_set_states(t, img_ax_click(t, TB_A11Y_BUTTON, labels[i], bx2, by2, bw2, bh2), + i == 0 && T->img_layer_n <= 1 ? TB_A11Y_DISABLED : 0); + } + tb_a11y_pop(t); + } +} + void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) { Tab* T = &CT; img_ensure(ed, T); + img_ax(ed, T); rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_PAINT_BG); diff --git a/libraries/tinyblocks-editor/src/tb_editor.c b/libraries/tinyblocks-editor/src/tb_editor.c index 285af2e..0b6de0d 100644 --- a/libraries/tinyblocks-editor/src/tb_editor.c +++ b/libraries/tinyblocks-editor/src/tb_editor.c @@ -884,7 +884,7 @@ static void draw_slot(TinyBlocks_RenderableBlock* rb, const EdBlock* b, int s, * nome, valor, estados, acoes e retangulo. A arvore serve ao narrador (por * uma ponte) e aos testes (acham componentes por papel + nome). So o * desenho da janela principal monta a arvore (ed->ax_on). */ -static TinyBlocks_A11yTree* ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; } +static TinyBlocks_A11yTree* ax(Ed* ed) { return ed_ax(ed); } static int ax_push(Ed* ed, TinyBlocks_A11yRole r, const char* name, float x, float y, float w, float h) { return tb_a11y_push(ax(ed), r, name, x, y, w, h); @@ -969,7 +969,9 @@ static void ax_block(Ed* ed, Tab* T, int bi, float ox, float oy, uint32_t acts) int n = tb_a11y_push(t, TB_A11Y_BLOCK, label, x, y, b->w, b->h); tb_a11y_set_key(t, n, b->type_name); /* o id nao muda ao editar */ tb_a11y_set_point(t, n, x + fminf(8.f, b->w * 0.5f), y + b->row_y + b->row_h * 0.5f); - tb_a11y_set_actions(t, n, acts); + bool in_ws = T == &CT && (acts & TB_A11Y_ACT_MENU); /* na area de scripts */ + tb_a11y_set_actions(t, n, acts | (in_ws && !shape_is_value(shape_of(b->type)) && !is_cap(b->type) + ? TB_A11Y_ACT_DROP : 0)); /* solta embaixo dele */ if (T == &CT && (x + b->w < WS_X || x > WS_X + WS_W || y + b->h < WS_Y || y > WS_Y + WS_H)) tb_a11y_add_states(t, n, TB_A11Y_OFFSCREEN); /* existe, mas a aba esta rolada */ const TinyBlocks_BlockMeta* meta = tb_meta_find(b->type_name); @@ -1006,7 +1008,8 @@ static void ax_block(Ed* ed, Tab* T, int bi, float ox, float oy, uint32_t acts) } for (int k = 0; k < shape_mouths(shape_of(b->type)); k++) { const char* mn = k == 0 ? "dentro" : mouth_label(b->type, k - 1); - tb_a11y_push(t, TB_A11Y_GROUP, mn, x + ARM_W, y + b->sub_y[k], b->w - ARM_W, b->sub_h[k]); + int mg = tb_a11y_push(t, TB_A11Y_GROUP, mn, x + ARM_W, y + b->sub_y[k], b->w - ARM_W, b->sub_h[k]); + if (in_ws) tb_a11y_set_actions(t, mg, TB_A11Y_ACT_DROP); /* solta dentro da boca */ if (b->sub[k] >= 0) ax_chain(ed, T, b->sub[k], ox, oy, acts); tb_a11y_pop(t); } @@ -2353,6 +2356,9 @@ static void draw_detach_btn(Ed* ed, TinyBlocks_RenderableBlock* rb, int v) { bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, DETACH_S, DETACH_S); if (hov) rb_fill_rrect(rb, bx, by, DETACH_S, DETACH_S, 5, COL_HOVER); draw_window_icon(rb, bx - 2, by, DETACH_S + 4, ed->area[v].detached, hov ? COL_MENU : COL_TEXT_DIM); + char nm[64]; + snprintf(nm, sizeof(nm), "%s a área %s", ed->area[v].detached ? "Recolher" : "Destacar", view_name(v)); + ax_button(ed, nm, bx, by, DETACH_S, DETACH_S); } static void draw_grip(Ed* ed, TinyBlocks_RenderableBlock* rb, int v) { @@ -2360,6 +2366,11 @@ static void draw_grip(Ed* ed, TinyBlocks_RenderableBlock* rb, int v) { if (!ed->area[v].shown) return; float gx, gy; grip_pos(ed, v, &gx, &gy); + { /* alca: arraste e solte sobre outra area (PANE) para trocar de lugar */ + char nm[64]; + snprintf(nm, sizeof(nm), "Mover a área %s", view_name(v)); + tb_a11y_set_actions(ax(ed), ax_add(ed, TB_A11Y_BUTTON, nm, gx, gy, GRIP_S, GRIP_S), TB_A11Y_ACT_DRAG); + } bool hov = ed->area_drag == v || in_rect(ed->mouse_x, ed->mouse_y, gx, gy, GRIP_S, GRIP_S); if (hov) rb_fill_rrect(rb, gx - 2, gy - 2, GRIP_S + 4, GRIP_S + 4, 5, COL_HOVER); Col c = hov ? COL_MENU : COL_TEXT_DIM; @@ -2368,6 +2379,37 @@ static void draw_grip(Ed* ed, TinyBlocks_RenderableBlock* rb, int v) { rb_fill_circle(rb, gx + 6 + i * 6, gy + 3 + j * 6, 1.6f, c); } +/* Primeira area (folha) de um no do layout, para dar nome as bordas */ +static int lay_first_view(Ed* ed, int n) { + for (int k = 0; k < LAY_MAX && n >= 0 && n < ed->lay_n; k++) { + if (ed->lay[n].kind == LN_LEAF) return ed->lay[n].view; + n = ed->lay[n].a; + } + return -1; +} + +/* Bordas arrastaveis entre as areas: "Borda entre Blocos e Scripts". Para + * mover, solte a borda sobre ela mesma com um deslocamento (drop_at). */ +static void ax_separators(Ed* ed) { + TinyBlocks_A11yTree* t = ax(ed); + if (!t) return; + for (int n = 0; n < ed->lay_n; n++) { + const LayNode* N = &ed->lay[n]; + if (N->kind == LN_LEAF || N->w <= 0 || N->h <= 0) continue; + int va = lay_first_view(ed, N->a), vb = lay_first_view(ed, N->b); + char name[96]; + snprintf(name, sizeof(name), "Borda entre %s e %s", view_name(va), view_name(vb)); + bool hz = N->kind == LN_HSPLIT; + int s = hz ? tb_a11y_add(t, TB_A11Y_SEPARATOR, name, N->pos - 3, N->y, 6, N->h) + : tb_a11y_add(t, TB_A11Y_SEPARATOR, name, N->x, N->pos - 3, N->w, 6); + tb_a11y_set_actions(t, s, TB_A11Y_ACT_DRAG | TB_A11Y_ACT_DROP); + char val[16]; + snprintf(val, sizeof(val), "%.0f", N->pos - (hz ? N->x : N->y)); + tb_a11y_set_value(t, s, val); + tb_a11y_set_description(t, s, hz ? "vertical" : "horizontal"); + } +} + /* Borda sob o mouse e alvo da troca de areas */ static void render_areas_overlay(Ed* ed, TinyBlocks_RenderableBlock* rb) { int sp = ed->split_drag >= 0 ? ed->split_drag : ed->split_hover; @@ -3886,6 +3928,11 @@ static void render_toasts(Ed* ed, TinyBlocks_RenderableBlock* rb) { /* temporizador: barra que encolhe (para com o mouse em cima) */ int an = ax_push(ed, TB_A11Y_STATUS, t->text, t->x, t->y, w, h); tb_a11y_set_description(ax(ed), an, t->ok ? "aviso" : "erro"); + if (t->count > 1) { + char cnt[32]; + snprintf(cnt, sizeof(cnt), "%d vezes", t->count); + tb_a11y_set_value(ax(ed), an, cnt); + } ax_button(ed, "Fechar aviso", cx - 11, cy - 11, 22, 22); ax_pop(ed); float k = t->total_ms > 0 ? fmaxf(0.f, t->left_ms / t->total_ms) : 0.f; @@ -3943,7 +3990,8 @@ static void render_tab_bar(Ed* ed, TinyBlocks_RenderableBlock* rb) { int an = ax_push(ed, TB_A11Y_TAB, ed->tabs[i].name, tx, y0 + 6, TAB_W - 4, TAB_H - 6); tb_a11y_set_point(ax(ed), an, tx + 14, cy); tb_a11y_set_states(ax(ed), an, cur ? TB_A11Y_SELECTED : 0); - tb_a11y_set_actions(ax(ed), an, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_MENU | TB_A11Y_ACT_DRAG); + tb_a11y_set_actions(ax(ed), an, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_MENU | TB_A11Y_ACT_DRAG | + TB_A11Y_ACT_DROP); tb_a11y_set_description(ax(ed), an, tab_class(&ed->tabs[i])->name); if (ed->tab_n > 1 && ed->tabctx < 0) { /* fechar: um X desenhado */ float qx = tx + TAB_W - 18; @@ -4011,7 +4059,8 @@ static void render_flyout(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_line(rb, FLY_R-1, PAL_Y, FLY_R-1, PAL_B, 1.f, COL_BORDER); clip_set(ed, rb, FLY_X, PAL_Y, FLY_R - FLY_X - 1, PAL_B-PAL_Y); float oy = PAL_Y - ed->fly_scroll; - ax_push(ed, TB_A11Y_LIST, "Paleta", FLY_X, PAL_Y, FLY_R - FLY_X, PAL_B - PAL_Y); + tb_a11y_set_actions(ax(ed), ax_push(ed, TB_A11Y_LIST, "Paleta", FLY_X, PAL_Y, FLY_R - FLY_X, PAL_B - PAL_Y), + TB_A11Y_ACT_DROP); /* bloco solto aqui e apagado */ bool ax_grp = false; for (int i = 0; i < ed->fly_n; i++) { FlyItem* it = &ed->fly_items[i]; @@ -4569,6 +4618,12 @@ void render_tooltip(Ed* ed, TinyBlocks_RenderableBlock* rb) { p = nl + 1; } rb_text_c(rb, x + 12, y + h - 8, "clique para abrir o codigo nesta linha", COL_TEXT_DIM, 9.f); + int tn = ax_push(ed, TB_A11Y_TOOLTIP, ed->tip_title, x, y, w, h); + tb_a11y_set_value(ax(ed), tn, ed->tip_loc); + tb_a11y_set_description(ax(ed), tn, ed->tip_doc); + tb_a11y_set_value(ax(ed), ax_button(ed, "Abrir o código nesta linha", x + 6, ed->tip_prev_y - 2, w - 12, + ed->tip_prev_h + 4), ed->tip_preview); + ax_pop(ed); } /* == Classes de aba (ver TabClass) ===================================== */ @@ -4640,22 +4695,13 @@ static void code_tab_a11y(Ed* ed) { tb_a11y_set_description(ax(ed), n, desc); } -/* Aba de imagem: a tela de desenho, com o tamanho como valor */ -static void image_tab_a11y(Ed* ed) { - char val[32]; - snprintf(val, sizeof(val), "%d x %d", CT.img_w, CT.img_h); - int n = ax_add(ed, TB_A11Y_CANVAS, "Imagem", WS_X, WS_Y, WS_W, WS_H); - tb_a11y_set_value(ax(ed), n, val); - tb_a11y_set_description(ax(ed), n, CT.img_path[0] ? CT.img_path : "sem arquivo"); -} - static const TabClass s_tab_classes[] = { [TK_BLOCKS] = { "Blocos", true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, [TK_CODE] = { "Código", false, NULL, render_code_tab, code_tab_click, NULL, NULL, code_key, code_text, code_tab_scroll, code_tab_icon, code_tab_a11y }, [TK_IMAGE] = { "Imagem", false, image_tab_init, image_tab_render, image_tab_click, image_tab_release, image_tab_motion, image_tab_key, NULL, - image_tab_scroll, image_tab_icon, image_tab_a11y }, + image_tab_scroll, image_tab_icon, NULL }, /* o modulo se descreve */ }; const TabClass* tab_class(const Tab* T) { @@ -4794,6 +4840,7 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) { const TabClass* tc = tab_class(&CT); int panel = ax_push(ed, TB_A11Y_TAB_PANEL, CT.name, WS_X, WS_Y, WS_W, WS_H); tb_a11y_set_description(ax(ed), panel, tc->name); + tb_a11y_set_actions(ax(ed), panel, tc->blocks ? TB_A11Y_ACT_DROP : 0); /* solta solto (drop_at) */ if (tc->a11y) tc->a11y(ed); if (tc->render) { tc->render(ed, rb); ax_pop(ed); return; } float ox = WS_X - CT.ws_sx, oy = WS_Y - CT.ws_sy; @@ -5001,7 +5048,7 @@ static void render_stage(Ed* ed, TinyBlocks_RenderableBlock* rb) { rb_fill_rrect(rb, bx, by, bw, ph, 8, COL_BORDER); TinyBlocks_RenderableBlock* sub = NULL; tb_stage_set_view(bw-2, ph-2); - ax_add(ed, TB_A11Y_CANVAS, "Palco", bx, by, bw, ph); + ax_add(ed, TB_A11Y_CANVAS, "Palco", bx + 1, by + 1, bw - 2, ph - 2); /* a vista do palco */ clip_set(ed, rb, bx+1, by+1, bw-2, ph-2); if (ed->stage->type->on_draw(ed->stage, ed->rt, &sub) && sub) { tb_draw_merge_offset(rb, sub, bx+1, by+1); @@ -6185,14 +6232,7 @@ static void libman_scroll_m(Ed* ed, float dy) { libman_scroll_by(ed, dy); } /* o explorador vem do modulo do editor (pode faltar) */ static bool files_is_open(Ed* ed) { return ed->fdlg.open; } -static void files_render_m(Ed* ed, TinyBlocks_RenderableBlock* rb) { - if (!files_view) return; - files_view(ed, rb); - /* o modulo desenha; aqui so o dialogo e o caminho (o conteudo fica para o modulo) */ - tb_a11y_set_states(ax(ed), ax_push(ed, TB_A11Y_DIALOG, ed->fdlg.mode == PM_LOAD ? "Abrir" : "Salvar", - 0, 0, WIN_W, WIN_H), TB_A11Y_MODAL); - ax_pop(ed); -} +static void files_render_m(Ed* ed, TinyBlocks_RenderableBlock* rb) { if (files_view) files_view(ed, rb); } static void files_click_m(Ed* ed, float mx, float my) { if (files_click) files_click(ed, mx, my); } static void files_key_m(Ed* ed, int sc, bool ctrl) { if (files_key) files_key(ed, sc, ctrl); else ed->fdlg.open = false; } static void files_text_m(Ed* ed, const char* t) { if (files_text) files_text(ed, t); } @@ -6794,38 +6834,104 @@ static void hover_update(Ed* ed, float mx, float my) { } } +/* Ponteiro se moveu: bordas e areas, aba arrastada, bloco arrastado, + * grupo, rolagem da area e a aba (imagem). `from` = janela do evento. */ +static void pointer_motion(Ed* ed, float mx, float my, int from) { + /* == Areas: borda sendo arrastada / area levada pela alca === */ + if (ed->split_drag >= 0) { split_drag_to(ed, ed->split_drag, mx, my); lay_compute(ed); } + if (ed->area_drag >= 0) ed->area_drop = view_at(ed, mx, my); + bool modal = modal_top(ed) != NULL; + ed->split_hover = modal ? -1 : split_at(ed, mx, my); + + /* == Aba sendo arrastada: reordena ao passar do meio da vizinha === */ + if (ed->tab_press >= 0 && (ed->capture_view == -2 || ed->capture_view == from)) { + if (!ed->tab_drag && fabsf(mx - ed->tab_press_x) + fabsf(my - ed->tab_press_y) > 6.f) + ed->tab_drag = true; + if (ed->tab_drag) { + int vis[MAX_TABS], vn = tabs_visible_list(ed, vis); + int slot = (int)floorf((mx - ed->tab_grab_dx - (WS_X + 8) + TAB_W * 0.5f) / TAB_W); + if (slot < 0) slot = 0; + if (slot >= vn) slot = vn - 1; + if (vn > 1 && vis[slot] != ed->tab_press) { + int to = vis[slot]; + tab_move(ed, ed->tab_press, to); + ed->tab_press = to; + } + } + } + + /* == Movimento === */ + if (ed->state == ES_PRESS && fabsf(mx - ed->press_mx) + fabsf(my - ed->press_my) > 4.f && + (ed->capture_view == -2 || ed->capture_view == from)) + start_drag(ed); + if (ed->state == ES_DRAG && ed->drag_bi >= 0 && (ed->capture_view == -2 || ed->capture_view == from)) { + EdBlock* b = &CT.ws[ed->drag_bi]; + ed->drag_tab = ed->cur_tab; + ed->drag_ws_x = WS_X; ed->drag_ws_y = WS_Y; + b->x = mx - ed->drag_ox - WS_X + CT.ws_sx; + b->y = my - ed->drag_oy - WS_Y + CT.ws_sy; + layout_tab(&CT); + compute_snap(ed); + } + if (ed->grp_drag >= 0 && (ed->capture_view == -2 || ed->capture_view == from)) + group_motion(ed, mx, my); + if (ed->state == ES_PAN && (ed->capture_view == -2 || ed->capture_view == from)) { + CT.ws_sx = ed->pan_sx - (mx - ed->pan_mx); + CT.ws_sy = ed->pan_sy - (my - ed->pan_my); + } + if (tab_class(&CT)->motion) tab_class(&CT)->motion(ed, mx, my); +} + /* Acoes da arvore acessivel: agem como o mouse no ponto do componente * (o mesmo caminho do clique, entao narrador, testes e mouse nao divergem) */ -static bool ax_perform(void* user, const TinyBlocks_A11yTree* t, int node, TinyBlocks_A11yAction a) { +/* Area rolavel de um no: TAB_PANEL (scripts), LIST "Paleta" ou NONE */ +static TinyBlocks_A11yRole ax_area(const TinyBlocks_A11yTree* t, int node) { + for (int p = node; p >= 0; p = tb_a11y_node(t, p)->parent) { + const TinyBlocks_A11yNode* nd = tb_a11y_node(t, p); + if (nd->role == TB_A11Y_TAB_PANEL) return nd->role; + if (nd->role == TB_A11Y_LIST && !strcmp(nd->name, "Paleta")) return nd->role; + } + return TB_A11Y_NONE; +} + +/* Rola a area do no ate o ponto (x, y) ficar visivel; devolve o deslocamento + * aplicado (o que estava naquela area se move junto) */ +static void ax_scroll_into_view(Ed* ed, TinyBlocks_A11yRole area, float x, float y, float* dx, float* dy) { + *dx = *dy = 0; + if (area == TB_A11Y_TAB_PANEL) { + *dx = x - (WS_X + WS_W * 0.5f); + *dy = y - (WS_Y + WS_H * 0.5f); + CT.ws_sx += *dx; CT.ws_sy += *dy; + } else if (area == TB_A11Y_LIST) { + float before = ed->fly_scroll; + ed->fly_scroll += y - (PAL_Y + (PAL_B - PAL_Y) * 0.5f); + if (ed->fly_scroll > fly_max_scroll(ed)) ed->fly_scroll = fly_max_scroll(ed); + if (ed->fly_scroll < 0) ed->fly_scroll = 0; + *dy = ed->fly_scroll - before; + } +} + +/* Acoes da arvore acessivel: agem como o mouse no ponto do componente (o + * mesmo caminho do clique e do arrasto, entao narrador, testes e mouse nao + * divergem). Componente fora da vista: rola ate ele antes, como o GTK. */ +static bool ax_perform(void* user, const TinyBlocks_A11yTree* t, int node, const TinyBlocks_A11yRequest* req) { Ed* ed = user; + const TinyBlocks_A11yNode* src = tb_a11y_node(t, node); float x, y; tb_a11y_point(t, node, &x, &y); + float offx = x - src->x, offy = y - src->y; /* ponto de pegar, relativo ao canto */ + TinyBlocks_A11yRole sarea = ax_area(t, node); g_active_ed = ed; lay_compute(ed); - if (tb_a11y_node(t, node)->states & TB_A11Y_OFFSCREEN) { - /* fora da vista: rola ate ele antes (como o GTK faz) */ - TinyBlocks_A11yRole area = TB_A11Y_NONE; - for (int p = node; p >= 0 && area == TB_A11Y_NONE; p = tb_a11y_node(t, p)->parent) { - const TinyBlocks_A11yNode* nd = tb_a11y_node(t, p); - if (nd->role == TB_A11Y_TAB_PANEL || (nd->role == TB_A11Y_LIST && !strcmp(nd->name, "Paleta"))) - area = nd->role; - } - if (area == TB_A11Y_TAB_PANEL) { - float dx = x - (WS_X + WS_W * 0.5f), dy = y - (WS_Y + WS_H * 0.5f); - CT.ws_sx += dx; CT.ws_sy += dy; - x -= dx; y -= dy; - } else if (area == TB_A11Y_LIST) { - float before = ed->fly_scroll; - ed->fly_scroll += y - (PAL_Y + (PAL_B - PAL_Y) * 0.5f); - if (ed->fly_scroll > fly_max_scroll(ed)) ed->fly_scroll = fly_max_scroll(ed); - if (ed->fly_scroll < 0) ed->fly_scroll = 0; - y -= ed->fly_scroll - before; - } + float sdx = 0, sdy = 0; + if (src->states & TB_A11Y_OFFSCREEN) { + ax_scroll_into_view(ed, sarea, x, y, &sdx, &sdy); + x -= sdx; y -= sdy; } ed->mouse_x = x; ed->mouse_y = y; layout_tab(&CT); hover_update(ed, x, y); - switch (a) { + switch (req->action) { case TB_A11Y_ACT_ACTIVATE: case TB_A11Y_ACT_EDIT: ed->capture_view = -1; @@ -6836,8 +6942,41 @@ static bool ax_perform(void* user, const TinyBlocks_A11yTree* t, int node, TinyB case TB_A11Y_ACT_MENU: on_rmb_down(ed, x, y); return true; + case TB_A11Y_ACT_DRAG: { + const TinyBlocks_A11yNode* dst = tb_a11y_node(t, req->target); + if (!dst) return false; + float dxr = dst->x, dyr = dst->y, dpx = dst->px, dpy = dst->py; + TinyBlocks_A11yRole darea = ax_area(t, req->target); + if (darea == sarea) { dxr -= sdx; dyr -= sdy; dpx -= sdx; dpy -= sdy; } /* rolou junto */ + if (!req->at && (dst->states & TB_A11Y_OFFSCREEN) && darea == TB_A11Y_TAB_PANEL) { + float ddx, ddy; /* destino fora da vista: rola ate ele */ + ax_scroll_into_view(ed, darea, dpx, dpy, &ddx, &ddy); + dxr -= ddx; dyr -= ddy; dpx -= ddx; dpy -= ddy; + if (sarea == darea) { x -= ddx; y -= ddy; } + } + /* onde o canto da origem vai parar: pelo papel do destino, ou (x, y) dado */ + bool corner = true; + float cx = dxr, cy = dyr; + if (req->at) { cx = dxr + req->x; cy = dyr + req->y; } + else if (dst->role == TB_A11Y_BLOCK) cy = dyr + dst->h; /* embaixo do bloco */ + else if (dst->role != TB_A11Y_TEXT_FIELD && dst->role != TB_A11Y_SLOT && + dst->role != TB_A11Y_GROUP) corner = false; /* sobre o destino */ + float x1 = corner ? cx + offx : dpx, y1 = corner ? cy + offy : dpy; + ed->capture_view = -1; + ed->mouse_x = x; ed->mouse_y = y; + on_lmb_down(ed, x, y); + float mx1 = x + 8, my1 = y + 8; /* passa do limiar de arrasto */ + ed->mouse_x = mx1; ed->mouse_y = my1; + pointer_motion(ed, mx1, my1, -1); + ed->mouse_x = x1; ed->mouse_y = y1; + hover_update(ed, x1, y1); + pointer_motion(ed, x1, y1, -1); + on_lmb_up(ed, x1, y1); + ed->capture_view = -2; + return true; + } default: - return false; /* arrastar precisa de um destino: use o retangulo */ + return false; } } @@ -6909,49 +7048,7 @@ static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) { update_tooltip(ed, (ev_int(evb, GFX_IN_MOD_STATE) & TB_MOD_ALT) != 0); - /* == Areas: borda sendo arrastada / area levada pela alca === */ - if (ed->split_drag >= 0) { split_drag_to(ed, ed->split_drag, mx, my); lay_compute(ed); } - if (ed->area_drag >= 0) ed->area_drop = view_at(ed, mx, my); - bool modal = modal_top(ed) != NULL; - ed->split_hover = modal ? -1 : split_at(ed, mx, my); - - /* == Aba sendo arrastada: reordena ao passar do meio da vizinha === */ - if (ed->tab_press >= 0 && (ed->capture_view == -2 || ed->capture_view == from)) { - if (!ed->tab_drag && fabsf(mx - ed->tab_press_x) + fabsf(my - ed->tab_press_y) > 6.f) - ed->tab_drag = true; - if (ed->tab_drag) { - int vis[MAX_TABS], vn = tabs_visible_list(ed, vis); - int slot = (int)floorf((mx - ed->tab_grab_dx - (WS_X + 8) + TAB_W * 0.5f) / TAB_W); - if (slot < 0) slot = 0; - if (slot >= vn) slot = vn - 1; - if (vn > 1 && vis[slot] != ed->tab_press) { - int to = vis[slot]; - tab_move(ed, ed->tab_press, to); - ed->tab_press = to; - } - } - } - - /* == Movimento === */ - if (ed->state == ES_PRESS && fabsf(mx - ed->press_mx) + fabsf(my - ed->press_my) > 4.f && - (ed->capture_view == -2 || ed->capture_view == from)) - start_drag(ed); - if (ed->state == ES_DRAG && ed->drag_bi >= 0 && (ed->capture_view == -2 || ed->capture_view == from)) { - EdBlock* b = &CT.ws[ed->drag_bi]; - ed->drag_tab = ed->cur_tab; - ed->drag_ws_x = WS_X; ed->drag_ws_y = WS_Y; - b->x = mx - ed->drag_ox - WS_X + CT.ws_sx; - b->y = my - ed->drag_oy - WS_Y + CT.ws_sy; - layout_tab(&CT); - compute_snap(ed); - } - if (ed->grp_drag >= 0 && (ed->capture_view == -2 || ed->capture_view == from)) - group_motion(ed, mx, my); - if (ed->state == ES_PAN && (ed->capture_view == -2 || ed->capture_view == from)) { - CT.ws_sx = ed->pan_sx - (mx - ed->pan_mx); - CT.ws_sy = ed->pan_sy - (my - ed->pan_my); - } - if (tab_class(&CT)->motion) tab_class(&CT)->motion(ed, mx, my); + pointer_motion(ed, mx, my, from); /* == Scroll === */ double sdx = ev_real(evb, GFX_IN_SCROLL_DX); @@ -7177,10 +7274,12 @@ static bool editor_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, tb_a11y_begin(ax(ed), "TinyBlocks", WIN_W, WIN_H); for (int v = 0; v < V_COUNT; v++) { /* as escondidas nao desenham */ bool shown = AREA(v).shown; - if (shown) ax_push(ed, TB_A11Y_PANE, view_name(v), AREA(v).x, AREA(v).y, AREA(v).w, AREA(v).h); + if (shown) tb_a11y_set_actions(ax(ed), ax_push(ed, TB_A11Y_PANE, view_name(v), AREA(v).x, AREA(v).y, + AREA(v).w, AREA(v).h), TB_A11Y_ACT_DROP); /* troca */ view_class(v)->render(ed, rb); if (shown) ax_pop(ed); } + ax_separators(ed); render_menu(ed, rb); /* A pilha arrastada fica por cima de tudo (pode passar sobre a paleta) */ diff --git a/tests/a11y_test.c b/tests/a11y_test.c index 6df1a8a..2e3d042 100644 --- a/tests/a11y_test.c +++ b/tests/a11y_test.c @@ -7,9 +7,12 @@ static int fails = 0; #define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; } } while (0) static int performed = -1; -static bool perform(void* user, const TinyBlocks_A11yTree* t, int node, TinyBlocks_A11yAction a) { +static int dropped_on = -1; +static float drop_x = -1; +static bool perform(void* user, const TinyBlocks_A11yTree* t, int node, const TinyBlocks_A11yRequest* req) { (void)user; (void)t; - if (a != TB_A11Y_ACT_ACTIVATE) return false; + if (req->action == TB_A11Y_ACT_DRAG) { dropped_on = req->target; drop_x = req->at ? req->x : -1; return true; } + if (req->action != TB_A11Y_ACT_ACTIVATE) return false; performed = node; return true; } @@ -86,6 +89,13 @@ int main(void) { CHECK(tb_a11y_do_action(t, abrir, TB_A11Y_ACT_ACTIVATE) && performed == abrir, "ação executada por quem desenha"); int salvar = tb_a11y_find(t, 0, TB_A11Y_BUTTON, "Salvar", 0); CHECK(!tb_a11y_do_action(t, salvar, TB_A11Y_ACT_ACTIVATE), "ação não declarada é recusada"); + int fld = tb_a11y_find(t, 0, TB_A11Y_TEXT_FIELD, "vezes", 0); + tb_a11y_set_actions(t, abrir, TB_A11Y_ACT_ACTIVATE | TB_A11Y_ACT_DRAG); + CHECK(!tb_a11y_drop(t, abrir, fld), "soltar exige DROP no destino"); + tb_a11y_set_actions(t, fld, TB_A11Y_ACT_DROP); + CHECK(tb_a11y_drop(t, abrir, fld) && dropped_on == fld && drop_x < 0, "arrastar e soltar sobre o destino"); + CHECK(tb_a11y_drop_at(t, abrir, fld, 12, 3) && drop_x == 12, "soltar numa posição do destino"); + CHECK(!tb_a11y_drop(t, salvar, fld), "soltar exige DRAG na origem"); uint32_t id_aba2 = tb_a11y_node(t, tb_a11y_find(t, 0, TB_A11Y_TAB, "Aba 2", 0))->id; uint32_t id_blk = tb_a11y_node(t, blk)->id; diff --git a/tests/editor_harness.c b/tests/editor_harness.c index 56874c3..e5dc288 100644 --- a/tests/editor_harness.c +++ b/tests/editor_harness.c @@ -64,23 +64,6 @@ static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char draw(); g_scroll_dy = 0.f; } -/* Roda do mouse (usada para o zoom na aba de imagem) */ -static void scroll(float mx, float my, float dy) { - g_scroll_dy = dy; - frame(mx, my, 0, 0, 0, 0, NULL); -} - -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; - } -} - /* == Interface de acessibilidade: componentes por papel + nome === * (nao depende do texto desenhado nem de coordenadas fixas) */ static TinyBlocks_A11yTree* A(void) { return tb_editor_accessible(scene); } @@ -99,102 +82,23 @@ static int ax_count(int from, TinyBlocks_A11yRole r, const char* name) { return k; } -/* Categoria (aba da coluna "Categorias") */ -static bool find_cat(const char* s, int nth, float* x, float* y) { - int list = ax_in(0, TB_A11Y_TAB_LIST, "Categorias"); - int n = list >= 0 ? tb_a11y_find(A(), list, TB_A11Y_TAB, s, nth) : -1; - if (n < 0) return false; - tb_a11y_point(A(), n, x, y); - 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) { - if (region == R_CAT) return find_cat(s, nth, x, 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; -} - -/* Bloco "+" na area de trabalho (nao o "+" da barra de abas) */ -static bool block_plus(float* x, float* y, float min_y) { - for (int k = 0; find("+", R_WS, k, x, y); k++) if (*y > min_y) return true; - printf("FAIL não achei o bloco \"+\"\n"); fails++; - return false; -} - -/* Texto s na mesma linha de (ax, ay), a direita de ax */ -static bool find_near(const char* s, float ax, float ay, float* x, float* y) { - for (int k = 0; find(s, R_WS, k, x, y); k++) - if (*y > ay - 6 && *y < ay + 6 && *x > ax) 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; -} -/* Mensagens de status: palco/saída ou avisos flutuantes (toasts), em qualquer lugar */ +/* Texto em qualquer lugar do quadro (ex.: marcação que não deve aparecer) */ static bool any_has(const char* s) { for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_TEXT && 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 int ws_count(const char* s) { - int n = 0; - 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) n++; - return n; -} -static bool find_tabbar(const char* s, 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) continue; - if (c->y < 40 || c->y > 86) continue; - *x = c->x + 3; *y = c->y - c->font_size*0.36f; - return true; - } - return false; -} -static bool find_sub(const char* sub, float* x, float* y) { - for (uint32_t i = 0; i < ncmd; i++) { - TinyBlocks_DrawCmd* c = &cmds[i]; - if (c->kind != TB_DRAW_TEXT || !strstr(c->text, sub)) continue; - *x = c->x + 3; *y = c->y - c->font_size*0.36f; - return true; - } - return false; -} -/* Conta pixels nao-brancos da ultima imagem desenhada no workspace */ -/* Largura da maior imagem do workspace (a folha de desenho) */ -static float img_draw_w(void) { - float best = 0, w = 0; - for (uint32_t i = 0; i < ncmd; i++) { - if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image || !in_region(cmds[i].x, R_WS)) continue; - float a = cmds[i].w * cmds[i].h; - if (a > best) { best = a; w = cmds[i].w; } - } - return w; -} +/* Pixels não-brancos da folha de desenho: a MAIOR imagem desenhada no painel + * da aba (as miniaturas das camadas são pequenas); -1 se não há imagem */ static int img_nonwhite(void) { - /* A folha de desenho e a MAIOR imagem do workspace (miniaturas sao pequenas) */ + const TinyBlocks_A11yNode* w = N(ax_in(0, TB_A11Y_TAB_PANEL, NULL)); const TinyBlocks_Image* im = NULL; float best = 0; - for (uint32_t i = 0; i < ncmd; i++) { - if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image || !in_region(cmds[i].x, R_WS)) continue; + for (uint32_t i = 0; w && i < ncmd; i++) { + if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image) continue; + if (cmds[i].x < w->x || cmds[i].x > w->x + w->w) continue; float a = cmds[i].w * cmds[i].h; - if (a < 20000.f) continue; /* ignora miniaturas */ + if (a < 20000.f) continue; if (a > best) { best = a; im = cmds[i].image; } } if (!im) return -1; @@ -207,26 +111,13 @@ static int img_nonwhite(void) { } return n; } -static bool any_substr(const char* s) { - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, s)) return true; - return false; -} -static bool ws_substr(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) && strstr(cmds[i].text, s)) return true; - return false; -} -static void dump_ws(void) { - 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); -} -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); +/* Numa falha, mostra a saída (console), lida da árvore */ +static void dump_console(void) { + int c = ax_in(ax_in(0, TB_A11Y_PANE, "Saída"), TB_A11Y_LIST, "Console"); + for (int i = c >= 0 ? N(c)->first_child : -1; i >= 0; i = N(i)->next_sibling) printf(" | %s\n", N(i)->name); } -#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; dump_stage(); } } while (0) +#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; dump_console(); } } 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) { @@ -237,7 +128,6 @@ static void drag(float x0, float y0, float x1, float y1) { } 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); } /* Executa uma acao acessivel e roda um quadro (a arvore e redesenhada) */ static bool ax_do(int n, TinyBlocks_A11yAction a) { @@ -248,20 +138,97 @@ static bool ax_do(int n, TinyBlocks_A11yAction a) { frame(x, y, 0, 0, 0, 0, NULL); return ok; } -/* Arrasta o componente pelo seu ponto, levando o canto dele para (tx, ty) */ -static void ax_drag_to(int n, float tx, float ty) { - if (n < 0) return; - float px, py; - tb_a11y_point(A(), n, &px, &py); - drag(px, py, tx + (px - N(n)->x), ty + (py - N(n)->y)); +/* Arrastar e soltar pela arvore (o editor decide o encaixe pelo papel do destino) */ +static bool ax_drop(int src, int dst) { + if (src < 0 || dst < 0) { printf("FAIL soltar: origem %d, destino %d\n", src, dst); fails++; return false; } + bool ok = tb_a11y_drop(A(), src, dst); + frame(0, 0, 0, 0, 0, 0, NULL); + return ok; +} +/* Soltar com o canto da origem em (x, y) relativo ao canto do destino */ +static bool ax_drop_at(int src, int dst, float x, float y) { + if (src < 0 || dst < 0) { printf("FAIL soltar: origem %d, destino %d\n", src, dst); fails++; return false; } + bool ok = tb_a11y_drop_at(A(), src, dst, x, y); + frame(0, 0, 0, 0, 0, 0, NULL); + return ok; } -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++; +/* Partes da tela */ +static int ws(void) { return ax_in(0, TB_A11Y_TAB_PANEL, NULL); } +static int pane(const char* n) { return ax_in(0, TB_A11Y_PANE, n); } +static int pal(void) { return ax_in(pane("Blocos"), TB_A11Y_LIST, "Paleta"); } +static int menu_btn(const char* n) { return ax_need(ax_in(0, TB_A11Y_TOOLBAR, "Menu"), TB_A11Y_BUTTON, n); } +static void cat(const char* n) { + ax_do(ax_need(ax_in(0, TB_A11Y_TAB_LIST, "Categorias"), TB_A11Y_TAB, n), TB_A11Y_ACT_ACTIVATE); +} +/* Bloco da paleta, na categoria, pelo trecho do rotulo */ +static int pal_block(const char* category, const char* part) { + int n = ax_part(ax_in(pal(), TB_A11Y_GROUP, category), TB_A11Y_BLOCK, part); + if (n < 0) { printf("FAIL não achei \"%s\" em %s na paleta\n", part, category); fails++; } + return n; +} +static int ws_block(const char* part, int nth) { return tb_a11y_find_part(A(), ws(), TB_A11Y_BLOCK, part, nth); } +static int ws_count(const char* part) { + int k = 0; + while (ws_block(part, k) >= 0) k++; + return k; +} +/* 1o bloco da pilha solta cujo nome comeca com o rotulo */ +static int stack_head(const char* label) { + char nm[160]; + snprintf(nm, sizeof(nm), "Pilha: %s", label); + return ax_in(ax_part(ws(), TB_A11Y_LIST, nm), TB_A11Y_BLOCK, NULL); +} +static int field(int block, int nth) { return block >= 0 ? tb_a11y_find(A(), block, TB_A11Y_TEXT_FIELD, NULL, nth) : -1; } +static void flag(void) { ax_do(ax_in(pane("Palco"), TB_A11Y_BUTTON, "Executar"), TB_A11Y_ACT_ACTIVATE); } +static void stop(void) { ax_do(ax_in(pane("Palco"), TB_A11Y_BUTTON, "Parar"), TB_A11Y_ACT_ACTIVATE); } +/* Linha da saida (console) que contem `sub`: posicao (0..) ou -1 */ +static int console_line(const char* sub) { + int c = ax_in(pane("Saída"), TB_A11Y_LIST, "Console"); + int n = c >= 0 ? tb_a11y_find_part(A(), c, TB_A11Y_LABEL, sub, 0) : -1; + if (n < 0) return -1; + int k = 0; + for (int i = N(c)->first_child; i >= 0 && i != n; i = N(i)->next_sibling) k++; + return k; +} +static bool console_has(const char* sub) { return console_line(sub) >= 0; } +static int console_count(const char* sub) { + int c = ax_in(pane("Saída"), TB_A11Y_LIST, "Console"), k = 0; + while (c >= 0 && tb_a11y_find_part(A(), c, TB_A11Y_LABEL, sub, k) >= 0) k++; + return k; +} +static bool toast_has(const char* sub) { return ax_part(0, TB_A11Y_STATUS, sub) >= 0; } +static const char* result_value(void) { return ax_value(ax_in(0, TB_A11Y_STATUS, "Resultado")); } +/* Apaga o campo com o foco (o valor dele na arvore) */ +static void clear_focus(void) { + for (int i = 0; i < 300 && tb_a11y_focus(A()) >= 0 && N(tb_a11y_focus(A()))->value[0]; i++) + key(TB_KEY_BACKSPACE, 0, 0); +} +/* Escreve um caminho no campo com o foco e confirma */ +static void type_path(const char* path) { clear_focus(); type(path); key(TB_KEY_RETURN, 0, 0); } +/* Ponto a uma fracao do retangulo do componente (pintar na folha, mover o mouse no palco) */ +static void at(int node, float fx, float fy, float* x, float* y) { + *x = node >= 0 ? N(node)->x + N(node)->w * fx : 0; + *y = node >= 0 ? N(node)->y + N(node)->h * fy : 0; +} +/* Desenho dentro do retangulo de um componente (para conferir o que se ve) */ +static bool cmd_in(const TinyBlocks_DrawCmd* c, int node) { + return node >= 0 && c->x >= N(node)->x && c->x <= N(node)->x + N(node)->w && + c->y >= N(node)->y && c->y <= N(node)->y + N(node)->h; +} +static int drawn_count(TinyBlocks_DrawCmdKind kind, int node) { + int k = 0; + for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == kind && cmd_in(&cmds[i], node)) k++; + return k; +} +static bool drawn_text(int node, const char* sub) { + for (uint32_t i = 0; i < ncmd; i++) + if (cmds[i].kind == TB_DRAW_TEXT && cmd_in(&cmds[i], node) && strstr(cmds[i].text, sub)) return true; return false; } + + int main(void) { /* configurações isoladas: o harness não lê nem grava o ~/.config real */ setenv("XDG_CONFIG_HOME", "/tmp/tb_harness_cfg", 1); @@ -287,83 +254,72 @@ int main(void) { 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"), + CHECK(console_has("x vale = 1") && console_has("x vale = 5") && !console_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á!)"); + /* 2. Arrastar "escreva" da paleta para uma área livre e ativar */ + cat("Aparência"); + ax_drop_at(pal_block("Aparência", "escreva"), ws(), 282, 470); + CHECK(ws_count("escreva") == 2, "bloco da paleta aparece na área de scripts"); + ax_do(stack_head("escreva"), TB_A11Y_ACT_ACTIVATE); + CHECK(console_has("Olá!"), "ativar o bloco solto executa (Olá!)"); /* 3. Encaixar o "escreva Olá!" logo abaixo do chapéu */ - float hx, hy; - if (need("quando a bandeira 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); - } + ax_drop(stack_head("escreva"), ws_block("quando a bandeira for clicado", 0)); 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"); + CHECK(console_has("Olá!") && console_has("x vale = 5"), "encaixe sob o chapéu: script roda os dois"); + CHECK(console_line("Olá!") >= 0 && console_line("Olá!") < console_line("x vale = 1"), + "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); click(x, y); } /* clique duplo */ + /* 4. Repórter "+": solto, editar campos, ativar duas vezes - balão */ + cat("Operadores"); + ax_drop_at(pal_block("Operadores", ") + ("), ws(), 322, 390); + { + int plus = stack_head("(0) + (0)"); + ax_do(field(plus, 0), TB_A11Y_ACT_EDIT); + key(TB_KEY_BACKSPACE, 0, 0); type("2"); key(TB_KEY_RETURN, 0, 0); + ax_do(field(stack_head("(2) + (0)"), 1), TB_A11Y_ACT_EDIT); + key(TB_KEY_BACKSPACE, 0, 0); type("3"); key(TB_KEY_RETURN, 0, 0); + plus = stack_head("(2) + (3)"); + ax_do(plus, TB_A11Y_ACT_ACTIVATE); + ax_do(plus, TB_A11Y_ACT_ACTIVATE); /* clique duplo */ } - CHECK(ws_has("5"), "clique duplo no repórter mostra balão com 5 (2+3)"); + CHECK(!strcmp(result_value(), "5"), "clique duplo no repórter 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)); - } + ax_drop(stack_head("(2) + (3)"), field(ws_block("mude (x) para", 0), 1)); flag(); - CHECK(stage_has("x vale = 10") && stage_has("x vale = 6") && !stage_has("x vale = 5"), + CHECK(console_has("x vale = 10") && console_has("x vale = 6") && !console_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); + /* 6. Delete com o mouse sobre o "escreva Olá!" apaga só ele; o resto sobe */ + { + float px, py; + int b = ws_block("escreva (Olá!)", 0); + if (b >= 0) { tb_a11y_point(A(), b, &px, &py); key(TB_KEY_DELETE, px, py); } } flag(); - CHECK(!stage_has("Olá!") && stage_has("x vale = 10"), "Delete remove o bloco e mantém o resto do script"); + CHECK(!console_has("Olá!") && console_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"); + /* 7. Soltar o bloco sobre a paleta apaga */ + cat("Aparência"); + ax_drop_at(pal_block("Aparência", "escreva"), ws(), 382, 520); + { + int before = ws_count("escreva"); + ax_drop(stack_head("escreva"), pal()); + CHECK(ws_count("escreva") == before - 1, "soltar bloco sobre a paleta apaga"); + } /* 8. Bloco composto "dobro(n)" criado pelo diálogo; corpo: devolva n + 1. * Tudo achado pela interface de acessibilidade (papel + nome). */ - if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y); - ax_do(ax_need(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE); + cat("Meus Blocos"); + ax_do(ax_need(pal(), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE); { int dlg = ax_need(0, TB_A11Y_DIALOG, "Criar um Bloco"); int nome = ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco"); @@ -386,23 +342,23 @@ int main(void) { CHECK(ax_count(panel, TB_A11Y_BLOCK, "n") == 1 && ax_in(def, TB_A11Y_BLOCK, "n") >= 0, "sem parâmetros soltos: o \"n\" está no protótipo do defina"); CHECK(ax_in(panel, TB_A11Y_BLOCK, "quando a bandeira for clicado") >= 0, "sem abrir aba nova: os scripts continuam ali"); - float dfx = def >= 0 ? N(def)->x : 0, dfy = def >= 0 ? N(def)->y : 0, dfh = def >= 0 ? N(def)->h : 0; + /* posição do "defina" no painel, para soltar coisas ao lado dele */ + float dfx = def >= 0 ? N(def)->x - N(panel)->x : 0, dfy = def >= 0 ? N(def)->y - N(panel)->y : 0; /* devolva embaixo do "defina"; um "+" solto ao lado */ - if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y); - ax_drag_to(ax_part(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BLOCK, "devolva"), dfx, dfy + dfh); - if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y); + cat("Meus Blocos"); + ax_drop(ax_part(pal(), TB_A11Y_BLOCK, "devolva"), ax_in(ws(), TB_A11Y_BLOCK, "defina dobro (n)")); + cat("Operadores"); { - int ops = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Operadores"); - ax_drag_to(ax_part(ops, TB_A11Y_BLOCK, ") + ("), dfx + 300, dfy + 110); + int ops = ax_in(pal(), TB_A11Y_GROUP, "Operadores"); + ax_drop_at(ax_part(ops, TB_A11Y_BLOCK, ") + ("), ws(), dfx + 300, dfy + 110); } /* o parâmetro sai arrastando de dentro do "defina" para o 1o campo do "+" */ { panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL); int plus = ax_in(ax_in(panel, TB_A11Y_LIST, "Pilha: (0) + (0)"), TB_A11Y_BLOCK, "(0) + (0)"); int slot = ax_in(plus, TB_A11Y_TEXT_FIELD, NULL); - if (slot >= 0) ax_drag_to(ax_in(ax_in(panel, TB_A11Y_BLOCK, "defina dobro (n)"), TB_A11Y_BLOCK, "n"), - N(slot)->x, N(slot)->y); + ax_drop(ax_in(ax_in(panel, TB_A11Y_BLOCK, "defina dobro (n)"), TB_A11Y_BLOCK, "n"), slot); panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL); CHECK(ax_in(panel, TB_A11Y_BLOCK, "(n) + (0)") >= 0, "arrastar o parâmetro do defina põe \"n\" no +"); } @@ -414,16 +370,16 @@ int main(void) { { int dev = ax_part(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "devolva"); int val = dev >= 0 ? tb_a11y_find(A(), dev, TB_A11Y_TEXT_FIELD, NULL, 1) : -1; - if (val >= 0) ax_drag_to(ax_need(0, TB_A11Y_BLOCK, "(n) + (1)"), N(val)->x, N(val)->y); + ax_drop(ax_need(0, TB_A11Y_BLOCK, "(n) + (1)"), val); CHECK(ax_part(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "= ((n) + (1))") >= 0, "corpo: devolva (n) + (1)"); } - if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y); + cat("Meus Blocos"); { - int mine = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Meus Blocos"); + int mine = ax_in(pal(), TB_A11Y_GROUP, "Meus Blocos"); int call = ax_in(mine, TB_A11Y_BLOCK, "dobro (n)"); CHECK(call >= 0, "bloco dobro aparece em Meus Blocos"); - ax_drag_to(call, dfx + 330, dfy - 60); + ax_drop_at(call, ws(), dfx + 330, dfy - 60); } { panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL); @@ -438,86 +394,68 @@ int main(void) { CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_STATUS, "Resultado")), "22"), "bloco composto dobro(21) = 22"); /* 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); + cat("Controle"); + ax_drop_at(pal_block("Controle", "repita até que"), ws(), 382, 220); + ax_do(stack_head("repita até que"), TB_A11Y_ACT_ACTIVATE); /* laço sem fim roda quadro a quadro (estilo Scratch): não trava nem aborta */ for (int i = 0; i < 5; i++) frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(!stage_has("limite de passos"), "laço sem fim roda sem travar (sem aviso de limite)"); - click(1280 - 360 + 76, 44 + 22); /* botão vermelho */ - frame(0, 0, 0, 0, 0, 0, NULL); + CHECK(!console_has("limite de passos"), "laço sem fim roda sem travar (sem aviso de limite)"); + stop(); /* 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"); + { + int stage = ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco"); + int circles_before = drawn_count(TB_DRAW_FILL_CIRCLE, stage); + cat("Caneta"); + ax_drop_at(pal_block("Caneta", "desenhe círculo em x"), ws(), 282, 570); + ax_do(stack_head("desenhe círculo em x"), TB_A11Y_ACT_ACTIVATE); + stage = ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco"); + float scx, scy, cx = 0, cy = 0; + at(stage, 0.5f, 0.5f, &scx, &scy); + for (uint32_t i = 0; i < ncmd; i++) + if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmd_in(&cmds[i], stage)) { cx = cmds[i].x; cy = cmds[i].y; } + printf(" círculo no palco: (%.1f, %.1f), centro do palco (%.1f, %.1f)\n", cx, cy, scx, scy); + CHECK(drawn_count(TB_DRAW_FILL_CIRCLE, stage) == circles_before + 1 && + fabsf(cx - scx) < 2 && fabsf(cy - scy) < 2, "bloco da caneta desenha círculo centrado no palco embutido"); + cat("Caneta"); + ax_drop_at(pal_block("Caneta", "apague tudo"), ws(), 420, 600); /* longe do círculo (não encaixa) */ + ax_do(stack_head("apague tudo"), TB_A11Y_ACT_ACTIVATE); + CHECK(drawn_count(TB_DRAW_FILL_CIRCLE, ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco")) == 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); - frame(0, 0, 0, 0, 0, 0, NULL); - /* a área do palco sai da janela principal; fica um botão "Palco" no menu */ - bool no_menu = false, no_painel = false; - float cx = 0, cy = 0; - for (uint32_t i = 0; i < ncmd; i++) { - if (cmds[i].kind != TB_DRAW_TEXT || strcmp(cmds[i].text, "Palco") != 0) continue; - if (cmds[i].y < 44) { no_menu = true; cx = cmds[i].x + 3; cy = 22; } - else no_painel = true; - } - CHECK(no_menu && !no_painel, "palco destacado abre janela própria (botão \"Palco\" no menu)"); - if (no_menu) click(cx, cy); /* recolhe no próximo quadro */ - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 920 && y > 44, "palco recolhido volta ao painel"); - } + ax_do(ax_in(pane("Palco"), TB_A11Y_BUTTON, "Destacar o palco"), TB_A11Y_ACT_ACTIVATE); + frame(0, 0, 0, 0, 0, 0, NULL); + CHECK(pane("Palco") < 0 && ax_in(ax_in(0, TB_A11Y_TOOLBAR, "Menu"), TB_A11Y_BUTTON, "Palco") >= 0, + "palco destacado abre janela própria (botão \"Palco\" no menu)"); + ax_do(ax_in(ax_in(0, TB_A11Y_TOOLBAR, "Menu"), TB_A11Y_BUTTON, "Palco"), TB_A11Y_ACT_ACTIVATE); + frame(0, 0, 0, 0, 0, 0, NULL); + CHECK(pane("Palco") >= 0 && ax_in(pane("Palco"), TB_A11Y_BUTTON, "Executar") >= 0, "palco recolhido volta ao painel"); /* 12. Salvar e abrir projeto (.json) via tinyblocks-blueprint */ const char* proj = "/tmp/tb_harness_proj.json"; remove(proj); - if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 16; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(proj); - key(TB_KEY_RETURN, 0, 0); - CHECK(any_has("Projeto salvo"), "salvar projeto escreve o .json"); + ax_do(menu_btn("Salvar"), TB_A11Y_ACT_ACTIVATE); + type_path(proj); + CHECK(toast_has("Projeto salvo"), "salvar projeto escreve o .json"); { - /* aviso flutuante (toast) sobre a área de scripts, não no menu */ - bool flutua = false; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "Projeto salvo") && - cmds[i].x > 318 && cmds[i].x < 920 && cmds[i].y > 400) flutua = true; - CHECK(flutua, "mensagem vira aviso flutuante no canto da área de scripts"); - /* salvar de novo: a mesma mensagem vira contador (x2) */ - if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(proj); - key(TB_KEY_RETURN, 0, 0); - if (find("Substituir", R_ANY, 0, &x, &y)) click(x, y); + /* aviso flutuante (toast) sobre a área de scripts, embaixo */ + int t = ax_part(0, TB_A11Y_STATUS, "Projeto salvo"), sc = pane("Scripts"); + CHECK(t >= 0 && sc >= 0 && N(t)->x > N(sc)->x && N(t)->x + N(t)->w <= N(sc)->x + N(sc)->w && + N(t)->y > N(sc)->y + N(sc)->h * 0.5f, "mensagem vira aviso flutuante no canto da área de scripts"); + /* salvar de novo: a mesma mensagem vira contador */ + ax_do(menu_btn("Salvar"), TB_A11Y_ACT_ACTIVATE); + type_path(proj); + ax_do(ax_in(ax_in(0, TB_A11Y_DIALOG, "Substituir arquivo"), TB_A11Y_BUTTON, "Substituir"), TB_A11Y_ACT_ACTIVATE); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("(x2)"), "mensagem repetida vira contador (x2)"); + CHECK(!strcmp(ax_value(ax_part(0, TB_A11Y_STATUS, "Projeto salvo")), "2 vezes"), "mensagem repetida vira contador"); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(proj); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(proj); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("Projeto aberto"), "abrir projeto le o .json"); - CHECK(find("quando a bandeira for clicado", R_WS, 0, &x, &y), - "estado restaurado apos abrir (chapéu de exemplo de volta)"); + CHECK(toast_has("Projeto aberto"), "abrir projeto le o .json"); + CHECK(ws_block("quando a bandeira for clicado", 0) >= 0, "estado restaurado apos abrir (chapéu de exemplo de volta)"); remove(proj); /* 13. Abrir um projeto escrito a mao (aba distinta) */ @@ -534,13 +472,11 @@ int main(void) { "\"user_blocks\":[],\"variables\":[{\"name\":\"x\",\"kind\":0,\"num\":7,\"text\":\"\"}]}", pf); fclose(pf); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(openjson); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(openjson); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Aberto!", R_ANY, 0, &x, &y), "abrir projeto de arquivo externo (aba Aberto!)"); - CHECK(find("Oi do arquivo", R_WS, 0, &x, &y), "bloco do arquivo externo aparece no workspace"); + CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_TAB, "Aberto!") >= 0, "abrir projeto de arquivo externo (aba Aberto!)"); + CHECK(ws_block("escreva (Oi do arquivo)", 0) >= 0, "bloco do arquivo externo aparece na área de scripts"); remove(openjson); /* 13b. Explorador de arquivos (tinyblocks-editor-files) */ @@ -562,33 +498,35 @@ int main(void) { "\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", tf); fclose(tf); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - CHECK(find("Abrir projeto", R_ANY, 0, &x, &y), "Abrir mostra o explorador de arquivos"); - type(fdir); - key(TB_KEY_RETURN, 0, 0); - CHECK(find("proj.json", R_ANY, 0, &x, &y) && find("sub", R_ANY, 0, &x, &y) - && !find("nota.md", R_ANY, 0, &x, &y), - "explorador lista pastas + .json e filtra o resto"); - if (need("proj.json", R_ANY, 0, &x, &y)) { click(x, y); click(x, y); } + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + int dlg = ax_in(0, TB_A11Y_DIALOG, "Abrir projeto"); + CHECK(dlg >= 0 && tb_a11y_focus(A()) == ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome"), + "Abrir mostra o explorador de arquivos, com o foco no nome"); + type_path(fdir); + int files = ax_in(ax_in(0, TB_A11Y_DIALOG, "Abrir projeto"), TB_A11Y_LIST, "Arquivos"); + CHECK(ax_in(files, TB_A11Y_LIST_ITEM, "proj.json") >= 0 && ax_in(files, TB_A11Y_LIST_ITEM, "sub") >= 0 && + ax_in(files, TB_A11Y_LIST_ITEM, "nota.md") < 0, "explorador lista pastas + .json e filtra o resto"); + int pj = ax_in(files, TB_A11Y_LIST_ITEM, "proj.json"); + ax_do(pj, TB_A11Y_ACT_ACTIVATE); + ax_do(pj, TB_A11Y_ACT_ACTIVATE); /* clique duplo */ frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("Projeto aberto") && find("Explorado", R_ANY, 0, &x, &y), + CHECK(toast_has("Projeto aberto") && ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_TAB, "Explorado") >= 0, "duplo clique no explorador abre o projeto"); - if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y); - CHECK(find("Salvar projeto", R_ANY, 0, &x, &y), "Salvar mostra o explorador de arquivos"); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type("proj"); - key(TB_KEY_RETURN, 0, 0); - CHECK(find("Substituir", R_ANY, 0, &x, &y), "salvar sobre arquivo existente pede confirmacao"); - if (need("Substituir", R_ANY, 0, &x, &y)) click(x, y); + ax_do(menu_btn("Salvar"), TB_A11Y_ACT_ACTIVATE); + CHECK(ax_in(0, TB_A11Y_DIALOG, "Salvar projeto") >= 0, "Salvar mostra o explorador de arquivos"); + type_path("proj"); + int conf = ax_in(0, TB_A11Y_DIALOG, "Substituir arquivo"); + CHECK(conf >= 0, "salvar sobre arquivo existente pede confirmação"); + ax_do(ax_in(conf, TB_A11Y_BUTTON, "Substituir"), TB_A11Y_ACT_ACTIVATE); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("Projeto salvo") && !find("Salvar projeto", R_ANY, 0, &x, &y), - "Substituir grava o .json (extensao completada) e fecha"); + CHECK(toast_has("Projeto salvo") && ax_in(0, TB_A11Y_DIALOG, "Salvar projeto") < 0, + "Substituir grava o .json (extensão completada) e fecha"); - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); key(TB_KEY_ESCAPE, 0, 0); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(!find("Abrir projeto", R_ANY, 0, &x, &y), "Esc fecha o explorador"); + CHECK(ax_in(0, TB_A11Y_DIALOG, "Abrir projeto") < 0, "Esc fecha o explorador"); remove(fp); snprintf(fp, sizeof(fp), "%s/nota.md", fdir); remove(fp); @@ -596,7 +534,7 @@ int main(void) { rmdir(fdir); } - /* 13c. "desenhe [lista de pontos]" (Caneta) + tipo do valor no balao */ + /* 13c. "desenhe [lista de pontos]" (Caneta) + tipo do valor no balão */ { const char* dj = "/tmp/tb_harness_draw.json"; FILE* df = fopen(dj, "wb"); @@ -614,24 +552,21 @@ int main(void) { "],\"top\":[0,3]}],\"user_blocks\":[],\"variables\":[]}", df); fclose(df); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(dj); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(dj); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Desenho", R_ANY, 0, &x, &y), "projeto com 'desenhe' aberto"); - int before = 0, after = 0; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_STROKE_LINE && cmds[i].x >= 920) before++; + CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_TAB, "Desenho") >= 0, "projeto com 'desenhe' aberto"); + int before = drawn_count(TB_DRAW_STROKE_LINE, ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco")); flag(); frame(0, 0, 0, 0, 0, 0, NULL); - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_STROKE_LINE && cmds[i].x >= 920) after++; - CHECK(after >= before + 10, "desenhe (reta com 10 passos) traca 10 segmentos no palco"); + int after = drawn_count(TB_DRAW_STROKE_LINE, ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco")); + CHECK(after >= before + 10, "desenhe (reta com 10 passos) traça 10 segmentos no palco"); /* repórter solto (o encaixado roda a pilha inteira, como no Scratch) */ - if (need("reta de x", R_WS, 1, &x, &y)) { click(x, y); click(x, y); } - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("lista de pontos", R_WS, 0, &x, &y), "balao mostra o tipo 'lista de pontos'"); + int reta = stack_head("reta de x"); + ax_do(reta, TB_A11Y_ACT_ACTIVATE); + ax_do(reta, TB_A11Y_ACT_ACTIVATE); + CHECK(!strcmp(N(ax_in(0, TB_A11Y_STATUS, "Resultado"))->description, "lista de pontos"), + "balão mostra o tipo 'lista de pontos'"); remove(dj); } @@ -652,24 +587,17 @@ int main(void) { "],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", ff); fclose(ff); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(fj); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(fj); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("sempre", R_WS, 0, &x, &y), "bloco 'sempre' aparece no projeto"); + CHECK(ws_block("sempre", 0) >= 0, "bloco 'sempre' aparece no projeto"); flag(); for (int i = 0; i < 6; i++) frame(0, 0, 0, 0, 0, 0, NULL); - int voltas = 0; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, "volta")) voltas++; + int voltas = console_count("volta"); CHECK(voltas >= 4 && voltas <= 12, "'sempre' com caneta anima: ~uma volta por quadro"); - click(1280 - 360 + 76, 44 + 22); /* botão vermelho */ + stop(); for (int i = 0; i < 6; i++) frame(0, 0, 0, 0, 0, 0, NULL); - int depois = 0; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, "volta")) depois++; - CHECK(depois == 0, "botão vermelho para o 'sempre' (e limpa a saída)"); + CHECK(console_count("volta") == 0, "botão vermelho para o 'sempre' (e limpa a saída)"); remove(fj); } @@ -690,302 +618,250 @@ int main(void) { "],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", sf); fclose(sf); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(sj); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(sj); frame(0, 0, 0, 0, 0, 0, NULL); flag(); - /* vista do palco no painel: origem (929, 89), 342 px = 480 do palco; - x do palco 100 -> 929 + 171 + 100 * 342/480 */ - float px = 929.f + 171.f + 100.f * 342.f / 480.f, py = 89.f + 100.f; + /* o palco tem 480 de largura: x = 100 fica a 100/480 da largura à direita do centro */ + int stage = ax_in(pane("Palco"), TB_A11Y_CANVAS, "Palco"); + float px, py; + at(stage, 0.5f + 100.f / 480.f, 0.4f, &px, &py); for (int i = 0; i < 3; i++) frame(px, py, 0, 0, 0, 0, NULL); - CHECK(stage_has("100"), "posição x do mouse sobre o palco = 100"); - if (!stage_has("100")) - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920) printf(" palco: '%s'\n", cmds[i].text); + CHECK(console_has("100"), "posição x do mouse sobre o palco = 100"); frame(px, py, 0, 0, 0, TB_KEY_SPACE, NULL); for (int i = 0; i < 3; i++) frame(px, py, 0, 0, 0, 0, NULL); - CHECK(stage_has("espaço"), "última tecla = espaço"); - click(1280 - 360 + 76, 44 + 22); /* botão vermelho */ - frame(0, 0, 0, 0, 0, 0, NULL); + CHECK(console_has("espaço"), "última tecla = espaço"); + stop(); remove(sj); } - /* 14. Exportar pelo menu de contexto do botao Exportar */ - if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y); - CHECK(find("Exportar JSON", R_FLY, 0, &x, &y) && find("Exportar XML", R_FLY, 0, &x, &y) - && find("Exportar CSV", R_FLY, 0, &x, &y), "botao Exportar abre menu com JSON/XML/CSV"); - const char* expf = "/tmp/tb_harness_export.xml"; - remove(expf); - if (need("Exportar XML", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(expf); - key(TB_KEY_RETURN, 0, 0); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("Exportado xml"), "exportar XML pelo menu escreve o arquivo"); - remove(expf); - - /* 15. Regressao: arrastar um bloco da Caneta para o chapeu */ - if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - int clear_before = 0; - { float a, b; for (int k = 0; find("apague tudo", R_WS, k, &a, &b); k++) clear_before++; } - if (need("apague tudo", R_FLY, 0, &x, &y)) { - float hx, hy; - if (need("quando a bandeira for clicado", R_WS, 0, &hx, &hy)) { - float bx = hx - 3 - 10, by = hy - 18 - 18; - float gx = x - 3 - 10, gy = y - 18; - drag(x, y, x + (bx - gx), y + (by + 54 - gy) + 6); - } + /* 14. Exportar pelo menu do botão Exportar */ + ax_do(menu_btn("Exportar"), TB_A11Y_ACT_ACTIVATE); + { + int m = ax_in(0, TB_A11Y_MENU, "Menu de contexto"); + CHECK(ax_in(m, TB_A11Y_MENU_ITEM, "Exportar JSON") >= 0 && ax_in(m, TB_A11Y_MENU_ITEM, "Exportar XML") >= 0 && + ax_in(m, TB_A11Y_MENU_ITEM, "Exportar CSV") >= 0, "botão Exportar abre menu com JSON/XML/CSV"); + const char* expf = "/tmp/tb_harness_export.xml"; + remove(expf); + ax_do(ax_in(m, TB_A11Y_MENU_ITEM, "Exportar XML"), TB_A11Y_ACT_ACTIVATE); + type_path(expf); + frame(0, 0, 0, 0, 0, 0, NULL); + CHECK(toast_has("Exportado xml"), "exportar XML pelo menu escreve o arquivo"); + remove(expf); + } + + /* 15. Regressão: arrastar um bloco da Caneta para o chapéu */ + cat("Caneta"); + { + int before = ws_count("apague tudo"); + ax_drop(pal_block("Caneta", "apague tudo"), ws_block("quando a bandeira for clicado", 0)); + CHECK(ws_count("apague tudo") == before + 1, "arrastar bloco da Caneta para o chapéu"); } - frame(0, 0, 0, 0, 0, 0, NULL); - int clear_after = 0; - { float a, b; for (int k = 0; find("apague tudo", R_WS, k, &a, &b); k++) clear_after++; } - CHECK(clear_after == clear_before + 1, "arrastar bloco da Caneta para o chapeu"); /* 16. Gestor de libraries (tinyblocks-libman), UI desenhada pelo editor */ - CHECK(!find("Blueprint", R_CAT, 0, &x, &y), "categoria Blueprint ainda nao existe"); - if (need("Bibliotecas", R_WS, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Escolha uma Extensão", R_ANY, 0, &x, &y), "abre a tela do libman"); - CHECK(find("Buscar", R_ANY, 0, &x, &y), "libman mostra o campo de busca"); - type("blueprint"); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("tinyblocks-blueprint", R_ANY, 0, &x, &y), "busca filtra por nome"); - if (need("tinyblocks-blueprint", R_ANY, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(!find("Escolha uma Extensão", R_ANY, 0, &x, &y), "libman fecha apos carregar"); - CHECK(find("Blueprint", R_CAT, 0, &x, &y), "library carregada aparece na paleta"); + CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Categorias"), TB_A11Y_TAB, "Blueprint") < 0, + "categoria Blueprint ainda não existe"); + ax_do(menu_btn("Bibliotecas"), TB_A11Y_ACT_ACTIVATE); + { + int lm = ax_in(0, TB_A11Y_DIALOG, "Escolha uma Extensão"); + CHECK(lm >= 0, "abre a tela do libman"); + CHECK(tb_a11y_focus(A()) == ax_in(lm, TB_A11Y_TEXT_FIELD, "Buscar"), "libman abre com o foco na busca"); + type("blueprint"); + frame(0, 0, 0, 0, 0, 0, NULL); + int item = ax_in(ax_in(0, TB_A11Y_LIST, "Libraries"), TB_A11Y_LIST_ITEM, "tinyblocks-blueprint"); + CHECK(item >= 0, "busca filtra por nome"); + ax_do(item, TB_A11Y_ACT_ACTIVATE); + CHECK(ax_in(0, TB_A11Y_DIALOG, "Escolha uma Extensão") < 0, "libman fecha após carregar"); + CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Categorias"), TB_A11Y_TAB, "Blueprint") >= 0, + "library carregada aparece na paleta"); + } - /* 17. Botao de extensoes no fim do painel (estilo Scratch) */ - frame(0, 0, 0, 0, 0, 0, NULL); - click(34, 720 - 28); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Escolha uma Extensão", R_ANY, 0, &x, &y), "botao de extensoes no painel abre o libman"); + /* 17. Botão de extensões no fim do painel (estilo Scratch) */ + ax_do(ax_in(pane("Blocos"), TB_A11Y_BUTTON, "Adicionar extensão"), TB_A11Y_ACT_ACTIVATE); + CHECK(ax_in(0, TB_A11Y_DIALOG, "Escolha uma Extensão") >= 0, "botão de extensões no painel abre o libman"); key(TB_KEY_ESCAPE, 0, 0); frame(0, 0, 0, 0, 0, 0, NULL); - /* 18. Tela de Configuracoes (settings da tinyblocks-environ) */ + /* 18. Tela de Configurações (settings da tinyblocks-environ) */ remove("build/settings_test.csv"); setenv("TINYBLOCKS_SETTINGS", "build/settings_test.csv", 1); - click(1231, 22); /* botao Config (WIN_W=1280) */ - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Configurações", R_ANY, 0, &x, &y), "botao Config abre a tela de configuracoes"); - CHECK(find("Detectar caminho de TINYBLOCKS_SETTINGS", R_ANY, 0, &x, &y), - "mostra o toggle da variavel de ambiente"); - CHECK(find("autor", R_ANY, 0, &x, &y), "listas as settings do store (autor)"); - click(50, 84); /* liga o toggle de deteccao pelo env */ - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("build/settings_test.csv", R_ANY, 0, &x, &y), - "toggle passa a usar o caminho de TINYBLOCKS_SETTINGS"); - click(200, 194); /* seleciona a linha 'autor' */ - type("maria"); - key(TB_KEY_RETURN, 0, 0); - frame(0, 0, 0, 0, 0, 0, NULL); - click(922, 136); /* botao Salvar (CSV no arquivo de config) */ - frame(0, 0, 0, 0, 0, 0, NULL); + ax_do(menu_btn("Config"), TB_A11Y_ACT_ACTIVATE); { + int cfg = ax_in(0, TB_A11Y_DIALOG, "Configurações"); + CHECK(cfg >= 0, "botão Config abre a tela de configurações"); + int env = ax_in(cfg, TB_A11Y_CHECKBOX, "Detectar caminho de TINYBLOCKS_SETTINGS"); + CHECK(env >= 0, "mostra o toggle da variável de ambiente"); + CHECK(ax_in(cfg, TB_A11Y_LIST_ITEM, "autor") >= 0, "lista as settings do store (autor)"); + ax_do(env, TB_A11Y_ACT_ACTIVATE); + CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Arquivo de configurações")), "build/settings_test.csv"), + "toggle passa a usar o caminho de TINYBLOCKS_SETTINGS"); + ax_do(ax_in(ax_in(0, TB_A11Y_DIALOG, "Configurações"), TB_A11Y_LIST_ITEM, "autor"), TB_A11Y_ACT_ACTIVATE); + CHECK(N(tb_a11y_focus(A()))->role == TB_A11Y_LIST_ITEM, "a linha escolhida fica editando (com o foco)"); + type("maria"); + key(TB_KEY_RETURN, 0, 0); + frame(0, 0, 0, 0, 0, 0, NULL); + ax_do(ax_in(ax_in(0, TB_A11Y_DIALOG, "Configurações"), TB_A11Y_BUTTON, "Salvar"), TB_A11Y_ACT_ACTIVATE); FILE* sf = fopen("build/settings_test.csv", "rb"); char sbuf[512] = ""; if (sf) { size_t sn = fread(sbuf, 1, sizeof(sbuf)-1, sf); sbuf[sn] = 0; fclose(sf); } CHECK(strstr(sbuf, "# arquivo_config,build/settings_test.csv") != NULL, - "CSV inclui o caminho do arquivo de configuracao"); - CHECK(strstr(sbuf, "chave,valor") != NULL, "settings salvas em CSV (cabecalho)"); + "CSV inclui o caminho do arquivo de configuração"); + CHECK(strstr(sbuf, "chave,valor") != NULL, "settings salvas em CSV (cabeçalho)"); CHECK(strstr(sbuf, "autor,maria") != NULL, "valor editado gravado no CSV"); remove("build/settings_test.csv"); } key(TB_KEY_ESCAPE, 0, 0); /* fecha a tela */ frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(!find("Configurações", R_ANY, 0, &x, &y), "Esc fecha as configuracoes"); + CHECK(ax_in(0, TB_A11Y_DIALOG, "Configurações") < 0, "Esc fecha as configurações"); unsetenv("TINYBLOCKS_SETTINGS"); - /* 19. Previa de resultado: curva (lista de pontos) em balão, clique duplo */ - if (need("Curvas", R_CAT, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - if (need("círculo em (", R_FLY, 0, &x, &y)) drag(x, y, 620, 500); - frame(0, 0, 0, 0, 0, 0, NULL); - if (need("círculo em (", R_WS, 0, &x, &y)) { click(x, y); click(x, y); } - frame(0, 0, 0, 0, 0, 0, NULL); + /* 19. Prévia de resultado: curva (lista de pontos) em balão, clique duplo */ + cat("Curvas"); + ax_drop_at(pal_block("Curvas", "círculo em ("), ws(), 302, 420); { - int lines = 0; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_STROKE_LINE && in_region(cmds[i].x, R_WS)) lines++; - CHECK(lines >= 20, "clique duplo na curva desenha a polilinha no balão"); + int c = stack_head("círculo em ("); + ax_do(c, TB_A11Y_ACT_ACTIVATE); + ax_do(c, TB_A11Y_ACT_ACTIVATE); } - CHECK(ws_has("37 pontos"), "balão mostra a contagem de pontos da curva"); + CHECK(drawn_count(TB_DRAW_STROKE_LINE, ws()) >= 20, "clique duplo na curva desenha a polilinha no balão"); + CHECK(strstr(result_value(), "37 pontos") != NULL, "balão mostra a contagem de pontos da curva"); - /* 20. Previa de imagem: PPM.New em balão desenha TB_DRAW_IMAGE */ - if (need("PPM", R_CAT, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - if (need("nova imagem(", R_FLY, 0, &x, &y)) drag(x, y, 640, 520); - frame(0, 0, 0, 0, 0, 0, NULL); - if (need("nova imagem(", R_WS, 0, &x, &y)) { click(x, y); click(x, y); } - frame(0, 0, 0, 0, 0, 0, NULL); + /* 20. Prévia de imagem: PPM.New em balão desenha TB_DRAW_IMAGE */ + cat("PPM"); + ax_drop_at(pal_block("PPM", "nova imagem("), ws(), 322, 440); { - int imgs = 0; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_IMAGE) imgs++; - CHECK(imgs >= 1, "clique duplo numa imagem desenha TB_DRAW_IMAGE no balão"); + int im = stack_head("nova imagem("); + ax_do(im, TB_A11Y_ACT_ACTIVATE); + ax_do(im, TB_A11Y_ACT_ACTIVATE); } - CHECK(ws_has("32x32"), "balão mostra as dimensões da imagem"); + CHECK(drawn_count(TB_DRAW_IMAGE, ws()) >= 1, "clique duplo numa imagem desenha TB_DRAW_IMAGE no balão"); + CHECK(strstr(result_value(), "32x32") != NULL, "balão mostra as dimensões da imagem"); - /* 21. Tooltip de metadados: Alt + hover sobre um bloco (Stage.Clear) */ - if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - if (need("apague tudo", R_FLY, 0, &x, &y)) drag(x, y, 520, 430); - frame(0, 0, 0, 0, 0, 0, NULL); + /* 21. Tooltip de metadados: Alt + mouse sobre um bloco (Stage.Clear) */ + cat("Caneta"); + ax_drop_at(pal_block("Caneta", "apague tudo"), ws(), 202, 350); { - float bx = 0, by = 0; - if (find("apague tudo", R_WS, 0, &bx, &by)) { - mods(TB_MOD_ALT); - frame(bx, by, 0, 0, 0, 0, NULL); - CHECK(any_substr("eval_clear"), "Alt+hover mostra o tooltip com a funcao C"); - CHECK(any_substr("tb_pen.c"), "tooltip mostra o arquivo-fonte"); - CHECK(any_substr("Limpa o palco"), "tooltip mostra a descricao (doc)"); - /* clica na previa do codigo -> abre aba de codigo na linha */ - float px = 0, py = 0; - if (find_sub("tb_stage_clear", &px, &py)) { - mods(0); - click(px, py); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_substr("tb_pen.c"), "clique na previa abre aba de codigo do arquivo"); - CHECK(ws_substr("eval_clear"), "aba de codigo mostra o codigo na linha da funcao"); - } else { mods(0); CHECK(false, "achei a previa do codigo no tooltip"); } - } else { CHECK(false, "achei o bloco 'apague tudo' no workspace"); } + float bx, by; + int b = stack_head("apague tudo"); + tb_a11y_point(A(), b, &bx, &by); + mods(TB_MOD_ALT); + frame(bx, by, 0, 0, 0, 0, NULL); + int tip = ax_in(0, TB_A11Y_TOOLTIP, NULL); + CHECK(tip >= 0 && strstr(N(tip)->name, "eval_clear"), "Alt + mouse mostra a dica com a função C"); + CHECK(tip >= 0 && strstr(N(tip)->value, "tb_pen.c"), "dica mostra o arquivo-fonte"); + CHECK(tip >= 0 && strstr(N(tip)->description, "Limpa o palco"), "dica mostra a descrição (doc)"); + mods(0); + /* a prévia do código abre a aba de código na linha */ + ax_do(ax_in(tip, TB_A11Y_BUTTON, "Abrir o código nesta linha"), TB_A11Y_ACT_ACTIVATE); + int code = ax_in(0, TB_A11Y_TEXT_FIELD, "Código"); + CHECK(code >= 0 && strstr(N(code)->description, "tb_pen.c"), "a prévia abre aba de código do arquivo"); + CHECK(drawn_text(ws(), "eval_clear"), "aba de código mostra o código na linha da função"); } - /* 22. Botao "+" -> nova aba: Editor de Codigo */ + /* 22. Botão "+" -> nova aba: Editor de Código */ key(TB_KEY_ESCAPE, 0, 0); frame(0, 0, 0, 0, 0, 0, NULL); + ax_do(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_BUTTON, "Nova aba"), TB_A11Y_ACT_ACTIVATE); { - float px = 0, py = 0; - if (find_tabbar("+", &px, &py)) click(px, py); else { CHECK(false, "achei o botao +"); } - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Editor de Código", R_ANY, 0, &x, &y) && find("Novo bloco", R_ANY, 0, &x, &y) && - find("Blueprint", R_ANY, 0, &x, &y), "menu '+' lista Blueprint, Novo bloco, Imagem e Código"); - CHECK(find("Edição de Imagem", R_ANY, 0, &x, &y), "menu '+' oferece Edição de Imagem"); - if (need("Editor de Código", R_ANY, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); + int m = ax_in(0, TB_A11Y_MENU, "Nova aba"); + CHECK(ax_in(m, TB_A11Y_MENU_ITEM, "Editor de Código") >= 0 && ax_in(m, TB_A11Y_MENU_ITEM, "Novo bloco") >= 0 && + ax_in(m, TB_A11Y_MENU_ITEM, "Blueprint") >= 0, "menu '+' lista Blueprint, Novo bloco, Imagem e Código"); + CHECK(ax_in(m, TB_A11Y_MENU_ITEM, "Edição de Imagem") >= 0, "menu '+' oferece Edição de Imagem"); + ax_do(ax_in(m, TB_A11Y_MENU_ITEM, "Editor de Código"), TB_A11Y_ACT_ACTIVATE); type("int x = 42;"); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(ws_has("int"), "aba de codigo realca 'int' (palavra-chave)"); - CHECK(ws_has("42"), "aba de codigo realca o numero 42"); - CHECK(ws_has(";"), "aba de codigo realca a pontuacao"); - CHECK(!any_has(""), "aba de codigo nao mostra a marcacao "); + CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Código")), "int x = 42;"), "o código digitado é o valor do campo"); + CHECK(drawn_text(ws(), "int"), "aba de código realça 'int' (palavra-chave)"); + CHECK(drawn_text(ws(), "42"), "aba de código realça o número 42"); + CHECK(drawn_text(ws(), ";"), "aba de código realça a pontuação"); + CHECK(!drawn_text(0, "") && !any_has(""), "aba de código não mostra a marcação "); } - /* 23. Botao "+" -> nova aba: Edição de Imagem */ + /* 23. Botão "+" -> nova aba: Edição de Imagem */ key(TB_KEY_ESCAPE, 0, 0); frame(0, 0, 0, 0, 0, 0, NULL); + ax_do(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_BUTTON, "Nova aba"), TB_A11Y_ACT_ACTIVATE); + ax_do(ax_in(ax_in(0, TB_A11Y_MENU, "Nova aba"), TB_A11Y_MENU_ITEM, "Edição de Imagem"), TB_A11Y_ACT_ACTIVATE); { - float px = 0, py = 0; - if (find_tabbar("+", &px, &py)) click(px, py); else { CHECK(false, "achei o botao +"); } - frame(0, 0, 0, 0, 0, 0, NULL); - if (need("Edição de Imagem", R_ANY, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Camadas", R_WS, 0, &x, &y), "aba de imagem mostra a lista de camadas"); - CHECK(find("Salvar", R_WS, 0, &x, &y), "aba de imagem mostra o botao Salvar"); - CHECK(find("Desfazer", R_WS, 0, &x, &y), "aba de imagem mostra o botao Desfazer"); - CHECK(find("Cores", R_WS, 0, &x, &y), "aba de imagem mostra a coluna de cores"); - CHECK(find("Paleta", R_WS, 0, &x, &y), "aba de imagem mostra a paleta rapida"); - CHECK(x > 700, "cores ficam na lateral direita"); - { - int imgs = 0; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_IMAGE && in_region(cmds[i].x, R_WS)) imgs++; - CHECK(imgs >= 1, "aba de imagem desenha a folha de desenho"); - } + int w = ws(); + CHECK(ax_in(w, TB_A11Y_LIST, "Camadas") >= 0, "aba de imagem mostra a lista de camadas"); + CHECK(ax_in(ax_in(w, TB_A11Y_TOOLBAR, "Arquivo"), TB_A11Y_BUTTON, "Salvar") >= 0, "aba de imagem mostra o botão Salvar"); + CHECK(ax_in(w, TB_A11Y_BUTTON, "Desfazer") >= 0, "aba de imagem mostra o botão Desfazer"); + int cores = ax_in(w, TB_A11Y_GROUP, "Cores"); + CHECK(cores >= 0 && ax_in(cores, TB_A11Y_LIST, "Paleta de cores") >= 0, "aba de imagem mostra as cores e a paleta rápida"); + CHECK(cores >= 0 && N(cores)->x > N(w)->x + N(w)->w * 0.5f, "cores ficam na lateral direita"); + CHECK(drawn_count(TB_DRAW_IMAGE, w) >= 1, "aba de imagem desenha a folha de desenho"); } - /* 24. Pintar na aba de imagem (ferramenta pincel) */ + /* 24. Pintar na aba de imagem */ { - int before = img_nonwhite(); - CHECK(before == 0, "folha de desenho comeca em branco"); - click(345, 192); /* botao da ferramenta pincel */ - frame(0, 0, 0, 0, 0, 0, NULL); - drag(500, 300, 560, 400); /* pinta um traco no canvas */ - frame(0, 0, 0, 0, 0, 0, NULL); - int after = img_nonwhite(); - CHECK(after > 0, "pincel pinta pixels na folha de desenho"); - click(421, 703); /* botao Desfazer */ - frame(0, 0, 0, 0, 0, 0, NULL); + float x0, y0, x1, y1; + int tools = ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"); + CHECK(img_nonwhite() == 0, "folha de desenho começa em branco"); + ax_do(ax_in(tools, TB_A11Y_RADIO, "pincel"), TB_A11Y_ACT_ACTIVATE); + CHECK(N(ax_in(ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"), TB_A11Y_RADIO, "pincel"))->states & TB_A11Y_CHECKED, + "a ferramenta escolhida fica marcada"); + int folha = ax_in(ws(), TB_A11Y_CANVAS, "Folha"); + at(folha, 0.2f, 0.2f, &x0, &y0); at(folha, 0.35f, 0.5f, &x1, &y1); + drag(x0, y0, x1, y1); /* um traço na folha */ + CHECK(img_nonwhite() > 0, "pincel pinta pixels na folha de desenho"); + ax_do(ax_in(ws(), TB_A11Y_BUTTON, "Desfazer"), TB_A11Y_ACT_ACTIVATE); CHECK(img_nonwhite() == 0, "Desfazer volta a folha em branco"); - click(345, 292); /* ferramenta retangulo */ - frame(0, 0, 0, 0, 0, 0, NULL); - drag(560, 280, 680, 360); - frame(0, 0, 0, 0, 0, 0, NULL); + ax_do(ax_in(ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"), TB_A11Y_RADIO, "retangulo"), TB_A11Y_ACT_ACTIVATE); + folha = ax_in(ws(), TB_A11Y_CANVAS, "Folha"); + at(folha, 0.55f, 0.3f, &x0, &y0); at(folha, 0.8f, 0.5f, &x1, &y1); + drag(x0, y0, x1, y1); int rect_px = img_nonwhite(); - CHECK(rect_px > 100, "ferramenta retangulo desenha o contorno"); - click(345, 342); /* ferramenta elipse */ - frame(0, 0, 0, 0, 0, 0, NULL); - drag(620, 290, 690, 390); - frame(0, 0, 0, 0, 0, 0, NULL); + CHECK(rect_px > 100, "ferramenta retângulo desenha o contorno"); + ax_do(ax_in(ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"), TB_A11Y_RADIO, "elipse"), TB_A11Y_ACT_ACTIVATE); + at(folha, 0.65f, 0.32f, &x0, &y0); at(folha, 0.85f, 0.6f, &x1, &y1); + drag(x0, y0, x1, y1); CHECK(img_nonwhite() > rect_px, "ferramenta elipse desenha o contorno"); - click(345, 392); /* ferramenta preencher */ + ax_do(ax_in(ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"), TB_A11Y_RADIO, "preencher"), TB_A11Y_ACT_ACTIVATE); + at(folha, 0.58f, 0.45f, &x0, &y0); click(x0, y0); /* dentro do retângulo */ + at(folha, 0.2f, 0.8f, &x0, &y0); click(x0, y0); /* fora das formas */ frame(0, 0, 0, 0, 0, 0, NULL); - click(620, 320); /* dentro do retangulo */ + CHECK(img_nonwhite() > rect_px * 3, "ferramenta preencher alaga a área branca"); + ax_do(ax_in(ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"), TB_A11Y_RADIO, "conta-gotas"), TB_A11Y_ACT_ACTIVATE); + click(x0, y0); frame(0, 0, 0, 0, 0, 0, NULL); - click(520, 400); /* fora das formas */ - frame(0, 0, 0, 0, 0, 0, NULL); - int fill_px = img_nonwhite(); - CHECK(fill_px > rect_px * 3, "ferramenta preencher alaga a area branca"); - click(345, 492); /* conta-gotas */ - frame(0, 0, 0, 0, 0, 0, NULL); - click(520, 400); - frame(0, 0, 0, 0, 0, 0, NULL); - { - bool found = false; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "Cor do pixel")) found = true; - CHECK(found, "conta-gotas informa a cor capturada"); - } - /* 24b. Escolher uma cor na paleta lateral e desenhar com ela */ - { - click(803, 277); /* segundo quadradinho da paleta (branco) */ - frame(0, 0, 0, 0, 0, 0, NULL); - bool dark = false; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "#FFFFFF")) dark = true; - CHECK(dark, "paleta lateral troca a cor da ferramenta"); - click(345, 142); /* selecionar */ - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Desfazer", R_WS, 0, &x, &y), "ferramenta selecionar continua disponivel"); - } - CHECK(find("Fundo", R_WS, 0, &x, &y), "lista de camadas mostra a camada Fundo"); - CHECK(find("+ Raster", R_WS, 0, &x, &y), "botao de nova camada raster"); - CHECK(find("+ Vetor", R_WS, 0, &x, &y), "botao de nova camada vetorial"); - CHECK(find("Fundo", R_WS, 0, &x, &y), "achei a camada Fundo"); - click(x - 29, y + 6); /* olho da camada Fundo: esconde */ - frame(0, 0, 0, 0, 0, 0, NULL); - /* sem camada visivel nao ha imagem nenhuma na folha (=-1) */ + CHECK(toast_has("Cor do pixel"), "conta-gotas informa a cor capturada"); + /* 24b. Escolher uma cor na paleta lateral */ + ax_do(ax_in(ax_in(ws(), TB_A11Y_LIST, "Paleta de cores"), TB_A11Y_RADIO, "Branco"), TB_A11Y_ACT_ACTIVATE); + CHECK(!strcmp(ax_value(ax_in(ws(), TB_A11Y_LABEL, "Cor atual")), "#FFFFFF"), "paleta lateral troca a cor da ferramenta"); + ax_do(ax_in(ax_in(ws(), TB_A11Y_TOOLBAR, "Ferramentas"), TB_A11Y_RADIO, "selecionar"), TB_A11Y_ACT_ACTIVATE); + CHECK(ax_in(ws(), TB_A11Y_BUTTON, "Desfazer") >= 0, "ferramenta selecionar continua disponível"); + int camadas = ax_in(ws(), TB_A11Y_LIST, "Camadas"); + CHECK(ax_in(camadas, TB_A11Y_LIST_ITEM, "Fundo") >= 0, "lista de camadas mostra a camada Fundo"); + CHECK(ax_in(camadas, TB_A11Y_BUTTON, "Nova camada raster") >= 0, "botão de nova camada raster"); + CHECK(ax_in(camadas, TB_A11Y_BUTTON, "Nova camada vetorial") >= 0, "botão de nova camada vetorial"); + int eye = ax_in(ax_in(camadas, TB_A11Y_LIST_ITEM, "Fundo"), TB_A11Y_CHECKBOX, "Visível"); + CHECK(eye >= 0 && (N(eye)->states & TB_A11Y_CHECKED), "camada Fundo começa visível"); + ax_do(eye, TB_A11Y_ACT_ACTIVATE); + /* sem camada visível não há imagem nenhuma na folha (-1) */ CHECK(img_nonwhite() <= 0, "camada pode ser escondida"); - click(x - 29, y + 6); /* olho: mostra de novo */ - frame(0, 0, 0, 0, 0, 0, NULL); + ax_do(ax_in(ax_in(ax_in(ws(), TB_A11Y_LIST, "Camadas"), TB_A11Y_LIST_ITEM, "Fundo"), TB_A11Y_CHECKBOX, "Visível"), + TB_A11Y_ACT_ACTIVATE); CHECK(img_nonwhite() > 0, "camada pode ser mostrada de novo"); } - /* 22. Áreas estilo Blender: redimensionar arrastando a borda, trocar de lugar pela alça */ + /* 22b. Áreas estilo Blender: redimensionar arrastando a borda, trocar de lugar pela alça */ { frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Blocos", R_ANY, 0, &x, &y) && x < 100, "paleta tem cabeçalho \"Blocos\" com alça"); - /* borda paleta | scripts em x = 318: arrasta 100 px para a direita */ - drag(318, 400, 418, 400); - frame(0, 0, 0, 0, 0, 0, NULL); - bool largo = false; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_SET_CLIP && cmds[i].x == 68 && cmds[i].w > 340) largo = true; - CHECK(largo, "arrastar a borda alarga a paleta (418 px)"); - float px0 = 0, py0 = 0; - CHECK(find("Palco", R_ANY, 0, &px0, &py0) && px0 > 920, "palco continua na direita"); - /* alça do palco (ao lado do botão de destacar) -> solta sobre os scripts */ - drag(1280 - 50 - 18 - 8 + 9, 44 + 22, 640, 400); - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 418 && x < 900, "alça troca o palco com a área de scripts"); - /* e de volta: a alça do palco agora está no meio da tela */ - drag(418 + (1280 - 360 - 418) - 50 - 18 - 8 + 9, 44 + 22, 1100, 200); /* scripts, em cima à direita */ - frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 920, "trocar de novo devolve o palco à direita"); + int pb = pane("Blocos"); + CHECK(pb >= 0 && N(pb)->x < 100 && ax_in(pb, TB_A11Y_BUTTON, "Mover a área Blocos") >= 0, + "paleta é a área \"Blocos\", com alça"); + /* borda paleta | scripts: 100 px para a direita */ + int sep = ax_in(0, TB_A11Y_SEPARATOR, "Borda entre Blocos e Scripts"); + ax_drop_at(sep, sep, 100, 0); + CHECK(fabsf(N(pane("Blocos"))->w - 418.f) < 1.f, "arrastar a borda alarga a paleta (418 px)"); + CHECK(N(pane("Palco"))->x > 900, "palco continua na direita"); + /* alça do palco -> solta sobre os scripts */ + ax_drop(ax_in(pane("Palco"), TB_A11Y_BUTTON, "Mover a área Palco"), pane("Scripts")); + CHECK(N(pane("Palco"))->x >= 418 && N(pane("Palco"))->x < 900, "alça troca o palco com a área de scripts"); + /* e de volta: os scripts agora estão à direita */ + ax_drop(ax_in(pane("Palco"), TB_A11Y_BUTTON, "Mover a área Palco"), pane("Scripts")); + CHECK(N(pane("Palco"))->x > 900, "trocar de novo devolve o palco à direita"); /* layout salvo nas configurações (arquivo isolado do harness) */ CHECK(!strcmp(tb_environ_get("editor.layout"), "H0:418(p,H1:360(s,V0:310(t,o)))"), "layout salvo em editor.layout (paleta com 418 px)"); @@ -995,49 +871,30 @@ int main(void) { CHECK(strstr(cbuf, "editor.layout") != NULL, "layout gravado no arquivo de configurações"); } - /* 23. Abas: arrastar na barra reordena (como no navegador) */ + /* 23b. Abas: soltar uma aba sobre a vizinha reordena (como no navegador) */ { frame(0, 0, 0, 0, 0, 0, NULL); - /* rótulos das abas na barra (y 44..80), em ordem de x */ - char nomes[8][64]; float xs[8]; int n = 0; - for (uint32_t i = 0; i < ncmd && n < 8; i++) { - if (cmds[i].kind != TB_DRAW_TEXT || cmds[i].y < 50 || cmds[i].y > 80) continue; - if (cmds[i].x < 318 || cmds[i].x > 900 || !strcmp(cmds[i].text, "=") || !strcmp(cmds[i].text, "+")) continue; - snprintf(nomes[n], 64, "%s", cmds[i].text); xs[n] = cmds[i].x; n++; - } - CHECK(n >= 2, "há pelo menos duas abas para reordenar"); - if (n >= 2) { - char primeira[64]; snprintf(primeira, 64, "%s", nomes[0]); - float sx = xs[0] + 10; - drag(sx, 62, sx + 150 + 20, 62); /* passa do meio da vizinha */ - frame(0, 0, 0, 0, 0, 0, NULL); - float nx = 0, ny = 0; - bool achou = false; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && !strcmp(cmds[i].text, primeira) && cmds[i].y > 50 && cmds[i].y < 80) { - nx = cmds[i].x; ny = cmds[i].y; achou = true; - } - (void)ny; - CHECK(achou && nx > xs[1] - 20, "arrastar a aba para a direita troca a ordem com a vizinha"); + int tabs = ax_in(0, TB_A11Y_TAB_LIST, "Abas"); + int t0 = tb_a11y_find(A(), tabs, TB_A11Y_TAB, NULL, 0), t1 = tb_a11y_find(A(), tabs, TB_A11Y_TAB, NULL, 1); + CHECK(t0 >= 0 && t1 >= 0, "há pelo menos duas abas para reordenar"); + if (t0 >= 0 && t1 >= 0) { + char primeira[128]; + snprintf(primeira, sizeof(primeira), "%s", N(t0)->name); + ax_drop(t0, t1); + tabs = ax_in(0, TB_A11Y_TAB_LIST, "Abas"); + CHECK(!strcmp(N(tb_a11y_find(A(), tabs, TB_A11Y_TAB, NULL, 1))->name, primeira), + "soltar a aba sobre a vizinha troca a ordem"); - /* arrastar a aba para longe da barra destaca numa janela própria */ - drag(nx + 10, 62, nx + 10, 400); + /* soltar a aba longe da barra destaca numa janela própria */ + int t = ax_in(tabs, TB_A11Y_TAB, primeira), sc = pane("Scripts"); + ax_drop_at(t, sc, N(t)->x - N(sc)->x, 300); + CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_TAB, primeira) < 0 && + ax_in(ax_in(0, TB_A11Y_TOOLBAR, "Menu"), TB_A11Y_BUTTON, primeira) >= 0, + "aba arrastada para fora vira janela (botão no menu)"); + ax_do(ax_in(ax_in(0, TB_A11Y_TOOLBAR, "Menu"), TB_A11Y_BUTTON, primeira), TB_A11Y_ACT_ACTIVATE); frame(0, 0, 0, 0, 0, 0, NULL); - bool na_barra = false, no_menu = false; - float mxp = 0; - for (uint32_t i = 0; i < ncmd; i++) { - if (cmds[i].kind != TB_DRAW_TEXT || strcmp(cmds[i].text, primeira) != 0) continue; - if (cmds[i].y > 50 && cmds[i].y < 80) na_barra = true; - if (cmds[i].y < 44) { no_menu = true; mxp = cmds[i].x + 3; } - } - CHECK(!na_barra && no_menu, "aba arrastada para fora vira janela (botão no menu)"); - if (no_menu) click(mxp, 22); /* volta para a barra */ - frame(0, 0, 0, 0, 0, 0, NULL); - na_barra = false; - for (uint32_t i = 0; i < ncmd; i++) - if (cmds[i].kind == TB_DRAW_TEXT && !strcmp(cmds[i].text, primeira) && cmds[i].y > 50 && cmds[i].y < 80) - na_barra = true; - CHECK(na_barra, "botão no menu traz a aba de volta para a barra"); + CHECK(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_TAB, primeira) >= 0, + "botão no menu traz a aba de volta para a barra"); } } @@ -1056,29 +913,25 @@ int main(void) { if (f) { fputs(script, f); fclose(f); } remove(dst); frame(0, 0, 0, 0, 0, 0, NULL); - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(src); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(src); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("Importado: 1 script"), "Abrir um .txt em scratchblocks cria aba com o script"); - CHECK(any_has("de tb_harness_sb.txt"), "aba nova recebe o nome do arquivo"); - CHECK(find("repita", R_WS, 0, &x, &y) || ws_has("repita"), "blocos importados aparecem (repita)"); - if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y); - if (need("Exportar scratchblocks", R_ANY, 0, &x, &y)) click(x, y); - frame(0, 0, 0, 0, 0, 0, NULL); - /* prévia: mostra o texto antes de exportar */ - CHECK(find("when flag clicked", R_ANY, 0, &x, &y) && find("Copiar", R_ANY, 0, &x, &y), - "Exportar scratchblocks abre a prévia com o texto"); - if (need("Copiar", R_ANY, 0, &x, &y)) click(x, y); + CHECK(toast_has("Importado: 1 script"), "Abrir um .txt em scratchblocks cria aba com o script"); + CHECK(toast_has("de tb_harness_sb.txt"), "aba nova recebe o nome do arquivo"); + CHECK(ws_block("repita", 0) >= 0, "blocos importados aparecem (repita)"); + ax_do(menu_btn("Exportar"), TB_A11Y_ACT_ACTIVATE); + ax_do(ax_in(ax_in(0, TB_A11Y_MENU, "Menu de contexto"), TB_A11Y_MENU_ITEM, "Exportar scratchblocks"), + TB_A11Y_ACT_ACTIVATE); + int prev = ax_part(0, TB_A11Y_DIALOG, "Prévia scratchblocks"); + CHECK(prev >= 0 && strstr(ax_value(ax_in(prev, TB_A11Y_TEXT_FIELD, "scratchblocks")), "when flag clicked") && + ax_in(prev, TB_A11Y_BUTTON, "Copiar") >= 0, "Exportar scratchblocks abre a prévia com o texto"); + ax_do(ax_in(prev, TB_A11Y_BUTTON, "Copiar"), TB_A11Y_ACT_ACTIVATE); char* clip = tb_graphics_get_clipboard(); CHECK(clip && strstr(clip, "[scratchblocks]\nwhen flag clicked\n") && strstr(clip, "[/scratchblocks]"), "Copiar põe o texto com [scratchblocks] na área de transferência"); free(clip); - if (need("Salvar...", R_ANY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(dst); - key(TB_KEY_RETURN, 0, 0); + ax_do(ax_in(ax_part(0, TB_A11Y_DIALOG, "Prévia scratchblocks"), TB_A11Y_BUTTON, "Salvar..."), TB_A11Y_ACT_ACTIVATE); + type_path(dst); frame(0, 0, 0, 0, 0, 0, NULL); char got[512] = ""; f = fopen(dst, "rb"); @@ -1087,10 +940,11 @@ int main(void) { if (strcmp(got, script)) printf("---- exportado:\n%s----\n", got); /* colar do fórum: a área de transferência vira uma aba */ tb_graphics_set_clipboard("[scratchblocks]\nwhen flag clicked\nerase all\n[/scratchblocks]\n"); - if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y); - if (need("Colar scratchblocks", R_ANY, 0, &x, &y)) click(x, y); + ax_do(menu_btn("Exportar"), TB_A11Y_ACT_ACTIVATE); + ax_do(ax_in(ax_in(0, TB_A11Y_MENU, "Menu de contexto"), TB_A11Y_MENU_ITEM, "Colar scratchblocks"), + TB_A11Y_ACT_ACTIVATE); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(any_has("Importado: 1 script(s) de Colado"), "Colar scratchblocks importa da área de transferência"); + CHECK(toast_has("Importado: 1 script(s) de Colado"), "Colar scratchblocks importa da área de transferência"); remove(src); remove(dst); } @@ -1118,53 +972,54 @@ int main(void) { "],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", f); fclose(f); } - if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(pj); - key(TB_KEY_RETURN, 0, 0); - if (find("Descartar", R_ANY, 0, &x, &y)) click(x, y); + ax_do(menu_btn("Abrir"), TB_A11Y_ACT_ACTIVATE); + type_path(pj); frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(ws_has("tente") && ws_has("se der erro") && ws_has("finalmente"), + int tente = ws_block("tente", 0); + CHECK(tente >= 0 && ax_in(tente, TB_A11Y_GROUP, "se der erro") >= 0 && ax_in(tente, TB_A11Y_GROUP, "finalmente") >= 0, "bloco tente / se der erro / finalmente com três bocas"); flag(); for (int i = 0; i < 3; i++) frame(0, 0, 0, 0, 0, 0, NULL); - CHECK(stage_has("deu ruim") && !stage_has("nao roda"), "erro pula o resto do tente e vai para o se der erro"); - CHECK(stage_has("no finalmente"), "finalmente roda depois"); - CHECK(stage_has("77"), "tente obter + desembrulhe + valor de ... ou: erro vira valor (Result)"); - CHECK(stage_has("[ERRO] sem tente") && !stage_has("nunca"), "erro sem tente para o script e aparece no palco"); + CHECK(console_has("deu ruim") && !console_has("nao roda"), "erro pula o resto do tente e vai para o se der erro"); + CHECK(console_has("no finalmente"), "finalmente roda depois"); + CHECK(console_has("77"), "tente obter + desembrulhe + valor de ... ou: erro vira valor (Result)"); + CHECK(console_has("[ERRO] sem tente") && !console_has("nunca"), "erro sem tente para o script e aparece na saída"); remove(pj); } /* 25. Grupos (como no Unreal): agrupar a pilha e mover tudo pelo título */ { - float hx0, hy0; frame(0, 0, 0, 0, 0, 0, NULL); - if (need("quando a bandeira for clicado", R_WS, 0, &hx0, &hy0)) { - drag(hx0, hy0, hx0 + 40, hy0 + 160); /* longe da barra de abas */ - need("quando a bandeira for clicado", R_WS, 0, &hx0, &hy0); - frame(hx0, hy0, 0, 0, 1, 0, NULL); /* botão direito na pilha */ - frame(hx0, hy0, 0, 0, 0, 0, NULL); - if (need("Agrupar esta pilha", R_ANY, 0, &x, &y)) click(x, y); + int hat = ws_block("quando a bandeira for clicado", 0); + CHECK(hat >= 0, "achei o chapéu"); + if (hat >= 0) { + int w = ws(); + ax_drop_at(hat, w, N(hat)->x - N(w)->x + 40, N(hat)->y - N(w)->y + 160); /* longe da barra de abas */ + hat = ws_block("quando a bandeira for clicado", 0); + float hx0 = N(hat)->x, hy0 = N(hat)->y; + ax_do(hat, TB_A11Y_ACT_MENU); + ax_do(ax_in(ax_in(0, TB_A11Y_MENU, "Menu de contexto"), TB_A11Y_MENU_ITEM, "Agrupar esta pilha"), + TB_A11Y_ACT_ACTIVATE); + CHECK(N(tb_a11y_focus(A()))->role == TB_A11Y_GROUP, "o título do grupo novo recebe o foco"); for (int i = 0; i < 12; i++) key(TB_KEY_BACKSPACE, 0, 0); type("Principal"); key(TB_KEY_RETURN, 0, 0); - CHECK(find("Principal", R_WS, 0, &x, &y), "Agrupar esta pilha cria o grupo com título"); - float tx = x, ty = y; - drag(tx, ty, tx + 120, ty + 70); /* arrasta pelo título */ - float nx, ny; - CHECK(find("quando a bandeira for clicado", R_WS, 0, &nx, &ny) && - fabsf(nx - (hx0 + 120)) < 2 && fabsf(ny - (hy0 + 70)) < 2, + int g = ax_in(ws(), TB_A11Y_GROUP, "Principal"); + CHECK(g >= 0, "Agrupar esta pilha cria o grupo com título"); + float gx0 = g >= 0 ? N(g)->x : 0; + w = ws(); + ax_drop_at(g, w, N(g)->x - N(w)->x + 120, N(g)->y - N(w)->y + 70); /* arrasta pelo título */ + hat = ws_block("quando a bandeira for clicado", 0); + CHECK(hat >= 0 && fabsf(N(hat)->x - (hx0 + 120)) < 2 && fabsf(N(hat)->y - (hy0 + 70)) < 2, "arrastar o título do grupo move a pilha junto"); - CHECK(find("Principal", R_WS, 0, &x, &y) && fabsf(x - (tx + 120)) < 2, - "o grupo vai junto com a pilha"); + g = ax_in(ws(), TB_A11Y_GROUP, "Principal"); + CHECK(g >= 0 && fabsf(N(g)->x - (gx0 + 120)) < 2, "o grupo vai junto com a pilha"); /* salvar e abrir de novo mantém o grupo */ const char* gp = "/tmp/tb_harness_grp.json"; remove(gp); - if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y); - for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0); - type(gp); - key(TB_KEY_RETURN, 0, 0); + ax_do(menu_btn("Salvar"), TB_A11Y_ACT_ACTIVATE); + type_path(gp); FILE* f = fopen(gp, "rb"); char buf[65536] = ""; if (f) { size_t n = fread(buf, 1, sizeof(buf) - 1, f); buf[n] = 0; fclose(f); } @@ -1176,13 +1031,13 @@ int main(void) { { const char* nomes[2] = { "render", "draw button" }; for (int k = 0; k < 2; k++) { - if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y); - ax_do(ax_need(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE); + cat("Meus Blocos"); + ax_do(ax_need(pal(), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE); type(nomes[k]); /* o foco abre no nome do bloco */ key(TB_KEY_RETURN, 0, 0); } - if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y); - int mine = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Meus Blocos"); + cat("Meus Blocos"); + int mine = ax_in(pal(), TB_A11Y_GROUP, "Meus Blocos"); CHECK(ax_in(mine, TB_A11Y_BLOCK, "render") >= 0 && ax_in(mine, TB_A11Y_BLOCK, "draw button") >= 0, "dois blocos definidos aparecem na paleta"); } @@ -1223,10 +1078,10 @@ int main(void) { CHECK(run >= 0 && N(run)->id == run_id, "a11y: ids estáveis entre quadros"); /* blocos da paleta fora da vista ficam OFFSCREEN, mas estão na árvore */ - int pal = ax_in(0, TB_A11Y_LIST, "Paleta"); - int far = ax_in(pal, TB_A11Y_GROUP, "Meus Blocos"); - CHECK(far >= 0 && (N(far)->states & TB_A11Y_OFFSCREEN) && ax_in(pal, TB_A11Y_GROUP, "Controle") >= 0 && - !(N(ax_in(pal, TB_A11Y_GROUP, "Controle"))->states & TB_A11Y_OFFSCREEN), + int pl = pal(); + int far = ax_in(pl, TB_A11Y_GROUP, "Meus Blocos"); + CHECK(far >= 0 && (N(far)->states & TB_A11Y_OFFSCREEN) && ax_in(pl, TB_A11Y_GROUP, "Controle") >= 0 && + !(N(ax_in(pl, TB_A11Y_GROUP, "Controle"))->states & TB_A11Y_OFFSCREEN), "a11y: a paleta toda está na árvore; o que não aparece é OFFSCREEN"); /* dialogo: abrir pelo botão, evento SHOWN, voltar fecha */