editor: roda do mouse da zoom na aba de imagem e nao pinta mais
- Aba de imagem: roda do mouse = zoom centrado no ponteiro (como no Krita), com deslocamento (pan) para nao perder o ponto de referencia; com zoom <= 100% a pagina volta ao centro. O scroll nao pinta nem move blocos. - tinyblocks-editor-image exporta tb_editor_image_zoom e a tabela da API (tb_ed_img.zoom) faz a ponte, entao o editor so chama por ponteiro. - Removida a barra cinza decorativa no fim da tela (parecia uma barra de rolagem falsa). - harness: scroll() e testes 'roda do mouse aproxima/afasta/nao pinta'.
This commit is contained in:
1 parent
0143d3efd5
commit
2b6bc65062
7 files changed
+77
-7
No files matched your search
+4
@@ -39,6 +39,10 @@ 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);
|
||||
|
||||
/* Zoom centrado no ponteiro (roda do mouse): steps > 0 aproxima, < 0 afasta.
|
||||
Fora da area de desenho nao faz nada (o scroll nao pinta nem move blocos). */
|
||||
void tb_editor_image_zoom(Ed* ed, float mx, float my, int steps);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+45
-5
@@ -122,8 +122,15 @@ static void img_view(Ed* ed, Tab* T, float* dx, float* dy, float* dw, float* dh)
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
*dw = T->img_w * T->img_zoom;
|
||||
*dh = T->img_h * T->img_zoom;
|
||||
*dx = ax + (aw - *dw) * 0.5f;
|
||||
*dy = ay + (ah - *dh) * 0.5f;
|
||||
*dx = ax + (aw - *dw) * 0.5f + T->img_pan_x;
|
||||
*dy = ay + (ah - *dh) * 0.5f + T->img_pan_y;
|
||||
}
|
||||
/* Canto da pagina sem o deslocamento (usado para reposicionar no zoom) */
|
||||
static void img_base(Ed* ed, Tab* T, float zoom, float* bx, float* by) {
|
||||
float ax, ay, aw, ah;
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
*bx = ax + (aw - T->img_w * zoom) * 0.5f;
|
||||
*by = ay + (ah - T->img_h * zoom) * 0.5f;
|
||||
}
|
||||
static void img_tool_rect(Ed* ed, int i, float* x, float* y) {
|
||||
*x = WS_X + (IMG_TOOL_W - IMG_TH) * 0.5f;
|
||||
@@ -742,7 +749,6 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
}
|
||||
}
|
||||
clip_clear(ed, rb);
|
||||
rb_fill_rrect(rb, ax + 40, ay + ah - 10, aw - 80, 6, 3, COL_PAINT_SHAD);
|
||||
}
|
||||
|
||||
/* --- rodape: controles do desenho --- */
|
||||
@@ -1002,8 +1008,8 @@ bool tb_editor_image_click(Ed* ed, float mx, float my) {
|
||||
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) { T->img_zoom *= 0.8f; if (T->img_zoom < 0.1f) T->img_zoom = 0.1f; return true; }
|
||||
if (i == 3) { T->img_zoom *= 1.25f; if (T->img_zoom > 8.f) T->img_zoom = 8.f; 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;
|
||||
}
|
||||
@@ -1069,6 +1075,39 @@ bool tb_editor_image_click(Ed* ed, float mx, float my) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Zoom centrado no cursor (roda do mouse), como no Krita: o ponto que esta
|
||||
embaixo do ponteiro continua no mesmo lugar; com zoom <= 100% a pagina
|
||||
cabe na tela e volta ao centro. */
|
||||
void tb_editor_image_zoom(Ed* ed, float mx, float my, int steps) {
|
||||
Tab* T = &CT;
|
||||
if (steps == 0) return;
|
||||
float ax, ay, aw, ah;
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
if (!in_rect(mx, my, ax, ay, aw, ah)) return; /* so na area de desenho */
|
||||
float old = T->img_zoom;
|
||||
float nz = old * powf(1.18f, (float)steps);
|
||||
if (nz < 0.1f) nz = 0.1f;
|
||||
if (nz > 8.f) nz = 8.f;
|
||||
if (fabsf(nz - old) < 1e-4f) return;
|
||||
float dx, dy, dw, dh;
|
||||
img_view(ed, T, &dx, &dy, &dw, &dh);
|
||||
(void)dw; (void)dh;
|
||||
float ix = (mx - dx) / old, iy = (my - dy) / old; /* ponto na pagina */
|
||||
T->img_zoom = nz;
|
||||
if (nz <= 1.f) {
|
||||
T->img_pan_x = T->img_pan_y = 0.f; /* cabe: centraliza */
|
||||
} else {
|
||||
float bx, by;
|
||||
img_base(ed, T, nz, &bx, &by);
|
||||
T->img_pan_x = (mx - ix * nz) - bx;
|
||||
T->img_pan_y = (my - iy * nz) - by;
|
||||
}
|
||||
char msg[48];
|
||||
snprintf(msg, sizeof(msg), "Zoom %d%%", (int)(nz * 100.f + 0.5f));
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "%s", msg);
|
||||
ed->hot_status_ok = true;
|
||||
}
|
||||
|
||||
void tb_editor_image_drag(Ed* ed, float mx, float my) {
|
||||
Tab* T = &CT;
|
||||
if (!T->img_drag) return;
|
||||
@@ -1171,6 +1210,7 @@ void tb_editor_image_load_file(Ed* ed, const char* path, int kind) {
|
||||
scopy(T->img_path, sizeof(T->img_path), path);
|
||||
scopy(T->name, sizeof(T->name), base);
|
||||
T->img_zoom = 1.f;
|
||||
T->img_pan_x = 0.f; T->img_pan_y = 0.f;
|
||||
snprintf(ed->hot_status, sizeof(ed->hot_status), "Imagem aberta: %.200s", path);
|
||||
ed->hot_status_ok = true;
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user