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.
This commit is contained in:
Germano Cavalcante 2022-02-04 19:34:56 -03:00
parent ec9f237a9e
commit b1b1a74af1
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by commit 81d2eda2bf, Fix error in b1b1a74af1
8 changed files with 80 additions and 71 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -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)

View File

@ -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;
}

View File

@ -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)

View File

@ -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)

View File

@ -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);