Partial fix of T42052: Clip editor does not support Continue zoom style

This commit is contained in:
Sergey Sharybin 2014-10-07 17:24:14 +02:00
parent 1519b6a23e
commit 26083d5de5
Notes: blender-bot 2023-02-14 10:01:10 +01:00
Referenced by issue #42137, Keymap editing is broken
Referenced by issue #42052, "Continue" zoom style doesn't work in all views / editors
1 changed files with 64 additions and 12 deletions

View File

@ -79,6 +79,8 @@
#include "UI_view2d.h"
#include "PIL_time.h"
#include "clip_intern.h" // own include
/******************** view navigation utilities *********************/
@ -486,18 +488,25 @@ typedef struct ViewZoomData {
float zoom;
int event_type;
float location[2];
wmTimer *timer;
double timer_lastdraw;
} ViewZoomData;
static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
{
SpaceClip *sc = CTX_wm_space_clip(C);
ARegion *ar = CTX_wm_region(C);
ViewZoomData *vpd;
op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData");
WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
if (U.viewzoom == USER_ZOOM_CONT) {
/* needs a timer to continue redrawing */
vpd->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
vpd->timer_lastdraw = PIL_check_seconds_timer();
}
vpd->x = event->x;
vpd->y = event->y;
vpd->zoom = sc->zoom;
@ -518,6 +527,10 @@ static void view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
ED_region_tag_redraw(CTX_wm_region(C));
}
if (vpd->timer) {
WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
}
WM_cursor_modal_restore(CTX_wm_window(C));
MEM_freeN(op->customdata);
}
@ -555,22 +568,61 @@ static int view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
}
static void view_zoom_apply(bContext *C,
ViewZoomData *vpd,
wmOperator *op,
const wmEvent *event)
{
float factor;
if (U.viewzoom == USER_ZOOM_CONT) {
SpaceClip *sclip = CTX_wm_space_clip(C);
double time = PIL_check_seconds_timer();
float time_step = (float)(time - vpd->timer_lastdraw);
float fac;
float zfac;
if (U.uiflag & USER_ZOOM_HORIZ) {
fac = (float)(event->x - vpd->x);
}
else {
fac = (float)(event->y - vpd->y);
}
if (U.uiflag & USER_ZOOM_INVERT) {
fac = -fac;
}
zfac = 1.0f + ((fac / 20.0f) * time_step);
vpd->timer_lastdraw = time;
factor = (sclip->zoom * zfac) / vpd->zoom;
}
else {
float delta = event->x - vpd->x + event->y - vpd->y;
if (U.uiflag & USER_ZOOM_INVERT) {
delta *= -1;
}
factor = 1.0f + delta / 300.0f;
}
RNA_float_set(op->ptr, "factor", factor);
sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
ED_region_tag_redraw(CTX_wm_region(C));
}
static int view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
ViewZoomData *vpd = op->customdata;
float delta, factor;
switch (event->type) {
case TIMER:
if (event->customdata == vpd->timer) {
view_zoom_apply(C, vpd, op, event);
}
break;
case MOUSEMOVE:
delta = event->x - vpd->x + event->y - vpd->y;
if (U.uiflag & USER_ZOOM_INVERT)
delta *= -1;
factor = 1.0f + delta / 300.0f;
RNA_float_set(op->ptr, "factor", factor);
sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
ED_region_tag_redraw(CTX_wm_region(C));
view_zoom_apply(C, vpd, op, event);
break;
default:
if (event->type == vpd->event_type && event->val == KM_RELEASE) {