Editor: zoom (Ctrl+roda, pinca), selecao de texto e partes do bloco moveis
- 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>
This commit is contained in:
1 parent
a6f834f88e
commit
f180eaf75a
9 files changed
+1281
-203
No files matched your search
@@ -176,6 +176,9 @@ TB_API void tb_a11y_set_name (TinyBlocks_A11yTree* tree, int node, const c
|
|||||||
TB_API void tb_a11y_set_key (TinyBlocks_A11yTree* tree, int node, const char* key);
|
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) */
|
/* 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);
|
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) */
|
/* Aviso para o narrador ler (mensagens de status, erros) */
|
||||||
TB_API void tb_a11y_announce(TinyBlocks_A11yTree* tree, const char* text);
|
TB_API void tb_a11y_announce(TinyBlocks_A11yTree* tree, const char* text);
|
||||||
|
|
||||||
|
|||||||
@@ -199,6 +199,16 @@ void tb_a11y_set_point(TinyBlocks_A11yTree* t, int node, float x, float y) {
|
|||||||
t->nodes[node].py = y;
|
t->nodes[node].py = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tb_a11y_scale_from(TinyBlocks_A11yTree* t, int first, float ox, float oy, float s) {
|
||||||
|
if (!t || first < 0) return;
|
||||||
|
for (int i = first; i < t->n; i++) {
|
||||||
|
TinyBlocks_A11yNode* nd = &t->nodes[i];
|
||||||
|
nd->x = ox + (nd->x - ox) * s; nd->y = oy + (nd->y - oy) * s;
|
||||||
|
nd->px = ox + (nd->px - ox) * s; nd->py = oy + (nd->py - oy) * s;
|
||||||
|
nd->w *= s; nd->h *= s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tb_a11y_announce(TinyBlocks_A11yTree* t, const char* text) {
|
void tb_a11y_announce(TinyBlocks_A11yTree* t, const char* text) {
|
||||||
if (!t || !text || !text[0] || t->announce_n >= 8) return;
|
if (!t || !text || !text[0] || t->announce_n >= 8) return;
|
||||||
scopy(t->announce[t->announce_n++], TB_A11Y_DESC_MAX, text);
|
scopy(t->announce[t->announce_n++], TB_A11Y_DESC_MAX, text);
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ typedef struct {
|
|||||||
} TbBpTab;
|
} TbBpTab;
|
||||||
|
|
||||||
/* -- Blocos compostos (protótipo) --- */
|
/* -- Blocos compostos (protótipo) --- */
|
||||||
typedef enum { TB_BP_PARAM_NUM, TB_BP_PARAM_BOOL, TB_BP_PARAM_LABEL } TbBpParamKind;
|
typedef enum { TB_BP_PARAM_NUM, TB_BP_PARAM_BOOL, TB_BP_PARAM_LABEL,
|
||||||
|
TB_BP_PARAM_NAME /* posicao do nome (sem ela: na frente) */ } TbBpParamKind;
|
||||||
typedef struct { TbBpParamKind kind; char name[32]; } TbBpParam;
|
typedef struct { TbBpParamKind kind; char name[32]; } TbBpParam;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ static const Col COL_CODE_BG TB_EW_UNUSED = C( 40, 44, 52);
|
|||||||
static const Col COL_CODE_GUTTER TB_EW_UNUSED = C( 33, 37, 43);
|
static const Col COL_CODE_GUTTER TB_EW_UNUSED = C( 33, 37, 43);
|
||||||
static const Col COL_CODE_CURLINE TB_EW_UNUSED = C( 51, 57, 67);
|
static const Col COL_CODE_CURLINE TB_EW_UNUSED = C( 51, 57, 67);
|
||||||
static const Col COL_CODE_FOCUS TB_EW_UNUSED = C( 62, 74, 53);
|
static const Col COL_CODE_FOCUS TB_EW_UNUSED = C( 62, 74, 53);
|
||||||
|
static const Col COL_CODE_SEL TB_EW_UNUSED = C( 38, 79,120); /* selecao no editor de codigo */
|
||||||
static const Col COL_CODE_BAR TB_EW_UNUSED = C( 33, 37, 43);
|
static const Col COL_CODE_BAR TB_EW_UNUSED = C( 33, 37, 43);
|
||||||
static const Col COL_CODE_TEXT TB_EW_UNUSED = C(212, 212, 212);
|
static const Col COL_CODE_TEXT TB_EW_UNUSED = C(212, 212, 212);
|
||||||
static const Col COL_TIP_BG TB_EW_UNUSED = C( 37, 37, 38);
|
static const Col COL_TIP_BG TB_EW_UNUSED = C( 37, 37, 38);
|
||||||
@@ -597,6 +598,7 @@ typedef struct Tab {
|
|||||||
int top_cap;
|
int top_cap;
|
||||||
int top_n;
|
int top_n;
|
||||||
float ws_sx, ws_sy;
|
float ws_sx, ws_sy;
|
||||||
|
float ws_zoom; /* escala da area de scripts (0 = 100%) */
|
||||||
char name[48];
|
char name[48];
|
||||||
bool is_composite;
|
bool is_composite;
|
||||||
int comp_id;
|
int comp_id;
|
||||||
@@ -608,6 +610,8 @@ typedef struct Tab {
|
|||||||
char* code_text;
|
char* code_text;
|
||||||
int code_len, code_cap;
|
int code_len, code_cap;
|
||||||
int code_caret; /* posicao do cursor (offset em bytes) */
|
int code_caret; /* posicao do cursor (offset em bytes) */
|
||||||
|
int code_anchor; /* outra ponta da selecao (= caret: sem selecao) */
|
||||||
|
bool code_drag; /* mouse estendendo a selecao */
|
||||||
int code_scroll; /* primeira linha visivel (0-based) */
|
int code_scroll; /* primeira linha visivel (0-based) */
|
||||||
int code_focus; /* linha destacada (1-based), -1 = nenhuma */
|
int code_focus; /* linha destacada (1-based), -1 = nenhuma */
|
||||||
char code_path[256];
|
char code_path[256];
|
||||||
@@ -644,7 +648,8 @@ typedef struct Tab {
|
|||||||
int group_n;
|
int group_n;
|
||||||
} Tab;
|
} Tab;
|
||||||
|
|
||||||
typedef enum { PARAM_NUM, PARAM_BOOL, PARAM_LABEL } ParamKind;
|
/* PARAM_NAME marca onde o nome do bloco aparece; sem ela, o nome vai na frente */
|
||||||
|
typedef enum { PARAM_NUM, PARAM_BOOL, PARAM_LABEL, PARAM_NAME } ParamKind;
|
||||||
|
|
||||||
typedef struct { ParamKind kind; char name[32]; } UserParam;
|
typedef struct { ParamKind kind; char name[32]; } UserParam;
|
||||||
|
|
||||||
@@ -820,14 +825,13 @@ typedef struct Ed {
|
|||||||
int comp_dialog_def; /* -1 = novo; senão índice em user_blocks */
|
int comp_dialog_def; /* -1 = novo; senão índice em user_blocks */
|
||||||
bool comp_dialog_in_tab; /* novo bloco: chapéu "defina" na aba atual */
|
bool comp_dialog_in_tab; /* novo bloco: chapéu "defina" na aba atual */
|
||||||
bool comp_dialog_editing; /* true = edição de nome/rótulo em andamento */
|
bool comp_dialog_editing; /* true = edição de nome/rótulo em andamento */
|
||||||
int comp_dialog_edit_part; /* índice da parte em edição, -1 = nome do bloco */
|
int comp_dialog_edit_part; /* índice da parte em edição (a PARAM_NAME edita o nome) */
|
||||||
char comp_dialog_name[48];
|
char comp_dialog_name[48];
|
||||||
UserParam comp_dialog_parts[MAX_UBLK_PARTS];
|
UserParam comp_dialog_parts[MAX_UBLK_PARTS + 1]; /* + a PARAM_NAME */
|
||||||
int comp_dialog_part_n;
|
int comp_dialog_part_n;
|
||||||
int comp_dialog_sel; /* parte selecionada (-1 = nenhuma) */
|
int comp_dialog_sel; /* parte selecionada (-1 = nenhuma) */
|
||||||
int comp_dialog_color;
|
int comp_dialog_color;
|
||||||
float comp_dialog_geom[MAX_UBLK_PARTS][2]; /* x,w desenhados (para hit test) */
|
float comp_dialog_geom[MAX_UBLK_PARTS + 1][2]; /* x,w desenhados (para hit test) */
|
||||||
float comp_dialog_name_x, comp_dialog_name_w;
|
|
||||||
|
|
||||||
bool ctx_menu_open;
|
bool ctx_menu_open;
|
||||||
bool ctx_export; /* menu de contexto aberto e o de exportacao */
|
bool ctx_export; /* menu de contexto aberto e o de exportacao */
|
||||||
@@ -862,6 +866,8 @@ typedef struct Ed {
|
|||||||
SnapKind snap_kind;
|
SnapKind snap_kind;
|
||||||
int snap_bi, snap_idx;
|
int snap_bi, snap_idx;
|
||||||
float pan_mx, pan_my, pan_sx, pan_sy;
|
float pan_mx, pan_my, pan_sx, pan_sy;
|
||||||
|
bool pinch; /* dois dedos na area de scripts: zoom */
|
||||||
|
float pinch_d0, pinch_z0, pinch_wx, pinch_wy;
|
||||||
|
|
||||||
bool editing;
|
bool editing;
|
||||||
int edit_bi, edit_in;
|
int edit_bi, edit_in;
|
||||||
@@ -1034,8 +1040,38 @@ typedef struct Ed {
|
|||||||
|
|
||||||
/* Servidor MCP: agentes leem e editam as pilhas por ferramentas */
|
/* Servidor MCP: agentes leem e editam as pilhas por ferramentas */
|
||||||
struct TbMcpServer* mcp;
|
struct TbMcpServer* mcp;
|
||||||
|
|
||||||
|
/* Edicao de texto (te_*): o campo em edicao tem cursor e selecao; o
|
||||||
|
editor de codigo tem os dele (code_caret/code_anchor). Alcas e barra
|
||||||
|
de acoes (toque) servem aos dois (te_owner). */
|
||||||
|
unsigned frame_no, draw_no; /* quadros (entrada) e desenhos da principal */
|
||||||
|
bool key_shift, key_ctrl; /* modificadores da tecla/clique atual */
|
||||||
|
char* te_buf; /* campo ligado (NULL = nenhum) */
|
||||||
|
size_t te_cap;
|
||||||
|
bool te_multi; /* aceita quebra de linha */
|
||||||
|
int te_caret, te_anchor; /* selecao = entre os dois (bytes) */
|
||||||
|
unsigned te_frame, te_draw_frame; /* ultimo uso (quadro) / desenho (draw_no) */
|
||||||
|
float te_x, te_y, te_lh, te_fs; /* desenho: x do texto, centro da 1a linha */
|
||||||
|
bool te_ws; /* desenhado na area de scripts (zoom) */
|
||||||
|
bool ws_drawing; /* desenhando a area de scripts agora */
|
||||||
|
int te_owner; /* TE_FIELD / TE_CODE */
|
||||||
|
bool te_drag; /* mouse estendendo a selecao */
|
||||||
|
bool te_handles; /* toque: alcas + barra de acoes */
|
||||||
|
int te_handle_drag; /* alca arrastada (0 = inicio, 1 = fim) */
|
||||||
|
bool te_press; /* dedo apertou no texto (segurar = palavra) */
|
||||||
|
bool te_eat_up; /* o soltar deste toque ja foi tratado */
|
||||||
|
int te_press_owner;
|
||||||
|
float te_press_x, te_press_y;
|
||||||
|
unsigned te_press_t;
|
||||||
|
unsigned te_click_t; /* clique duplo = palavra */
|
||||||
|
float te_click_x, te_click_y;
|
||||||
|
bool te_hvis; /* alcas desenhadas neste quadro */
|
||||||
|
float te_hx[2], te_hy[2]; /* ponta de cima de cada alca (tela) */
|
||||||
|
float te_bar_x, te_bar_y, te_bar_w; /* barra Recortar/Copiar/Colar/Tudo */
|
||||||
} Ed;
|
} Ed;
|
||||||
|
|
||||||
|
enum { TE_NONE, TE_FIELD, TE_CODE };
|
||||||
|
|
||||||
static inline TinyBlocks_A11yTree* ed_ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; }
|
static inline TinyBlocks_A11yTree* ed_ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; }
|
||||||
|
|
||||||
#define CT (ed->tabs[ed->cur_tab])
|
#define CT (ed->tabs[ed->cur_tab])
|
||||||
@@ -1049,6 +1085,13 @@ void bubble_clear(Ed* ed);
|
|||||||
void palette_rebuild(Ed* ed);
|
void palette_rebuild(Ed* ed);
|
||||||
void utf8_pop(char* s);
|
void utf8_pop(char* s);
|
||||||
void append_text(char* dst, size_t cap, const char* add);
|
void append_text(char* dst, size_t cap, const char* add);
|
||||||
|
/* Campo de texto em edicao (cursor, selecao, Ctrl+A/C/X/V): as teclas e o
|
||||||
|
texto vao para te_key/te_insert e quem desenha chama te_draw depois do
|
||||||
|
texto (x = inicio do texto, cy = centro da 1a linha, lh = altura da linha) */
|
||||||
|
bool te_key(Ed* ed, char* buf, size_t cap, int sc, bool multi);
|
||||||
|
void te_insert(Ed* ed, char* buf, size_t cap, const char* s, bool multi);
|
||||||
|
void te_draw(Ed* ed, TinyBlocks_RenderableBlock* rb, char* buf, size_t cap, bool multi,
|
||||||
|
float x, float cy, float lh, float fs, Col caret);
|
||||||
void dlg_open(Ed* ed, int def_idx);
|
void dlg_open(Ed* ed, int def_idx);
|
||||||
void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb);
|
void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb);
|
||||||
bool dlg_click(Ed* ed, float mx, float my);
|
bool dlg_click(Ed* ed, float mx, float my);
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -82,7 +82,9 @@ enum {
|
|||||||
#define GFX_IN_MOUSE_IN 25 /* int: 1 se o mouse está sobre esta janela */
|
#define GFX_IN_MOUSE_IN 25 /* int: 1 se o mouse está sobre esta janela */
|
||||||
#define GFX_IN_GMOUSE_X 26 /* real: mouse na tela (global), x */
|
#define GFX_IN_GMOUSE_X 26 /* real: mouse na tela (global), x */
|
||||||
#define GFX_IN_GMOUSE_Y 27 /* real: mouse na tela (global), y */
|
#define GFX_IN_GMOUSE_Y 27 /* real: mouse na tela (global), y */
|
||||||
#define GFX_IN_COUNT 28
|
#define GFX_IN_ZOOM 28 /* real: pinça do touchpad neste frame (fator; *
|
||||||
|
* 0 = nenhuma, >1 aproxima) */
|
||||||
|
#define GFX_IN_COUNT 29
|
||||||
|
|
||||||
#define GFX_MAX_TOUCHES 10
|
#define GFX_MAX_TOUCHES 10
|
||||||
|
|
||||||
@@ -107,6 +109,7 @@ typedef struct TinyBlocks_GfxInput {
|
|||||||
int win_x, win_y; /* posicao da janela na tela */
|
int win_x, win_y; /* posicao da janela na tela */
|
||||||
int mouse_in; /* o mouse esta sobre esta janela */
|
int mouse_in; /* o mouse esta sobre esta janela */
|
||||||
float gmouse_x, gmouse_y; /* mouse na tela (coordenadas globais) */
|
float gmouse_x, gmouse_y; /* mouse na tela (coordenadas globais) */
|
||||||
|
float zoom; /* pinca do touchpad: fator (0 = nenhuma) */
|
||||||
} TinyBlocks_GfxInput;
|
} TinyBlocks_GfxInput;
|
||||||
|
|
||||||
/* -- Contrato de um backend gráfico --- */
|
/* -- Contrato de um backend gráfico --- */
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ static const TinyBlocks_SlotDesc s_input_outs[GFX_IN_COUNT] = {
|
|||||||
{"win_x", TB_VALUE_INTEGER}, {"win_y", TB_VALUE_INTEGER},
|
{"win_x", TB_VALUE_INTEGER}, {"win_y", TB_VALUE_INTEGER},
|
||||||
{"mouse_in", TB_VALUE_INTEGER},
|
{"mouse_in", TB_VALUE_INTEGER},
|
||||||
{"gmouse_x", TB_VALUE_REAL}, {"gmouse_y", TB_VALUE_REAL},
|
{"gmouse_x", TB_VALUE_REAL}, {"gmouse_y", TB_VALUE_REAL},
|
||||||
|
{"zoom", TB_VALUE_REAL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void eval_input(TinyBlocks_Block* self, TinyBlocks* rt) {
|
static void eval_input(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||||
@@ -279,6 +280,7 @@ static void input_push(TinyBlocks_Block* b, const TinyBlocks_GfxInput* in) {
|
|||||||
SET(GFX_IN_MOUSE_IN, tb_value_integer(in->mouse_in));
|
SET(GFX_IN_MOUSE_IN, tb_value_integer(in->mouse_in));
|
||||||
SET(GFX_IN_GMOUSE_X, tb_value_real(in->gmouse_x));
|
SET(GFX_IN_GMOUSE_X, tb_value_real(in->gmouse_x));
|
||||||
SET(GFX_IN_GMOUSE_Y, tb_value_real(in->gmouse_y));
|
SET(GFX_IN_GMOUSE_Y, tb_value_real(in->gmouse_y));
|
||||||
|
SET(GFX_IN_ZOOM, tb_value_real(in->zoom));
|
||||||
#undef SET
|
#undef SET
|
||||||
b->dirty = false;
|
b->dirty = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,10 +76,10 @@ static void eval_handle_noop(TinyBlocks_Block* self, TinyBlocks* rt) {
|
|||||||
/* ===
|
/* ===
|
||||||
* Fonte TTF - cache por tamanho
|
* Fonte TTF - cache por tamanho
|
||||||
* === */
|
* === */
|
||||||
#define FONT_CACHE_CAP 8
|
#define FONT_CACHE_CAP 64 /* o zoom da area de scripts pede muitos tamanhos */
|
||||||
#define FONT_SEARCH_COUNT 9
|
#define FONT_SEARCH_COUNT 9
|
||||||
|
|
||||||
typedef struct { int size; TTF_Font* font; } FontEntry;
|
typedef struct { int size; TTF_Font* font; unsigned used; } FontEntry;
|
||||||
|
|
||||||
static FontEntry s_font_cache[FONT_CACHE_CAP];
|
static FontEntry s_font_cache[FONT_CACHE_CAP];
|
||||||
static int s_font_cache_n = 0;
|
static int s_font_cache_n = 0;
|
||||||
@@ -114,18 +114,27 @@ static TTF_Font* bundled_font(int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static TTF_Font* get_font(int size) {
|
static TTF_Font* get_font(int size) {
|
||||||
|
static unsigned tick = 0;
|
||||||
|
tick++;
|
||||||
for (int i = 0; i < s_font_cache_n; i++)
|
for (int i = 0; i < s_font_cache_n; i++)
|
||||||
if (s_font_cache[i].size == size) return s_font_cache[i].font;
|
if (s_font_cache[i].size == size) { s_font_cache[i].used = tick; return s_font_cache[i].font; }
|
||||||
|
|
||||||
TTF_Font* f = bundled_font(size);
|
TTF_Font* f = bundled_font(size);
|
||||||
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++)
|
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++)
|
||||||
f = TTF_OpenFont(s_font_paths[i], size);
|
f = TTF_OpenFont(s_font_paths[i], size);
|
||||||
|
if (!f) return NULL;
|
||||||
|
|
||||||
if (f && s_font_cache_n < FONT_CACHE_CAP) {
|
/* cheio: fecha o usado ha mais tempo (antes vazava uma fonte por chamada) */
|
||||||
s_font_cache[s_font_cache_n].size = size;
|
int slot = s_font_cache_n;
|
||||||
s_font_cache[s_font_cache_n].font = f;
|
if (slot >= FONT_CACHE_CAP) {
|
||||||
s_font_cache_n++;
|
slot = 0;
|
||||||
}
|
for (int i = 1; i < FONT_CACHE_CAP; i++)
|
||||||
|
if (s_font_cache[i].used < s_font_cache[slot].used) slot = i;
|
||||||
|
TTF_CloseFont(s_font_cache[slot].font);
|
||||||
|
} else s_font_cache_n++;
|
||||||
|
s_font_cache[slot].size = size;
|
||||||
|
s_font_cache[slot].font = f;
|
||||||
|
s_font_cache[slot].used = tick;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,12 +465,104 @@ typedef struct SdlWin {
|
|||||||
Uint32 id;
|
Uint32 id;
|
||||||
TinyBlocks_GfxInput in;
|
TinyBlocks_GfxInput in;
|
||||||
int pos_fresh; /* posicao do mouse veio de um evento neste quadro */
|
int pos_fresh; /* posicao do mouse veio de um evento neste quadro */
|
||||||
|
unsigned long xwin; /* janela X11 (0 fora do X11) */
|
||||||
|
float pinch_acc; /* pinca do touchpad acumulada (fator; 0 = nenhuma) */
|
||||||
|
float pinch_last; /* escala do gesto no evento anterior */
|
||||||
struct SdlWin* next;
|
struct SdlWin* next;
|
||||||
} SdlWin;
|
} SdlWin;
|
||||||
|
|
||||||
static SdlWin* s_wins = NULL;
|
static SdlWin* s_wins = NULL;
|
||||||
static bool s_be_inited = false;
|
static bool s_be_inited = false;
|
||||||
|
|
||||||
|
/* ===
|
||||||
|
* Pinca do touchpad no X11: o SDL2 nao repassa os gestos do XInput 2.4, entao
|
||||||
|
* a janela os pede (XISelectEvents) e um observador de eventos le o
|
||||||
|
* SDL_SYSWMEVENT enquanto o cookie ainda tem os dados. libXi/libX11 vem por
|
||||||
|
* dlopen (o SDL ja os carregou); sem eles, ou fora do X11, nada muda.
|
||||||
|
* === */
|
||||||
|
#if defined(__linux__) && !defined(__ANDROID__) && defined(__has_include)
|
||||||
|
#if __has_include(<X11/extensions/XInput2.h>)
|
||||||
|
#define TB_XI_GESTURES 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TB_XI_GESTURES
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <SDL2/SDL_syswm.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/extensions/XInput2.h>
|
||||||
|
|
||||||
|
static int s_xi_state = 0; /* 0 = nao tentado, 1 = ok, -1 = indisponivel */
|
||||||
|
static int s_xi_opcode = 0;
|
||||||
|
static int (*p_XISelectEvents)(Display*, Window, XIEventMask*, int);
|
||||||
|
|
||||||
|
static int SDLCALL xi_watch(void* user, SDL_Event* e) {
|
||||||
|
(void)user;
|
||||||
|
if (e->type != SDL_SYSWMEVENT || !e->syswm.msg || e->syswm.msg->subsystem != SDL_SYSWM_X11) return 1;
|
||||||
|
XGenericEventCookie* ck = &e->syswm.msg->msg.x11.event.xcookie;
|
||||||
|
if (ck->type != GenericEvent || ck->extension != s_xi_opcode || !ck->data) return 1;
|
||||||
|
if (ck->evtype < XI_GesturePinchBegin || ck->evtype > XI_GesturePinchEnd) return 1;
|
||||||
|
const XIGesturePinchEvent* g = (const XIGesturePinchEvent*)ck->data;
|
||||||
|
for (SdlWin* w = s_wins; w; w = w->next) {
|
||||||
|
if (w->xwin != (unsigned long)g->event) continue;
|
||||||
|
if (ck->evtype == XI_GesturePinchBegin) { w->pinch_last = 1.f; break; }
|
||||||
|
float sc = (float)g->scale;
|
||||||
|
if (sc > 0.f && w->pinch_last > 0.f) {
|
||||||
|
w->pinch_acc = (w->pinch_acc > 0.f ? w->pinch_acc : 1.f) * (sc / w->pinch_last);
|
||||||
|
w->pinch_last = sc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dlsym -> ponteiro de funcao sem cast fora do padrao */
|
||||||
|
static void sym_fn(void* dst, void* lib, const char* name) {
|
||||||
|
void* p = dlsym(lib, name);
|
||||||
|
memcpy(dst, &p, sizeof(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool xi_init(Display* dpy) {
|
||||||
|
if (s_xi_state) return s_xi_state > 0;
|
||||||
|
s_xi_state = -1;
|
||||||
|
void* xi = dlopen("libXi.so.6", RTLD_NOW | RTLD_LOCAL);
|
||||||
|
void* x11 = dlopen("libX11.so.6", RTLD_NOW | RTLD_LOCAL);
|
||||||
|
if (!xi || !x11) return false;
|
||||||
|
Bool (*q_ext)(Display*, const char*, int*, int*, int*);
|
||||||
|
Status (*q_ver)(Display*, int*, int*);
|
||||||
|
sym_fn(&q_ext, x11, "XQueryExtension");
|
||||||
|
sym_fn(&q_ver, xi, "XIQueryVersion");
|
||||||
|
sym_fn(&p_XISelectEvents, xi, "XISelectEvents");
|
||||||
|
int ev, err, major = 2, minor = 4;
|
||||||
|
if (!q_ext || !q_ver || !p_XISelectEvents) return false;
|
||||||
|
if (!q_ext(dpy, "XInputExtension", &s_xi_opcode, &ev, &err)) return false;
|
||||||
|
if (q_ver(dpy, &major, &minor) != Success || major < 2 || (major == 2 && minor < 4)) return false;
|
||||||
|
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
|
||||||
|
SDL_AddEventWatch(xi_watch, NULL);
|
||||||
|
s_xi_state = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pede os gestos de pinca na janela. A mascara substitui a que o SDL pos
|
||||||
|
(toque), entao os eventos de toque vao junto. */
|
||||||
|
static void xi_select(SdlWin* sw) {
|
||||||
|
SDL_SysWMinfo info;
|
||||||
|
SDL_VERSION(&info.version);
|
||||||
|
if (!SDL_GetWindowWMInfo(sw->win, &info) || info.subsystem != SDL_SYSWM_X11) return;
|
||||||
|
Display* dpy = info.info.x11.display;
|
||||||
|
if (!xi_init(dpy)) return;
|
||||||
|
unsigned char bits[XIMaskLen(XI_GesturePinchEnd)] = {0};
|
||||||
|
XISetMask(bits, XI_TouchBegin); XISetMask(bits, XI_TouchUpdate); XISetMask(bits, XI_TouchEnd);
|
||||||
|
XISetMask(bits, XI_GesturePinchBegin); XISetMask(bits, XI_GesturePinchUpdate);
|
||||||
|
XISetMask(bits, XI_GesturePinchEnd);
|
||||||
|
XIEventMask m = { XIAllMasterDevices, (int)sizeof(bits), bits };
|
||||||
|
p_XISelectEvents(dpy, info.info.x11.window, &m, 1);
|
||||||
|
sw->xwin = (unsigned long)info.info.x11.window;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void xi_select(SdlWin* sw) { (void)sw; }
|
||||||
|
#endif
|
||||||
|
|
||||||
static int map_key(SDL_Scancode sc) {
|
static int map_key(SDL_Scancode sc) {
|
||||||
if (sc >= SDL_SCANCODE_A && sc <= SDL_SCANCODE_Z) return TB_KEY_A + (sc - SDL_SCANCODE_A);
|
if (sc >= SDL_SCANCODE_A && sc <= SDL_SCANCODE_Z) return TB_KEY_A + (sc - SDL_SCANCODE_A);
|
||||||
if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_9) return TB_KEY_0 + 1 + (sc - SDL_SCANCODE_1);
|
if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_9) return TB_KEY_0 + 1 + (sc - SDL_SCANCODE_1);
|
||||||
@@ -578,6 +679,7 @@ static void* be_window_open(const char* title, int w, int h) {
|
|||||||
sw->in.win_w = w; sw->in.win_h = h;
|
sw->in.win_w = w; sw->in.win_h = h;
|
||||||
sw->next = s_wins;
|
sw->next = s_wins;
|
||||||
s_wins = sw;
|
s_wins = sw;
|
||||||
|
xi_select(sw);
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,6 +778,10 @@ static void be_poll(void) {
|
|||||||
while (!s_has_pending && SDL_PollEvent(&ev)) {
|
while (!s_has_pending && SDL_PollEvent(&ev)) {
|
||||||
if (!be_apply(&ev)) { s_pending = ev; s_has_pending = true; }
|
if (!be_apply(&ev)) { s_pending = ev; s_has_pending = true; }
|
||||||
}
|
}
|
||||||
|
for (SdlWin* w = s_wins; w; w = w->next) { /* pinca do touchpad (xi_watch) */
|
||||||
|
w->in.zoom = w->pinch_acc;
|
||||||
|
w->pinch_acc = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
/* Dispositivo: teclas seguradas (janela com o foco do teclado), dedos na
|
/* Dispositivo: teclas seguradas (janela com o foco do teclado), dedos na
|
||||||
tela e sensores (todas as janelas) */
|
tela e sensores (todas as janelas) */
|
||||||
|
|||||||
@@ -50,6 +50,24 @@ static void draw(void) {
|
|||||||
|
|
||||||
static float g_scroll_dy = 0.f;
|
static float g_scroll_dy = 0.f;
|
||||||
static int g_win_w = 1280, g_win_h = 720;
|
static int g_win_w = 1280, g_win_h = 720;
|
||||||
|
static int g_l_held = 0; /* botao/dedo segurado (GFX_IN_MOUSE_L_HELD) */
|
||||||
|
static float g_zoom = 0.f; /* pinca do touchpad (GFX_IN_ZOOM) */
|
||||||
|
static int g_touch_n = 0; /* dedos na tela (pinca) */
|
||||||
|
static float g_touch[2][2];
|
||||||
|
static TinyBlocks_Value touches_json(void) {
|
||||||
|
TinyBlocks_JsonValue* arr = tb_json_array();
|
||||||
|
for (int i = 0; arr && i < g_touch_n; i++) {
|
||||||
|
TinyBlocks_JsonValue* p = tb_json_array();
|
||||||
|
for (int k = 0; p && k < 2; k++) {
|
||||||
|
TinyBlocks_JsonValue* n = tb_json_number(g_touch[i][k]);
|
||||||
|
if (n) { tb_json_array_push(p, n); tb_json_release(n); }
|
||||||
|
}
|
||||||
|
if (p) { tb_json_array_push(arr, p); tb_json_release(p); }
|
||||||
|
}
|
||||||
|
TinyBlocks_Value v = tb_value_json(arr);
|
||||||
|
tb_json_release(arr);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char* text) {
|
static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char* text) {
|
||||||
tb_block_set_output(ev, GFX_IN_MOUSE_X, tb_value_real(mx));
|
tb_block_set_output(ev, GFX_IN_MOUSE_X, tb_value_real(mx));
|
||||||
tb_block_set_output(ev, GFX_IN_MOUSE_Y, tb_value_real(my));
|
tb_block_set_output(ev, GFX_IN_MOUSE_Y, tb_value_real(my));
|
||||||
@@ -65,9 +83,13 @@ static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char
|
|||||||
tb_block_set_output(ev, GFX_IN_SCROLL_DY, tb_value_real(g_scroll_dy));
|
tb_block_set_output(ev, GFX_IN_SCROLL_DY, tb_value_real(g_scroll_dy));
|
||||||
tb_block_set_output(ev, GFX_IN_WIN_W, tb_value_integer(g_win_w));
|
tb_block_set_output(ev, GFX_IN_WIN_W, tb_value_integer(g_win_w));
|
||||||
tb_block_set_output(ev, GFX_IN_WIN_H, tb_value_integer(g_win_h));
|
tb_block_set_output(ev, GFX_IN_WIN_H, tb_value_integer(g_win_h));
|
||||||
|
tb_block_set_output(ev, GFX_IN_TOUCHES, touches_json());
|
||||||
|
tb_block_set_output(ev, GFX_IN_ZOOM, tb_value_real(g_zoom));
|
||||||
|
tb_block_set_output(ev, GFX_IN_MOUSE_L_HELD, tb_value_integer(g_l_held));
|
||||||
tb_block_eval(scene, rt);
|
tb_block_eval(scene, rt);
|
||||||
draw();
|
draw();
|
||||||
g_scroll_dy = 0.f;
|
g_scroll_dy = 0.f;
|
||||||
|
g_zoom = 0.f;
|
||||||
}
|
}
|
||||||
/* == Interface de acessibilidade: componentes por papel + nome ===
|
/* == Interface de acessibilidade: componentes por papel + nome ===
|
||||||
* (nao depende do texto desenhado nem de coordenadas fixas) */
|
* (nao depende do texto desenhado nem de coordenadas fixas) */
|
||||||
@@ -829,6 +851,27 @@ int main(void) {
|
|||||||
CHECK(drawn_text(ws(), "42"), "aba de código realça o número 42");
|
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(ws(), ";"), "aba de código realça a pontuação");
|
||||||
CHECK(!drawn_text(0, "</code>") && !any_has("</code>"), "aba de código não mostra a marcação </code>");
|
CHECK(!drawn_text(0, "</code>") && !any_has("</code>"), "aba de código não mostra a marcação </code>");
|
||||||
|
/* seleção e área de transferência no editor de código */
|
||||||
|
mods(TB_MOD_SHIFT); key(TB_KEY_HOME, 0, 0); mods(0);
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('c' - 'a'), 0, 0); mods(0);
|
||||||
|
key(TB_KEY_END, 0, 0); key(TB_KEY_RETURN, 0, 0);
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('v' - 'a'), 0, 0); mods(0);
|
||||||
|
/* o valor acessível é a linha do cursor; a descrição diz qual */
|
||||||
|
#define CODE_LINE ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Código"))
|
||||||
|
#define CODE_DESC N(ax_in(0, TB_A11Y_TEXT_FIELD, "Código"))->description
|
||||||
|
CHECK(!strcmp(CODE_LINE, "int x = 42;") && !strncmp(CODE_DESC, "linha 2 ", 8),
|
||||||
|
"código: Shift+Home seleciona, Ctrl+C / Ctrl+V duplicam a linha");
|
||||||
|
mods(TB_MOD_SHIFT); key(TB_KEY_LEFT, 0, 0); key(TB_KEY_LEFT, 0, 0); key(TB_KEY_LEFT, 0, 0); mods(0);
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('x' - 'a'), 0, 0); mods(0);
|
||||||
|
type("7;");
|
||||||
|
CHECK(!strcmp(CODE_LINE, "int x = 7;"), "código: Ctrl+X recorta a seleção e digitar substitui");
|
||||||
|
key(TB_KEY_UP, 0, 0);
|
||||||
|
CHECK(!strcmp(CODE_LINE, "int x = 42;") && !strncmp(CODE_DESC, "linha 1 ", 8), "código: a 1ª linha ficou igual");
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('a' - 'a'), 0, 0); mods(0);
|
||||||
|
type("ok");
|
||||||
|
CHECK(!strcmp(CODE_LINE, "ok") && !strncmp(CODE_DESC, "linha 1 ", 8), "código: Ctrl+A seleciona tudo");
|
||||||
|
#undef CODE_LINE
|
||||||
|
#undef CODE_DESC
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 23. Botão "+" -> nova aba: Edição de Imagem */
|
/* 23. Botão "+" -> nova aba: Edição de Imagem */
|
||||||
@@ -1495,6 +1538,172 @@ int main(void) {
|
|||||||
CHECK(pane("Palco") >= 0 && pane("Scripts") >= 0 && pane("Blocos") >= 0, "janela larga volta ao layout de áreas");
|
CHECK(pane("Palco") >= 0 && pane("Scripts") >= 0 && pane("Blocos") >= 0, "janela larga volta ao layout de áreas");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 32. Zoom da area de scripts: roda do mouse (ancorada no ponteiro) e
|
||||||
|
* pinca com dois dedos; clique/arrasto continuam acertando o bloco */
|
||||||
|
{
|
||||||
|
int b = ws_block("sempre", 0);
|
||||||
|
const TinyBlocks_A11yNode* n0 = b >= 0 ? N(b) : NULL;
|
||||||
|
float w0 = n0 ? n0->w : 0, px = 0, py = 0;
|
||||||
|
if (b >= 0) tb_a11y_point(A(), b, &px, &py);
|
||||||
|
CHECK(b >= 0 && w0 > 0, "zoom: bloco na área de scripts");
|
||||||
|
float bx0 = b >= 0 ? N(b)->x : 0, by0 = b >= 0 ? N(b)->y : 0;
|
||||||
|
g_scroll_dy = 1.f; /* roda sozinha: rola na vertical */
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
b = ws_block("sempre", 0);
|
||||||
|
CHECK(b >= 0 && fabsf(N(b)->y - (by0 + 40.f)) < 0.5f && fabsf(N(b)->x - bx0) < 0.5f && N(b)->w == w0,
|
||||||
|
"roda: desloca na vertical, sem zoom");
|
||||||
|
mods(TB_MOD_SHIFT); /* Shift+roda: horizontal */
|
||||||
|
g_scroll_dy = -1.f;
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
mods(0);
|
||||||
|
b = ws_block("sempre", 0);
|
||||||
|
CHECK(b >= 0 && fabsf(N(b)->x - (bx0 - 40.f)) < 0.5f && fabsf(N(b)->y - (by0 + 40.f)) < 0.5f,
|
||||||
|
"Shift+roda: desloca na horizontal");
|
||||||
|
g_scroll_dy = -1.f; /* volta ao lugar */
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
mods(TB_MOD_SHIFT); g_scroll_dy = 1.f;
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
mods(TB_MOD_CTRL); /* Ctrl+roda: zoom */
|
||||||
|
g_scroll_dy = 3.f;
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
mods(0);
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
b = ws_block("sempre", 0);
|
||||||
|
float r = b >= 0 ? N(b)->w / w0 : 0;
|
||||||
|
CHECK(fabsf(r - 1.331f) < 0.01f, "Ctrl+roda para cima aproxima (1,1 por passo)");
|
||||||
|
float qx = 0, qy = 0;
|
||||||
|
if (b >= 0) tb_a11y_point(A(), b, &qx, &qy);
|
||||||
|
CHECK(fabsf(qx - px) < 1.f && fabsf(qy - py) < 1.f, "zoom: o ponto sob o ponteiro fica parado");
|
||||||
|
float x0 = b >= 0 ? N(b)->x : 0;
|
||||||
|
drag(qx, qy, qx + 60, qy + 30); /* arrasto com zoom: acompanha o mouse */
|
||||||
|
b = ws_block("sempre", 0);
|
||||||
|
CHECK(b >= 0 && fabsf(N(b)->x - (x0 + 60)) < 1.f, "zoom: arrastar o bloco segue o ponteiro");
|
||||||
|
|
||||||
|
/* pinca: os dedos se afastam ao dobro -> zoom dobra */
|
||||||
|
tb_a11y_point(A(), b, &px, &py);
|
||||||
|
float w1 = N(b)->w;
|
||||||
|
g_touch_n = 2;
|
||||||
|
g_touch[0][0] = px - 30; g_touch[0][1] = py;
|
||||||
|
g_touch[1][0] = px + 30; g_touch[1][1] = py;
|
||||||
|
frame(px - 30, py, 1, 0, 0, 0, NULL);
|
||||||
|
g_touch[0][0] = px - 45; g_touch[1][0] = px + 45;
|
||||||
|
frame(px - 45, py, 0, 0, 0, 0, NULL);
|
||||||
|
g_touch[0][0] = px - 60; g_touch[1][0] = px + 60;
|
||||||
|
frame(px - 60, py, 0, 0, 0, 0, NULL);
|
||||||
|
b = ws_block("sempre", 0);
|
||||||
|
r = b >= 0 ? N(b)->w / w1 : 0;
|
||||||
|
CHECK(fabsf(r - 2.f) < 0.02f, "pinça: afastar os dedos aproxima");
|
||||||
|
tb_a11y_point(A(), b, &qx, &qy);
|
||||||
|
CHECK(fabsf(qx - px) < 1.f, "pinça: ancorada no meio dos dedos");
|
||||||
|
g_touch_n = 0;
|
||||||
|
frame(px - 60, py, 0, 1, 0, 0, NULL);
|
||||||
|
CHECK(ax_in(0, TB_A11Y_MENU, NULL) < 0 && fabsf(N(ws_block("sempre", 0))->w / w1 - 2.f) < 0.02f,
|
||||||
|
"pinça: soltar não abre menu nem mexe");
|
||||||
|
g_zoom = 0.5f; /* pinca do touchpad: fecha pela metade */
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
CHECK(fabsf(N(ws_block("sempre", 0))->w / w1 - 1.f) < 0.02f, "pinça no touchpad: afasta pelo fator");
|
||||||
|
mods(TB_MOD_CTRL);
|
||||||
|
g_scroll_dy = -40.f; /* afasta ate o minimo */
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
mods(0);
|
||||||
|
frame(px, py, 0, 0, 0, 0, NULL);
|
||||||
|
CHECK(fabsf(N(ws_block("sempre", 0))->w / w0 - 0.3f) < 0.01f, "zoom: mínimo de 30%");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 33. Diálogo de bloco: o campo do nome também se apaga (o rótulo
|
||||||
|
* seguinte vira o nome); sozinho, sem rótulo depois, não */
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
type("a");
|
||||||
|
ax_do(ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
CHECK(ax_in(dlg, TB_A11Y_BUTTON, "Apagar a parte") < 0, "nome sozinho: sem lixeira (o bloco precisa de nome)");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Adicionar rótulo"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
type("vezes");
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
int nome = ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco");
|
||||||
|
CHECK(nome >= 0 && (N(nome)->states & TB_A11Y_SELECTED), "clicar no nome seleciona o campo");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Apagar a parte"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
CHECK(!strcmp(ax_value(ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco")), "vezes") &&
|
||||||
|
ax_in(dlg, TB_A11Y_TEXT_FIELD, "Rótulo") < 0, "apagar o nome: o rótulo seguinte vira o nome");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Cancelar"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
|
||||||
|
/* reordenar: o rótulo passa para a frente do nome */
|
||||||
|
ax_do(ax_need(pal(), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
type("girar");
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Adicionar entrada de número ou texto"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
type("g");
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Adicionar rótulo"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
type("vezes");
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Mover para a esquerda"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Mover para a esquerda"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
int proto = ax_in(dlg, TB_A11Y_BLOCK, "Protótipo");
|
||||||
|
int first = proto >= 0 ? tb_a11y_find(A(), proto, TB_A11Y_TEXT_FIELD, NULL, 0) : -1;
|
||||||
|
CHECK(first >= 0 && !strcmp(N(first)->name, "Rótulo"), "mover para a esquerda passa o rótulo à frente do nome");
|
||||||
|
/* o nome também se move: vai para o fim */
|
||||||
|
ax_do(ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "Mover para a direita"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
dlg = ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
||||||
|
ax_do(ax_need(dlg, TB_A11Y_BUTTON, "OK"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||||
|
cat("Meus Blocos");
|
||||||
|
CHECK(ax_in(ax_in(pal(), TB_A11Y_GROUP, "Meus Blocos"), TB_A11Y_BLOCK, "vezes (g) girar") >= 0,
|
||||||
|
"bloco com o nome no fim: \"vezes (g) girar\"");
|
||||||
|
CHECK(ax_part(ws(), TB_A11Y_BLOCK, "defina vezes (g) girar") >= 0, "o defina segue a mesma ordem");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 34. Campos de texto: cursor, seleção, Ctrl+A/C/X/V e, no toque,
|
||||||
|
* segurar seleciona a palavra e mostra a barra Recortar/Copiar/... */
|
||||||
|
{
|
||||||
|
cat("Meus Blocos");
|
||||||
|
ax_do(ax_need(pal(), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
type("abc def");
|
||||||
|
#define NOME ax_value(ax_in(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_TEXT_FIELD, "Nome do bloco"))
|
||||||
|
mods(TB_MOD_SHIFT); for (int i = 0; i < 3; i++) key(TB_KEY_LEFT, 0, 0); mods(0);
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('c' - 'a'), 0, 0); mods(0);
|
||||||
|
key(TB_KEY_END, 0, 0);
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('v' - 'a'), 0, 0); mods(0);
|
||||||
|
CHECK(!strcmp(NOME, "abc defdef"), "campo: Shift+← seleciona, Ctrl+C e Ctrl+V colam no cursor");
|
||||||
|
key(TB_KEY_HOME, 0, 0); type("X");
|
||||||
|
CHECK(!strcmp(NOME, "Xabc defdef"), "campo: Home leva o cursor ao começo e digitar insere ali");
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('a' - 'a'), 0, 0); key(TB_KEY_A + ('x' - 'a'), 0, 0); mods(0);
|
||||||
|
CHECK(!strcmp(NOME, ""), "campo: Ctrl+A + Ctrl+X recortam tudo");
|
||||||
|
mods(TB_MOD_CTRL); key(TB_KEY_A + ('v' - 'a'), 0, 0); mods(0);
|
||||||
|
CHECK(!strcmp(NOME, "Xabc defdef"), "campo: Ctrl+V cola de volta");
|
||||||
|
mods(TB_MOD_SHIFT); key(TB_KEY_LEFT, 0, 0); mods(0);
|
||||||
|
key(TB_KEY_BACKSPACE, 0, 0);
|
||||||
|
CHECK(!strcmp(NOME, "Xabc defde"), "campo: Backspace apaga a seleção");
|
||||||
|
|
||||||
|
/* toque: segurar o dedo na palavra "defde" (lado direito do campo) */
|
||||||
|
int nome = ax_in(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_TEXT_FIELD, "Nome do bloco");
|
||||||
|
float fx = N(nome)->x + N(nome)->w * 0.5f + 20.f, fy = N(nome)->y + N(nome)->h * 0.5f;
|
||||||
|
g_touch_n = 1; g_touch[0][0] = fx; g_touch[0][1] = fy; g_l_held = 1;
|
||||||
|
frame(fx, fy, 1, 0, 0, 0, NULL);
|
||||||
|
usleep(620 * 1000);
|
||||||
|
frame(fx, fy, 0, 0, 0, 0, NULL);
|
||||||
|
frame(fx, fy, 0, 0, 0, 0, NULL);
|
||||||
|
g_touch_n = 0; g_l_held = 0;
|
||||||
|
frame(fx, fy, 0, 1, 0, 0, NULL);
|
||||||
|
int bar = ax_in(0, TB_A11Y_TOOLBAR, "Seleção");
|
||||||
|
CHECK(bar >= 0 && ax_in(bar, TB_A11Y_BUTTON, "Copiar") >= 0 && ax_in(bar, TB_A11Y_BUTTON, "Colar") >= 0,
|
||||||
|
"toque: segurar no texto mostra a barra Recortar/Copiar/Colar/Selecionar tudo");
|
||||||
|
CHECK(!strcmp(NOME, "Xabc defde"), "toque: soltar depois de segurar não muda o texto");
|
||||||
|
ax_do(ax_in(bar, TB_A11Y_BUTTON, "Recortar"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
CHECK(!strcmp(NOME, "Xabc "), "toque: Recortar tira a palavra segurada");
|
||||||
|
#undef NOME
|
||||||
|
ax_do(ax_need(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_BUTTON, "Cancelar"), TB_A11Y_ACT_ACTIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
tinyblocks_deinit(&rt);
|
tinyblocks_deinit(&rt);
|
||||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||||
return fails != 0;
|
return fails != 0;
|
||||||
|
|||||||
Reference in new issue
Block a user