diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-02-24 17:31:18 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-02-24 17:31:18 +0400 |
commit | 826cb607315f247e24d1b561bb3eb1e54691d6eb (patch) | |
tree | eb76c28e3e2742737a846d401946d0e0c3ededbc | |
parent | f7c948560572f353390ba833d5ccb0c84326869f (diff) |
CLIP_OT_view_zoom (Ctrl-MMB) now takes into account Zoom to Mouse Position setting
-rw-r--r-- | source/blender/editors/space_clip/clip_ops.c | 139 |
1 files changed, 71 insertions, 68 deletions
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index a77e6dccbb8..d2f0cf019ab 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -68,35 +68,66 @@ /******************** view navigation utilities *********************/ -static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom) +static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom, float mpos[2]) { float oldzoom= sc->zoom; int width, height; sc->zoom= zoom; - if (sc->zoom > 0.1f && sc->zoom < 4.0f) - return; + if (sc->zoom < 0.1f || sc->zoom > 4.0f) { + /* check zoom limits */ + ED_space_clip_size(sc, &width, &height); + + width*= sc->zoom; + height*= sc->zoom; - /* check zoom limits */ - ED_space_clip_size(sc, &width, &height); + if((width < 4) && (height < 4)) + sc->zoom= oldzoom; + else if((ar->winrct.xmax - ar->winrct.xmin) <= sc->zoom) + sc->zoom= oldzoom; + else if((ar->winrct.ymax - ar->winrct.ymin) <= sc->zoom) + sc->zoom= oldzoom; + } - width*= sc->zoom; - height*= sc->zoom; + if((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && mpos) { + ED_space_clip_size(sc, &width, &height); - if((width < 4) && (height < 4)) - sc->zoom= oldzoom; - else if((ar->winrct.xmax - ar->winrct.xmin) <= sc->zoom) - sc->zoom= oldzoom; - else if((ar->winrct.ymax - ar->winrct.ymin) <= sc->zoom) - sc->zoom= oldzoom; + sc->xof+= ((mpos[0]-0.5f)*width-sc->xof)*(sc->zoom-oldzoom)/sc->zoom; + sc->yof+= ((mpos[1]-0.5f)*height-sc->yof)*(sc->zoom-oldzoom)/sc->zoom; + } } -static void sclip_zoom_set_factor(SpaceClip *sc, ARegion *ar, float zoomfac) +static void sclip_zoom_set_factor(SpaceClip *sc, ARegion *ar, float zoomfac, float mpos[2]) { - sclip_zoom_set(sc, ar, sc->zoom*zoomfac); + sclip_zoom_set(sc, ar, sc->zoom*zoomfac, mpos); } +static void sclip_zoom_set_factor_exec(bContext *C, wmEvent *event, float factor) +{ + SpaceClip *sc= CTX_wm_space_clip(C); + ARegion *ar= CTX_wm_region(C); + float co[2], *mpos = NULL; + + if (event) { + ED_clip_mouse_pos(C, event, co); + mpos = co; + } + + sclip_zoom_set_factor(sc, ar, factor, mpos); + + ED_region_tag_redraw(CTX_wm_region(C)); +} + +static void view_zoom_in_do_exec(bContext *C, wmEvent *event) +{ + sclip_zoom_set_factor_exec(C, event, 1.25f); +} + +static void view_zoom_out_do_exec(bContext *C, wmEvent *event) +{ + sclip_zoom_set_factor_exec(C, event, 0.8f); +} /******************** open clip operator ********************/ @@ -393,6 +424,7 @@ typedef struct ViewZoomData { float x, y; float zoom; int event_type; + float co[2]; } ViewZoomData; static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event) @@ -408,6 +440,8 @@ static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event) vpd->zoom= sc->zoom; vpd->event_type= event->type; + ED_clip_mouse_pos(C, event, vpd->co); + WM_event_add_modal_handler(C, op); } @@ -430,7 +464,7 @@ static int view_zoom_exec(bContext *C, wmOperator *op) SpaceClip *sc= CTX_wm_space_clip(C); ARegion *ar= CTX_wm_region(C); - sclip_zoom_set_factor(sc, ar, RNA_float_get(op->ptr, "factor")); + sclip_zoom_set_factor(sc, ar, RNA_float_get(op->ptr, "factor"), NULL); ED_region_tag_redraw(CTX_wm_region(C)); @@ -440,19 +474,18 @@ static int view_zoom_exec(bContext *C, wmOperator *op) static int view_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event) { if (event->type==MOUSEZOOM) { - SpaceClip *sc= CTX_wm_space_clip(C); - ARegion *ar= CTX_wm_region(C); float factor; factor= 1.0f + (event->x-event->prevx+event->y-event->prevy)/300.0f; RNA_float_set(op->ptr, "factor", factor); - sclip_zoom_set(sc, ar, sc->zoom*factor); - ED_region_tag_redraw(CTX_wm_region(C)); + + sclip_zoom_set_factor_exec(C, event, factor); return OPERATOR_FINISHED; } else { view_zoom_init(C, op, event); + return OPERATOR_RUNNING_MODAL; } } @@ -468,7 +501,7 @@ static int view_zoom_modal(bContext *C, wmOperator *op, wmEvent *event) case MOUSEMOVE: factor= 1.0f + (vpd->x-event->x+vpd->y-event->y)/300.0f; RNA_float_set(op->ptr, "factor", factor); - sclip_zoom_set(sc, ar, vpd->zoom*factor); + sclip_zoom_set(sc, ar, vpd->zoom*factor, vpd->co); ED_region_tag_redraw(CTX_wm_region(C)); break; default: @@ -513,57 +546,18 @@ void CLIP_OT_view_zoom(wmOperatorType *ot) static int view_zoom_in_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceClip *sc= CTX_wm_space_clip(C); - ARegion *ar= CTX_wm_region(C); - - sclip_zoom_set_factor(sc, ar, 1.25f); - - ED_region_tag_redraw(CTX_wm_region(C)); + view_zoom_in_do_exec(C, NULL); return OPERATOR_FINISHED; } -static int view_zoom_out_exec(bContext *C, wmOperator *UNUSED(op)) +static int view_zoom_in_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) { - SpaceClip *sc= CTX_wm_space_clip(C); - ARegion *ar= CTX_wm_region(C); - - sclip_zoom_set_factor(sc, ar, 0.8f); - - ED_region_tag_redraw(CTX_wm_region(C)); - - return OPERATOR_FINISHED; -} - -static int view_zoom_inout_invoke(bContext *C, wmOperator *op, wmEvent *event, int out) -{ - SpaceClip *sc= CTX_wm_space_clip(C); - float co[2], oldzoom= sc->zoom; - - ED_clip_mouse_pos(C, event, co); - - if(out) - view_zoom_out_exec(C, op); - else - view_zoom_in_exec(C, op); - - if(U.uiflag&USER_ZOOM_TO_MOUSEPOS) { - int width, height; - - ED_space_clip_size(sc, &width, &height); - - sc->xof+= ((co[0]-0.5f)*width-sc->xof)*(sc->zoom-oldzoom)/sc->zoom; - sc->yof+= ((co[1]-0.5f)*height-sc->yof)*(sc->zoom-oldzoom)/sc->zoom; - } + view_zoom_in_do_exec(C, event); return OPERATOR_FINISHED; } -static int view_zoom_in_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - return view_zoom_inout_invoke(C, op, event, 0); -} - void CLIP_OT_view_zoom_in(wmOperatorType *ot) { /* identifiers */ @@ -576,9 +570,18 @@ void CLIP_OT_view_zoom_in(wmOperatorType *ot) ot->poll= ED_space_clip_poll; } -static int view_zoom_out_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int view_zoom_out_exec(bContext *C, wmOperator *UNUSED(op)) { - return view_zoom_inout_invoke(C, op, event, 1); + view_zoom_out_do_exec(C, NULL); + + return OPERATOR_FINISHED; +} + +static int view_zoom_out_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) +{ + view_zoom_out_do_exec(C, event); + + return OPERATOR_FINISHED; } void CLIP_OT_view_zoom_out(wmOperatorType *ot) @@ -600,7 +603,7 @@ static int view_zoom_ratio_exec(bContext *C, wmOperator *op) SpaceClip *sc= CTX_wm_space_clip(C); ARegion *ar= CTX_wm_region(C); - sclip_zoom_set(sc, ar, RNA_float_get(op->ptr, "ratio")); + sclip_zoom_set(sc, ar, RNA_float_get(op->ptr, "ratio"), NULL); /* ensure pixel exact locations for draw */ sc->xof= (int)sc->xof; @@ -655,10 +658,10 @@ static int view_all_exec(bContext *C, wmOperator *UNUSED(op)) /* find the zoom value that will fit the image in the image space */ zoomx= (float)width/w; zoomy= (float)height/h; - sclip_zoom_set(sc, ar, 1.0f/power_of_2(1/MIN2(zoomx, zoomy))); + sclip_zoom_set(sc, ar, 1.0f/power_of_2(1/MIN2(zoomx, zoomy)), NULL); } else - sclip_zoom_set(sc, ar, 1.0f); + sclip_zoom_set(sc, ar, 1.0f, NULL); sc->xof= sc->yof= 0.0f; |