Cleanup: Remove duplicated View2D zoom polling logic

`view_zoomdrag_init()` would perform a number of sanity checks that
`view_zoom_poll()` already executed. The design of operators forsees that
(non-expensive) context sanity checks are done by the `poll()` callbacks, and
the execution callbacks can then just assume that happened. No reason to be
overly pedantic, we don't do that elsewhere either.

Note that this code is from the earliest days of an operator design. So it's
not surprising that it wasn't using the design "properly".
This commit is contained in:
Julian Eisel 2020-10-03 16:31:09 +02:00
parent cb6234fccf
commit 21fc4ae206
Notes: blender-bot 2023-02-14 06:17:14 +01:00
Referenced by commit 9668fc582c, Fix compile error when compiling with WITH_INPUT_NDOF after View2D changes
1 changed files with 19 additions and 42 deletions

View File

@ -807,35 +807,6 @@ static void view_zoom_axis_lock_defaults(bContext *C, bool r_do_zoom_xy[2])
}
}
/* initialize panning customdata */
static bool view_zoomdrag_init(bContext *C, wmOperator *op)
{
ARegion *region = CTX_wm_region(C);
v2dViewZoomData *vzd;
View2D *v2d;
/* regions now have v2d-data by default, so check for region */
if (region == NULL) {
return false;
}
v2d = &region->v2d;
/* check that 2d-view is zoomable */
if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y)) {
return false;
}
/* set custom-data for operator */
vzd = MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
op->customdata = vzd;
/* set pointers to owners */
vzd->v2d = v2d;
vzd->region = region;
return true;
}
/* check if step-zoom can be applied */
static bool view_zoom_poll(bContext *C)
{
@ -863,6 +834,21 @@ static bool view_zoom_poll(bContext *C)
return true;
}
/* initialize panning customdata */
static void view_zoomdrag_init(bContext *C, wmOperator *op)
{
/* Should've been checked before. */
BLI_assert(view_zoom_poll(C));
/* set custom-data for operator */
v2dViewZoomData *vzd = MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
op->customdata = vzd;
/* set pointers to owners */
vzd->region = CTX_wm_region(C);
vzd->v2d = &vzd->region->v2d;
}
/* apply transform to view (i.e. adjust 'cur' rect) */
static void view_zoomstep_apply_ex(
bContext *C, v2dViewZoomData *vzd, const bool zoom_to_pos, const float facx, const float facy)
@ -1024,9 +1010,7 @@ static int view_zoomin_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
v2dViewZoomData *vzd;
if (!view_zoomdrag_init(C, op)) {
return OPERATOR_PASS_THROUGH;
}
view_zoomdrag_init(C, op);
vzd = op->customdata;
@ -1092,9 +1076,7 @@ static int view_zoomout_invoke(bContext *C, wmOperator *op, const wmEvent *event
{
v2dViewZoomData *vzd;
if (!view_zoomdrag_init(C, op)) {
return OPERATOR_PASS_THROUGH;
}
view_zoomdrag_init(C, op);
vzd = op->customdata;
@ -1255,10 +1237,7 @@ static void view_zoomdrag_cancel(bContext *C, wmOperator *op)
/* for 'redo' only, with no user input */
static int view_zoomdrag_exec(bContext *C, wmOperator *op)
{
if (!view_zoomdrag_init(C, op)) {
return OPERATOR_PASS_THROUGH;
}
view_zoomdrag_init(C, op);
view_zoomdrag_apply(C, op);
view_zoomdrag_exit(C, op);
return OPERATOR_FINISHED;
@ -1272,9 +1251,7 @@ static int view_zoomdrag_invoke(bContext *C, wmOperator *op, const wmEvent *even
View2D *v2d;
/* set up customdata */
if (!view_zoomdrag_init(C, op)) {
return OPERATOR_PASS_THROUGH;
}
view_zoomdrag_init(C, op);
vzd = op->customdata;
v2d = vzd->v2d;