[Bf-blender-cvs] [21fc4ae2069] master: Cleanup: Remove duplicated View2D zoom polling logic

Julian Eisel noreply at git.blender.org
Sat Oct 3 18:35:05 CEST 2020


Commit: 21fc4ae206920a072168886074f45ea6302ffe30
Author: Julian Eisel
Date:   Sat Oct 3 16:31:09 2020 +0200
Branches: master
https://developer.blender.org/rB21fc4ae206920a072168886074f45ea6302ffe30

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".

===================================================================

M	source/blender/editors/interface/view2d_ops.c

===================================================================

diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 32caf043119..060e4354b70 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -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;



More information about the Bf-blender-cvs mailing list