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:
mguinhosandClaude Opus 5.5 committed 2026-10-22 17:53:07 -03:00
1 parent 22588b281e
commit 649ae14fb3
17 files changed
+2463 -183

No files matched your search

@@ -9,6 +9,7 @@
#include <time.h>
#include <dlfcn.h>
#include <tinyblocks/tb_json_block.h>
#include "../include/tb_graphics.h"
#ifdef TB_GRAPHICS_DEFAULT_SDL2
@@ -164,6 +165,11 @@ static const TinyBlocks_SlotDesc s_input_outs[GFX_IN_COUNT] = {
{"close", TB_VALUE_INTEGER}, {"win_w", TB_VALUE_INTEGER},
{"win_h", TB_VALUE_INTEGER}, {"drop_file", TB_VALUE_TEXT},
{"mod_state", TB_VALUE_INTEGER},
{"keys_held", TB_VALUE_JSON}, {"touches", TB_VALUE_JSON},
{"accel", TB_VALUE_JSON}, {"gyro", TB_VALUE_JSON},
{"win_x", TB_VALUE_INTEGER}, {"win_y", TB_VALUE_INTEGER},
{"mouse_in", TB_VALUE_INTEGER},
{"gmouse_x", TB_VALUE_REAL}, {"gmouse_y", TB_VALUE_REAL},
};
static void eval_input(TinyBlocks_Block* self, TinyBlocks* rt) {
@@ -174,12 +180,57 @@ static void eval_input(TinyBlocks_Block* self, TinyBlocks* rt) {
switch (s_input_outs[i].expected_kind) {
case TB_VALUE_REAL: self->outputs[i] = tb_value_real(0.0); break;
case TB_VALUE_TEXT: self->outputs[i] = tb_value_text(""); break;
case TB_VALUE_JSON: {
TinyBlocks_JsonValue* e = tb_json_array();
self->outputs[i] = tb_value_json(e);
tb_json_release(e);
break;
}
default: self->outputs[i] = tb_value_integer(0); break;
}
}
self->dirty = false;
}
/* Valores JSON das saidas de dispositivo (teclas seguradas, toques, sensores) */
static void json_push_num(TinyBlocks_JsonValue* arr, double d) {
TinyBlocks_JsonValue* n = tb_json_number(d);
if (n) { tb_json_array_push(arr, n); tb_json_release(n); }
}
static TinyBlocks_Value json_out(TinyBlocks_JsonValue* arr) {
TinyBlocks_Value v = tb_value_json(arr); /* retem */
tb_json_release(arr);
return v;
}
static TinyBlocks_Value json_keys(const TinyBlocks_GfxInput* in) {
TinyBlocks_JsonValue* arr = tb_json_array();
for (int k = 1; arr && k < 128; k++)
if (in->keys_held[k]) json_push_num(arr, k);
return json_out(arr);
}
static TinyBlocks_Value json_touches(const TinyBlocks_GfxInput* in) {
TinyBlocks_JsonValue* arr = tb_json_array();
int n = in->touch_n < GFX_MAX_TOUCHES ? in->touch_n : GFX_MAX_TOUCHES;
for (int i = 0; arr && i < n; i++) {
TinyBlocks_JsonValue* p = tb_json_array();
if (!p) break;
json_push_num(p, in->touch_x[i]);
json_push_num(p, in->touch_y[i]);
tb_json_array_push(arr, p);
tb_json_release(p);
}
return json_out(arr);
}
static TinyBlocks_Value json_vec3(int has, const float v[3]) {
TinyBlocks_JsonValue* arr = tb_json_array();
for (int i = 0; arr && has && i < 3; i++) json_push_num(arr, v[i]);
return json_out(arr);
}
static void input_push(TinyBlocks_Block* b, const TinyBlocks_GfxInput* in) {
if (!b || b->output_count < GFX_IN_COUNT) return;
#define SET(idx, v) tb_block_set_output(b, idx, v)
@@ -202,6 +253,15 @@ static void input_push(TinyBlocks_Block* b, const TinyBlocks_GfxInput* in) {
SET(GFX_IN_WIN_H, tb_value_integer(in->win_h));
SET(GFX_IN_DROP_FILE, tb_value_text(in->drop_file));
SET(GFX_IN_MOD_STATE, tb_value_integer(in->mod_state));
SET(GFX_IN_KEYS_HELD, json_keys(in));
SET(GFX_IN_TOUCHES, json_touches(in));
SET(GFX_IN_ACCEL, json_vec3(in->has_accel, in->accel));
SET(GFX_IN_GYRO, json_vec3(in->has_gyro, in->gyro));
SET(GFX_IN_WIN_X, tb_value_integer(in->win_x));
SET(GFX_IN_WIN_Y, tb_value_integer(in->win_y));
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_Y, tb_value_real(in->gmouse_y));
#undef SET
b->dirty = false;
}