editor: Sensores, avisos flutuantes, áreas e abas destacáveis (estilo Blender/navegador)
Sensores (tinyblocks-input, categoria Sensores) - Mouse (posição no palco, botões, rolagem), teclas seguradas e última tecla, toques, acelerômetro, giroscópio e cronômetro. - Estado no core (tinyblocks/tb_input.h), alimentado pelo editor em coordenadas do palco (tb_stage_view_to_stage); o graphics passa teclas seguradas, toques e sensores (saídas JSON do Graphics.Input) e o backend SDL2 os lê (SDL_GetKeyboardState, toque, SDL_Sensor). - test-input + cenário no harness. Avisos flutuantes (estilo EditorToaster do Godot) - Mensagens de status viram avisos no canto da área de scripts, com barra de tempo, pausa com o mouse em cima, "x" para fechar e contador para repetidas. O menu fica só com os botões. Áreas (estilo Blender) - Layout em árvore de divisões (paleta, scripts, palco, saída): bordas arrastáveis, alça para trocar views de lugar, destacar qualquer view numa janela própria (cena Editor.Area) e voltar pelo menu ou fechando a janela; blocos podem ser arrastados entre janelas. - Layout salvo em "editor.layout" nas configurações. - Coluna de categorias se compacta para caber. Abas (estilo navegador) - Arrastar reordena; arrastar para fora destaca a aba numa janela; soltar na barra principal, o menu ou fechar a janela devolvem. - Blocos passam da paleta/outra aba para a janela de uma aba (só abas de blocos recebem blocos). Correções - SDL2: SDL_QUIT (SIGTERM/Ctrl+C) fecha o editor; posição do clique do evento vale mais que o estado global; posição da janela e mouse global no contrato (a posição local do SDL atrasa depois de mover a janela). - Aba de código não mostra mais "</code>" na última linha. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
22588b281e
commit
649ae14fb3
17 files changed
+2463
-183
No files matched your search
+158
-5
@@ -1,3 +1,4 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
/* Harness headless do editor: dirige Editor.Scene com um bloco de eventos
|
||||
* falso e inspeciona os comandos de desenho produzidos por on_draw. */
|
||||
#include <stdio.h>
|
||||
@@ -19,6 +20,8 @@
|
||||
#include <tb_curves.h>
|
||||
#include <tb_base64.h>
|
||||
#include <tb_ppm.h>
|
||||
#include <tb_input_lib.h>
|
||||
#include <tb_environ.h>
|
||||
|
||||
static TinyBlocks* rt;
|
||||
static TinyBlocks_Block *ev, *scene;
|
||||
@@ -93,9 +96,10 @@ static bool stage_has(const char* s) {
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, s)) return true;
|
||||
return false;
|
||||
}
|
||||
/* Mensagens de status: palco/saída ou avisos flutuantes (toasts), em qualquer lugar */
|
||||
static bool any_has(const char* s) {
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, s)) return true;
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, s)) return true;
|
||||
return false;
|
||||
}
|
||||
static bool ws_has(const char* s) {
|
||||
@@ -192,6 +196,10 @@ static bool need(const char* s, int region, int nth, float* x, float* y) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* configurações isoladas: o harness não lê nem grava o ~/.config real */
|
||||
setenv("XDG_CONFIG_HOME", "/tmp/tb_harness_cfg", 1);
|
||||
unsetenv("TINYBLOCKS_SETTINGS");
|
||||
remove("/tmp/tb_harness_cfg/tinyblocks/settings.csv");
|
||||
tinyblocks_init(&rt, NULL);
|
||||
tb_graphics_set_backend(tb_graphics_null_backend());
|
||||
tb_library_register(rt, tb_events_get_library());
|
||||
@@ -203,6 +211,7 @@ int main(void) {
|
||||
tb_library_register(rt, tb_curves_get_library());
|
||||
tb_library_register(rt, tb_base64_get_library());
|
||||
tb_library_register(rt, tb_ppm_get_library());
|
||||
tb_library_register(rt, tb_input_get_library());
|
||||
tb_library_register(rt, tb_graphics_get_library());
|
||||
tb_library_register(rt, tb_editor_get_library());
|
||||
(void)eval_ev;
|
||||
@@ -370,10 +379,22 @@ int main(void) {
|
||||
CHECK(circles == circles_before, "\"apague tudo\" limpa o palco");
|
||||
|
||||
/* 11. Destacar o palco numa janela própria e recolher de volta */
|
||||
click(1280 - 50 + 20, 44 + 22);
|
||||
CHECK(any_has("Palco aberto em outra janela"), "palco destacado abre janela própria");
|
||||
click(1280 - 50 + 20, 44 + 22);
|
||||
CHECK(!any_has("Palco aberto em outra janela"), "palco recolhido volta ao painel");
|
||||
{
|
||||
click(1280 - 50 + 20, 44 + 22);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
/* a área do palco sai da janela principal; fica um botão "Palco" no menu */
|
||||
bool no_menu = false, no_painel = false;
|
||||
float cx = 0, cy = 0;
|
||||
for (uint32_t i = 0; i < ncmd; i++) {
|
||||
if (cmds[i].kind != TB_DRAW_TEXT || strcmp(cmds[i].text, "Palco") != 0) continue;
|
||||
if (cmds[i].y < 44) { no_menu = true; cx = cmds[i].x + 3; cy = 22; }
|
||||
else no_painel = true;
|
||||
}
|
||||
CHECK(no_menu && !no_painel, "palco destacado abre janela própria (botão \"Palco\" no menu)");
|
||||
if (no_menu) click(cx, cy); /* recolhe no próximo quadro */
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 920 && y > 44, "palco recolhido volta ao painel");
|
||||
}
|
||||
|
||||
/* 12. Salvar e abrir projeto (.json) via tinyblocks-blueprint */
|
||||
const char* proj = "/tmp/tb_harness_proj.json";
|
||||
@@ -383,6 +404,22 @@ int main(void) {
|
||||
type(proj);
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
CHECK(any_has("Projeto salvo"), "salvar projeto escreve o .json");
|
||||
{
|
||||
/* aviso flutuante (toast) sobre a área de scripts, não no menu */
|
||||
bool flutua = false;
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "Projeto salvo") &&
|
||||
cmds[i].x > 318 && cmds[i].x < 920 && cmds[i].y > 400) flutua = true;
|
||||
CHECK(flutua, "mensagem vira aviso flutuante no canto da área de scripts");
|
||||
/* salvar de novo: a mesma mensagem vira contador (x2) */
|
||||
if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y);
|
||||
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type(proj);
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
if (find("Substituir", R_ANY, 0, &x, &y)) click(x, y);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
CHECK(any_has("(x2)"), "mensagem repetida vira contador (x2)");
|
||||
}
|
||||
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
||||
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type(proj);
|
||||
@@ -546,6 +583,45 @@ int main(void) {
|
||||
remove(fj);
|
||||
}
|
||||
|
||||
/* 13e. Sensores: posição do mouse no palco e última tecla, num "sempre" */
|
||||
{
|
||||
const char* sj = "/tmp/tb_harness_sensores.json";
|
||||
FILE* sf = fopen(sj, "wb");
|
||||
if (sf) {
|
||||
fputs("{\"format\":\"tinyblocks-project\",\"version\":1,\"cur_tab\":0,"
|
||||
"\"tabs\":[{\"name\":\"Sensores\",\"composite\":false,\"comp_id\":-1,\"color\":0,"
|
||||
"\"blocks\":["
|
||||
"{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1},"
|
||||
"{\"i\":1,\"type\":\"Control.Forever\",\"x\":40,\"y\":100,\"parent\":0,\"prel\":0,\"sub\":[2,-1]},"
|
||||
"{\"i\":2,\"type\":\"Stage.Clear\",\"x\":0,\"y\":0,\"parent\":1,\"prel\":1,\"next\":3},"
|
||||
"{\"i\":3,\"type\":\"IO.Print\",\"x\":0,\"y\":0,\"parent\":2,\"prel\":0,\"args\":[4,5]},"
|
||||
"{\"i\":4,\"type\":\"Input.MouseX\",\"x\":0,\"y\":0,\"parent\":3,\"prel\":3},"
|
||||
"{\"i\":5,\"type\":\"Input.LastKey\",\"x\":0,\"y\":0,\"parent\":3,\"prel\":4}"
|
||||
"],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", sf);
|
||||
fclose(sf);
|
||||
}
|
||||
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
||||
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type(sj);
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
flag();
|
||||
/* vista do palco no painel: origem (929, 89), 342 px = 480 do palco;
|
||||
x do palco 100 -> 929 + 171 + 100 * 342/480 */
|
||||
float px = 929.f + 171.f + 100.f * 342.f / 480.f, py = 89.f + 100.f;
|
||||
for (int i = 0; i < 3; i++) frame(px, py, 0, 0, 0, 0, NULL);
|
||||
CHECK(stage_has("100"), "posição x do mouse sobre o palco = 100");
|
||||
if (!stage_has("100"))
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920) printf(" palco: '%s'\n", cmds[i].text);
|
||||
frame(px, py, 0, 0, 0, TB_KEY_SPACE, NULL);
|
||||
for (int i = 0; i < 3; i++) frame(px, py, 0, 0, 0, 0, NULL);
|
||||
CHECK(stage_has("espaço"), "última tecla = espaço");
|
||||
click(1280 - 360 + 76, 44 + 22); /* botão vermelho */
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
remove(sj);
|
||||
}
|
||||
|
||||
/* 14. Exportar pelo menu de contexto do botao Exportar */
|
||||
if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y);
|
||||
CHECK(find("Exportar JSON", R_FLY, 0, &x, &y) && find("Exportar XML", R_FLY, 0, &x, &y)
|
||||
@@ -705,6 +781,7 @@ int main(void) {
|
||||
CHECK(ws_has("int"), "aba de codigo realca 'int' (palavra-chave)");
|
||||
CHECK(ws_has("42"), "aba de codigo realca o numero 42");
|
||||
CHECK(ws_has(";"), "aba de codigo realca a pontuacao");
|
||||
CHECK(!any_has("</code>"), "aba de codigo nao mostra a marcacao </code>");
|
||||
}
|
||||
|
||||
/* 23. Botao "+" -> nova aba: Edicao de Imagem */
|
||||
@@ -797,6 +874,82 @@ int main(void) {
|
||||
CHECK(img_nonwhite() > 0, "camada pode ser mostrada de novo");
|
||||
}
|
||||
|
||||
/* 22. Áreas estilo Blender: redimensionar arrastando a borda, trocar de lugar pela alça */
|
||||
{
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
CHECK(find("Blocos", R_ANY, 0, &x, &y) && x < 100, "paleta tem cabeçalho \"Blocos\" com alça");
|
||||
/* borda paleta | scripts em x = 318: arrasta 100 px para a direita */
|
||||
drag(318, 400, 418, 400);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
bool largo = false;
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_SET_CLIP && cmds[i].x == 68 && cmds[i].w > 340) largo = true;
|
||||
CHECK(largo, "arrastar a borda alarga a paleta (418 px)");
|
||||
float px0 = 0, py0 = 0;
|
||||
CHECK(find("Palco", R_ANY, 0, &px0, &py0) && px0 > 920, "palco continua na direita");
|
||||
/* alça do palco (ao lado do botão de destacar) -> solta sobre os scripts */
|
||||
drag(1280 - 50 - 18 - 8 + 9, 44 + 22, 640, 400);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 418 && x < 900, "alça troca o palco com a área de scripts");
|
||||
/* e de volta: a alça do palco agora está no meio da tela */
|
||||
drag(418 + (1280 - 360 - 418) - 50 - 18 - 8 + 9, 44 + 22, 1100, 200); /* scripts, em cima à direita */
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 920, "trocar de novo devolve o palco à direita");
|
||||
/* layout salvo nas configurações (arquivo isolado do harness) */
|
||||
CHECK(!strcmp(tb_environ_get("editor.layout"), "H0:418(p,H1:360(s,V0:310(t,o)))"),
|
||||
"layout salvo em editor.layout (paleta com 418 px)");
|
||||
FILE* cf = fopen("/tmp/tb_harness_cfg/tinyblocks/settings.csv", "rb");
|
||||
char cbuf[1024] = "";
|
||||
if (cf) { size_t n = fread(cbuf, 1, sizeof(cbuf) - 1, cf); cbuf[n] = 0; fclose(cf); }
|
||||
CHECK(strstr(cbuf, "editor.layout") != NULL, "layout gravado no arquivo de configurações");
|
||||
}
|
||||
|
||||
/* 23. Abas: arrastar na barra reordena (como no navegador) */
|
||||
{
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
/* rótulos das abas na barra (y 44..80), em ordem de x */
|
||||
char nomes[8][64]; float xs[8]; int n = 0;
|
||||
for (uint32_t i = 0; i < ncmd && n < 8; i++) {
|
||||
if (cmds[i].kind != TB_DRAW_TEXT || cmds[i].y < 50 || cmds[i].y > 80) continue;
|
||||
if (cmds[i].x < 318 || cmds[i].x > 900 || !strcmp(cmds[i].text, "=") || !strcmp(cmds[i].text, "+")) continue;
|
||||
snprintf(nomes[n], 64, "%s", cmds[i].text); xs[n] = cmds[i].x; n++;
|
||||
}
|
||||
CHECK(n >= 2, "há pelo menos duas abas para reordenar");
|
||||
if (n >= 2) {
|
||||
char primeira[64]; snprintf(primeira, 64, "%s", nomes[0]);
|
||||
float sx = xs[0] + 10;
|
||||
drag(sx, 62, sx + 150 + 20, 62); /* passa do meio da vizinha */
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
float nx = 0, ny = 0;
|
||||
bool achou = false;
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && !strcmp(cmds[i].text, primeira) && cmds[i].y > 50 && cmds[i].y < 80) {
|
||||
nx = cmds[i].x; ny = cmds[i].y; achou = true;
|
||||
}
|
||||
(void)ny;
|
||||
CHECK(achou && nx > xs[1] - 20, "arrastar a aba para a direita troca a ordem com a vizinha");
|
||||
|
||||
/* arrastar a aba para longe da barra destaca numa janela própria */
|
||||
drag(nx + 10, 62, nx + 10, 400);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
bool na_barra = false, no_menu = false;
|
||||
float mxp = 0;
|
||||
for (uint32_t i = 0; i < ncmd; i++) {
|
||||
if (cmds[i].kind != TB_DRAW_TEXT || strcmp(cmds[i].text, primeira) != 0) continue;
|
||||
if (cmds[i].y > 50 && cmds[i].y < 80) na_barra = true;
|
||||
if (cmds[i].y < 44) { no_menu = true; mxp = cmds[i].x + 3; }
|
||||
}
|
||||
CHECK(!na_barra && no_menu, "aba arrastada para fora vira janela (botão no menu)");
|
||||
if (no_menu) click(mxp, 22); /* volta para a barra */
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
na_barra = false;
|
||||
for (uint32_t i = 0; i < ncmd; i++)
|
||||
if (cmds[i].kind == TB_DRAW_TEXT && !strcmp(cmds[i].text, primeira) && cmds[i].y > 50 && cmds[i].y < 80)
|
||||
na_barra = true;
|
||||
CHECK(na_barra, "botão no menu traz a aba de volta para a barra");
|
||||
}
|
||||
}
|
||||
|
||||
printf("comandos de desenho no último frame: %u\n", ncmd);
|
||||
tinyblocks_deinit(&rt);
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* input_test.c - testa o estado de entrada do core (tb_input) e os blocos
|
||||
* de Sensores da tinyblocks-input: mouse em coordenadas do palco, teclas
|
||||
* por nome, toques, sensores e cronometro.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tinyblocks/tb_input.h>
|
||||
#include <tinyblocks/tb_stage.h>
|
||||
#include <tb_graphics.h>
|
||||
#include <tb_input_lib.h>
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
|
||||
|
||||
static TinyBlocks* rt;
|
||||
static TinyBlocks_Block* last;
|
||||
|
||||
static TinyBlocks_Value* run(const char* type, const char* arg) {
|
||||
if (last) { tb_block_destroy(last, rt); last = NULL; }
|
||||
TinyBlocks_TypeBlock* t = tb_rt_find_type(rt, type);
|
||||
if (!t) { printf(" (tipo %s nao existe)\n", type); return NULL; }
|
||||
last = tb_block_create(rt, t);
|
||||
if (arg) {
|
||||
TinyBlocks_Value v = t->input_descs[0].expected_kind == TB_VALUE_INTEGER
|
||||
? tb_value_integer(atoll(arg)) : tb_value_text(arg);
|
||||
tb_block_set_default(last, 0, v);
|
||||
tb_value_free(&v);
|
||||
}
|
||||
tb_block_eval(last, rt);
|
||||
return last->output_count ? &last->outputs[0] : NULL;
|
||||
}
|
||||
|
||||
static long long num(TinyBlocks_Value* v) {
|
||||
if (!v) return -99999;
|
||||
if (v->kind == TB_VALUE_INTEGER) return v->as.integer;
|
||||
if (v->kind == TB_VALUE_REAL) return llround(v->as.real);
|
||||
return -99999;
|
||||
}
|
||||
static double real(TinyBlocks_Value* v) {
|
||||
if (!v) return -99999;
|
||||
return v->kind == TB_VALUE_REAL ? v->as.real : v->kind == TB_VALUE_INTEGER ? (double)v->as.integer : -99999;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
tinyblocks_init(&rt, NULL);
|
||||
TinyBlocks_LibraryBlock* lib = tb_library_register(rt, tb_input_get_library());
|
||||
CHECK(lib && !strcmp(tb_library_category(lib)->name, "Sensores"), "categoria 'Sensores'");
|
||||
|
||||
/* vista 480x360 = palco 1:1; (240,180) da vista = centro do palco */
|
||||
tb_stage_set_view(480, 360);
|
||||
tb_input_reset();
|
||||
tb_input_begin_frame();
|
||||
tb_input_set_mouse(240, 180, false, false);
|
||||
CHECK(num(run("Input.MouseX", NULL)) == 0 && num(run("Input.MouseY", NULL)) == 0,
|
||||
"centro da vista = (0, 0) do palco");
|
||||
tb_input_set_mouse(480, 0, true, false);
|
||||
CHECK(num(run("Input.MouseX", NULL)) == 240 && num(run("Input.MouseY", NULL)) == 180,
|
||||
"canto superior direito = (240, 180), y para cima");
|
||||
CHECK(num(run("Input.MouseDown", NULL)) == 1, "mouse pressionado?");
|
||||
tb_input_set_mouse(900, 500, false, false);
|
||||
CHECK(num(run("Input.MouseX", NULL)) == 240 && num(run("Input.MouseOver", NULL)) == 0,
|
||||
"fora do palco: posição presa na borda e 'sobre o palco?' falso");
|
||||
|
||||
/* vista maior com faixas (letterbox): 960x540 -> escala 1.5, faixas laterais */
|
||||
tb_stage_set_view(960, 540);
|
||||
tb_input_set_mouse(480, 270, false, false);
|
||||
CHECK(num(run("Input.MouseX", NULL)) == 0 && num(run("Input.MouseY", NULL)) == 0,
|
||||
"letterbox: centro continua (0, 0)");
|
||||
tb_input_set_mouse(120 + 720, 270, false, false);
|
||||
CHECK(num(run("Input.MouseX", NULL)) == 240, "letterbox: borda direita do palco = 240");
|
||||
tb_stage_set_view(480, 360);
|
||||
|
||||
/* teclado */
|
||||
CHECK(tb_input_key_from_name("espaço") == TB_KEY_SPACE && tb_input_key_from_name("Space") == TB_KEY_SPACE &&
|
||||
tb_input_key_from_name("seta para cima") == TB_KEY_UP && tb_input_key_from_name("a") == TB_KEY_A &&
|
||||
tb_input_key_from_name("7") == TB_KEY_0 + 7 && tb_input_key_from_name("qualquer") == -1 &&
|
||||
tb_input_key_from_name("f5") == TB_KEY_F5, "nomes de tecla (PT/EN, letras, números, F)");
|
||||
tb_input_clear_keys();
|
||||
tb_input_set_key(TB_KEY_SPACE, true);
|
||||
CHECK(num(run("Input.KeyPressed", "espaço")) == 1, "tecla espaço pressionada?");
|
||||
CHECK(num(run("Input.KeyPressed", "a")) == 0, "tecla a não pressionada");
|
||||
CHECK(num(run("Input.KeyPressed", "qualquer")) == 1, "qualquer tecla");
|
||||
tb_input_clear_keys();
|
||||
CHECK(num(run("Input.KeyPressed", "qualquer")) == 0, "soltou todas");
|
||||
tb_input_key_pressed(TB_KEY_UP);
|
||||
TinyBlocks_Value* lk = run("Input.LastKey", NULL);
|
||||
CHECK(lk && lk->kind == TB_VALUE_TEXT && !strcmp(lk->as.text, "seta para cima"), "última tecla em português");
|
||||
|
||||
/* toque */
|
||||
float tx[2] = {240, 0}, ty[2] = {180, 0};
|
||||
tb_input_set_touches(2, tx, ty);
|
||||
CHECK(num(run("Input.TouchCount", NULL)) == 2 && num(run("Input.Touching", NULL)) == 1, "dois dedos na tela");
|
||||
CHECK(num(run("Input.TouchX", "2")) == -240 && num(run("Input.TouchY", "2")) == 180, "toque 2 no canto (-240, 180)");
|
||||
tb_input_set_touches(0, NULL, NULL);
|
||||
CHECK(num(run("Input.Touching", NULL)) == 0, "sem toque");
|
||||
|
||||
/* sensores */
|
||||
CHECK(num(run("Input.HasAccel", NULL)) == 0 && num(run("Input.HasGyro", NULL)) == 0, "sem sensores por padrão");
|
||||
tb_input_set_accel(true, 0.5f, -9.81f, 0.f);
|
||||
tb_input_set_gyro(true, 0.f, 0.f, 3.14159265f);
|
||||
CHECK(num(run("Input.HasAccel", NULL)) == 1 && fabs(real(run("Input.Accel", "y")) + 9.81) < 1e-6,
|
||||
"acelerômetro y = -9.81");
|
||||
CHECK(fabs(real(run("Input.Gyro", "z")) - 180.0) < 0.01, "giroscópio em graus/s (pi rad/s = 180)");
|
||||
|
||||
/* cronômetro */
|
||||
run("Input.ResetTimer", NULL);
|
||||
double t = real(run("Input.Timer", NULL));
|
||||
CHECK(t >= 0 && t < 0.5, "zere o cronômetro");
|
||||
|
||||
/* booleanos declarados com '?' */
|
||||
TinyBlocks_TypeBlock* tk = tb_rt_find_type(rt, "Input.KeyPressed");
|
||||
CHECK(tk && tk->output_descs[0].name[strlen(tk->output_descs[0].name) - 1] == '?',
|
||||
"tecla pressionada? é booleano ('?')");
|
||||
|
||||
if (last) tb_block_destroy(last, rt);
|
||||
tinyblocks_deinit(&rt);
|
||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||
else printf("\nTUDO OK\n");
|
||||
return fails != 0;
|
||||
}
|
||||
Reference in new issue
Block a user