WM: refactor gestures for use as tools
[blender.git] / source / blender / editors / space_view3d / view3d_edit.c
index b2af2fe1d492e3a2af1141075c04773ebb762c7b..77a3556db0a7c34a4707876273753386d8a00d81 100644 (file)
@@ -726,10 +726,15 @@ static enum eViewOpsOrbit viewops_orbit_mode(void)
 
 /**
  * Calculate the values for #ViewOpsData
+ *
+ * \param use_ensure_persp: When enabled run #view3d_ensure_persp this may switch out of
+ * camera view when orbiting or switch from ortho to perspective when auto-persp is enabled.
+ * Some operations don't require this (view zoom/pan or ndof where subtle rotation is common
+ * so we don't want it to trigger auto-perspective).
  */
 static void viewops_data_create_ex(
         bContext *C, wmOperator *op, const wmEvent *event,
-        bool switch_from_camera, enum eViewOpsOrbit orbit_mode)
+        bool use_ensure_persp, enum eViewOpsOrbit orbit_mode)
 {
        ViewOpsData *vod = op->customdata;
        RegionView3D *rv3d = vod->rv3d;
@@ -750,8 +755,7 @@ static void viewops_data_create_ex(
                vod->use_dyn_ofs = false;
        }
 
-       if (switch_from_camera) {
-               /* switch from camera view when: */
+       if (use_ensure_persp) {
                if (view3d_ensure_persp(vod->v3d, vod->ar)) {
                        /* If we're switching from camera view to the perspective one,
                         * need to tag viewport update, so camera vuew and borders
@@ -853,10 +857,10 @@ static void viewops_data_create_ex(
        rv3d->rflag |= RV3D_NAVIGATING;
 }
 
-static void viewops_data_create(bContext *C, wmOperator *op, const wmEvent *event, bool switch_from_camera)
+static void viewops_data_create(bContext *C, wmOperator *op, const wmEvent *event, bool use_ensure_persp)
 {
        enum eViewOpsOrbit orbit_mode = viewops_orbit_mode();
-       viewops_data_create_ex(C, op, event, switch_from_camera, orbit_mode);
+       viewops_data_create_ex(C, op, event, use_ensure_persp, orbit_mode);
 }
 
 static void viewops_data_free(bContext *C, wmOperator *op)
@@ -1673,7 +1677,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                viewops_data_alloc(C, op);
                viewops_data_create_ex(
                        C, op, event,
-                       viewops_orbit_mode_ex((U.uiflag & USER_ORBIT_SELECTION) != 0, false), false);
+                       false, viewops_orbit_mode_ex((U.uiflag & USER_ORBIT_SELECTION) != 0, false));
                vod = op->customdata;
 
                ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->ar);
@@ -1742,7 +1746,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
                viewops_data_alloc(C, op);
                viewops_data_create_ex(
                        C, op, event,
-                       viewops_orbit_mode_ex((U.uiflag & USER_ORBIT_SELECTION) != 0, false), false);
+                       false, viewops_orbit_mode_ex((U.uiflag & USER_ORBIT_SELECTION) != 0, false));
 
                vod = op->customdata;
 
@@ -3503,10 +3507,10 @@ void VIEW3D_OT_render_border(wmOperatorType *ot)
        ot->idname = "VIEW3D_OT_render_border";
 
        /* api callbacks */
-       ot->invoke = WM_border_select_invoke;
+       ot->invoke = WM_gesture_border_invoke;
        ot->exec = render_border_exec;
-       ot->modal = WM_border_select_modal;
-       ot->cancel = WM_border_select_cancel;
+       ot->modal = WM_gesture_border_modal;
+       ot->cancel = WM_gesture_border_cancel;
 
        ot->poll = ED_operator_view3d_active;
 
@@ -3576,7 +3580,6 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
        View3D *v3d = CTX_wm_view3d(C);
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
        Scene *scene = CTX_data_scene(C);
-       int gesture_mode;
        const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
 
        /* Zooms in on a border drawn by the user */
@@ -3600,7 +3603,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
        WM_operator_properties_border_to_rcti(op, &rect);
 
        /* check if zooming in/out view */
-       gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
+       const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
 
        ED_view3d_dist_range_get(v3d, dist_range);
 
@@ -3698,7 +3701,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
                new_dist *= max_ff(xscale, yscale);
        }
 
-       if (gesture_mode == GESTURE_MODAL_OUT) {
+       if (!zoom_in) {
                sub_v3_v3v3(dvec, new_ofs, rv3d->ofs);
                new_dist = rv3d->dist * (rv3d->dist / new_dist);
                add_v3_v3v3(new_ofs, rv3d->ofs, dvec);
@@ -3724,7 +3727,7 @@ static int view3d_zoom_border_invoke(bContext *C, wmOperator *op, const wmEvent
 
        /* if in camera view do not exec the operator so we do not conflict with set render border*/
        if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d))
-               return WM_border_select_invoke(C, op, event);
+               return WM_gesture_border_invoke(C, op, event);
        else
                return OPERATOR_PASS_THROUGH;
 }
@@ -3739,8 +3742,8 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke = view3d_zoom_border_invoke;
        ot->exec = view3d_zoom_border_exec;
-       ot->modal = WM_border_select_modal;
-       ot->cancel = WM_border_select_cancel;
+       ot->modal = WM_gesture_border_modal;
+       ot->cancel = WM_gesture_border_cancel;
 
        ot->poll = ED_operator_region_view3d_active;
 
@@ -3748,7 +3751,7 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot)
        ot->flag = 0;
 
        /* rna */
-       WM_operator_properties_gesture_border(ot, false);
+       WM_operator_properties_gesture_border_zoom(ot);
 }
 
 /* sets the view to 1:1 camera/render-pixel */
@@ -4668,7 +4671,7 @@ static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *ev
                return OPERATOR_FINISHED;
        }
        else {
-               return WM_border_select_invoke(C, op, event);
+               return WM_gesture_border_invoke(C, op, event);
        }
 }
 
@@ -4684,8 +4687,8 @@ void VIEW3D_OT_clip_border(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke = view3d_clipping_invoke;
        ot->exec = view3d_clipping_exec;
-       ot->modal = WM_border_select_modal;
-       ot->cancel = WM_border_select_cancel;
+       ot->modal = WM_gesture_border_modal;
+       ot->cancel = WM_gesture_border_cancel;
 
        ot->poll = ED_operator_region_view3d_active;
 
@@ -4758,7 +4761,7 @@ void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
                        float co_curr[2], co_prev[2];
 
                        if ((ED_view3d_project_float_global(ar, fp_prev, co_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
-                               (ED_view3d_project_float_global(ar, fp_curr, co_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
+                           (ED_view3d_project_float_global(ar, fp_curr, co_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
                        {
                                rv3d->ofs_lock[0] += (co_curr[0] - co_prev[0]) / (ar->winx * 0.5f);
                                rv3d->ofs_lock[1] += (co_curr[1] - co_prev[1]) / (ar->winy * 0.5f);