Acessibilidade: arrastar e soltar como ação; harness inteiro pela árvore
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
600c4fc520
commit
8f046833e7
10 files changed
+953
-747
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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 --- */
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
#include <tb_editor_files.h>
|
||||
#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
|
||||
|
||||
@@ -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 $@
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tb_editor_internal.h>
|
||||
#include <tb_a11y.h>
|
||||
#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];
|
||||
|
||||
@@ -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 $@
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* editor ficam pendentes e sao resolvidos na carga.
|
||||
*/
|
||||
#include <tb_editor_internal.h>
|
||||
#include <tb_a11y.h>
|
||||
#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);
|
||||
|
||||
|
||||
@@ -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) */
|
||||
|
||||
Reference in new issue
Block a user