Files
tinyblocks/include/tinyblocks/tb_renderable_block.h
T
mguinhosandClaude Opus 5.5 0cb2019704 Editor: redesign visual no Material 3 (Roboto, Material Symbols, cores de sempre)
- Fontes em assets/fonts (Roboto Regular/Medium, Material Symbols contorno e
  preenchido; Apache 2.0). TB_DRAW_TEXT escolhe a fonte pelo param
  (tb_draw_text_font, TB_FONT_*); backend SDL2 com cache por familia e
  DejaVu de reserva. Pacotes AppImage/Android/Windows levam as fontes.
- tb_editor_m3.h: papeis de cor do M3 sobre a paleta do editor, formas,
  tipografia, camadas de estado, elevacao, icones e componentes (botoes,
  icon button, menu, campo, dialogo, chip, snackbar, switch).
- Top app bar, abas primarias, navigation rail das categorias, FAB de
  extensoes, palco, saida, menus, snackbars, dialogos, explorador,
  Bibliotecas, Configuracoes, previa scratchblocks, editores de codigo e
  de imagem no estilo M3.
- Widgets: icon, text_f e shadow. Backend: TINYBLOCKS_SHOT salva a janela
  (conferir o visual); editor: TINYBLOCKS_OPEN abre uma tela no inicio.
- Console: linhas roladas continuam na arvore acessivel (OFFSCREEN).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 21:34:04 -03:00

140 lines
6.7 KiB
C

/*
* TinyBlocks - tb_renderable_block.h
*
* TinyBlocks_RenderableBlock: lista de comandos de desenho produzida por on_draw.
* O backend (ex: SDL2.App) interpreta os comandos para renderizar na tela.
*
* Uso típico:
* bool my_on_draw(TinyBlocks_Block* self, TinyBlocks* rt,
* TinyBlocks_RenderableBlock** dst) {
* TinyBlocks_RenderableBlock* rb = tb_renderable_acquire();
* if (!rb) return false;
* tb_draw_clear(rb, 0.1f, 0.1f, 0.18f, 1.f);
* tb_draw_fill_rect(rb, 10, 10, 200, 100, 0.5f, 0.3f, 0.9f, 1.f);
* tb_draw_text(rb, 20, 50, "Olá", 13.f, 1,1,1,1);
* *dst = rb;
* return true;
* }
* // Após renderizar: tb_renderable_release_all();
*/
#ifndef TINYBLOCKS_RENDERABLE_BLOCK_H
#define TINYBLOCKS_RENDERABLE_BLOCK_H
#include "tb_defs.h"
/* -- Tipos de comando --- */
typedef enum {
TB_DRAW_CLEAR, /* limpa toda a área com uma cor */
TB_DRAW_FILL_RECT, /* retângulo preenchido */
TB_DRAW_FILL_RRECT, /* retângulo com cantos arredondados (param=radius) */
TB_DRAW_FILL_CIRCLE, /* círculo preenchido (x=cx, y=cy, param=radius) */
TB_DRAW_STROKE_LINE, /* linha (x,y -> w,h como x2,y2; param=espessura) */
TB_DRAW_STROKE_RECT, /* contorno de retângulo (param=espessura) */
TB_DRAW_STROKE_CIRCLE, /* contorno de círculo (x=cx,y=cy,param=r,w=espessura)*/
TB_DRAW_SET_CLIP, /* define rect de clip (coordenadas tela) */
TB_DRAW_CLEAR_CLIP, /* remove clip */
TB_DRAW_TEXT, /* texto (x,y=baseline-left; font_size em px) */
TB_DRAW_IMAGE, /* imagem escalada em (x,y,w,h); ver field image */
} TinyBlocks_DrawCmdKind;
typedef struct {
TinyBlocks_DrawCmdKind kind;
float x, y, w, h; /* geometria (significado varia por kind) */
float r, g, b, a; /* cor RGBA [0..1] */
float param; /* radius (rrect/circle), espessura (linha/stroke); *
* no TB_DRAW_TEXT, a fonte (TB_FONT_*) */
float font_size; /* tamanho da fonte em pixels (TB_DRAW_TEXT) */
char text[128]; /* conteúdo do texto (TB_DRAW_TEXT) */
const TinyBlocks_Image* image; /* pixels (TB_DRAW_IMAGE, não-owning) */
} TinyBlocks_DrawCmd;
/* -- RenderableBlock --- */
#define TB_DRAW_CMD_CAP 8192
struct TinyBlocks_RenderableBlock {
TinyBlocks_DrawCmd cmds[TB_DRAW_CMD_CAP];
uint32_t count;
};
/* -- Pool de renderables (reset por frame, sem malloc durante o loop) --- */
/* Adquire um renderable limpo do pool. Retorna NULL se esgotado. */
TB_API TinyBlocks_RenderableBlock* tb_renderable_acquire(void);
/* Libera um renderable individual de volta ao pool (uso após merge). */
TB_API void tb_renderable_release(TinyBlocks_RenderableBlock* rb);
/* Libera todos os renderables de volta ao pool (chamar uma vez por frame,
depois que o backend terminar de renderizar). */
TB_API void tb_renderable_release_all(void);
/* -- Helpers para acrescentar comandos --- */
TB_API void tb_draw_clear (TinyBlocks_RenderableBlock* rb,
float r, float g, float b, float a);
TB_API void tb_draw_fill_rect (TinyBlocks_RenderableBlock* rb,
float x, float y, float w, float h,
float r, float g, float b, float a);
TB_API void tb_draw_fill_rrect (TinyBlocks_RenderableBlock* rb,
float x, float y, float w, float h, float radius,
float r, float g, float b, float a);
TB_API void tb_draw_fill_circle(TinyBlocks_RenderableBlock* rb,
float cx, float cy, float radius,
float r, float g, float b, float a);
TB_API void tb_draw_stroke_line(TinyBlocks_RenderableBlock* rb,
float x1, float y1, float x2, float y2, float w,
float r, float g, float b, float a);
TB_API void tb_draw_stroke_rect (TinyBlocks_RenderableBlock* rb,
float x, float y, float w, float h, float stroke_w,
float r, float g, float b, float a);
TB_API void tb_draw_stroke_circle(TinyBlocks_RenderableBlock* rb,
float cx, float cy, float radius, float stroke_w,
float r, float g, float b, float a);
TB_API void tb_draw_set_clip (TinyBlocks_RenderableBlock* rb,
float x, float y, float w, float h);
TB_API void tb_draw_clear_clip (TinyBlocks_RenderableBlock* rb);
TB_API void tb_draw_text (TinyBlocks_RenderableBlock* rb,
float x, float y, const char* text, float font_size,
float r, float g, float b, float a);
/* Fontes do texto (param do TB_DRAW_TEXT). Os icones sao glifos do Material
* Symbols (codepoints da area privada, ex.: U+E8B8 = "settings"); o backend
* sem a fonte de icones nao desenha nada. */
#define TB_FONT_REGULAR 0 /* Roboto Regular */
#define TB_FONT_MEDIUM 1 /* Roboto Medium (rotulos, titulos) */
#define TB_FONT_ICON 2 /* Material Symbols Outlined */
#define TB_FONT_ICON_FILLED 3 /* Material Symbols (preenchido) */
#define TB_FONT_COUNT 4
TB_API void tb_draw_text_font (TinyBlocks_RenderableBlock* rb,
float x, float y, const char* text, float font_size, int font,
float r, float g, float b, float a);
/* Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é
* ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a
* imagem precisa continuar viva até o backend renderizar o frame. */
TB_API void tb_draw_image (TinyBlocks_RenderableBlock* rb,
float x, float y, float w, float h,
const TinyBlocks_Image* image);
/* Mescla src em dst deslocando todas as coordenadas por (dx, dy).
Usado pelo editor para incorporar sub-renderables de blocos com on_draw. */
TB_API void tb_draw_merge_offset(TinyBlocks_RenderableBlock* dst,
const TinyBlocks_RenderableBlock* src,
float dx, float dy);
/* Estimativa de largura de texto (independente de fonte real).
Precisa ser substituída por medição real pelo backend quando disponível. */
TB_API float tb_measure_text(const char* text, float font_size);
#endif /* TINYBLOCKS_RENDERABLE_BLOCK_H */