From 384c2e1f36ebfe2ce9ff424b3a5907808f35a4cc Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 14 Jul 2023 17:08:42 -0300 Subject: [PATCH] View3D Refactor: use structs to confine the Operator's navigation data Adopt the use of structs to enclose and organize operator-specific navigation data. With this, we create well-defined boundaries for the navigation data of individual operators. This makes the code more flexible and easier to maintain and avoid errors. --- .../editors/space_view3d/view3d_navigate.cc | 261 ++++++------------ .../editors/space_view3d/view3d_navigate.hh | 81 ++---- .../space_view3d/view3d_navigate_dolly.cc | 13 +- .../space_view3d/view3d_navigate_move.cc | 25 +- .../space_view3d/view3d_navigate_ndof.cc | 70 ++++- .../space_view3d/view3d_navigate_roll.cc | 12 +- .../space_view3d/view3d_navigate_rotate.cc | 26 +- .../space_view3d/view3d_navigate_view_pan.cc | 17 +- .../space_view3d/view3d_navigate_zoom.cc | 26 +- 9 files changed, 261 insertions(+), 270 deletions(-) diff --git a/source/blender/editors/space_view3d/view3d_navigate.cc b/source/blender/editors/space_view3d/view3d_navigate.cc index 275c9064c7b..ed1e7f284c9 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.cc +++ b/source/blender/editors/space_view3d/view3d_navigate.cc @@ -45,39 +45,28 @@ #include "view3d_navigate.hh" /* own include */ -/* Prototypes. */ -static eViewOpsFlag viewops_flag_from_prefs(); - -const char *viewops_operator_idname_get(eV3D_OpMode nav_type) +static eViewOpsFlag viewops_flag_from_prefs() { - switch (nav_type) { - case V3D_OP_MODE_ZOOM: - return "VIEW3D_OT_zoom"; - case V3D_OP_MODE_ROTATE: - return "VIEW3D_OT_rotate"; - case V3D_OP_MODE_MOVE: - return "VIEW3D_OT_move"; - case V3D_OP_MODE_VIEW_PAN: - return "VIEW3D_OT_view_pan"; - case V3D_OP_MODE_VIEW_ROLL: - return "VIEW3D_OT_view_roll"; - case V3D_OP_MODE_DOLLY: - return "VIEW3D_OT_dolly"; -#ifdef WITH_INPUT_NDOF - case V3D_OP_MODE_NDOF_ORBIT: - return "VIEW3D_OT_ndof_orbit"; - case V3D_OP_MODE_NDOF_ORBIT_ZOOM: - return "VIEW3D_OT_ndof_orbit_zoom"; - case V3D_OP_MODE_NDOF_PAN: - return "VIEW3D_OT_ndof_pan"; - case V3D_OP_MODE_NDOF_ALL: - return "VIEW3D_OT_ndof_all"; -#endif - case V3D_OP_MODE_NONE: - break; + const bool use_select = (U.uiflag & USER_ORBIT_SELECTION) != 0; + const bool use_depth = (U.uiflag & USER_DEPTH_NAVIGATE) != 0; + const bool use_zoom_to_mouse = (U.uiflag & USER_ZOOM_TO_MOUSEPOS) != 0; + const bool use_auto_persp = (U.uiflag & USER_AUTOPERSP) != 0; + + enum eViewOpsFlag flag = VIEWOPS_FLAG_NONE; + if (use_select) { + flag |= VIEWOPS_FLAG_ORBIT_SELECT; } - BLI_assert(false); - return nullptr; + if (use_depth) { + flag |= VIEWOPS_FLAG_DEPTH_NAVIGATE; + } + if (use_zoom_to_mouse) { + flag |= VIEWOPS_FLAG_ZOOM_TO_MOUSE; + } + if (use_auto_persp) { + flag |= VIEWOPS_FLAG_PERSP_ENSURE; + } + + return flag; } /* -------------------------------------------------------------------- */ @@ -221,45 +210,28 @@ static eViewOpsFlag navigate_pivot_get(bContext *C, void ViewOpsData::init_navigation(bContext *C, const wmEvent *event, - const eV3D_OpMode nav_type, + const ViewOpsType *nav_type, const bool use_cursor_init) { - eViewOpsFlag viewops_flag = viewops_flag_from_prefs(); + this->nav_type = nav_type; + eViewOpsFlag viewops_flag = nav_type->flag & viewops_flag_from_prefs(); + + if (!use_cursor_init) { + viewops_flag &= ~(VIEWOPS_FLAG_USE_MOUSE_INIT | VIEWOPS_FLAG_DEPTH_NAVIGATE | + VIEWOPS_FLAG_ZOOM_TO_MOUSE); + } + bool calc_rv3d_dist = true; - - if (use_cursor_init) { - viewops_flag |= VIEWOPS_FLAG_USE_MOUSE_INIT; - } - - switch (nav_type) { - case V3D_OP_MODE_ZOOM: - case V3D_OP_MODE_MOVE: - case V3D_OP_MODE_VIEW_PAN: - case V3D_OP_MODE_DOLLY: - viewops_flag &= ~VIEWOPS_FLAG_ORBIT_SELECT; - break; - case V3D_OP_MODE_ROTATE: - viewops_flag |= VIEWOPS_FLAG_PERSP_ENSURE; - break; #ifdef WITH_INPUT_NDOF - case V3D_OP_MODE_NDOF_PAN: - viewops_flag &= ~VIEWOPS_FLAG_ORBIT_SELECT; - [[fallthrough]]; - case V3D_OP_MODE_NDOF_ORBIT: - case V3D_OP_MODE_NDOF_ORBIT_ZOOM: - case V3D_OP_MODE_NDOF_ALL: - viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE; - calc_rv3d_dist = false; - break; + if (ELEM(nav_type, + &ViewOpsType_ndof_orbit, + &ViewOpsType_ndof_orbit_zoom, + &ViewOpsType_ndof_pan, + &ViewOpsType_ndof_all)) + { + calc_rv3d_dist = false; + } #endif - default: - break; - } - - /* Could do this more nicely. */ - if ((viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) == 0) { - viewops_flag &= ~(VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_ZOOM_TO_MOUSE); - } /* Set the view from the camera, if view locking is enabled. * we may want to make this optional but for now its needed always. */ @@ -285,7 +257,7 @@ void ViewOpsData::init_navigation(bContext *C, negate_v3_v3(this->dyn_ofs, pivot_new); this->use_dyn_ofs = true; - if (nav_type != V3D_OP_MODE_ROTATE) { + if (!(nav_type->flag & VIEWOPS_FLAG_ORBIT_SELECT)) { /* Calculate new #RegionView3D::ofs and #RegionView3D::dist. */ if (rv3d->is_persp) { @@ -369,7 +341,6 @@ void ViewOpsData::init_navigation(bContext *C, this->reverse = -1.0f; } - this->nav_type = nav_type; this->viewops_flag = viewops_flag; /* Default. */ @@ -427,11 +398,11 @@ static eV3D_OpEvent view3d_navigate_event(ViewOpsData *vod, const wmEvent *event case VIEWROT_MODAL_SWITCH_ZOOM: case VIEWROT_MODAL_SWITCH_MOVE: case VIEWROT_MODAL_SWITCH_ROTATE: { - const eV3D_OpMode nav_type_new = (event->val == VIEWROT_MODAL_SWITCH_ZOOM) ? - V3D_OP_MODE_ZOOM : - (event->val == VIEWROT_MODAL_SWITCH_MOVE) ? - V3D_OP_MODE_MOVE : - V3D_OP_MODE_ROTATE; + const ViewOpsType *nav_type_new = (event->val == VIEWROT_MODAL_SWITCH_ZOOM) ? + &ViewOpsType_zoom : + (event->val == VIEWROT_MODAL_SWITCH_MOVE) ? + &ViewOpsType_move : + &ViewOpsType_rotate; if (nav_type_new == vod->nav_type) { break; } @@ -459,30 +430,16 @@ static eV3D_OpEvent view3d_navigate_event(ViewOpsData *vod, const wmEvent *event return VIEW_PASS; } -static int view3d_navigation_modal(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]) -{ - switch (vod->nav_type) { - case V3D_OP_MODE_ZOOM: - return viewzoom_modal_impl(C, vod, event_code, xy); - case V3D_OP_MODE_ROTATE: - return viewrotate_modal_impl(C, vod, event_code, xy); - case V3D_OP_MODE_MOVE: - return viewmove_modal_impl(C, vod, event_code, xy); - default: - break; - } - return OPERATOR_CANCELLED; -} - static int view3d_navigation_invoke_generic(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr, - const eV3D_OpMode nav_type) + const ViewOpsType *nav_type) { + if (!nav_type->init_fn) { + return OPERATOR_CANCELLED; + } + bool use_cursor_init = false; if (PropertyRNA *prop = RNA_struct_find_property(ptr, "use_cursor_init")) { use_cursor_init = RNA_property_boolean_get(ptr, prop); @@ -491,35 +448,13 @@ static int view3d_navigation_invoke_generic(bContext *C, vod->init_navigation(C, event, nav_type, use_cursor_init); ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - switch (nav_type) { - case V3D_OP_MODE_ZOOM: - return viewzoom_invoke_impl(C, vod, event, ptr); - case V3D_OP_MODE_ROTATE: - return viewrotate_invoke_impl(vod, event); - case V3D_OP_MODE_MOVE: - return viewmove_invoke_impl(vod, event); - case V3D_OP_MODE_VIEW_PAN: - return viewpan_invoke_impl(vod, ptr); -#ifdef WITH_INPUT_NDOF - case V3D_OP_MODE_NDOF_ORBIT: - return ndof_orbit_invoke_impl(C, vod, event); - case V3D_OP_MODE_NDOF_ORBIT_ZOOM: - return ndof_orbit_zoom_invoke_impl(C, vod, event); - case V3D_OP_MODE_NDOF_PAN: - return ndof_pan_invoke_impl(C, vod, event); - case V3D_OP_MODE_NDOF_ALL: - return ndof_all_invoke_impl(C, vod, event); -#endif - default: - break; - } - return OPERATOR_CANCELLED; + return nav_type->init_fn(C, vod, event, ptr); } int view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, - const eV3D_OpMode nav_type) + const ViewOpsType *nav_type) { ViewOpsData *vod = new ViewOpsData(); vod->init_context(C); @@ -561,17 +496,16 @@ int view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod = static_cast(op->customdata); - const eV3D_OpMode nav_type_prev = vod->nav_type; + const ViewOpsType *nav_type_prev = vod->nav_type; const eV3D_OpEvent event_code = view3d_navigate_event(vod, event); if (nav_type_prev != vod->nav_type) { - wmOperatorType *ot_new = WM_operatortype_find(viewops_operator_idname_get(vod->nav_type), - false); + wmOperatorType *ot_new = WM_operatortype_find(vod->nav_type->idname, false); WM_operator_type_set(op, ot_new); vod->end_navigation(C); return view3d_navigation_invoke_generic(C, vod, event, op->ptr, vod->nav_type); } - int ret = view3d_navigation_modal(C, vod, event_code, event->xy); + int ret = vod->nav_type->apply_fn(C, vod, event_code, event->xy); if ((ret & OPERATOR_RUNNING_MODAL) == 0) { if (ret & OPERATOR_FINISHED) { @@ -819,29 +753,9 @@ bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) return is_set; } -static eViewOpsFlag viewops_flag_from_prefs() -{ - const bool use_select = (U.uiflag & USER_ORBIT_SELECTION) != 0; - const bool use_depth = (U.uiflag & USER_DEPTH_NAVIGATE) != 0; - const bool use_zoom_to_mouse = (U.uiflag & USER_ZOOM_TO_MOUSEPOS) != 0; - - enum eViewOpsFlag flag = VIEWOPS_FLAG_NONE; - if (use_select) { - flag |= VIEWOPS_FLAG_ORBIT_SELECT; - } - if (use_depth) { - flag |= VIEWOPS_FLAG_DEPTH_NAVIGATE; - } - if (use_zoom_to_mouse) { - flag |= VIEWOPS_FLAG_ZOOM_TO_MOUSE; - } - - return flag; -} - ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, - const eV3D_OpMode nav_type, + const ViewOpsType *nav_type, const bool use_cursor_init) { ViewOpsData *vod = new ViewOpsData(); @@ -1007,15 +921,30 @@ void viewmove_apply(ViewOpsData *vod, int x, int y) /* Detect the navigation operation, by the name of the navigation operator (obtained by * `wmKeyMapItem::idname`) */ -static eV3D_OpMode view3d_navigation_type_from_idname(const char *idname) +static const ViewOpsType *view3d_navigation_type_from_idname(const char *idname) { + const blender::Array nav_types = { + &ViewOpsType_zoom, + &ViewOpsType_rotate, + &ViewOpsType_move, + &ViewOpsType_pan, +// &ViewOpsType_roll, +// &ViewOpsType_dolly, +#ifdef WITH_INPUT_NDOF + &ViewOpsType_ndof_orbit, + &ViewOpsType_ndof_orbit_zoom, + &ViewOpsType_ndof_pan, + &ViewOpsType_ndof_all, +#endif + }; + const char *op_name = idname + sizeof("VIEW3D_OT_"); - for (int i = 0; i < V3D_OP_MODE_LEN; i++) { - if (STREQ(op_name, viewops_operator_idname_get((eV3D_OpMode)i) + sizeof("VIEW3D_OT_"))) { - return (eV3D_OpMode)i; + for (const ViewOpsType *nav_type : nav_types) { + if (STREQ(op_name, nav_type->idname + sizeof("VIEW3D_OT_"))) { + return nav_type; } } - return V3D_OP_MODE_NONE; + return nullptr; } /* Unlike `viewops_data_create`, `ED_view3d_navigation_init` creates a navigation context along @@ -1034,36 +963,14 @@ ViewOpsData *ED_view3d_navigation_init(bContext *C) } /* Checks and initializes the navigation modal operation. */ -static int view3d_navigation_invoke( - bContext *C, ViewOpsData *vod, const wmEvent *event, wmKeyMapItem *kmi, eV3D_OpMode nav_type) +static int view3d_navigation_invoke(bContext *C, + ViewOpsData *vod, + const wmEvent *event, + wmKeyMapItem *kmi, + const ViewOpsType *nav_type) { - switch (nav_type) { - case V3D_OP_MODE_ZOOM: - if (!view3d_zoom_or_dolly_poll(C)) { - return OPERATOR_CANCELLED; - } - break; - case V3D_OP_MODE_MOVE: - case V3D_OP_MODE_VIEW_PAN: - if (!view3d_location_poll(C)) { - return OPERATOR_CANCELLED; - } - break; - case V3D_OP_MODE_ROTATE: - if (!view3d_rotation_poll(C)) { - return OPERATOR_CANCELLED; - } - break; - case V3D_OP_MODE_VIEW_ROLL: - case V3D_OP_MODE_DOLLY: -#ifdef WITH_INPUT_NDOF - case V3D_OP_MODE_NDOF_ORBIT: - case V3D_OP_MODE_NDOF_ORBIT_ZOOM: - case V3D_OP_MODE_NDOF_PAN: - case V3D_OP_MODE_NDOF_ALL: -#endif - case V3D_OP_MODE_NONE: - break; + if (nav_type->poll_fn && !nav_type->poll_fn(C)) { + return OPERATOR_CANCELLED; } return view3d_navigation_invoke_generic(C, vod, event, kmi->ptr, nav_type); @@ -1088,14 +995,14 @@ bool ED_view3d_navigation_do(bContext *C, ViewOpsData *vod, const wmEvent *event if (vod->is_modal_event) { const eV3D_OpEvent event_code = view3d_navigate_event(vod, event); - op_return = view3d_navigation_modal(C, vod, event_code, event->xy); + op_return = vod->nav_type->apply_fn(C, vod, event_code, event->xy); if (op_return != OPERATOR_RUNNING_MODAL) { vod->end_navigation(C); vod->is_modal_event = false; } } else { - eV3D_OpMode nav_type; + const ViewOpsType *nav_type; LISTBASE_FOREACH (wmKeyMapItem *, kmi, &vod->keymap->items) { if (!STRPREFIX(kmi->idname, "VIEW3D")) { continue; @@ -1103,7 +1010,7 @@ bool ED_view3d_navigation_do(bContext *C, ViewOpsData *vod, const wmEvent *event if (kmi->flag & KMI_INACTIVE) { continue; } - if ((nav_type = view3d_navigation_type_from_idname(kmi->idname)) == V3D_OP_MODE_NONE) { + if ((nav_type = view3d_navigation_type_from_idname(kmi->idname)) == nullptr) { continue; } if (!WM_event_match(event, kmi)) { diff --git a/source/blender/editors/space_view3d/view3d_navigate.hh b/source/blender/editors/space_view3d/view3d_navigate.hh index ff6924a4408..fba56411765 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.hh +++ b/source/blender/editors/space_view3d/view3d_navigate.hh @@ -32,27 +32,6 @@ struct wmOperator; struct wmOperatorType; struct wmWindowManager; -enum eV3D_OpMode { - V3D_OP_MODE_NONE = -1, - V3D_OP_MODE_ZOOM = 0, - V3D_OP_MODE_ROTATE, - V3D_OP_MODE_MOVE, - V3D_OP_MODE_VIEW_PAN, - V3D_OP_MODE_VIEW_ROLL, - V3D_OP_MODE_DOLLY, -#ifdef WITH_INPUT_NDOF - V3D_OP_MODE_NDOF_ORBIT, - V3D_OP_MODE_NDOF_ORBIT_ZOOM, - V3D_OP_MODE_NDOF_PAN, - V3D_OP_MODE_NDOF_ALL, -#endif -}; -#ifndef WITH_INPUT_NDOF -# define V3D_OP_MODE_LEN V3D_OP_MODE_DOLLY + 1 -#else -# define V3D_OP_MODE_LEN V3D_OP_MODE_NDOF_ALL + 1 -#endif - enum eV3D_OpPropFlag { V3D_OP_PROP_MOUSE_CO = (1 << 0), V3D_OP_PROP_DELTA = (1 << 1), @@ -99,6 +78,14 @@ enum eViewOpsFlag { }; ENUM_OPERATORS(eViewOpsFlag, VIEWOPS_FLAG_ZOOM_TO_MOUSE); +struct ViewOpsType { + eViewOpsFlag flag; + const char *idname; + bool (*poll_fn)(bContext *C); + int (*init_fn)(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr); + int (*apply_fn)(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2]); +}; + /** Generic View Operator Custom-Data */ struct ViewOpsData { /** Context pointers (assigned by #viewops_data_create). */ @@ -170,7 +157,7 @@ struct ViewOpsData { float viewquat[4]; } curr; - eV3D_OpMode nav_type; + const ViewOpsType *nav_type; eViewOpsFlag viewops_flag; float reverse; @@ -198,7 +185,7 @@ struct ViewOpsData { void state_restore(); void init_navigation(bContext *C, const wmEvent *event, - const eV3D_OpMode nav_type, + const ViewOpsType *nav_type, const bool use_cursor_init); void end_navigation(bContext *C); @@ -209,11 +196,6 @@ struct ViewOpsData { /* view3d_navigate.cc */ -/** - * Navigation operators that share the `ViewOpsData` utility. - */ -const char *viewops_operator_idname_get(eV3D_OpMode nav_type); - bool view3d_location_poll(bContext *C); bool view3d_rotation_poll(bContext *C); bool view3d_zoom_or_dolly_poll(bContext *C); @@ -221,7 +203,7 @@ bool view3d_zoom_or_dolly_poll(bContext *C); int view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, - const eV3D_OpMode nav_type); + const ViewOpsType *nav_type); int view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event); void view3d_navigate_cancel_fn(bContext *C, wmOperator *op); @@ -247,7 +229,7 @@ void viewops_data_free(bContext *C, ViewOpsData *vod); */ ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, - const eV3D_OpMode nav_type, + const ViewOpsType *nav_type, const bool use_cursor_init); void axis_set_view(bContext *C, View3D *v3d, @@ -264,6 +246,8 @@ void axis_set_view(bContext *C, void viewdolly_modal_keymap(wmKeyConfig *keyconf); void VIEW3D_OT_dolly(wmOperatorType *ot); +extern ViewOpsType ViewOpsType_dolly; + /* view3d_navigate_fly.cc */ void fly_modal_keymap(wmKeyConfig *keyconf); @@ -272,24 +256,15 @@ void VIEW3D_OT_fly(wmOperatorType *ot); /* view3d_navigate_move.cc */ -int viewmove_modal_impl(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]); -int viewmove_invoke_impl(ViewOpsData *vod, const wmEvent *event); void viewmove_modal_keymap(wmKeyConfig *keyconf); void VIEW3D_OT_move(wmOperatorType *ot); +extern const ViewOpsType ViewOpsType_move; + /* view3d_navigate_ndof.cc */ #ifdef WITH_INPUT_NDOF struct wmNDOFMotionData; - -int ndof_orbit_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event); -int ndof_orbit_zoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event); -int ndof_pan_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event); -int ndof_all_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event); - /** * Called from both fly mode and walk mode, */ @@ -304,22 +279,26 @@ void VIEW3D_OT_ndof_orbit(wmOperatorType *ot); void VIEW3D_OT_ndof_orbit_zoom(wmOperatorType *ot); void VIEW3D_OT_ndof_pan(wmOperatorType *ot); void VIEW3D_OT_ndof_all(wmOperatorType *ot); + +extern const ViewOpsType ViewOpsType_ndof_orbit; +extern const ViewOpsType ViewOpsType_ndof_orbit_zoom; +extern const ViewOpsType ViewOpsType_ndof_pan; +extern const ViewOpsType ViewOpsType_ndof_all; #endif /* WITH_INPUT_NDOF */ /* view3d_navigate_roll.cc */ void VIEW3D_OT_view_roll(wmOperatorType *ot); +extern const ViewOpsType ViewOpsType_roll; + /* view3d_navigate_rotate.cc */ -int viewrotate_modal_impl(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]); -int viewrotate_invoke_impl(ViewOpsData *vod, const wmEvent *event); void viewrotate_modal_keymap(wmKeyConfig *keyconf); void VIEW3D_OT_rotate(wmOperatorType *ot); +extern const ViewOpsType ViewOpsType_rotate; + /* view3d_navigate_smoothview.cc */ /** @@ -409,9 +388,10 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot); /* view3d_navigate_view_pan.cc */ -int viewpan_invoke_impl(ViewOpsData *vod, PointerRNA *ptr); void VIEW3D_OT_view_pan(wmOperatorType *ot); +extern const ViewOpsType ViewOpsType_pan; + /* view3d_navigate_walk.cc */ void walk_modal_keymap(wmKeyConfig *keyconf); @@ -419,14 +399,11 @@ void VIEW3D_OT_walk(wmOperatorType *ot); /* view3d_navigate_zoom.cc */ -int viewzoom_modal_impl(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]); -int viewzoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr); void viewzoom_modal_keymap(wmKeyConfig *keyconf); void VIEW3D_OT_zoom(wmOperatorType *ot); +extern const ViewOpsType ViewOpsType_zoom; + /* view3d_navigate_zoom_border.cc */ void VIEW3D_OT_zoom_border(wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.cc b/source/blender/editors/space_view3d/view3d_navigate_dolly.cc index 7ca93306cd3..b1d04faea7c 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_dolly.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.cc @@ -246,7 +246,7 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - vod = viewops_data_create(C, event, V3D_OP_MODE_DOLLY, use_cursor_init); + vod = viewops_data_create(C, event, &ViewOpsType_dolly, use_cursor_init); op->customdata = vod; ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -311,7 +311,7 @@ void VIEW3D_OT_dolly(wmOperatorType *ot) /* identifiers */ ot->name = "Dolly View"; ot->description = "Dolly in/out in the view"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_DOLLY); + ot->idname = ViewOpsType_dolly.idname; /* api callbacks */ ot->invoke = viewdolly_invoke; @@ -329,3 +329,12 @@ void VIEW3D_OT_dolly(wmOperatorType *ot) } /** \} */ + +ViewOpsType ViewOpsType_dolly = { + /*flag*/ (VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_ZOOM_TO_MOUSE | + VIEWOPS_FLAG_USE_MOUSE_INIT), + /*idname*/ "VIEW3D_OT_dolly", + /*init_fn*/ nullptr, + /*apply_fn*/ nullptr, + /*cancel_fn*/ nullptr, +}; diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.cc b/source/blender/editors/space_view3d/view3d_navigate_move.cc index c26be30cff7..e27358e0899 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_move.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_move.cc @@ -51,10 +51,10 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_assign(keymap, "VIEW3D_OT_move"); } -int viewmove_modal_impl(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]) +static int viewmove_modal_impl(bContext *C, + ViewOpsData *vod, + const eV3D_OpEvent event_code, + const int xy[2]) { bool use_autokey = false; int ret = OPERATOR_RUNNING_MODAL; @@ -88,7 +88,10 @@ int viewmove_modal_impl(bContext *C, return ret; } -int viewmove_invoke_impl(ViewOpsData *vod, const wmEvent *event) +static int viewmove_invoke_impl(bContext * /*C*/, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA * /*ptr*/) { eV3D_OpEvent event_code = event->type == MOUSEPAN ? VIEW_CONFIRM : VIEW_PASS; @@ -105,7 +108,7 @@ int viewmove_invoke_impl(ViewOpsData *vod, const wmEvent *event) static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_MOVE); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_move); } void VIEW3D_OT_move(wmOperatorType *ot) @@ -113,7 +116,7 @@ void VIEW3D_OT_move(wmOperatorType *ot) /* identifiers */ ot->name = "Pan View"; ot->description = "Move the view"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_MOVE); + ot->idname = ViewOpsType_move.idname; /* api callbacks */ ot->invoke = viewmove_invoke; @@ -129,3 +132,11 @@ void VIEW3D_OT_move(wmOperatorType *ot) } /** \} */ + +const ViewOpsType ViewOpsType_move = { + /*flag*/ (VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_USE_MOUSE_INIT), + /*idname*/ "VIEW3D_OT_move", + /*poll_fn*/ view3d_location_poll, + /*init_fn*/ viewmove_invoke_impl, + /*apply_fn*/ viewmove_modal_impl, +}; diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.cc b/source/blender/editors/space_view3d/view3d_navigate_ndof.cc index b49e0e61062..cd77ed9c35c 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_ndof.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.cc @@ -420,7 +420,10 @@ static int view3d_ndof_cameraview_pan_zoom(ViewOpsData *vod, const wmNDOFMotionD /** \name NDOF Orbit/Translate Operator * \{ */ -int ndof_orbit_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) +static int ndof_orbit_invoke_impl(bContext *C, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA * /*ptr*/) { if (event->type != NDOF_MOTION) { return OPERATOR_CANCELLED; @@ -471,7 +474,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_NDOF_ORBIT); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_ndof_orbit); } void VIEW3D_OT_ndof_orbit(wmOperatorType *ot) @@ -479,7 +482,7 @@ void VIEW3D_OT_ndof_orbit(wmOperatorType *ot) /* identifiers */ ot->name = "NDOF Orbit View"; ot->description = "Orbit the view using the 3D mouse"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_NDOF_ORBIT); + ot->idname = ViewOpsType_ndof_orbit.idname; /* api callbacks */ ot->invoke = ndof_orbit_invoke; @@ -495,7 +498,10 @@ void VIEW3D_OT_ndof_orbit(wmOperatorType *ot) /** \name NDOF Orbit/Zoom Operator * \{ */ -int ndof_orbit_zoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) +static int ndof_orbit_zoom_invoke_impl(bContext *C, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA * /*ptr*/) { if (event->type != NDOF_MOTION) { return OPERATOR_CANCELLED; @@ -586,7 +592,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev return OPERATOR_CANCELLED; } - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_NDOF_ORBIT_ZOOM); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_ndof_orbit_zoom); } void VIEW3D_OT_ndof_orbit_zoom(wmOperatorType *ot) @@ -594,7 +600,7 @@ void VIEW3D_OT_ndof_orbit_zoom(wmOperatorType *ot) /* identifiers */ ot->name = "NDOF Orbit View with Zoom"; ot->description = "Orbit and zoom the view using the 3D mouse"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_NDOF_ORBIT_ZOOM); + ot->idname = ViewOpsType_ndof_orbit_zoom.idname; /* api callbacks */ ot->invoke = ndof_orbit_zoom_invoke; @@ -610,7 +616,10 @@ void VIEW3D_OT_ndof_orbit_zoom(wmOperatorType *ot) /** \name NDOF Pan/Zoom Operator * \{ */ -int ndof_pan_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) +static int ndof_pan_invoke_impl(bContext *C, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA * /*ptr*/) { if (event->type != NDOF_MOTION) { return OPERATOR_CANCELLED; @@ -668,7 +677,7 @@ static int ndof_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_NDOF_PAN); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_ndof_pan); } void VIEW3D_OT_ndof_pan(wmOperatorType *ot) @@ -676,7 +685,7 @@ void VIEW3D_OT_ndof_pan(wmOperatorType *ot) /* identifiers */ ot->name = "NDOF Pan View"; ot->description = "Pan the view with the 3D mouse"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_NDOF_PAN); + ot->idname = ViewOpsType_ndof_pan.idname; /* api callbacks */ ot->invoke = ndof_pan_invoke; @@ -695,7 +704,10 @@ void VIEW3D_OT_ndof_pan(wmOperatorType *ot) /** * wraps #ndof_orbit_zoom but never restrict to orbit. */ -int ndof_all_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) +static int ndof_all_invoke_impl(bContext *C, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA * /*ptr*/) { /* weak!, but it works */ const int ndof_flag = U.ndof_flag; @@ -703,7 +715,7 @@ int ndof_all_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) U.ndof_flag &= ~NDOF_MODE_ORBIT; - ret = ndof_orbit_zoom_invoke_impl(C, vod, event); + ret = ndof_orbit_zoom_invoke_impl(C, vod, event, nullptr); U.ndof_flag = ndof_flag; @@ -716,7 +728,7 @@ static int ndof_all_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_NDOF_ALL); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_ndof_all); } void VIEW3D_OT_ndof_all(wmOperatorType *ot) @@ -724,7 +736,7 @@ void VIEW3D_OT_ndof_all(wmOperatorType *ot) /* identifiers */ ot->name = "NDOF Transform View"; ot->description = "Pan and rotate the view with the 3D mouse"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_NDOF_ALL); + ot->idname = ViewOpsType_ndof_all.idname; /* api callbacks */ ot->invoke = ndof_all_invoke; @@ -737,3 +749,35 @@ void VIEW3D_OT_ndof_all(wmOperatorType *ot) #endif /* WITH_INPUT_NDOF */ /** \} */ + +const ViewOpsType ViewOpsType_ndof_orbit = { + /*flag*/ VIEWOPS_FLAG_ORBIT_SELECT, + /*idname*/ "VIEW3D_OT_ndof_orbit", + /*poll_fn*/ nullptr, + /*init_fn*/ ndof_orbit_invoke_impl, + /*apply_fn*/ nullptr, +}; + +const ViewOpsType ViewOpsType_ndof_orbit_zoom = { + /*flag*/ VIEWOPS_FLAG_ORBIT_SELECT, + /*idname*/ "VIEW3D_OT_ndof_orbit_zoom", + /*poll_fn*/ nullptr, + /*init_fn*/ ndof_orbit_zoom_invoke_impl, + /*apply_fn*/ nullptr, +}; + +const ViewOpsType ViewOpsType_ndof_pan = { + /*flag*/ VIEWOPS_FLAG_NONE, + /*idname*/ "VIEW3D_OT_ndof_pan", + /*poll_fn*/ nullptr, + /*init_fn*/ ndof_pan_invoke_impl, + /*apply_fn*/ nullptr, +}; + +const ViewOpsType ViewOpsType_ndof_all = { + /*flag*/ VIEWOPS_FLAG_ORBIT_SELECT, + /*idname*/ "VIEW3D_OT_ndof_all", + /*poll_fn*/ nullptr, + /*init_fn*/ ndof_all_invoke_impl, + /*apply_fn*/ nullptr, +}; diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.cc b/source/blender/editors/space_view3d/view3d_navigate_roll.cc index f0504acabb9..654d359f53b 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_roll.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_roll.cc @@ -251,7 +251,7 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) } else { /* makes op->customdata */ - vod = viewops_data_create(C, event, V3D_OP_MODE_VIEW_ROLL, false); + vod = viewops_data_create(C, event, &ViewOpsType_roll, false); const float start_position[2] = {float(BLI_rcti_cent_x(&vod->region->winrct)), float(BLI_rcti_cent_y(&vod->region->winrct))}; vod->init.dial = BLI_dial_init(start_position, FLT_EPSILON); @@ -286,7 +286,7 @@ void VIEW3D_OT_view_roll(wmOperatorType *ot) /* identifiers */ ot->name = "View Roll"; ot->description = "Roll the view"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_VIEW_ROLL); + ot->idname = ViewOpsType_roll.idname; /* api callbacks */ ot->invoke = viewroll_invoke; @@ -312,3 +312,11 @@ void VIEW3D_OT_view_roll(wmOperatorType *ot) } /** \} */ + +const ViewOpsType ViewOpsType_roll = { + /*flag*/ (VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_ORBIT_SELECT), + /*idname*/ "VIEW3D_OT_view_roll", + /*init_fn*/ nullptr, + /*apply_fn*/ nullptr, + /*cancel_fn*/ nullptr, +}; diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.cc b/source/blender/editors/space_view3d/view3d_navigate_rotate.cc index 668fced9405..fb647eadbf1 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_rotate.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.cc @@ -295,10 +295,10 @@ static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2]) ED_region_tag_redraw(vod->region); } -int viewrotate_modal_impl(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]) +static int viewrotate_modal_impl(bContext *C, + ViewOpsData *vod, + const eV3D_OpEvent event_code, + const int xy[2]) { bool use_autokey = false; int ret = OPERATOR_RUNNING_MODAL; @@ -332,7 +332,10 @@ int viewrotate_modal_impl(bContext *C, return ret; } -int viewrotate_invoke_impl(ViewOpsData *vod, const wmEvent *event) +static int viewrotate_invoke_impl(bContext * /*C*/, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA * /*ptr*/) { if (vod->use_dyn_ofs && (vod->rv3d->is_persp == false)) { vod->use_dyn_ofs_ortho_correction = true; @@ -362,7 +365,7 @@ int viewrotate_invoke_impl(ViewOpsData *vod, const wmEvent *event) static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_ROTATE); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_rotate); } void VIEW3D_OT_rotate(wmOperatorType *ot) @@ -370,7 +373,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) /* identifiers */ ot->name = "Rotate View"; ot->description = "Rotate the view"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_ROTATE); + ot->idname = ViewOpsType_rotate.idname; /* api callbacks */ ot->invoke = viewrotate_invoke; @@ -385,3 +388,12 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) } /** \} */ + +const ViewOpsType ViewOpsType_rotate = { + /*flag*/ (VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_USE_MOUSE_INIT | + VIEWOPS_FLAG_PERSP_ENSURE | VIEWOPS_FLAG_ORBIT_SELECT), + /*idname*/ "VIEW3D_OT_rotate", + /*poll_fn*/ view3d_rotation_poll, + /*init_fn*/ viewrotate_invoke_impl, + /*apply_fn*/ viewrotate_modal_impl, +}; diff --git a/source/blender/editors/space_view3d/view3d_navigate_view_pan.cc b/source/blender/editors/space_view3d/view3d_navigate_view_pan.cc index bd6dca71889..8cfc52cfe61 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_view_pan.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_view_pan.cc @@ -66,7 +66,10 @@ static const EnumPropertyItem prop_view_pan_items[] = { {0, nullptr, 0, nullptr, nullptr}, }; -int viewpan_invoke_impl(ViewOpsData *vod, PointerRNA *ptr) +static int viewpan_invoke_impl(bContext * /*C*/, + ViewOpsData *vod, + const wmEvent * /*event*/, + PointerRNA *ptr) { int x = 0, y = 0; int pandir = RNA_enum_get(ptr, "type"); @@ -91,7 +94,7 @@ int viewpan_invoke_impl(ViewOpsData *vod, PointerRNA *ptr) static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_VIEW_PAN); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_pan); } void VIEW3D_OT_view_pan(wmOperatorType *ot) @@ -99,7 +102,7 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot) /* identifiers */ ot->name = "Pan View Direction"; ot->description = "Pan the view in a given direction"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_VIEW_PAN); + ot->idname = ViewOpsType_pan.idname; /* api callbacks */ ot->invoke = viewpan_invoke; @@ -114,3 +117,11 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot) } /** \} */ + +const ViewOpsType ViewOpsType_pan = { + /*flag*/ (VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_USE_MOUSE_INIT), + /*idname*/ "VIEW3D_OT_view_pan", + /*poll_fn*/ view3d_location_poll, + /*init_fn*/ viewpan_invoke_impl, + /*apply_fn*/ nullptr, +}; diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.cc b/source/blender/editors/space_view3d/view3d_navigate_zoom.cc index 0d64df55ddb..c640b8a52a7 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_zoom.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.cc @@ -347,10 +347,10 @@ static void viewzoom_apply(ViewOpsData *vod, } } -int viewzoom_modal_impl(bContext *C, - ViewOpsData *vod, - const eV3D_OpEvent event_code, - const int xy[2]) +static int viewzoom_modal_impl(bContext *C, + ViewOpsData *vod, + const eV3D_OpEvent event_code, + const int xy[2]) { bool use_autokey = false; int ret = OPERATOR_RUNNING_MODAL; @@ -466,7 +466,10 @@ static int viewzoom_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -int viewzoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr) +static int viewzoom_invoke_impl(bContext *C, + ViewOpsData *vod, + const wmEvent *event, + PointerRNA *ptr) { int xy[2]; @@ -522,7 +525,7 @@ int viewzoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, Po /* viewdolly_invoke() copied this function, changes here may apply there */ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - return view3d_navigate_invoke_impl(C, op, event, V3D_OP_MODE_ZOOM); + return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_zoom); } void VIEW3D_OT_zoom(wmOperatorType *ot) @@ -530,7 +533,7 @@ void VIEW3D_OT_zoom(wmOperatorType *ot) /* identifiers */ ot->name = "Zoom View"; ot->description = "Zoom in/out in the view"; - ot->idname = viewops_operator_idname_get(V3D_OP_MODE_ZOOM); + ot->idname = ViewOpsType_zoom.idname; /* api callbacks */ ot->invoke = viewzoom_invoke; @@ -548,3 +551,12 @@ void VIEW3D_OT_zoom(wmOperatorType *ot) } /** \} */ + +const ViewOpsType ViewOpsType_zoom = { + /*flag*/ (VIEWOPS_FLAG_DEPTH_NAVIGATE | VIEWOPS_FLAG_USE_MOUSE_INIT | + VIEWOPS_FLAG_ZOOM_TO_MOUSE), + /*idname*/ "VIEW3D_OT_zoom", + /*poll_fn*/ view3d_zoom_or_dolly_poll, + /*init_fn*/ viewzoom_invoke_impl, + /*apply_fn*/ viewzoom_modal_impl, +};