- Animacoes (curvas do M3): blocos criados por codigo surgem em cascata, apagados saem de cena (fantasma que encolhe), os de baixo deslizam ao mudar de lugar na pilha; rolagem e zoom suaves. TINYBLOCKS_REDUCE_MOTION=1 desliga (o harness usa). Texto respeita a opacidade no backend SDL2. - Botao direito: "Ver codigo-fonte" (funcao C do bloco na aba de codigo), "Compartilhar pilha/blueprint (QR)" (scratchblocks em partes de 220 bytes, "TB1|id|parte|total|", em loop de 1 s) e "Receber blocos (QR)" (camera, partes em qualquer ordem, importa onde clicou). - tinyblocks-qr: qrcodegen (MIT) + quirc (ISC) e camera em cinza: V4L2 no Linux, Camera2 do NDK no Android (sem Java), nada no Windows. - Captura de desenvolvimento: TINYBLOCKS_SHOT_COUNT/STEP salvam sequencias. - Testes: test-qr (ida e volta) e harness cenario 35. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
316 lines
13 KiB
C
316 lines
13 KiB
C
/*
|
|
* TinyBlocks - tb_editor_m3.h
|
|
*
|
|
* Linguagem visual do editor: Material 3 (m3.material.io) com as cores que o
|
|
* editor ja usava. Papeis de cor do M3 apontam para a paleta do TinyBlocks;
|
|
* formas, tipografia (Roboto), icones (Material Symbols), camadas de estado
|
|
* e elevacao seguem o M3. Densidade -2 do M3 (desktop): alturas 4 px menores.
|
|
*
|
|
* Incluido por tb_editor_internal.h (usa Col, C(), COLA() e rb_*).
|
|
*/
|
|
#ifndef TB_EDITOR_M3_H
|
|
#define TB_EDITOR_M3_H
|
|
|
|
/* == Papeis de cor (M3) -> paleta do editor === */
|
|
#define M3_PRIMARY COL_MENU /* #4C97FF */
|
|
#define M3_ON_PRIMARY COL_WHITE
|
|
#define M3_PRIMARY_DARK COL_MENU_DARK
|
|
#define M3_PRIMARY_CONTAINER COL_HOVER /* #D6E4F8 */
|
|
#define M3_SECONDARY_CONTAINER COL_TAB_OFF /* #D9E3F2 */
|
|
#define M3_SURFACE COL_PANEL /* branco */
|
|
#define M3_SURFACE_LOW COL_FLY /* #F9F9F9 */
|
|
#define M3_SURFACE_CONTAINER COL_UI_BG /* #E5F0FF */
|
|
#define M3_ON_SURFACE COL_TEXT /* #575E75 */
|
|
#define M3_ON_SURFACE_VAR COL_TEXT_DIM
|
|
#define M3_OUTLINE COL_TEXT_DIM
|
|
#define M3_OUTLINE_VAR COL_BORDER
|
|
#define M3_INVERSE_SURFACE COL_TIP_BG
|
|
#define M3_INVERSE_ON_SURFACE COL_CODE_TEXT
|
|
#define M3_INVERSE_PRIMARY COL_TIP_LINK
|
|
#define M3_ERROR COL_STOP
|
|
|
|
/* == Formas (raio dos cantos) === */
|
|
#define M3_SHAPE_XS 4.f
|
|
#define M3_SHAPE_S 8.f
|
|
#define M3_SHAPE_M 12.f
|
|
#define M3_SHAPE_L 16.f
|
|
#define M3_SHAPE_XL 28.f
|
|
|
|
/* == Tipografia (tamanho em px; titulos e rotulos em Roboto Medium) === */
|
|
#define M3_HEADLINE_S 24.f
|
|
#define M3_TITLE_L 22.f
|
|
#define M3_TITLE_M 16.f
|
|
#define M3_TITLE_S 14.f
|
|
#define M3_LABEL_L 14.f
|
|
#define M3_LABEL_M 12.f
|
|
#define M3_LABEL_S 11.f
|
|
#define M3_BODY_L 16.f
|
|
#define M3_BODY_M 14.f
|
|
#define M3_BODY_S 12.f
|
|
|
|
/* == Camadas de estado (opacidade da cor do conteudo) === */
|
|
#define M3_HOVER 0.08f
|
|
#define M3_PRESSED 0.10f
|
|
#define M3_DRAGGED 0.16f
|
|
|
|
/* == Componentes: alturas (densidade -2) === */
|
|
#define M3_BUTTON_H 36.f /* botoes comuns (40 no M3 padrao) */
|
|
#define M3_ICON_BTN 36.f /* icon button: alvo (40 no padrao) */
|
|
#define M3_ICON 20.f /* icone dentro de botoes */
|
|
#define M3_MENU_ITEM 40.f /* item de menu (48 no padrao) */
|
|
|
|
/* == Icones (Material Symbols, codepoints) === */
|
|
#define MI_ADD 0xe145
|
|
#define MI_ARROW_BACK 0xe5c4
|
|
#define MI_ARROW_FORWARD 0xe5c8
|
|
#define MI_ARROW_UPWARD 0xe5d8
|
|
#define MI_ARROW_RIGHT 0xe5df
|
|
#define MI_BRUSH 0xe3ae
|
|
#define MI_CANCEL 0xe888
|
|
#define MI_CHECK 0xe668
|
|
#define MI_CHECK_CIRCLE 0xf0be
|
|
#define MI_CHEVRON_LEFT 0xe5cb
|
|
#define MI_CHEVRON_RIGHT 0xe5cc
|
|
#define MI_CIRCLE 0xef4a
|
|
#define MI_CLOSE 0xe5cd
|
|
#define MI_CODE 0xe86f
|
|
#define MI_COLORIZE 0xe3b8
|
|
#define MI_CONTENT_COPY 0xe14d
|
|
#define MI_CONTENT_CUT 0xe14e
|
|
#define MI_CONTENT_PASTE 0xe14f
|
|
#define MI_CREATE_FOLDER 0xe2cc
|
|
#define MI_DELETE 0xe92e
|
|
#define MI_DESCRIPTION 0xe873
|
|
#define MI_DRAFT 0xe66d
|
|
#define MI_DRAG_INDICATOR 0xe945
|
|
#define MI_EDIT 0xf097
|
|
#define MI_ERROR 0xf8b6
|
|
#define MI_EXPAND_MORE 0xe5cf
|
|
#define MI_EXTENSION 0xe87b
|
|
#define MI_FILL 0xe23a
|
|
#define MI_FLAG 0xf0c6
|
|
#define MI_FOLDER 0xe2c7
|
|
#define MI_GRID_VIEW 0xe9b0
|
|
#define MI_DATA_OBJECT 0xead3
|
|
#define MI_TABLE 0xf191
|
|
#define MI_ACCOUNT_TREE 0xe97a
|
|
#define MI_SELECT_ALL 0xe162
|
|
#define MI_ADD_BOX 0xe146
|
|
#define MI_FOLDER_OPEN 0xe2c8
|
|
#define MI_HOME 0xe9b2
|
|
#define MI_IMAGE 0xe3f4
|
|
#define MI_INFO 0xe88e
|
|
#define MI_ERASER 0xe6d0
|
|
#define MI_IOS_SHARE 0xe6b8
|
|
#define MI_LIBRARY_ADD 0xe03c
|
|
#define MI_LIBRARY_BOOKS 0xe02f
|
|
#define MI_MENU 0xe5d2
|
|
#define MI_MORE_VERT 0xe5d4
|
|
#define MI_OPEN_IN_NEW 0xe89e
|
|
#define MI_CLOSE_FULLSCR 0xf1cf
|
|
#define MI_PALETTE 0xe40a
|
|
#define MI_PAN_TOOL 0xe925
|
|
#define MI_PLAY_ARROW 0xe037
|
|
#define MI_RECTANGLE 0xeb54
|
|
#define MI_REDO 0xe15a
|
|
#define MI_REFRESH 0xe5d5
|
|
#define MI_SAVE 0xe161
|
|
#define MI_SEARCH 0xef7a
|
|
#define MI_SHARE 0xe80d
|
|
#define MI_QR_CODE 0xe00a
|
|
#define MI_QR_SCANNER 0xf206
|
|
#define MI_SOURCE 0xf1c8
|
|
#define MI_SELECT 0xf74d
|
|
#define MI_SETTINGS 0xe8b8
|
|
#define MI_STOP 0xe047
|
|
#define MI_STOP_CIRCLE 0xef71
|
|
#define MI_SWAP_HORIZ 0xe8d4
|
|
#define MI_TERMINAL 0xeb8e
|
|
#define MI_TEXT_FIELDS 0xe262
|
|
#define MI_UNDO 0xe166
|
|
#define MI_UPLOAD_FILE 0xe9fc
|
|
#define MI_WARNING 0xf083
|
|
#define MI_WIDGETS 0xe1bd
|
|
#define MI_ZOOM_IN 0xe8ff
|
|
#define MI_ZOOM_OUT 0xe900
|
|
|
|
/* == Movimento: curvas do M3 (cubic-bezier, como no CSS) === */
|
|
static inline float m3_bezier(float x1, float y1, float x2, float y2, float t) {
|
|
if (t <= 0.f) return 0.f;
|
|
if (t >= 1.f) return 1.f;
|
|
float lo = 0.f, hi = 1.f, u = t;
|
|
for (int i = 0; i < 24; i++) { /* acha u com x(u) = t (bissecao) */
|
|
u = (lo + hi) * 0.5f;
|
|
float iu = 1.f - u;
|
|
float x = 3.f * iu * iu * u * x1 + 3.f * iu * u * u * x2 + u * u * u;
|
|
if (x < t) lo = u; else hi = u;
|
|
}
|
|
float iu = 1.f - u;
|
|
return 3.f * iu * iu * u * y1 + 3.f * iu * u * u * y2 + u * u * u;
|
|
}
|
|
#define M3_EASE_STANDARD(t) m3_bezier(0.2f, 0.f, 0.f, 1.f, (t))
|
|
#define M3_EASE_EMPH_DECEL(t) m3_bezier(0.05f, 0.7f, 0.1f, 1.f, (t)) /* entrar */
|
|
#define M3_EASE_EMPH_ACCEL(t) m3_bezier(0.3f, 0.f, 0.8f, 0.15f, (t)) /* sair */
|
|
#define M3_DUR_SCROLL 260u /* ms */
|
|
#define M3_DUR_SLIDE 280u
|
|
#define M3_DUR_APPEAR 380u
|
|
#define M3_DUR_EXIT 220u
|
|
|
|
/* == Utilitarios === */
|
|
static inline Col m3_alpha(Col c, float a) { c.a = a; return c; }
|
|
|
|
/* c sobre o fundo bg com opacidade a (cor solida resultante) */
|
|
static inline Col m3_mix(Col bg, Col c, float a) {
|
|
Col r = { bg.r + (c.r - bg.r) * a, bg.g + (c.g - bg.g) * a, bg.b + (c.b - bg.b) * a, 1.f };
|
|
return r;
|
|
}
|
|
|
|
/* Largura de um rotulo em Roboto Medium (a medicao do backend e da Regular) */
|
|
static inline float m3_tw_m(const char* s, float fs) { return tw(s, fs) * 1.04f; }
|
|
|
|
/* Camada de estado: a cor do conteudo, translucida, sobre o componente */
|
|
static inline void m3_state(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad,
|
|
Col on, bool hover, bool pressed) {
|
|
float a = pressed ? M3_PRESSED : hover ? M3_HOVER : 0.f;
|
|
if (a > 0.f) rb_fill_rrect(rb, x, y, w, h, rad, m3_alpha(on, a));
|
|
rb_ripple(rb, x, y, w, h, rad, on); /* gota do toque/clique */
|
|
}
|
|
|
|
/* == Botoes (pilula): filled, tonal, outlined, text === */
|
|
enum { M3_FILLED, M3_TONAL, M3_OUTLINED, M3_TEXT };
|
|
|
|
static inline float m3_button_w(const char* label, unsigned icon) {
|
|
return m3_tw_m(label, M3_LABEL_L) + (icon ? 16.f + 18.f + 8.f + 24.f : 48.f);
|
|
}
|
|
|
|
/* accent = cor do papel "primary" deste botao (a do editor ou a do dialogo) */
|
|
static inline void m3_button(TinyBlocks_RenderableBlock* rb, int kind, float x, float y, float w, float h,
|
|
const char* label, unsigned icon, Col accent, bool hover, bool pressed) {
|
|
float r = h * 0.5f;
|
|
Col on = accent;
|
|
if (kind == M3_FILLED) {
|
|
rb_fill_rrect(rb, x, y, w, h, r, accent);
|
|
on = M3_ON_PRIMARY;
|
|
} else if (kind == M3_TONAL) {
|
|
rb_fill_rrect(rb, x, y, w, h, r, m3_mix(M3_SURFACE, accent, 0.16f));
|
|
on = col_mul(accent, 0.8f);
|
|
} else if (kind == M3_OUTLINED) {
|
|
rb_fill_rrect(rb, x, y, w, h, r, M3_OUTLINE_VAR);
|
|
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, r - 1, M3_SURFACE);
|
|
}
|
|
m3_state(rb, x, y, w, h, r, on, hover, pressed);
|
|
float lw = m3_tw_m(label, M3_LABEL_L);
|
|
float cx = x + w * 0.5f, cy = y + h * 0.5f;
|
|
if (icon) {
|
|
float total = 18.f + 8.f + lw;
|
|
float ix = cx - total * 0.5f;
|
|
rb_icon(rb, ix + 9.f, cy, icon, 18.f, on, false);
|
|
rb_text_f(rb, ix + 26.f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
|
|
} else {
|
|
rb_text_f(rb, cx - lw * 0.5f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
|
|
}
|
|
}
|
|
|
|
/* Icon button (padrao): so o icone; o circulo aparece no hover/pressionado.
|
|
selected = toggle ligado (container tonal) */
|
|
static inline void m3_icon_button(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned icon, Col c,
|
|
bool hover, bool selected) {
|
|
float s = M3_ICON_BTN;
|
|
if (selected) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, 0.16f));
|
|
if (hover) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, M3_HOVER));
|
|
rb_ripple(rb, cx - s * 0.5f, cy - s * 0.5f, s, s, s * 0.5f, c);
|
|
rb_icon(rb, cx, cy, icon, M3_ICON, c, selected);
|
|
}
|
|
|
|
/* == Superficies === */
|
|
/* Menu: canto XS, elevacao 2 */
|
|
static inline void m3_menu_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
|
|
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 2);
|
|
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_SURFACE);
|
|
}
|
|
|
|
/* Item de menu: icone opcional a esquerda, rotulo Label Large */
|
|
static inline void m3_menu_item(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
|
const char* label, unsigned icon, bool hover, Col fg) {
|
|
m3_state(rb, x, y, w, h, 0, M3_ON_SURFACE, hover, false);
|
|
float tx = x + 12.f;
|
|
if (icon) { rb_icon(rb, tx + 10.f, y + h * 0.5f, icon, M3_ICON, M3_ON_SURFACE_VAR, false); tx += 20.f + 12.f; }
|
|
rb_text_f(rb, tx, y + h * 0.5f, label, fg, M3_LABEL_L, TB_FONT_REGULAR);
|
|
}
|
|
|
|
/* Dialogo: canto XL, elevacao 3 */
|
|
static inline void m3_dialog_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
|
|
rb_shadow(rb, x, y, w, h, M3_SHAPE_XL, 3);
|
|
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XL, M3_SURFACE);
|
|
}
|
|
|
|
/* Scrim atras de dialogos modais */
|
|
static inline void m3_scrim(TinyBlocks_RenderableBlock* rb, float w, float h) {
|
|
rb_fill_rect(rb, 0, 0, w, h, COLA(0, 0, 0, 82));
|
|
}
|
|
|
|
/* Campo de texto "outlined": canto XS, contorno 1 px (2 px na cor
|
|
primaria quando em foco) */
|
|
static inline void m3_field(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
|
bool focused, Col accent) {
|
|
if (focused) {
|
|
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, accent);
|
|
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, M3_SHAPE_XS - 1, M3_SURFACE);
|
|
} else {
|
|
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_OUTLINE);
|
|
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_XS - 0.5f, M3_SURFACE);
|
|
}
|
|
}
|
|
|
|
/* Barra de busca: pilula, icone de lupa a esquerda */
|
|
static inline void m3_search_bar(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
|
bool focused, Col accent) {
|
|
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_SURFACE_CONTAINER);
|
|
if (focused) {
|
|
rb_fill_rrect(rb, x - 1, y - 1, w + 2, h + 2, h * 0.5f + 1, accent);
|
|
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, M3_SURFACE_CONTAINER);
|
|
}
|
|
rb_icon(rb, x + 16.f + 12.f, y + h * 0.5f, MI_SEARCH, 24.f, M3_ON_SURFACE_VAR, false);
|
|
}
|
|
|
|
/* Indicador da aba ativa (aba primaria): 3 px com cantos de cima redondos */
|
|
static inline void m3_tab_indicator(TinyBlocks_RenderableBlock* rb, float x, float y_bottom, float w, Col c) {
|
|
rb_fill_rrect(rb, x, y_bottom - 3.f, w, 6.f, 3.f, c);
|
|
}
|
|
|
|
/* Chip (assist/filter): canto S, 32 px */
|
|
static inline void m3_chip(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label,
|
|
unsigned icon, bool selected, bool hover) {
|
|
if (selected) rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_SECONDARY_CONTAINER);
|
|
else {
|
|
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_OUTLINE_VAR);
|
|
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_S - 1, M3_SURFACE);
|
|
}
|
|
m3_state(rb, x, y, w, h, M3_SHAPE_S, M3_ON_SURFACE, hover, false);
|
|
float tx = x + 12.f;
|
|
if (icon) { rb_icon(rb, x + 8.f + 9.f, y + h * 0.5f, icon, 18.f, M3_PRIMARY, false); tx = x + 8.f + 18.f + 8.f; }
|
|
rb_text_f(rb, tx, y + h * 0.5f, label, M3_ON_SURFACE, M3_LABEL_L, TB_FONT_MEDIUM);
|
|
}
|
|
|
|
/* Snackbar: superficie inversa, canto XS, elevacao 3 */
|
|
static inline void m3_snackbar_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
|
|
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 3);
|
|
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_INVERSE_SURFACE);
|
|
}
|
|
|
|
/* Interruptor (switch) do M3: trilho 52x32, alca 16 (24 ligado) */
|
|
static inline void m3_switch(TinyBlocks_RenderableBlock* rb, float x, float y, bool on, Col accent) {
|
|
const float w = 52.f, h = 32.f;
|
|
if (on) {
|
|
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, accent);
|
|
rb_fill_circle(rb, x + w - 16.f, y + h * 0.5f, 12.f, M3_ON_PRIMARY);
|
|
rb_icon(rb, x + w - 16.f, y + h * 0.5f, MI_CHECK, 16.f, accent, false);
|
|
} else {
|
|
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_OUTLINE);
|
|
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, h * 0.5f - 2, M3_SURFACE_CONTAINER);
|
|
rb_fill_circle(rb, x + 16.f, y + h * 0.5f, 8.f, M3_OUTLINE);
|
|
}
|
|
}
|
|
|
|
#endif /* TB_EDITOR_M3_H */
|