Cleanup: deduplicate code

This commit is contained in:
Germano Cavalcante
2023-03-29 09:47:41 -03:00
parent bb2c89b20d
commit cc7634f2ea
7 changed files with 20 additions and 35 deletions

View File

@@ -74,6 +74,18 @@ bool view3d_zoom_or_dolly_poll(bContext *C)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Generic Callbacks
* \{ */
void view3d_navigate_cancel_fn(bContext *C, wmOperator *op)
{
viewops_data_free(C, (ViewOpsData *)op->customdata);
op->customdata = NULL;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Generic View Operator Properties
* \{ */

View File

@@ -30,6 +30,7 @@ struct View3D;
struct bContext;
struct rcti;
struct wmEvent;
struct wmOperator;
enum eV3D_OpPropFlag {
V3D_OP_PROP_MOUSE_CO = (1 << 0),
@@ -158,6 +159,8 @@ bool view3d_location_poll(struct bContext *C);
bool view3d_rotation_poll(struct bContext *C);
bool view3d_zoom_or_dolly_poll(struct bContext *C);
void view3d_navigate_cancel_fn(struct bContext *C, struct wmOperator *op);
enum eViewOpsFlag viewops_flag_from_prefs(void);
void calctrackballvec(const struct rcti *rect, const int event_xy[2], float r_dir[3]);
void viewmove_apply(ViewOpsData *vod, int x, int y);

View File

@@ -336,12 +336,6 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_FINISHED;
}
static void viewdolly_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
void VIEW3D_OT_dolly(wmOperatorType *ot)
{
/* identifiers */
@@ -354,7 +348,7 @@ void VIEW3D_OT_dolly(wmOperatorType *ot)
ot->exec = viewdolly_exec;
ot->modal = viewdolly_modal;
ot->poll = view3d_rotation_poll;
ot->cancel = viewdolly_cancel;
ot->cancel = view3d_navigate_cancel_fn;
/* flags */
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY | OPTYPE_DEPENDS_ON_CURSOR;

View File

@@ -203,12 +203,6 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
static void viewmove_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
void VIEW3D_OT_move(wmOperatorType *ot)
{
@@ -221,7 +215,7 @@ void VIEW3D_OT_move(wmOperatorType *ot)
ot->invoke = viewmove_invoke;
ot->modal = viewmove_modal;
ot->poll = view3d_location_poll;
ot->cancel = viewmove_cancel;
ot->cancel = view3d_navigate_cancel_fn;
/* flags */
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY;

View File

@@ -277,12 +277,6 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_FINISHED;
}
static void viewroll_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
void VIEW3D_OT_view_roll(wmOperatorType *ot)
{
PropertyRNA *prop;
@@ -297,7 +291,7 @@ void VIEW3D_OT_view_roll(wmOperatorType *ot)
ot->exec = viewroll_exec;
ot->modal = viewroll_modal;
ot->poll = ED_operator_rv3d_user_region_poll;
ot->cancel = viewroll_cancel;
ot->cancel = view3d_navigate_cancel_fn;
/* flags */
ot->flag = 0;

View File

@@ -464,12 +464,6 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
static void viewrotate_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
void VIEW3D_OT_rotate(wmOperatorType *ot)
{
/* identifiers */
@@ -481,7 +475,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
ot->invoke = viewrotate_invoke;
ot->modal = viewrotate_modal;
ot->poll = view3d_rotation_poll;
ot->cancel = viewrotate_cancel;
ot->cancel = view3d_navigate_cancel_fn;
/* flags */
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY;

View File

@@ -607,12 +607,6 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_FINISHED;
}
static void viewzoom_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
void VIEW3D_OT_zoom(wmOperatorType *ot)
{
/* identifiers */
@@ -625,7 +619,7 @@ void VIEW3D_OT_zoom(wmOperatorType *ot)
ot->exec = viewzoom_exec;
ot->modal = viewzoom_modal;
ot->poll = view3d_zoom_or_dolly_poll;
ot->cancel = viewzoom_cancel;
ot->cancel = view3d_navigate_cancel_fn;
/* flags */
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY;