Commit: 6b107daf23c5b8b6b7b9aebfa7384e103928a8d3
Author: julianeisel
Date:   Sun Feb 8 22:33:58 2015 +0100
Branches: master
https://developer.blender.org/rB6b107daf23c5b8b6b7b9aebfa7384e103928a8d3

Fix T43554: Zoom to mousepos makes 2D Views pan after zoom limits are
reached

There are a couple of things that I don't like here, but it seems like
the best way to handle this for now.

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

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

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

diff --git a/source/blender/editors/interface/view2d.c 
b/source/blender/editors/interface/view2d.c
index 12ee319..b4a120b 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -371,7 +371,8 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, 
int resize, int mask_
        float winx, winy;
        rctf *cur, *tot;
        
-       /* use mask as size of region that View2D resides in, as it takes into 
account scrollbars already  */
+       /* use mask as size of region that View2D resides in, as it takes into 
account
+        * scrollbars already - keep in sync with zoomx/zoomy in 
view_zoomstep_apply_ex! */
        winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1);
        winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1);
        
@@ -393,6 +394,7 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, 
int resize, int mask_
         */
        totwidth  = BLI_rctf_size_x(tot);
        totheight = BLI_rctf_size_y(tot);
+       /* keep in sync with zoomx/zoomy in view_zoomstep_apply_ex! */
        curwidth  = width  = BLI_rctf_size_x(cur);
        curheight = height = BLI_rctf_size_y(cur);
        
diff --git a/source/blender/editors/interface/view2d_ops.c 
b/source/blender/editors/interface/view2d_ops.c
index 297d8d0..88140d8 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -625,6 +625,7 @@ static void view_zoomstep_apply_ex(bContext *C, 
v2dViewZoomData *vzd, const bool
 {
        ARegion *ar = CTX_wm_region(C);
        View2D *v2d = &ar->v2d;
+       const rctf cur_old = v2d->cur;
        float dx, dy;
 
        /* calculate amount to move view by, ensuring symmetry so the
@@ -651,17 +652,23 @@ static void view_zoomstep_apply_ex(bContext *C, 
v2dViewZoomData *vzd, const bool
                                v2d->cur.xmax -= 2 * dx;
                }
                else {
+
+                       v2d->cur.xmin += dx;
+                       v2d->cur.xmax -= dx;
+
                        if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) 
{
-                               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);
-                               
-                               v2d->cur.xmin += ofs + dx;
-                               v2d->cur.xmax += ofs - dx;
-                       }
-                       else {
-                               v2d->cur.xmin += dx;
-                               v2d->cur.xmax -= dx;
+                               /* 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);
+
+                               /* only move view to mouse if zoom fac is 
inside minzoom/maxzoom */
+                               if (IN_RANGE_INCL(zoomx, v2d->minzoom, 
v2d->maxzoom)) {
+                                       float mval_fac = (vzd->mx_2d - 
cur_old.xmin) / BLI_rctf_size_x(&cur_old);
+                                       float mval_faci = 1.0f - mval_fac;
+                                       float ofs = (mval_fac * dx) - 
(mval_faci * dx);
+
+                                       v2d->cur.xmin += ofs;
+                                       v2d->cur.xmax += ofs;
+                               }
                        }
                }
        }
@@ -676,17 +683,23 @@ static void view_zoomstep_apply_ex(bContext *C, 
v2dViewZoomData *vzd, const bool
                                v2d->cur.ymax -= 2 * dy;
                }
                else {
+
+                       v2d->cur.ymin += dy;
+                       v2d->cur.ymax -= dy;
+
                        if (use_mousepos && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) 
{
-                               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);
-                               
-                               v2d->cur.ymin += ofs + dy;
-                               v2d->cur.ymax += ofs - dy;
-                       }
-                       else {
-                               v2d->cur.ymin += dy;
-                               v2d->cur.ymax -= dy;
+                               /* 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);
+
+                               /* only move view to mouse if zoom fac is 
inside minzoom/maxzoom */
+                               if (IN_RANGE_INCL(zoomy, v2d->minzoom, 
v2d->maxzoom)) {
+                                       float mval_fac = (vzd->my_2d - 
cur_old.ymin) / BLI_rctf_size_y(&cur_old);
+                                       float mval_faci = 1.0f - mval_fac;
+                                       float ofs = (mval_fac * dy) - 
(mval_faci * dy);
+
+                                       v2d->cur.ymin += ofs;
+                                       v2d->cur.ymax += ofs;
+                               }
                        }
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to