- Ripple (gota que cresce do toque/clique) em todo componente com camada de estado; recortado no formato do componente (tb_ew_ripple). - TB_DRAW_FILL_POLY: poligono convexo com antialias (pontos no espaco do text). Hexagono e encaixe deixam de ser faixas de 1 px (sumiam em linhas com zoom e na densidade do celular). - Encaixe macho com cantos arredondados; encaixe femea recortado no topo dos comandos e dos blocos C (e nos bracos de baixo/"senao"). - Destaque ao soltar um reporter num campo segue a forma do campo; sombra de encaixe da pilha com a forma de bloco. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
152 lines
7.5 KiB
C
152 lines
7.5 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 */
|
|
TB_DRAW_FILL_POLY, /* poligono convexo preenchido (antialias); os pontos *
|
|
* ficam no espaco do text (tb_draw_poly_get/set), *
|
|
* param = quantos; x,y,w,h = caixa que o contem */
|
|
} 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
|
|
|
|
/* Poligono convexo (ate TB_POLY_MAX pontos; xy = x0,y0,x1,y1,...). Formas
|
|
* inclinadas (hexagono, encaixe) ficam lisas em qualquer escala. */
|
|
#define TB_POLY_MAX 16
|
|
TB_API void tb_draw_fill_poly (TinyBlocks_RenderableBlock* rb, const float* xy, int n,
|
|
float r, float g, float b, float a);
|
|
/* Pontos de um TB_DRAW_FILL_POLY (quem transforma comandos usa os dois) */
|
|
TB_API int tb_draw_poly_get (const TinyBlocks_DrawCmd* c, float* xy);
|
|
TB_API void tb_draw_poly_set (TinyBlocks_DrawCmd* c, const float* xy, int n);
|
|
|
|
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 */
|