Imagens no palco por nome/número, paleta recarregável e slider de zoom
- Core: armazém de imagens nomeadas (tb_image_store_*) e tb_stage_image* para desenhar imagens no palco pelo nome ou pelo número. - Caneta: blocos "desenhe imagem nome/número". - tinyblocks-api: tb_api_load_named/tb_api_find_library e mtime em ns; o editor carrega as libraries de categoria como .so quando existem, para a paleta recarregar ao vivo. - Aba de imagem: slider de zoom no rodapé no lugar dos botões -/+. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b6bc65062
commit
adf5d2cd12
11 files changed
+378
-32
No files matched your search
+90
-7
@@ -165,6 +165,42 @@ static float img_pal_y(Ed* ed) {
|
||||
(void)cx;
|
||||
return cy + ro + 24;
|
||||
}
|
||||
/* Slider de zoom do rodape: trilha + botao redondo (mostra a porcentagem).
|
||||
E um widget novo do modulo: nasceu por hot reload, sem mudar o struct Tab
|
||||
(usa o img_zoom que ja existia). */
|
||||
#define IMG_SLIDER_H 6
|
||||
static void img_zoom_slider(Ed* ed, float* x, float* y, float* w, float* h) {
|
||||
float ax, ay, aw, ah;
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
*x = ax + 176;
|
||||
*w = aw - 176 - 14;
|
||||
*h = IMG_SLIDER_H;
|
||||
*y = img_foot_y(ed) + 22.f;
|
||||
(void)h; (void)ah;
|
||||
*h = IMG_SLIDER_H;
|
||||
}
|
||||
/* posicao (0..1) do botao na trilha, em escala logaritmica 10%..800% */
|
||||
static float img_zoom_t(float zoom) {
|
||||
if (zoom < 0.1f) zoom = 0.1f;
|
||||
if (zoom > 8.f) zoom = 8.f;
|
||||
return logf(zoom / 0.1f) / logf(80.f);
|
||||
}
|
||||
static float img_zoom_of_t(float t) {
|
||||
if (t < 0.f) t = 0.f;
|
||||
if (t > 1.f) t = 1.f;
|
||||
return 0.1f * powf(80.f, t);
|
||||
}
|
||||
/* aplica zoom "de verdade" (sem ancorar no ponteiro) */
|
||||
static void img_zoom_set(Ed* ed, float nz) {
|
||||
Tab* T = &CT;
|
||||
if (nz < 0.1f) nz = 0.1f;
|
||||
if (nz > 8.f) nz = 8.f;
|
||||
T->img_zoom = nz;
|
||||
if (nz <= 1.f) { T->img_pan_x = 0.f; T->img_pan_y = 0.f; }
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Zoom %d%%", (int)(nz * 100.f + 0.5f));
|
||||
ed->hot_status_ok = true;
|
||||
}
|
||||
|
||||
/* Rodape da area de desenho: Desfazer / Limpar / zoom */
|
||||
static void img_foot_btn(Ed* ed, int which, float* x, float* y, float* w, float* h) {
|
||||
float ax, ay, aw, ah, fy;
|
||||
@@ -174,8 +210,7 @@ static void img_foot_btn(Ed* ed, int which, float* x, float* y, float* w, float*
|
||||
switch (which) {
|
||||
case 0: *w = 78; *x = ax + 10; break; /* Desfazer */
|
||||
case 1: *w = 68; *x = ax + 96; break; /* Limpar */
|
||||
case 2: *w = 30; *x = ax + aw - 40; break; /* zoom - */
|
||||
case 3: *w = 30; *x = ax + aw - 78; break; /* zoom + */
|
||||
|
||||
default: *w = 30; *x = ax + aw - 40; break;
|
||||
}
|
||||
}
|
||||
@@ -758,8 +793,8 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
fy = img_foot_y(ed);
|
||||
rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, COL_PANEL);
|
||||
rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, COL_PAINT_LINE);
|
||||
const char* labels[4] = { "Desfazer", "Limpar", "-", "+" };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const char* labels[2] = { "Desfazer", "Limpar" };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
float bx, by, bw, bh;
|
||||
img_foot_btn(ed, i, &bx, &by, &bw, &bh);
|
||||
bool enabled = !(i == 0 && T->img_undo_n == 0);
|
||||
@@ -769,6 +804,37 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_text_c(rb, bx + (bw - tw(labels[i], FS_UI-1)) * 0.5f, by + bh * 0.5f,
|
||||
labels[i], enabled ? COL_TEXT : COL_TEXT_DIM, FS_UI - 1);
|
||||
}
|
||||
|
||||
/* ---- widget novo: slider de zoom ---- */
|
||||
{
|
||||
float sx, sy, sw, sh;
|
||||
img_zoom_slider(ed, &sx, &sy, &sw, &sh);
|
||||
float t = img_zoom_t(T->img_zoom);
|
||||
float kx = sx + t * (sw - 14.f) + 7.f;
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx - 6, sy - 10, sw + 12, sh + 20);
|
||||
/* trilha */
|
||||
rb_fill_rrect(rb, sx, sy, sw, sh, 3, COL_PAINT_BTN);
|
||||
/* parte preenchida ate o botao */
|
||||
rb_fill_rrect(rb, sx, sy, kx - sx, sh, 3, hov ? COL_MENU : COLA(0, 122, 216, 255));
|
||||
rb_stroke_rect(rb, sx, sy, sw, sh, 1.f, COL_PAINT_LINE);
|
||||
/* marcas de 100% */
|
||||
{
|
||||
float mxr = sx + img_zoom_t(1.f) * (sw - 14.f) + 7.f;
|
||||
rb_fill_rect(rb, mxr - 0.5f, sy - 3, 1.f, sh + 6, COL_TEXT_DIM);
|
||||
}
|
||||
/* botao */
|
||||
rb_fill_circle(rb, kx, sy + sh * 0.5f, 7.f, COL_WHITE);
|
||||
rb_stroke_circle(rb, kx, sy + sh * 0.5f, 7.f, 2.f, hov ? COL_MENU : COLA(0, 122, 216, 255));
|
||||
/* porcentagem acima do botao */
|
||||
{
|
||||
char z[16];
|
||||
snprintf(z, sizeof(z), "%d%%", (int)(T->img_zoom * 100.f + 0.5f));
|
||||
float zx = kx - tw(z, 8.5f) * 0.5f;
|
||||
if (zx < sx - 2) zx = sx - 2;
|
||||
if (zx + tw(z, 8.5f) > sx + sw + 2) zx = sx + sw + 2 - tw(z, 8.5f);
|
||||
rb_text_c(rb, zx, sy - 7, z, COL_TEXT, 8.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --- coluna direita: cores (roda de matiz + saturacao/valor + paleta) --- */
|
||||
@@ -1002,14 +1068,24 @@ bool tb_editor_image_click(Ed* ed, float mx, float my) {
|
||||
/* rodape: botoes do desenho */
|
||||
float fy = img_foot_y(ed);
|
||||
if (my >= fy) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
/* widget novo: clique/arrasto no slider de zoom */
|
||||
{
|
||||
float sx, sy, sw, sh;
|
||||
img_zoom_slider(ed, &sx, &sy, &sw, &sh);
|
||||
if (in_rect(mx, my, sx - 6, fy, sw + 12, img_foot_y(ed) + IMG_FOOT_H - fy)) {
|
||||
img_zoom_set(ed, img_zoom_of_t((mx - (sx + 7.f)) / (sw - 14.f)));
|
||||
T->img_cdrag = 5;
|
||||
T->img_drag = 1;
|
||||
ed->img_mx = mx; ed->img_my = my;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
float rx, ry, rw, rh;
|
||||
img_foot_btn(ed, i, &rx, &ry, &rw, &rh);
|
||||
if (!in_rect(mx, my, rx, ry, rw, rh)) continue;
|
||||
if (i == 0) { img_sel_reset(T); img_undo_do(T); return true; }
|
||||
if (i == 1) { img_sel_reset(T); img_undo_push(T); img_clear_layer(T); return true; }
|
||||
if (i == 2) { tb_editor_image_zoom(ed, (rx + rw * 0.5f), WS_Y + WS_H * 0.5f, -1); T->img_pan_x = T->img_pan_y = 0.f; return true; }
|
||||
if (i == 3) { tb_editor_image_zoom(ed, (rx + rw * 0.5f), WS_Y + WS_H * 0.5f, +1); T->img_pan_x = T->img_pan_y = 0.f; return true; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1112,6 +1188,13 @@ void tb_editor_image_drag(Ed* ed, float mx, float my) {
|
||||
Tab* T = &CT;
|
||||
if (!T->img_drag) return;
|
||||
ed->img_mx = mx; ed->img_my = my;
|
||||
/* arrasto no slider de zoom (widget novo) */
|
||||
if (T->img_cdrag == 5) {
|
||||
float sx, sy, sw, sh;
|
||||
img_zoom_slider(ed, &sx, &sy, &sw, &sh);
|
||||
img_zoom_set(ed, img_zoom_of_t((mx - (sx + 7.f)) / (sw - 14.f)));
|
||||
return;
|
||||
}
|
||||
/* arrasto na roda de cor / quadrado saturacao-valor */
|
||||
if (T->img_cdrag) {
|
||||
float cx_, cy_, ro, ri, sx, sy, sw2, sh2;
|
||||
|
||||
Reference in new issue
Block a user