editor: bundle com libraries privadas + hot reload (tinyblocks-api) e aba de imagem estilo Krita

- tinyblocks-editor agora e um bundle: libraries privadas em
  libraries/tinyblocks-editor-{widgets,image} (.a + .so), com library.toml
  (bundle = tinyblocks-editor, private = true -> nao aparecem no libman).
- O editor carrega os modulos por dlopen via tinyblocks-api e chama tudo por
  tabelas de ponteiros (tb_ed_w, tb_ed_img): da para recompilar so a parte que
  mudou e o editor recarrega ao vivo (make ed-modules), sem reiniciar.
- tinyblocks-api ganhou modulos de codigo (tb_api_code_*) e watcher de
  arquivos (inotify, com mtime como reserva).
- libman: entradas com bundle/private nao sao listadas como extensao.
- Aba de imagem: layout estilo Krita - ferramentas na esquerda, tela no meio,
  roda de cores + paleta + camadas na coluna da direita; miniatura por camada
  (como as fantasias do Scratch); rodape enxuto (Desfazer/Limpar/zoom).
- Ferramenta selecionar (mover/redimensionar/excluir pixels) e consertada a
  geometria da folha (doc = area de desenho, zoom puro).
- Makefile: alvo ed-modules; AppImage empacota os .so do bundle.
- harness: testes de imagem atualizados + testes de cores na lateral.
This commit is contained in:
mguinhos committed 2026-10-20 23:31:42 -03:00
1 parent 036162280d
commit 0143d3efd5
21 files changed
+3775 -557

No files matched your search

@@ -0,0 +1,42 @@
# Makefile da library privada tinyblocks-editor-image
# Bundle "tinyblocks-editor". Constroi .a e .so.
CC := gcc
BUILD := build
CFLAGS := -std=c11 -Wall -Wextra -pedantic \
-DTB_EDITOR_IMAGE_BUILD \
-D_POSIX_C_SOURCE=200809L \
-I../../../../include -Iinclude \
-I../../internal \
-I../tinyblocks-editor-widgets/include \
-I../../../tinyblocks-graphics/include \
-I../../../tinyblocks-variables/include \
-I../../../tinyblocks-blueprint/include \
-I../../../tinyblocks-environ/include \
-I../../../tinyblocks-api/include \
-I../../../tinyblocks-libman/include \
-I../../../tinyblocks-syntax/include
OBJS := $(BUILD)/tb_editor_image.o
LIB_A := $(BUILD)/libtinyblocks-editor-image.a
LIB_SO := $(BUILD)/libtinyblocks-editor-image.so
.PHONY: all static shared clean
all: static shared
static: $(LIB_A)
shared: $(LIB_SO)
$(BUILD)/tb_editor_image.o: src/tb_editor_image.c include/tb_editor_image.h \
../../internal/tb_editor_internal.h \
../tinyblocks-editor-widgets/include/tb_editor_widgets.h
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -fPIC -c $< -o $@
$(LIB_A): $(OBJS)
ar rcs $@ $^
$(LIB_SO): $(OBJS)
$(CC) -shared -o $@ $^ -Wl,-z,lazy
clean:
$(RM) -r $(BUILD)
@@ -0,0 +1,46 @@
/*
* TinyBlocks - tb_editor_image.h
* Aba "Imagem" do editor (library privada do bundle tinyblocks-editor).
*
* O estado de cada aba mora em Tab (img_layers/img_sel/...), definido no
* cabecalho interno do editor. Estas funcoes recebem o Ed dono da aba e
* operam sempre na aba corrente (CT).
*/
#ifndef TB_EDITOR_IMAGE_H
#define TB_EDITOR_IMAGE_H
#include <stdbool.h>
#include <tinyblocks/tb_renderable_block.h>
#ifdef __cplusplus
extern "C" {
#endif
struct Ed;
struct Tab;
typedef struct Ed Ed;
typedef struct Tab Tab;
/* Desenha a aba de imagem inteira (painel, ferramentas, pagina, rodape) */
void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb);
/* Entrada: clique, arrasto e soltura do botao esquerdo */
bool tb_editor_image_click (Ed* ed, float mx, float my);
void tb_editor_image_drag (Ed* ed, float mx, float my);
void tb_editor_image_release(Ed* ed, float mx, float my);
/* Arquivo: kind < 0 abre como documento, senao adiciona uma camada
(0 = raster, 1 = vetor). Salvaguarda achata as camadas. */
void tb_editor_image_load_file(Ed* ed, const char* path, int kind);
void tb_editor_image_save (Ed* ed, const char* path);
/* Garante um documento vazio (usado ao criar a aba) e limpa selecao */
void tb_editor_image_ensure (Ed* ed, Tab* T);
void tb_editor_image_sel_reset (Tab* T);
void tb_editor_image_sel_commit(Tab* T);
#ifdef __cplusplus
}
#endif
#endif /* TB_EDITOR_IMAGE_H */
@@ -0,0 +1,17 @@
# Editor de imagem do editor (bundle "tinyblocks-editor").
[library]
name = "tinyblocks-editor-image"
bundle = "tinyblocks-editor"
private = true
version = "1.0.0"
category = "Editor"
description = "Aba Imagem: pintura com camadas raster/vetor"
color = [255, 152, 0, 255]
dark = [230, 119, 0, 255]
[build]
sources = ["src/tb_editor_image.c"]
includes = ["include"]
shared = "build/libtinyblocks-editor-image.so"
static = "build/libtinyblocks-editor-image.a"
depends = ["tinyblocks-editor-widgets"]
@@ -0,0 +1,31 @@
# Makefile da library privada tinyblocks-editor-widgets
# Bundle "tinyblocks-editor": vem junto com o editor.
# Constroi build/libtinyblocks-editor-widgets.a e .so
CC := gcc
BUILD := build
CFLAGS := -std=c11 -Wall -Wextra -pedantic \
-D_POSIX_C_SOURCE=200809L \
-I../../../../include -Iinclude -I../../../tinyblocks-graphics/include
OBJS := $(BUILD)/tb_editor_widgets.o
LIB_A := $(BUILD)/libtinyblocks-editor-widgets.a
LIB_SO := $(BUILD)/libtinyblocks-editor-widgets.so
.PHONY: all static shared clean
all: static shared
static: $(LIB_A)
shared: $(LIB_SO)
$(BUILD)/tb_editor_widgets.o: src/tb_editor_widgets.c include/tb_editor_widgets.h
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -fPIC -c $< -o $@
$(LIB_A): $(OBJS)
ar rcs $@ $^
$(LIB_SO): $(OBJS)
$(CC) -shared -o $@ $^
clean:
$(RM) -r $(BUILD)
@@ -0,0 +1,46 @@
/*
* TinyBlocks - tb_editor_widgets.h
* Library privada do editor: primitivas de desenho e "tema" (cores).
*
* E o tijolo mais baixo do editor: emite TinyBlocks_DrawCmd num
* TinyBlocks_RenderableBlock e nao guarda estado. Nao conhece o editor
* (Ed/Tab) nem o backend grafico, por isso pode ser usada por qualquer
* library do bundle do editor (blocos, imagem, codigo, dialogo...).
*/
#ifndef TB_EDITOR_WIDGETS_H
#define TB_EDITOR_WIDGETS_H
#include <stdbool.h>
#include <tinyblocks/tb_renderable_block.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Cor RGBA (0..1) */
typedef struct { float r, g, b, a; } TbEwColor;
#define TB_EW_RGB(r,g,b) {(r)/255.0f,(g)/255.0f,(b)/255.0f,1.0f}
#define TB_EW_RGBA(r,g,b,a) ((TbEwColor){(r)/255.0f,(g)/255.0f,(b)/255.0f,(a)/255.0f})
TbEwColor tb_ew_col_mul(TbEwColor c, float k);
/* Primitivas: espelham tb_draw_* mas com TbEwColor */
void tb_ew_fill_rect (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, TbEwColor c);
void tb_ew_fill_rrect (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, TbEwColor c);
void tb_ew_fill_circle(TinyBlocks_RenderableBlock* rb, float cx, float cy, float rad, TbEwColor c);
void tb_ew_stroke_rect(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float t, TbEwColor c);
void tb_ew_stroke_circle(TinyBlocks_RenderableBlock* rb, float cx, float cy, float rad, float t, TbEwColor c);
void tb_ew_line (TinyBlocks_RenderableBlock* rb, float x0, float y0, float x1, float y1, float w, TbEwColor c);
/* Texto alinhado a esquerda em x, centrado verticalmente em cy */
void tb_ew_text_c (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs);
/* Largura real do texto, medida pelo backend grafico */
float tb_ew_text_width(const char* s, float fs);
bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h);
#ifdef __cplusplus
}
#endif
#endif /* TB_EDITOR_WIDGETS_H */
@@ -0,0 +1,17 @@
# Widgets privados do editor (bundle "tinyblocks-editor").
[library]
name = "tinyblocks-editor-widgets"
bundle = "tinyblocks-editor"
private = true
version = "1.0.0"
category = "Editor"
description = "Primitivas de desenho e tema do editor"
color = [76, 151, 255, 255]
dark = [61, 121, 204, 255]
[build]
sources = ["src/tb_editor_widgets.c"]
includes = ["include"]
shared = "build/libtinyblocks-editor-widgets.so"
static = "build/libtinyblocks-editor-widgets.a"
depends = []
@@ -0,0 +1,44 @@
/*
* TinyBlocks - tb_editor_widgets.c
* Implementacao das primitivas de desenho do editor. Sem estado: apenas
* traduz chamadas em TinyBlocks_DrawCmd.
*/
#include <string.h>
#include <tb_graphics.h>
#include "tb_editor_widgets.h"
TbEwColor tb_ew_col_mul(TbEwColor c, float k) {
TbEwColor r;
r.r = c.r * k; r.g = c.g * k; r.b = c.b * k; r.a = c.a;
return r;
}
void tb_ew_fill_rect(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, TbEwColor c)
{ tb_draw_fill_rect(rb, x, y, w, h, c.r, c.g, c.b, c.a); }
void tb_ew_fill_rrect(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, TbEwColor c)
{ tb_draw_fill_rrect(rb, x, y, w, h, rad < 0 ? 0 : rad, c.r, c.g, c.b, c.a); }
void tb_ew_fill_circle(TinyBlocks_RenderableBlock* rb, float cx, float cy, float rad, TbEwColor c)
{ tb_draw_fill_circle(rb, cx, cy, rad, c.r, c.g, c.b, c.a); }
void tb_ew_stroke_rect(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float t, TbEwColor c)
{ tb_draw_stroke_rect(rb, x, y, w, h, t, c.r, c.g, c.b, c.a); }
void tb_ew_stroke_circle(TinyBlocks_RenderableBlock* rb, float cx, float cy, float rad, float t, TbEwColor c)
{ tb_draw_stroke_circle(rb, cx, cy, rad, t, c.r, c.g, c.b, c.a); }
void tb_ew_line(TinyBlocks_RenderableBlock* rb, float x0, float y0, float x1, float y1, float w, TbEwColor c)
{ tb_draw_stroke_line(rb, x0, y0, x1, y1, w, c.r, c.g, c.b, c.a); }
void tb_ew_text_c(TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs) {
if (!s || !s[0]) return;
tb_draw_text(rb, x, cy + fs * 0.36f, s, fs, c.r, c.g, c.b, c.a);
}
float tb_ew_text_width(const char* s, float fs) {
return tb_graphics_measure_text(s, fs);
}
bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h)
{ return mx >= x && mx < x + w && my >= y && my < y + h; }