[Bf-blender-cvs] [56a533c0711] master: WM: option to ignore cursor image/clip/view2d zoom

Campbell Barton noreply at git.blender.org
Fri May 31 13:51:56 CEST 2019


Commit: 56a533c0711a486375408afaa7ac51da1613ccee
Author: Campbell Barton
Date:   Fri May 31 19:53:24 2019 +1000
Branches: master
https://developer.blender.org/rB56a533c0711a486375408afaa7ac51da1613ccee

WM: option to ignore cursor image/clip/view2d zoom

In preparation for view navigation gizmos.

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

M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_gizmo_navigate.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_operator_props.c

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

diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index b400b9bf4ed..a1995806937 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -643,7 +643,7 @@ static bool view_zoom_poll(bContext *C)
 
 /* apply transform to view (i.e. adjust 'cur' rect) */
 static void view_zoomstep_apply_ex(
-    bContext *C, v2dViewZoomData *vzd, const bool use_mousepos, const float facx, const float facy)
+    bContext *C, v2dViewZoomData *vzd, const bool zoom_to_pos, const float facx, const float facy)
 {
   ARegion *ar = CTX_wm_region(C);
   View2D *v2d = &ar->v2d;
@@ -681,7 +681,7 @@ static void view_zoomstep_apply_ex(
       v2d->cur.xmin += dx;
       v2d->cur.xmax -= dx;
 
-      if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) {
+      if (zoom_to_pos) {
         /* get zoom fac the same way as in
          * ui_view2d_curRect_validate_resize - better keep in sync! */
         const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur);
@@ -716,7 +716,7 @@ static void view_zoomstep_apply_ex(
       v2d->cur.ymin += dy;
       v2d->cur.ymax -= dy;
 
-      if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) {
+      if (zoom_to_pos) {
         /* get zoom fac the same way as in
          * ui_view2d_curRect_validate_resize - better keep in sync! */
         const float zoomy = (float)(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur);
@@ -752,8 +752,9 @@ static void view_zoomstep_apply_ex(
 static void view_zoomstep_apply(bContext *C, wmOperator *op)
 {
   v2dViewZoomData *vzd = op->customdata;
+  const bool zoom_to_pos = U.uiflag & USER_ZOOM_TO_MOUSEPOS;
   view_zoomstep_apply_ex(
-      C, vzd, true, RNA_float_get(op->ptr, "zoomfacx"), RNA_float_get(op->ptr, "zoomfacy"));
+      C, vzd, zoom_to_pos, RNA_float_get(op->ptr, "zoomfacx"), RNA_float_get(op->ptr, "zoomfacy"));
 }
 
 /* --------------- Individual Operators ------------------- */
@@ -921,6 +922,9 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
   float dx, dy;
   const int snap_test = ED_region_snap_size_test(vzd->ar);
 
+  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
+  const bool zoom_to_pos = use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS);
+
   /* get amount to move view by */
   dx = RNA_float_get(op->ptr, "deltax");
   dy = RNA_float_get(op->ptr, "deltay");
@@ -947,7 +951,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
       v2d->cur.xmax -= 2 * dx;
     }
     else {
-      if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+      if (zoom_to_pos) {
         float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
         float mval_faci = 1.0f - mval_fac;
         float ofs = (mval_fac * dx) - (mval_faci * dx);
@@ -966,7 +970,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
       v2d->cur.ymax -= 2 * dy;
     }
     else {
-      if (U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
+      if (zoom_to_pos) {
         float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
         float mval_faci = 1.0f - mval_fac;
         float ofs = (mval_fac * dy) - (mval_faci * dy);
@@ -1248,6 +1252,8 @@ static void VIEW2D_OT_zoom(wmOperatorType *ot)
   RNA_def_property_flag(prop, PROP_HIDDEN);
   prop = RNA_def_float(ot->srna, "deltay", 0, -FLT_MAX, FLT_MAX, "Delta Y", "", -FLT_MAX, FLT_MAX);
   RNA_def_property_flag(prop, PROP_HIDDEN);
+
+  WM_operator_properties_use_cursor_init(ot);
 }
 
 /* ********************************************************* */
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 532d89f6fa2..ba40b8bfaae 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -80,7 +80,10 @@
 
 /******************** view navigation utilities *********************/
 
-static void sclip_zoom_set(const bContext *C, float zoom, float location[2])
+static void sclip_zoom_set(const bContext *C,
+                           float zoom,
+                           const float location[2],
+                           const bool zoom_to_pos)
 {
   SpaceClip *sc = CTX_wm_space_clip(C);
   ARegion *ar = CTX_wm_region(C);
@@ -108,7 +111,7 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2])
     }
   }
 
-  if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) {
+  if (zoom_to_pos && location) {
     float aspx, aspy, w, h, dx, dy;
 
     ED_space_clip_get_size(sc, &width, &height);
@@ -131,11 +134,14 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2])
   }
 }
 
-static void sclip_zoom_set_factor(const bContext *C, float zoomfac, float location[2])
+static void sclip_zoom_set_factor(const bContext *C,
+                                  float zoomfac,
+                                  const float location[2],
+                                  const bool zoom_to_pos)
 {
   SpaceClip *sc = CTX_wm_space_clip(C);
 
-  sclip_zoom_set(C, sc->zoom * zoomfac, location);
+  sclip_zoom_set(C, sc->zoom * zoomfac, location, zoom_to_pos);
 }
 
 static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor)
@@ -151,7 +157,7 @@ static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float
     mpos = location;
   }
 
-  sclip_zoom_set_factor(C, factor, mpos);
+  sclip_zoom_set_factor(C, factor, mpos, mpos ? (U.uiflag & USER_ZOOM_TO_MOUSEPOS) : false);
 
   ED_region_tag_redraw(ar);
 }
@@ -355,16 +361,23 @@ typedef struct ViewPanData {
   float x, y;
   float xof, yof, xorig, yorig;
   int event_type;
+  bool own_cursor;
   float *vec;
 } ViewPanData;
 
 static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
 {
+  wmWindow *win = CTX_wm_window(C);
   SpaceClip *sc = CTX_wm_space_clip(C);
   ViewPanData *vpd;
 
   op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ClipViewPanData");
-  WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
+
+  /* Grab will be set when running from gizmo. */
+  vpd->own_cursor = (win->grabcursor == 0);
+  if (vpd->own_cursor) {
+    WM_cursor_modal_set(win, BC_NSEW_SCROLLCURSOR);
+  }
 
   vpd->x = event->x;
   vpd->y = event->y;
@@ -394,7 +407,9 @@ static void view_pan_exit(bContext *C, wmOperator *op, bool cancel)
     ED_region_tag_redraw(CTX_wm_region(C));
   }
 
-  WM_cursor_modal_restore(CTX_wm_window(C));
+  if (vpd->own_cursor) {
+    WM_cursor_modal_restore(CTX_wm_window(C));
+  }
   MEM_freeN(op->customdata);
 }
 
@@ -519,16 +534,23 @@ typedef struct ViewZoomData {
   float location[2];
   wmTimer *timer;
   double timer_lastdraw;
+  bool own_cursor;
 } ViewZoomData;
 
 static void view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
 {
+  wmWindow *win = CTX_wm_window(C);
   SpaceClip *sc = CTX_wm_space_clip(C);
   ARegion *ar = CTX_wm_region(C);
   ViewZoomData *vpd;
 
   op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData");
-  WM_cursor_modal_set(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
+
+  /* Grab will be set when running from gizmo. */
+  vpd->own_cursor = (win->grabcursor == 0);
+  if (vpd->own_cursor) {
+    WM_cursor_modal_set(win, BC_NSEW_SCROLLCURSOR);
+  }
 
   if (U.viewzoom == USER_ZOOM_CONT) {
     /* needs a timer to continue redrawing */
@@ -560,13 +582,15 @@ static void view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
     WM_event_remove_timer(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
   }
 
-  WM_cursor_modal_restore(CTX_wm_window(C));
+  if (vpd->own_cursor) {
+    WM_cursor_modal_restore(CTX_wm_window(C));
+  }
   MEM_freeN(op->customdata);
 }
 
 static int view_zoom_exec(bContext *C, wmOperator *op)
 {
-  sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL);
+  sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL, false);
 
   ED_region_tag_redraw(CTX_wm_region(C));
 
@@ -598,7 +622,8 @@ static int view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   }
 }
 
-static void view_zoom_apply(bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event)
+static void view_zoom_apply(
+    bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos)
 {
   float factor;
 
@@ -635,21 +660,22 @@ static void view_zoom_apply(bContext *C, ViewZoomData *vpd, wmOperator *op, cons
   }
 
   RNA_float_set(op->ptr, "factor", factor);
-  sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
+  sclip_zoom_set(C, vpd->zoom * factor, vpd->location, zoom_to_pos);
   ED_region_tag_redraw(CTX_wm_region(C));
 }
 
 static int view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
   ViewZoomData *vpd = op->customdata;
+  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
   switch (event->type) {
     case TIMER:
       if (event->customdata == vpd->timer) {
-        view_zoom_apply(C, vpd, op, event);
+        view_zoom_apply(C, vpd, op, event, use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS));
       }
       break;
     case MOUSEMOVE:
-      view_zoom_apply(C, vpd, op, event);
+      view_zoom_apply(C, vpd, op, event, use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS));
       break;
     default:
       if (event->type == vpd->event_type && event->val == KM_RELEASE) {
@@ -698,6 +724,8 @@ void CLIP_OT_view_zoom(wmOperatorType *ot)
                        -FLT_MAX,
                        FLT_MAX);
   RNA_def_property_flag(prop, PROP_HIDDEN);
+
+  WM_operator_properties_use_cursor_init(ot);
 }
 
 /********************** view zoom in/out operator *********************/
@@ -708,7 +736,7 @@ static int view_zoom_in_exec(bContext *C, wmOperator *op)
 
   RNA_float_get_array(op->ptr, "location", location);
 
-  sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location);
+  sclip_zoom_set_factor(C, powf(2.0f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS);
 
   ED_region_tag_redraw(CTX_wm_region(C));
 
@@ -762,7 +790,7 @@ static int view_zoom_out_exec(bContext *C, wmOperator *op)
 
   RNA_float_get_array(op->ptr, "location", location);
 
-  sclip_zoom_set_factor(C, powf(0.5f, 1.0f / 3.0f), loc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list