From 56a533c0711a486375408afaa7ac51da1613ccee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 31 May 2019 19:53:24 +1000 Subject: WM: option to ignore cursor image/clip/view2d zoom In preparation for view navigation gizmos. --- source/blender/editors/interface/view2d_ops.c | 18 +++-- source/blender/editors/space_clip/clip_ops.c | 70 ++++++++++++------ source/blender/editors/space_image/image_ops.c | 82 +++++++++++++++------- source/blender/editors/space_view3d/view3d_edit.c | 38 +++++----- .../editors/space_view3d/view3d_gizmo_navigate.c | 2 +- source/blender/windowmanager/WM_api.h | 1 + .../windowmanager/intern/wm_operator_props.c | 11 +++ 7 files changed, 149 insertions(+), 73 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index b400b9bf4ed..a1995806937 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -643,7 +643,7 @@ static bool view_zoom_poll(bContext *C) /* apply transform to view (i.e. adjust 'cur' rect) */ static void view_zoomstep_apply_ex( - bContext *C, v2dViewZoomData *vzd, const bool use_mousepos, const float facx, const float facy) + bContext *C, v2dViewZoomData *vzd, const bool zoom_to_pos, const float facx, const float facy) { ARegion *ar = CTX_wm_region(C); View2D *v2d = &ar->v2d; @@ -681,7 +681,7 @@ static void view_zoomstep_apply_ex( v2d->cur.xmin += dx; v2d->cur.xmax -= dx; - if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { + if (zoom_to_pos) { /* get zoom fac the same way as in * ui_view2d_curRect_validate_resize - better keep in sync! */ const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); @@ -716,7 +716,7 @@ static void view_zoomstep_apply_ex( v2d->cur.ymin += dy; v2d->cur.ymax -= dy; - if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { + if (zoom_to_pos) { /* get zoom fac the same way as in * ui_view2d_curRect_validate_resize - better keep in sync! */ const float zoomy = (float)(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur); @@ -752,8 +752,9 @@ static void view_zoomstep_apply_ex( static void view_zoomstep_apply(bContext *C, wmOperator *op) { v2dViewZoomData *vzd = op->customdata; + const bool zoom_to_pos = U.uiflag & USER_ZOOM_TO_MOUSEPOS; view_zoomstep_apply_ex( - C, vzd, true, RNA_float_get(op->ptr, "zoomfacx"), RNA_float_get(op->ptr, "zoomfacy")); + C, vzd, zoom_to_pos, RNA_float_get(op->ptr, "zoomfacx"), RNA_float_get(op->ptr, "zoomfacy")); } /* --------------- Individual Operators ------------------- */ @@ -921,6 +922,9 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) float dx, dy; const int snap_test = ED_region_snap_size_test(vzd->ar); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + const bool zoom_to_pos = use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS); + /* get amount to move view by */ dx = RNA_float_get(op->ptr, "deltax"); dy = RNA_float_get(op->ptr, "deltay"); @@ -947,7 +951,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) v2d->cur.xmax -= 2 * dx; } else { - if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { + if (zoom_to_pos) { float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); float mval_faci = 1.0f - mval_fac; float ofs = (mval_fac * dx) - (mval_faci * dx); @@ -966,7 +970,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) v2d->cur.ymax -= 2 * dy; } else { - if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) { + if (zoom_to_pos) { float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); float mval_faci = 1.0f - mval_fac; float ofs = (mval_fac * dy) - (mval_faci * dy); @@ -1248,6 +1252,8 @@ static void VIEW2D_OT_zoom(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_HIDDEN); prop = RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX); RNA_def_property_flag(prop, PROP_HIDDEN); + + WM_operator_properties_use_cursor_init(ot); } /* ********************************************************* */ diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 532d89f6fa2..ba40b8bfaae 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -80,7 +80,10 @@ /******************** view navigation utilities *********************/ -static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) +static void sclip_zoom_set(const bContext *C, + float zoom, + const float location[2], + const bool zoom_to_pos) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); @@ -108,7 +111,7 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) } } - if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { + if (zoom_to_pos && location) { float aspx, aspy, w, h, dx, dy; ED_space_clip_get_size(sc, &width, &height); @@ -131,11 +134,14 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) } } -static void sclip_zoom_set_factor(const bContext *C, float zoomfac, float location[2]) +static void sclip_zoom_set_factor(const bContext *C, + float zoomfac, + const float location[2], + const bool zoom_to_pos) { SpaceClip *sc = CTX_wm_space_clip(C); - sclip_zoom_set(C, sc->zoom * zoomfac, location); + sclip_zoom_set(C, sc->zoom * zoomfac, location, zoom_to_pos); } static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor) @@ -151,7 +157,7 @@ static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float mpos = location; } - sclip_zoom_set_factor(C, factor, mpos); + sclip_zoom_set_factor(C, factor, mpos, mpos ? (U.uiflag & USER_ZOOM_TO_MOUSEPOS) : false); ED_region_tag_redraw(ar); } @@ -355,16 +361,23 @@ typedef struct ViewPanData { float x, y; float xof, yof, xorig, yorig; int event_type; + bool own_cursor; float *vec; } ViewPanData; static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event) { + wmWindow *win = CTX_wm_window(C); SpaceClip *sc = CTX_wm_space_clip(C); ViewPanData *vpd; op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ClipViewPanData"); - WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR); + + /* Grab will be set when running from gizmo. */ + vpd->own_cursor = (win->grabcursor == 0); + if (vpd->own_cursor) { + WM_cursor_modal_set(win, BC_NSEW_SCROLLCURSOR); + } vpd->x = event->x; vpd->y = event->y; @@ -394,7 +407,9 @@ static void view_pan_exit(bContext *C, wmOperator *op, bool cancel) ED_region_tag_redraw(CTX_wm_region(C)); } - WM_cursor_modal_restore(CTX_wm_window(C)); + if (vpd->own_cursor) { + WM_cursor_modal_restore(CTX_wm_window(C)); + } MEM_freeN(op->customdata); } @@ -519,16 +534,23 @@ typedef struct ViewZoomData { float location[2]; wmTimer *timer; double timer_lastdraw; + bool own_cursor; } ViewZoomData; static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event) { + wmWindow *win = CTX_wm_window(C); 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); + + /* Grab will be set when running from gizmo. */ + vpd->own_cursor = (win->grabcursor == 0); + if (vpd->own_cursor) { + WM_cursor_modal_set(win, BC_NSEW_SCROLLCURSOR); + } if (U.viewzoom == USER_ZOOM_CONT) { /* needs a timer to continue redrawing */ @@ -560,13 +582,15 @@ static void view_zoom_exit(bContext *C, wmOperator *op, bool cancel) WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer); } - WM_cursor_modal_restore(CTX_wm_window(C)); + if (vpd->own_cursor) { + WM_cursor_modal_restore(CTX_wm_window(C)); + } MEM_freeN(op->customdata); } static int view_zoom_exec(bContext *C, wmOperator *op) { - sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL); + sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL, false); ED_region_tag_redraw(CTX_wm_region(C)); @@ -598,7 +622,8 @@ 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) +static void view_zoom_apply( + bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos) { float factor; @@ -635,21 +660,22 @@ static void view_zoom_apply(bContext *C, ViewZoomData *vpd, wmOperator *op, cons } RNA_float_set(op->ptr, "factor", factor); - sclip_zoom_set(C, vpd->zoom * factor, vpd->location); + sclip_zoom_set(C, vpd->zoom * factor, vpd->location, zoom_to_pos); ED_region_tag_redraw(CTX_wm_region(C)); } static int view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event) { ViewZoomData *vpd = op->customdata; + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); switch (event->type) { case TIMER: if (event->customdata == vpd->timer) { - view_zoom_apply(C, vpd, op, event); + view_zoom_apply(C, vpd, op, event, use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)); } break; case MOUSEMOVE: - view_zoom_apply(C, vpd, op, event); + view_zoom_apply(C, vpd, op, event, use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)); break; default: if (event->type == vpd->event_type && event->val == KM_RELEASE) { @@ -698,6 +724,8 @@ void CLIP_OT_view_zoom(wmOperatorType *ot) -FLT_MAX, FLT_MAX); RNA_def_property_flag(prop, PROP_HIDDEN); + + WM_operator_properties_use_cursor_init(ot); } /********************** view zoom in/out operator *********************/ @@ -708,7 +736,7 @@ static int view_zoom_in_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "location", location); - sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location); + sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS); ED_region_tag_redraw(CTX_wm_region(C)); @@ -762,7 +790,7 @@ static int view_zoom_out_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "location", location); - sclip_zoom_set_factor(C, powf(0.5f, 1.0f / 3.0f), location); + sclip_zoom_set_factor(C, powf(0.5f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS); ED_region_tag_redraw(CTX_wm_region(C)); @@ -816,7 +844,7 @@ static int view_zoom_ratio_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); - sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), NULL); + sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), NULL, false); /* ensure pixel exact locations for draw */ sc->xof = (int)sc->xof; @@ -881,7 +909,7 @@ static int view_all_exec(bContext *C, wmOperator *op) zoomx = (float)width / (w + 2 * margin); zoomy = (float)height / (h + 2 * margin); - sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL); + sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL, false); } else { if ((w >= width || h >= height) && (width > 0 && height > 0)) { @@ -889,10 +917,10 @@ static int view_all_exec(bContext *C, wmOperator *op) zoomy = (float)height / h; /* find the zoom value that will fit the image in the image space */ - sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL); + sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL, false); } else { - sclip_zoom_set(C, 1.0f, NULL); + sclip_zoom_set(C, 1.0f, NULL, false); } } @@ -1535,7 +1563,7 @@ static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv mul_v2_fl(pan_vec, (speed * ndof->dt) / sc->zoom); pan_vec[2] *= -ndof->dt; - sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL); + sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL, false); sc->xof += pan_vec[0]; sc->yof += pan_vec[1]; diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 5b8b93b3af8..9ef646e6c71 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -106,7 +106,8 @@ /******************** view navigation utilities *********************/ -static void sima_zoom_set(SpaceImage *sima, ARegion *ar, float zoom, const float location[2]) +static void sima_zoom_set( + SpaceImage *sima, ARegion *ar, float zoom, const float location[2], const bool zoom_to_pos) { float oldzoom = sima->zoom; int width, height; @@ -131,7 +132,7 @@ static void sima_zoom_set(SpaceImage *sima, ARegion *ar, float zoom, const float } } - if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { + if (zoom_to_pos && location) { float aspx, aspy, w, h; ED_space_image_get_size(sima, &width, &height); @@ -145,12 +146,10 @@ static void sima_zoom_set(SpaceImage *sima, ARegion *ar, float zoom, const float } } -static void sima_zoom_set_factor(SpaceImage *sima, - ARegion *ar, - float zoomfac, - const float location[2]) +static void sima_zoom_set_factor( + SpaceImage *sima, ARegion *ar, float zoomfac, const float location[2], const bool zoom_to_pos) { - sima_zoom_set(sima, ar, sima->zoom * zoomfac, location); + sima_zoom_set(sima, ar, sima->zoom * zoomfac, location, zoom_to_pos); } /** @@ -178,7 +177,7 @@ static void sima_zoom_set_from_bounds(SpaceImage *sima, ARegion *ar, const rctf size = min_ff(size_xy[0], size_xy[1]); CLAMP_MAX(size, 100.0f); - sima_zoom_set(sima, ar, size, NULL); + sima_zoom_set(sima, ar, size, NULL, false); } static Image *image_from_context(const bContext *C) @@ -296,15 +295,22 @@ typedef struct ViewPanData { float x, y; float xof, yof; int event_type; + bool own_cursor; } ViewPanData; static void image_view_pan_init(bContext *C, wmOperator *op, const wmEvent *event) { + wmWindow *win = CTX_wm_window(C); SpaceImage *sima = CTX_wm_space_image(C); ViewPanData *vpd; op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ImageViewPanData"); - WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR); + + /* Grab will be set when running from gizmo. */ + vpd->own_cursor = (win->grabcursor == 0); + if (vpd->own_cursor) { + WM_cursor_modal_set(win, BC_NSEW_SCROLLCURSOR); + } vpd->x = event->x; vpd->y = event->y; @@ -326,7 +332,9 @@ static void image_view_pan_exit(bContext *C, wmOperator *op, bool cancel) ED_region_tag_redraw(CTX_wm_region(C)); } - WM_cursor_modal_restore(CTX_wm_window(C)); + if (vpd->own_cursor) { + WM_cursor_modal_restore(CTX_wm_window(C)); + } MEM_freeN(op->customdata); } @@ -435,6 +443,7 @@ typedef struct ViewZoomData { /* needed for continuous zoom */ wmTimer *timer; double timer_lastdraw; + bool own_cursor; /* */ SpaceImage *sima; @@ -443,12 +452,18 @@ typedef struct ViewZoomData { static void image_view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event) { + wmWindow *win = CTX_wm_window(C); SpaceImage *sima = CTX_wm_space_image(C); ARegion *ar = CTX_wm_region(C); ViewZoomData *vpd; op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ImageViewZoomData"); - WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR); + + /* Grab will be set when running from gizmo. */ + vpd->own_cursor = (win->grabcursor == 0); + if (vpd->own_cursor) { + WM_cursor_modal_set(win, BC_NSEW_SCROLLCURSOR); + } vpd->origx = event->x; vpd->origy = event->y; @@ -484,7 +499,9 @@ static void image_view_zoom_exit(bContext *C, wmOperator *op, bool cancel) WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer); } - WM_cursor_modal_restore(CTX_wm_window(C)); + if (vpd->own_cursor) { + WM_cursor_modal_restore(CTX_wm_window(C)); + } MEM_freeN(op->customdata); } @@ -493,7 +510,7 @@ static int image_view_zoom_exec(bContext *C, wmOperator *op) SpaceImage *sima = CTX_wm_space_image(C); ARegion *ar = CTX_wm_region(C); - sima_zoom_set_factor(sima, ar, RNA_float_get(op->ptr, "factor"), NULL); + sima_zoom_set_factor(sima, ar, RNA_float_get(op->ptr, "factor"), NULL, false); ED_region_tag_redraw(ar); @@ -523,7 +540,12 @@ static int image_view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev factor = 1.0f + delta / 300.0f; RNA_float_set(op->ptr, "factor", factor); - sima_zoom_set(sima, ar, sima->zoom * factor, location); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + sima_zoom_set(sima, + ar, + sima->zoom * factor, + location, + (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); ED_region_tag_redraw(ar); return OPERATOR_FINISHED; @@ -539,7 +561,8 @@ static void image_zoom_apply(ViewZoomData *vpd, const int x, const int y, const short viewzoom, - const short zoom_invert) + const short zoom_invert, + const bool zoom_to_pos) { float factor; @@ -579,7 +602,7 @@ static void image_zoom_apply(ViewZoomData *vpd, } RNA_float_set(op->ptr, "factor", factor); - sima_zoom_set(vpd->sima, vpd->ar, vpd->zoom * factor, vpd->location); + sima_zoom_set(vpd->sima, vpd->ar, vpd->zoom * factor, vpd->location, zoom_to_pos); ED_region_tag_redraw(vpd->ar); } @@ -601,7 +624,14 @@ static int image_view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *eve } if (event_code == VIEW_APPLY) { - image_zoom_apply(vpd, op, event->x, event->y, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + image_zoom_apply(vpd, + op, + event->x, + event->y, + U.viewzoom, + (U.uiflag & USER_ZOOM_INVERT) != 0, + (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); } else if (event_code == VIEW_CONFIRM) { image_view_zoom_exit(C, op, false); @@ -646,6 +676,8 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) -FLT_MAX, FLT_MAX); RNA_def_property_flag(prop, PROP_HIDDEN); + + WM_operator_properties_use_cursor_init(ot); } #ifdef WITH_INPUT_NDOF @@ -675,7 +707,7 @@ static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmE mul_v2_fl(pan_vec, (speed * ndof->dt) / sima->zoom); pan_vec[2] *= -ndof->dt; - sima_zoom_set_factor(sima, ar, 1.0f + pan_vec[2], NULL); + sima_zoom_set_factor(sima, ar, 1.0f + pan_vec[2], NULL, false); sima->xof += pan_vec[0]; sima->yof += pan_vec[1]; @@ -735,7 +767,7 @@ static int image_view_all_exec(bContext *C, wmOperator *op) zoomx = (float)width / (w + 2 * margin); zoomy = (float)height / (h + 2 * margin); - sima_zoom_set(sima, ar, min_ff(zoomx, zoomy), NULL); + sima_zoom_set(sima, ar, min_ff(zoomx, zoomy), NULL, false); } else { if ((w >= width || h >= height) && (width > 0 && height > 0)) { @@ -743,10 +775,10 @@ static int image_view_all_exec(bContext *C, wmOperator *op) zoomy = (float)height / h; /* find the zoom value that will fit the image in the image space */ - sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL); + sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL, false); } else { - sima_zoom_set(sima, ar, 1.0f, NULL); + sima_zoom_set(sima, ar, 1.0f, NULL, false); } } @@ -854,7 +886,8 @@ static int image_view_zoom_in_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "location", location); - sima_zoom_set_factor(sima, ar, powf(2.0f, 1.0f / 3.0f), location); + sima_zoom_set_factor( + sima, ar, powf(2.0f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS); ED_region_tag_redraw(ar); @@ -911,7 +944,8 @@ static int image_view_zoom_out_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "location", location); - sima_zoom_set_factor(sima, ar, powf(0.5f, 1.0f / 3.0f), location); + sima_zoom_set_factor( + sima, ar, powf(0.5f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS); ED_region_tag_redraw(ar); @@ -967,7 +1001,7 @@ static int image_view_zoom_ratio_exec(bContext *C, wmOperator *op) SpaceImage *sima = CTX_wm_space_image(C); ARegion *ar = CTX_wm_region(C); - sima_zoom_set(sima, ar, RNA_float_get(op->ptr, "ratio"), NULL); + sima_zoom_set(sima, ar, RNA_float_get(op->ptr, "ratio"), NULL, false); /* ensure pixel exact locations for draw */ sima->xof = (int)sima->xof; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index b12d081325f..63d28c7d2ec 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -115,11 +115,7 @@ static void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3 RNA_def_property_flag(prop, PROP_SKIP_SAVE); } if (flag & V3D_OP_PROP_USE_MOUSE_INIT) { - /* Disable when view operators are initialized from buttons. */ - PropertyRNA *prop; - prop = RNA_def_boolean( - ot->srna, "use_mouse_init", true, "Mouse Init", "Use initial mouse position"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); + WM_operator_properties_use_cursor_init(ot); } } @@ -885,7 +881,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod; - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); /* makes op->customdata */ viewops_data_alloc(C, op); @@ -903,7 +899,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) op, event, viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | - (use_mouse_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { /* Rotate direction we keep always same */ @@ -1748,7 +1744,7 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod; - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); /* makes op->customdata */ viewops_data_alloc(C, op); @@ -1756,7 +1752,7 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_mouse_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); vod = op->customdata; ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar); @@ -2163,12 +2159,12 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (event_code == VIEW_APPLY) { - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); viewzoom_apply(vod, &event->x, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0, - (use_mouse_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); + (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); if (ED_screen_animation_playing(CTX_wm_manager(C))) { use_autokey = true; } @@ -2202,7 +2198,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op) float dist_range[2]; const int delta = RNA_int_get(op->ptr, "delta"); - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); if (op->customdata) { ViewOpsData *vod = op->customdata; @@ -2223,7 +2219,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op) int zoom_xy_buf[2]; const int *zoom_xy = NULL; - if (use_mouse_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { + if (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : ar->winx / 2; zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : @@ -2278,7 +2274,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod; - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); /* makes op->customdata */ viewops_data_alloc(C, op); @@ -2286,7 +2282,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_mouse_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); vod = op->customdata; ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar); @@ -2315,7 +2311,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) &event->prevx, USER_ZOOM_DOLLY, (U.uiflag & USER_ZOOM_INVERT) != 0, - (use_mouse_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); + (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); @@ -2542,10 +2538,10 @@ static int viewdolly_exec(bContext *C, wmOperator *op) v3d = sa->spacedata.first; rv3d = ar->regiondata; - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); /* overwrite the mouse vector with the view direction (zoom into the center) */ - if ((use_mouse_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { + if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { normalize_v3_v3(mousevec, rv3d->viewinv[2]); } @@ -2601,13 +2597,13 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) ED_region_tag_redraw(vod->ar); } - const bool use_mouse_init = RNA_boolean_get(op->ptr, "use_mouse_init"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_mouse_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); /* if one or the other zoom position aren't set, set from event */ if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) { @@ -2620,7 +2616,7 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) } else { /* overwrite the mouse vector with the view direction (zoom into the center) */ - if ((use_mouse_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { + if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { negate_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); normalize_v3(vod->init.mousevec); } diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c index 87a1d0950b1..6d8d8ba93f5 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c @@ -205,7 +205,7 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup) for (int i = 0; i < ARRAY_SIZE(gz_ids); i++) { wmGizmo *gz = navgroup->gz_array[gz_ids[i]]; wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0); - RNA_boolean_set(&gzop->ptr, "use_mouse_init", false); + RNA_boolean_set(&gzop->ptr, "use_cursor_init", false); } } diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 7eefbb4d648..558eb97c54b 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -445,6 +445,7 @@ void WM_operator_properties_filesel(struct wmOperatorType *ot, short flag, short display, short sort); +void WM_operator_properties_use_cursor_init(struct wmOperatorType *ot); void WM_operator_properties_border(struct wmOperatorType *ot); void WM_operator_properties_border_to_rcti(struct wmOperator *op, struct rcti *rect); void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect); diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c index 3ad7247d993..c471cb6f922 100644 --- a/source/blender/windowmanager/intern/wm_operator_props.c +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -334,6 +334,17 @@ void WM_operator_properties_gesture_box_ex(wmOperatorType *ot, bool deselect, bo } } +/** + * Disable using cursor position, + * use when view operators are initialized from buttons. + */ +void WM_operator_properties_use_cursor_init(wmOperatorType *ot) +{ + PropertyRNA *prop = RNA_def_boolean( + ot->srna, "use_cursor_init", true, "Cursor Init", "Use initial cursor position"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); +} + void WM_operator_properties_gesture_box_select(wmOperatorType *ot) { WM_operator_properties_gesture_box_ex(ot, true, true); -- cgit v1.2.3