diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-02-05 01:34:56 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-02-05 02:38:53 +0300 |
commit | b1b1a74af15b4eaa0757ad88acfbcac73b9a64fe (patch) | |
tree | 0132cce785cc9305f8ea1dacf13fd453ede8f450 /source/blender/editors | |
parent | ec9f237a9ef01e5966228e0789eeecc419021f56 (diff) |
Cleanup: set 'op->customdata' out of 'viewops_data_create'
Setting the `op->customdata` out of `viewops_data_create` makes the usage of the function clearer thus making the code easier to read.
Diffstat (limited to 'source/blender/editors')
8 files changed, 80 insertions, 71 deletions
diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c index e647e80ff36..98eef94d5fb 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.c +++ b/source/blender/editors/space_view3d/view3d_navigate.c @@ -274,15 +274,11 @@ enum eViewOpsFlag viewops_flag_from_prefs(void) (U.uiflag & USER_DEPTH_NAVIGATE) != 0); } -void viewops_data_create(bContext *C, - wmOperator *op, - const wmEvent *event, - enum eViewOpsFlag viewops_flag) +ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, enum eViewOpsFlag viewops_flag) { ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), __func__); /* Store data. */ - op->customdata = vod; vod->bmain = CTX_data_main(C); vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); vod->scene = CTX_data_scene(C); @@ -423,13 +419,14 @@ void viewops_data_create(bContext *C, } rv3d->rflag |= RV3D_NAVIGATING; + + return vod; } -void viewops_data_free(bContext *C, wmOperator *op) +void viewops_data_free(bContext *C, ViewOpsData *vod) { ARegion *region; - if (op->customdata) { - ViewOpsData *vod = op->customdata; + if (vod) { region = vod->region; vod->rv3d->rflag &= ~RV3D_NAVIGATING; @@ -442,7 +439,6 @@ void viewops_data_free(bContext *C, wmOperator *op) } MEM_freeN(vod); - op->customdata = NULL; } else { region = CTX_wm_region(C); @@ -1565,12 +1561,12 @@ static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event) y = 25; } - viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT)); - ViewOpsData *vod = op->customdata; + ViewOpsData *vod = viewops_data_create( + C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT)); viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y); - viewops_data_free(C, op); + viewops_data_free(C, vod); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.h index 2f9a0ff603c..792d2a83bc2 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.h +++ b/source/blender/editors/space_view3d/view3d_navigate.h @@ -166,15 +166,17 @@ bool view3d_orbit_calc_center(struct bContext *C, float r_dyn_ofs[3]); void view3d_operator_properties_common(struct wmOperatorType *ot, const enum eV3D_OpPropFlag flag); -void viewops_data_free(struct bContext *C, struct wmOperator *op); +/** + * Allocate and fill in context pointers for #ViewOpsData + */ +void viewops_data_free(struct bContext *C, ViewOpsData *vod); /** * Allocate, fill in context pointers and calculate the values for #ViewOpsData */ -void viewops_data_create(struct bContext *C, - struct wmOperator *op, - const struct wmEvent *event, - enum eViewOpsFlag viewops_flag); +ViewOpsData *viewops_data_create(struct bContext *C, + const struct wmEvent *event, + enum eViewOpsFlag viewops_flag); void VIEW3D_OT_view_all(struct wmOperatorType *ot); void VIEW3D_OT_view_selected(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c index 07099ea221e..02783c2a244 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c +++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c @@ -174,7 +174,8 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); + viewops_data_free(C, vod); + op->customdata = NULL; } return ret; @@ -225,7 +226,8 @@ static int viewdolly_exec(bContext *C, wmOperator *op) ED_region_tag_redraw(region); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -241,13 +243,11 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - /* makes op->customdata */ - viewops_data_create(C, - op, - event, - (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - vod = op->customdata; + vod = op->customdata = viewops_data_create( + C, + event, + (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -294,7 +294,8 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) } viewdolly_apply(vod, event->prev_xy, (U.uiflag & USER_ZOOM_INVERT) == 0); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -307,7 +308,8 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void viewdolly_cancel(bContext *C, wmOperator *op) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } void VIEW3D_OT_dolly(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c index a84da76b05f..90acf20d24f 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_move.c +++ b/source/blender/editors/space_view3d/view3d_navigate_move.c @@ -119,7 +119,8 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } return ret; @@ -131,12 +132,11 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - /* makes op->customdata */ - viewops_data_create(C, - op, - event, - (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + vod = op->customdata = viewops_data_create( + C, + event, + (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); vod = op->customdata; ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -146,7 +146,8 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) viewmove_apply( vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -159,7 +160,8 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void viewmove_cancel(bContext *C, wmOperator *op) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } void VIEW3D_OT_move(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c index 668a5288190..285d5c02db2 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c +++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c @@ -378,8 +378,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event) const wmNDOFMotionData *ndof = event->customdata; - viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE)); - vod = op->customdata; + vod = op->customdata = viewops_data_create( + C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE)); ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -417,7 +417,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event) ED_region_tag_redraw(vod->region); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -457,9 +458,8 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev const wmNDOFMotionData *ndof = event->customdata; - viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE)); - - vod = op->customdata; + vod = op->customdata = viewops_data_create( + C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE)); ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -531,7 +531,8 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev ED_region_tag_redraw(vod->region); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c index 4675aad9af5..c9bfdc4412a 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_roll.c +++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c @@ -107,7 +107,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) /* Note this does not remove auto-keys on locked cameras. */ copy_qt_qt(vod->rv3d->viewquat, vod->init.quat); ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_CANCELLED; } else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { @@ -130,7 +131,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } return ret; @@ -201,11 +203,13 @@ static int viewroll_exec(bContext *C, wmOperator *op) .dyn_ofs = dyn_ofs_pt, }); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_CANCELLED; } @@ -220,8 +224,7 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) } else { /* makes op->customdata */ - viewops_data_create(C, op, event, viewops_flag_from_prefs()); - vod = op->customdata; + vod = op->customdata = viewops_data_create(C, event, viewops_flag_from_prefs()); vod->init.dial = BLI_dial_init((const float[2]){BLI_rcti_cent_x(&vod->region->winrct), BLI_rcti_cent_y(&vod->region->winrct)}, FLT_EPSILON); @@ -236,7 +239,8 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; viewroll_apply(vod, event->prev_xy[0], event->prev_xy[1]); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -249,7 +253,8 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void viewroll_cancel(bContext *C, wmOperator *op) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } void VIEW3D_OT_view_roll(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c index 30af53c4bc6..c3730b3b3b1 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c +++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c @@ -370,7 +370,8 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } return ret; @@ -383,13 +384,11 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); /* makes op->customdata */ - viewops_data_create(C, - op, - event, - viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - - vod = op->customdata; + vod = op->customdata = viewops_data_create( + C, + event, + viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -413,7 +412,8 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) viewrotate_apply(vod, event_xy); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -426,7 +426,8 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void viewrotate_cancel(bContext *C, wmOperator *op) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } void VIEW3D_OT_rotate(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c index d4f3de64341..d7b1daa93c2 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c +++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c @@ -418,7 +418,8 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; } return ret; @@ -499,7 +500,8 @@ static int viewzoom_exec(bContext *C, wmOperator *op) ED_region_tag_redraw(region); - viewops_data_free(C, op); + viewops_data_free(C, op->customdata); + op->customdata = NULL; return OPERATOR_FINISHED; } @@ -511,13 +513,11 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - /* makes op->customdata */ - viewops_data_create(C, - op, - event, - (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - vod = op->customdata; + vod = op->customdata = viewops_data_create( + C, + event, + (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); |