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
@@ -430,6 +430,8 @@ typedef struct Tab {
|
|||||||
float img_hue, img_sat, img_val; /* HSV da cor atual (roda de cor) */
|
float img_hue, img_sat, img_val; /* HSV da cor atual (roda de cor) */
|
||||||
int img_cdrag; /* arrasto na roda: 0=nada 1=matiz 2=SV */
|
int img_cdrag; /* arrasto na roda: 0=nada 1=matiz 2=SV */
|
||||||
float img_zoom; /* escala de exibicao (1.0 = 1:1) */
|
float img_zoom; /* escala de exibicao (1.0 = 1:1) */
|
||||||
|
float img_pan_x; /* deslocamento da pagina (zoom no cursor) */
|
||||||
|
float img_pan_y;
|
||||||
int img_drag; /* traco em andamento */
|
int img_drag; /* traco em andamento */
|
||||||
int img_drag_x, img_drag_y;
|
int img_drag_x, img_drag_y;
|
||||||
TinyBlocks_Image* img_undo[IMG_UNDO_MAX];
|
TinyBlocks_Image* img_undo[IMG_UNDO_MAX];
|
||||||
@@ -681,6 +683,7 @@ TB_ED_API void start_path(Ed* ed, int mode, const char* def);
|
|||||||
# define img_ensure tb_editor_image_ensure
|
# define img_ensure tb_editor_image_ensure
|
||||||
# define img_sel_reset tb_editor_image_sel_reset
|
# define img_sel_reset tb_editor_image_sel_reset
|
||||||
# define img_sel_commit tb_editor_image_sel_commit
|
# define img_sel_commit tb_editor_image_sel_commit
|
||||||
|
# define image_zoom tb_editor_image_zoom
|
||||||
#else
|
#else
|
||||||
# define render_image_tab tb_ed_img.view
|
# define render_image_tab tb_ed_img.view
|
||||||
# define image_click tb_ed_img.click
|
# define image_click tb_ed_img.click
|
||||||
@@ -691,6 +694,7 @@ TB_ED_API void start_path(Ed* ed, int mode, const char* def);
|
|||||||
# define img_ensure tb_ed_img.ensure
|
# define img_ensure tb_ed_img.ensure
|
||||||
# define img_sel_reset tb_ed_img.sel_reset
|
# define img_sel_reset tb_ed_img.sel_reset
|
||||||
# define img_sel_commit tb_ed_img.sel_commit
|
# define img_sel_commit tb_ed_img.sel_commit
|
||||||
|
# define image_zoom tb_ed_img.zoom
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Configuracoes (settings) - UI desenhada pelo editor */
|
/* Configuracoes (settings) - UI desenhada pelo editor */
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ typedef struct {
|
|||||||
void (*ensure) (Ed*, Tab*);
|
void (*ensure) (Ed*, Tab*);
|
||||||
void (*sel_reset) (Tab*);
|
void (*sel_reset) (Tab*);
|
||||||
void (*sel_commit)(Tab*);
|
void (*sel_commit)(Tab*);
|
||||||
|
void (*zoom) (Ed*, float, float, int); /* roda do mouse = zoom */
|
||||||
} TbEdImageApi;
|
} TbEdImageApi;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
+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_reset (Tab* T);
|
||||||
void tb_editor_image_sel_commit(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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
img_area(ed, &ax, &ay, &aw, &ah);
|
||||||
*dw = T->img_w * T->img_zoom;
|
*dw = T->img_w * T->img_zoom;
|
||||||
*dh = T->img_h * T->img_zoom;
|
*dh = T->img_h * T->img_zoom;
|
||||||
*dx = ax + (aw - *dw) * 0.5f;
|
*dx = ax + (aw - *dw) * 0.5f + T->img_pan_x;
|
||||||
*dy = ay + (ah - *dh) * 0.5f;
|
*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) {
|
static void img_tool_rect(Ed* ed, int i, float* x, float* y) {
|
||||||
*x = WS_X + (IMG_TOOL_W - IMG_TH) * 0.5f;
|
*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);
|
clip_clear(ed, rb);
|
||||||
rb_fill_rrect(rb, ax + 40, ay + ah - 10, aw - 80, 6, 3, COL_PAINT_SHAD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- rodape: controles do desenho --- */
|
/* --- 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 (!in_rect(mx, my, rx, ry, rw, rh)) continue;
|
||||||
if (i == 0) { img_sel_reset(T); img_undo_do(T); return true; }
|
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 == 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 == 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) { T->img_zoom *= 1.25f; if (T->img_zoom > 8.f) T->img_zoom = 8.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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1069,6 +1075,39 @@ bool tb_editor_image_click(Ed* ed, float mx, float my) {
|
|||||||
return true;
|
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) {
|
void tb_editor_image_drag(Ed* ed, float mx, float my) {
|
||||||
Tab* T = &CT;
|
Tab* T = &CT;
|
||||||
if (!T->img_drag) return;
|
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->img_path, sizeof(T->img_path), path);
|
||||||
scopy(T->name, sizeof(T->name), base);
|
scopy(T->name, sizeof(T->name), base);
|
||||||
T->img_zoom = 1.f;
|
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);
|
snprintf(ed->hot_status, sizeof(ed->hot_status), "Imagem aberta: %.200s", path);
|
||||||
ed->hot_status_ok = true;
|
ed->hot_status_ok = true;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -4332,6 +4332,9 @@ static void editor_eval(TinyBlocks_Block* self, TinyBlocks* rt) {
|
|||||||
} else if (CT.kind == TK_CODE && mx >= WS_X && mx < WIN_W - STAGE_W && my >= WS_Y) {
|
} else if (CT.kind == TK_CODE && mx >= WS_X && mx < WIN_W - STAGE_W && my >= WS_Y) {
|
||||||
CT.code_scroll -= (int)sdy * 3;
|
CT.code_scroll -= (int)sdy * 3;
|
||||||
if (CT.code_scroll < 0) CT.code_scroll = 0;
|
if (CT.code_scroll < 0) CT.code_scroll = 0;
|
||||||
|
} else if (CT.kind == TK_IMAGE && mx >= WS_X && mx < WIN_W - STAGE_W && my >= WS_Y) {
|
||||||
|
/* roda do mouse na aba de imagem = zoom no cursor (nao pinta) */
|
||||||
|
image_zoom(ed, mx, my, (int)(sdy > 0 ? 1 : sdy < 0 ? -1 : 0));
|
||||||
} else if (mx >= WS_X && mx < WIN_W - STAGE_W && my >= WS_Y) {
|
} else if (mx >= WS_X && mx < WIN_W - STAGE_W && my >= WS_Y) {
|
||||||
CT.ws_sx -= (float)sdx * 40.f;
|
CT.ws_sx -= (float)sdx * 40.f;
|
||||||
CT.ws_sy -= (float)sdy * 40.f;
|
CT.ws_sy -= (float)sdy * 40.f;
|
||||||
|
|||||||
@@ -131,8 +131,9 @@ static bool resolve_image(void) {
|
|||||||
sym_fn(&a.ensure, "tinyblocks-editor-image", "tb_editor_image_ensure");
|
sym_fn(&a.ensure, "tinyblocks-editor-image", "tb_editor_image_ensure");
|
||||||
sym_fn(&a.sel_reset, "tinyblocks-editor-image", "tb_editor_image_sel_reset");
|
sym_fn(&a.sel_reset, "tinyblocks-editor-image", "tb_editor_image_sel_reset");
|
||||||
sym_fn(&a.sel_commit, "tinyblocks-editor-image", "tb_editor_image_sel_commit");
|
sym_fn(&a.sel_commit, "tinyblocks-editor-image", "tb_editor_image_sel_commit");
|
||||||
|
sym_fn(&a.zoom, "tinyblocks-editor-image", "tb_editor_image_zoom");
|
||||||
bool ok = a.view && a.click && a.drag && a.release && a.load_file && a.save &&
|
bool ok = a.view && a.click && a.drag && a.release && a.load_file && a.save &&
|
||||||
a.ensure && a.sel_reset && a.sel_commit;
|
a.ensure && a.sel_reset && a.sel_commit && a.zoom;
|
||||||
if (ok) tb_ed_img = a;
|
if (ok) tb_ed_img = a;
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-1
@@ -37,6 +37,7 @@ static void draw(void) {
|
|||||||
tb_renderable_release_all();
|
tb_renderable_release_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float g_scroll_dy = 0.f;
|
||||||
static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char* text) {
|
static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char* text) {
|
||||||
tb_block_set_output(ev, GFX_IN_MOUSE_X, tb_value_real(mx));
|
tb_block_set_output(ev, GFX_IN_MOUSE_X, tb_value_real(mx));
|
||||||
tb_block_set_output(ev, GFX_IN_MOUSE_Y, tb_value_real(my));
|
tb_block_set_output(ev, GFX_IN_MOUSE_Y, tb_value_real(my));
|
||||||
@@ -49,11 +50,17 @@ static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char
|
|||||||
tb_block_set_output(ev, GFX_IN_TEXT, tb_value_text(text ? text : ""));
|
tb_block_set_output(ev, GFX_IN_TEXT, tb_value_text(text ? text : ""));
|
||||||
tb_block_set_output(ev, GFX_IN_DROP_FILE, tb_value_text(""));
|
tb_block_set_output(ev, GFX_IN_DROP_FILE, tb_value_text(""));
|
||||||
tb_block_set_output(ev, GFX_IN_SCROLL_DX, tb_value_real(0));
|
tb_block_set_output(ev, GFX_IN_SCROLL_DX, tb_value_real(0));
|
||||||
tb_block_set_output(ev, GFX_IN_SCROLL_DY, tb_value_real(0));
|
tb_block_set_output(ev, GFX_IN_SCROLL_DY, tb_value_real(g_scroll_dy));
|
||||||
tb_block_set_output(ev, GFX_IN_WIN_W, tb_value_integer(1280));
|
tb_block_set_output(ev, GFX_IN_WIN_W, tb_value_integer(1280));
|
||||||
tb_block_set_output(ev, GFX_IN_WIN_H, tb_value_integer(720));
|
tb_block_set_output(ev, GFX_IN_WIN_H, tb_value_integer(720));
|
||||||
tb_block_eval(scene, rt);
|
tb_block_eval(scene, rt);
|
||||||
draw();
|
draw();
|
||||||
|
g_scroll_dy = 0.f;
|
||||||
|
}
|
||||||
|
/* Roda do mouse (usada para o zoom na aba de imagem) */
|
||||||
|
static void scroll(float mx, float my, float dy) {
|
||||||
|
g_scroll_dy = dy;
|
||||||
|
frame(mx, my, 0, 0, 0, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { R_ANY, R_CAT, R_FLY, R_WS, R_STAGE };
|
enum { R_ANY, R_CAT, R_FLY, R_WS, R_STAGE };
|
||||||
@@ -114,6 +121,16 @@ static bool find_sub(const char* sub, float* x, float* y) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* Conta pixels nao-brancos da ultima imagem desenhada no workspace */
|
/* Conta pixels nao-brancos da ultima imagem desenhada no workspace */
|
||||||
|
/* Largura da maior imagem do workspace (a folha de desenho) */
|
||||||
|
static float img_draw_w(void) {
|
||||||
|
float best = 0, w = 0;
|
||||||
|
for (uint32_t i = 0; i < ncmd; i++) {
|
||||||
|
if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image || !in_region(cmds[i].x, R_WS)) continue;
|
||||||
|
float a = cmds[i].w * cmds[i].h;
|
||||||
|
if (a > best) { best = a; w = cmds[i].w; }
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
static int img_nonwhite(void) {
|
static int img_nonwhite(void) {
|
||||||
/* A folha de desenho e a MAIOR imagem do workspace (miniaturas sao pequenas) */
|
/* A folha de desenho e a MAIOR imagem do workspace (miniaturas sao pequenas) */
|
||||||
const TinyBlocks_Image* im = NULL;
|
const TinyBlocks_Image* im = NULL;
|
||||||
|
|||||||
Reference in new issue
Block a user