- Area de scripts com zoom: Ctrl+roda no ponteiro, roda rola na vertical e Shift+roda na horizontal; pinca com dois dedos (toque) e pinca do touchpad (XInput 2.4 no X11, GFX_IN_ZOOM). Desenho em escala 1 escalado depois (rb_scale_from); a arvore acessivel acompanha (tb_a11y_scale_from). - SDL2: cache de fontes com 64 tamanhos e descarte do menos usado (antes vazava uma fonte por chamada depois de 8 tamanhos). - Campos de texto e editor de codigo: cursor em qualquer posicao, selecao (mouse, Shift+setas, clique duplo), Ctrl+A/C/X/V; no toque, segurar seleciona a palavra com alcas e barra Recortar/Copiar/Colar/Tudo. - "Criar um Bloco": o nome e uma parte movel (PARAM_NAME) e pode ser apagado quando um rotulo logo depois assume; hexagono booleano sem corte. - Harness: cenarios 32-34 (zoom, pinca, dialogo, selecao e clipboard). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
223 lines
12 KiB
C
223 lines
12 KiB
C
/*
|
|
* TinyBlocks - tb_a11y.h
|
|
* Interface de acessibilidade (no espirito do ATK/GtkAccessible do GTK).
|
|
*
|
|
* Uma interface grafica descreve a cada quadro uma ARVORE ACESSIVEL: cada
|
|
* componente (botao, aba, bloco, campo...) vira um no com papel, nome,
|
|
* descricao, valor, estados, acoes e retangulo na tela. Quem consome:
|
|
* - um narrador / leitor de tela, por uma ponte (TinyBlocks_A11yBridge)
|
|
* que recebe os eventos (foco mudou, estado mudou, aviso...);
|
|
* - a automacao de testes, que acha componentes por papel + nome e os
|
|
* aciona por tb_a11y_do_action, sem depender de texto desenhado nem de
|
|
* coordenadas fixas.
|
|
*
|
|
* Construcao (modo imediato, a cada quadro):
|
|
*
|
|
* tb_a11y_begin(tree, "TinyBlocks", w, h);
|
|
* int bar = tb_a11y_push(tree, TB_A11Y_TOOLBAR, "Menu", 0, 0, w, 44);
|
|
* int b = tb_a11y_add(tree, TB_A11Y_BUTTON, "Abrir", x, y, bw, bh);
|
|
* tb_a11y_set_actions(tree, b, TB_A11Y_ACT_ACTIVATE);
|
|
* tb_a11y_pop(tree);
|
|
* tb_a11y_end(tree); // compara com o quadro anterior e gera eventos
|
|
*
|
|
* Os ids dos nos sao estaveis entre quadros (derivados do caminho: papel +
|
|
* nome + ordem entre irmaos iguais), entao foco e selecao podem ser seguidos.
|
|
*/
|
|
#ifndef TINYBLOCKS_TB_A11Y_H
|
|
#define TINYBLOCKS_TB_A11Y_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <tinyblocks/tb_defs.h>
|
|
|
|
/* == Papeis (o "tipo" do componente, como ATK_ROLE_* / GTK_ACCESSIBLE_ROLE_*) */
|
|
typedef enum TinyBlocks_A11yRole {
|
|
TB_A11Y_NONE = 0,
|
|
TB_A11Y_APPLICATION, /* raiz */
|
|
TB_A11Y_PANE, /* area da janela (paleta, scripts, palco) */
|
|
TB_A11Y_TOOLBAR, /* barra de botoes */
|
|
TB_A11Y_BUTTON,
|
|
TB_A11Y_CHECKBOX,
|
|
TB_A11Y_RADIO, /* uma opcao entre varias (ex.: cor) */
|
|
TB_A11Y_TEXT_FIELD, /* campo de texto editavel */
|
|
TB_A11Y_LABEL, /* texto estatico */
|
|
TB_A11Y_LIST,
|
|
TB_A11Y_LIST_ITEM,
|
|
TB_A11Y_TAB_LIST,
|
|
TB_A11Y_TAB,
|
|
TB_A11Y_TAB_PANEL,
|
|
TB_A11Y_MENU,
|
|
TB_A11Y_MENU_ITEM,
|
|
TB_A11Y_DIALOG,
|
|
TB_A11Y_GROUP, /* agrupamento (ex.: grupo colorido) */
|
|
TB_A11Y_CANVAS, /* area de desenho (palco, imagem) */
|
|
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;
|
|
|
|
/* == Estados (bits) */
|
|
enum {
|
|
TB_A11Y_FOCUSED = 1u << 0, /* recebe o teclado */
|
|
TB_A11Y_SELECTED = 1u << 1, /* aba/categoria/opcao atual */
|
|
TB_A11Y_CHECKED = 1u << 2,
|
|
TB_A11Y_EXPANDED = 1u << 3, /* menu aberto */
|
|
TB_A11Y_DISABLED = 1u << 4,
|
|
TB_A11Y_EDITABLE = 1u << 5,
|
|
TB_A11Y_EDITING = 1u << 6, /* texto sendo digitado agora */
|
|
TB_A11Y_MODAL = 1u << 7,
|
|
TB_A11Y_HOVERED = 1u << 8,
|
|
TB_A11Y_BUSY = 1u << 9, /* rodando */
|
|
TB_A11Y_OFFSCREEN = 1u << 10, /* existe, mas fora da area visivel */
|
|
};
|
|
|
|
/* == Acoes (bits), executadas por tb_a11y_do_action */
|
|
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_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
|
|
|
|
typedef struct TinyBlocks_A11yNode {
|
|
uint32_t id; /* estavel entre quadros */
|
|
uint32_t key; /* hash da chave (o nome, se nao *
|
|
* houver set_key); entra no id */
|
|
int parent; /* indice do pai (-1 na raiz) */
|
|
int first_child, last_child, next_sibling;
|
|
int child_count;
|
|
int depth;
|
|
TinyBlocks_A11yRole role;
|
|
uint32_t states;
|
|
uint32_t actions;
|
|
float x, y, w, h; /* retangulo na janela */
|
|
float px, py; /* onde agir (clique); centro se nao *
|
|
* houver set_point */
|
|
char name[TB_A11Y_NAME_MAX];
|
|
char description[TB_A11Y_DESC_MAX];
|
|
char value[TB_A11Y_VALUE_MAX];
|
|
} TinyBlocks_A11yNode;
|
|
|
|
/* == Eventos (o que muda entre quadros), para o narrador */
|
|
typedef enum TinyBlocks_A11yEventKind {
|
|
TB_A11Y_EV_FOCUS, /* `node` ganhou o foco */
|
|
TB_A11Y_EV_STATE, /* estados de `node` mudaram (old_states) */
|
|
TB_A11Y_EV_NAME, /* nome mudou */
|
|
TB_A11Y_EV_VALUE, /* valor mudou */
|
|
TB_A11Y_EV_SHOWN, /* no novo (dialogos, menus, avisos) */
|
|
TB_A11Y_EV_ANNOUNCE, /* aviso para ler em voz alta (`text`) */
|
|
} TinyBlocks_A11yEventKind;
|
|
|
|
typedef struct TinyBlocks_A11yEvent {
|
|
TinyBlocks_A11yEventKind kind;
|
|
int node; /* indice no quadro atual (-1 em ANNOUNCE) */
|
|
uint32_t id;
|
|
uint32_t old_states;
|
|
char text[TB_A11Y_DESC_MAX];
|
|
} TinyBlocks_A11yEvent;
|
|
|
|
typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
|
|
|
|
/* == Ponte para um narrador (interface implementada por cada plataforma:
|
|
* AT-SPI no Linux, UI Automation no Windows, um sintetizador de voz...) */
|
|
typedef struct TinyBlocks_A11yBridge {
|
|
const char* name;
|
|
void (*on_event)(void* user, const TinyBlocks_A11yTree* tree, const TinyBlocks_A11yEvent* ev);
|
|
void (*on_frame)(void* user, const TinyBlocks_A11yTree* tree); /* arvore nova (pode ser NULL) */
|
|
void* user;
|
|
} TinyBlocks_A11yBridge;
|
|
|
|
/* == Quem desenha a interface executa as acoes (ex.: clicar no ponto) */
|
|
typedef bool (*TinyBlocks_A11yPerform)(void* user, const TinyBlocks_A11yTree* tree,
|
|
int node, const TinyBlocks_A11yRequest* req);
|
|
|
|
/* -- Ciclo de vida --- */
|
|
TB_API TinyBlocks_A11yTree* tb_a11y_tree_new(void);
|
|
TB_API void tb_a11y_tree_free(TinyBlocks_A11yTree* tree);
|
|
TB_API void tb_a11y_set_perform(TinyBlocks_A11yTree* tree, TinyBlocks_A11yPerform fn, void* user);
|
|
TB_API void tb_a11y_set_bridge(TinyBlocks_A11yTree* tree, const TinyBlocks_A11yBridge* bridge);
|
|
|
|
/* -- Construcao (a cada quadro) --- */
|
|
TB_API void tb_a11y_begin(TinyBlocks_A11yTree* tree, const char* app_name, float w, float h);
|
|
TB_API int tb_a11y_push(TinyBlocks_A11yTree* tree, TinyBlocks_A11yRole role, const char* name,
|
|
float x, float y, float w, float h); /* abre um container */
|
|
TB_API int tb_a11y_add (TinyBlocks_A11yTree* tree, TinyBlocks_A11yRole role, const char* name,
|
|
float x, float y, float w, float h); /* folha */
|
|
TB_API void tb_a11y_pop (TinyBlocks_A11yTree* tree);
|
|
TB_API int tb_a11y_current(const TinyBlocks_A11yTree* tree); /* container aberto */
|
|
TB_API void tb_a11y_end (TinyBlocks_A11yTree* tree);
|
|
|
|
TB_API void tb_a11y_set_states (TinyBlocks_A11yTree* tree, int node, uint32_t states);
|
|
TB_API void tb_a11y_add_states (TinyBlocks_A11yTree* tree, int node, uint32_t states);
|
|
TB_API void tb_a11y_set_actions (TinyBlocks_A11yTree* tree, int node, uint32_t actions);
|
|
TB_API void tb_a11y_set_value (TinyBlocks_A11yTree* tree, int node, const char* value);
|
|
TB_API void tb_a11y_set_description(TinyBlocks_A11yTree* tree, int node, const char* desc);
|
|
TB_API void tb_a11y_set_name (TinyBlocks_A11yTree* tree, int node, const char* name);
|
|
/* Chave estavel para o id quando o nome muda com o conteudo (ex.: um bloco
|
|
* "repita (10) vezes" usa o tipo como chave). Chame antes dos filhos. */
|
|
TB_API void tb_a11y_set_key (TinyBlocks_A11yTree* tree, int node, const char* key);
|
|
/* Ponto onde as acoes agem (o centro pode cair num filho) */
|
|
TB_API void tb_a11y_set_point (TinyBlocks_A11yTree* tree, int node, float x, float y);
|
|
/* Escala os nos a partir de `first` (ate o ultimo criado) em torno de (ox, oy):
|
|
* conteudo desenhado com zoom (ex.: a area de scripts) */
|
|
TB_API void tb_a11y_scale_from (TinyBlocks_A11yTree* tree, int first, float ox, float oy, float s);
|
|
/* Aviso para o narrador ler (mensagens de status, erros) */
|
|
TB_API void tb_a11y_announce(TinyBlocks_A11yTree* tree, const char* text);
|
|
|
|
/* -- Consulta --- */
|
|
TB_API int tb_a11y_count(const TinyBlocks_A11yTree* tree);
|
|
TB_API const TinyBlocks_A11yNode* tb_a11y_node(const TinyBlocks_A11yTree* tree, int node);
|
|
TB_API int tb_a11y_root(const TinyBlocks_A11yTree* tree);
|
|
TB_API int tb_a11y_focus(const TinyBlocks_A11yTree* tree); /* -1 se nenhum */
|
|
TB_API int tb_a11y_by_id(const TinyBlocks_A11yTree* tree, uint32_t id);
|
|
/* n-esimo descendente de `from` com o papel (NONE = qualquer) e o nome
|
|
* (NULL = qualquer). Devolve o indice ou -1. */
|
|
TB_API int tb_a11y_find(const TinyBlocks_A11yTree* tree, int from, TinyBlocks_A11yRole role,
|
|
const char* name, int nth);
|
|
/* Como find, mas o nome so precisa conter `part` */
|
|
TB_API int tb_a11y_find_part(const TinyBlocks_A11yTree* tree, int from, TinyBlocks_A11yRole role,
|
|
const char* part, int nth);
|
|
/* Caminho separado por " > " (ex.: "Paleta > Meus Blocos > Criar um Bloco") */
|
|
TB_API char* tb_a11y_path(const TinyBlocks_A11yTree* tree, int node, char* out, size_t cap);
|
|
TB_API void tb_a11y_center(const TinyBlocks_A11yTree* tree, int node, float* x, float* y);
|
|
TB_API void tb_a11y_point (const TinyBlocks_A11yTree* tree, int node, float* x, float* y);
|
|
TB_API const char* tb_a11y_role_name(TinyBlocks_A11yRole role); /* "botão", "aba"... */
|
|
/* Arvore em texto, um no por linha (para depuracao e testes) */
|
|
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);
|
|
|
|
/* Ponte simples que escreve os eventos num FILE* (um "narrador" de texto) */
|
|
TB_API TinyBlocks_A11yBridge tb_a11y_log_bridge(FILE* out);
|
|
/* Frase que um narrador diria para o no: "Abrir, botão" */
|
|
TB_API char* tb_a11y_describe(const TinyBlocks_A11yTree* tree, int node, char* out, size_t cap);
|
|
|
|
#endif /* TINYBLOCKS_TB_A11Y_H */
|