Revision: 51255
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51255
Author:   campbellbarton
Date:     2012-10-10 12:22:45 +0000 (Wed, 10 Oct 2012)
Log Message:
-----------
add `All Regions` option to view_all (homekey), de-duplicate functions with 
view-selected.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c     
2012-10-10 11:37:38 UTC (rev 51254)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c     
2012-10-10 12:22:45 UTC (rev 51255)
@@ -2178,8 +2178,84 @@
        RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, 
INT_MAX);
 }
 
+static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar,
+                                          const float min[3], const float 
max[3],
+                                          int ok_dist)
+{
+       RegionView3D *rv3d = ar->regiondata;
+       float afm[3];
+       float size;
 
+       /* SMOOTHVIEW */
+       float new_ofs[3];
+       float new_dist;
 
+       sub_v3_v3v3(afm, max, min);
+       size = MAX3(afm[0], afm[1], afm[2]);
+
+       if (ok_dist) {
+               /* fix up zoom distance if needed */
+
+               if (rv3d->is_persp) {
+                       if (size <= v3d->near * 1.5f) {
+                               /* do not zoom closer than the near clipping 
plane */
+                               size = v3d->near * 1.5f;
+                       }
+               }
+               else { /* ortho */
+                       if (size < 0.0001f) {
+                               /* bounding box was a single point so do not 
zoom */
+                               ok_dist = 0;
+                       }
+                       else {
+                               /* adjust zoom so it looks nicer */
+                               size *= 0.7f;
+                       }
+               }
+       }
+
+       add_v3_v3v3(new_ofs, min, max);
+       mul_v3_fl(new_ofs, -0.5f);
+
+       new_dist = size;
+
+       /* correction for window aspect ratio */
+       if (ar->winy > 2 && ar->winx > 2) {
+               size = (float)ar->winx / (float)ar->winy;
+               if (size < 1.0f) size = 1.0f / size;
+               new_dist *= size;
+       }
+
+       if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, 
rv3d)) {
+               rv3d->persp = RV3D_PERSP;
+               view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, 
NULL, ok_dist ? &new_dist : NULL, NULL);
+       }
+       else {
+               view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, 
ok_dist ? &new_dist : NULL, NULL);
+       }
+
+       /* smooth view does viewlock RV3D_BOXVIEW copy */
+}
+
+/* same as view3d_from_minmax but for all regions (except cameras) */
+static void view3d_from_minmax_multi(bContext *C, View3D *v3d,
+                                     const float min[3], const float max[3],
+                                     const int ok_dist)
+{
+       ScrArea *sa = CTX_wm_area(C);
+       ARegion *ar;
+       for (ar = sa->regionbase.first; ar; ar = ar->next) {
+               if (ar->regiontype == RGN_TYPE_WINDOW) {
+                       RegionView3D *rv3d = ar->regiondata;
+                       /* when using all regions, don't jump out of camera 
view,
+                        * but _do_ allow locked cameras to be moved */
+                       if ((rv3d->persp != RV3D_CAMOB) || 
ED_view3d_camera_lock_check(v3d, rv3d)) {
+                               view3d_from_minmax(C, v3d, ar, min, max, 
ok_dist);
+                       }
+               }
+       }
+}
+
 static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() 
in 2.4x */
 {
        ARegion *ar = CTX_wm_region(C);
@@ -2189,10 +2265,10 @@
        Base *base;
        float *curs;
        const short skip_camera = ED_view3d_camera_lock_check(v3d, rv3d);
-
+       const short use_all_regions = RNA_boolean_get(op->ptr, 
"use_all_regions");
        int center = RNA_boolean_get(op->ptr, "center");
 
-       float size, min[3], max[3], afm[3];
+       float min[3], max[3];
        int ok = 1, onedone = FALSE;
 
        if (center) {
@@ -2229,44 +2305,25 @@
                return OPERATOR_FINISHED;
        }
 
-       sub_v3_v3v3(afm, max, min);
-       size = 0.7f * MAX3(afm[0], afm[1], afm[2]);
-       if (size == 0.0f) ok = 0;
+       if (ok == 0) {
+               return OPERATOR_FINISHED;
+       }
 
-       if (ok) {
-               float new_dist;
-               float new_ofs[3];
-
-               new_dist = size;
-               new_ofs[0] = -(min[0] + max[0]) / 2.0f;
-               new_ofs[1] = -(min[1] + max[1]) / 2.0f;
-               new_ofs[2] = -(min[2] + max[2]) / 2.0f;
-
-               /* correction for window aspect ratio */
-               if (ar->winy > 2 && ar->winx > 2) {
-                       size = (float)ar->winx / (float)ar->winy;
-                       if (size < 1.0f) size = 1.0f / size;
-                       new_dist *= size;
-               }
-
-               if ((rv3d->persp == RV3D_CAMOB) && 
!ED_view3d_camera_lock_check(v3d, rv3d)) {
-                       rv3d->persp = RV3D_PERSP;
-                       view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, 
new_ofs, NULL, &new_dist, NULL);
-               }
-               else {
-                       view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, 
NULL, &new_dist, NULL);
-               }
+       if (use_all_regions) {
+               view3d_from_minmax_multi(C, v3d, min, max, TRUE);
        }
-// XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
+       else {
+               view3d_from_minmax(C, v3d, ar, min, max, TRUE);
+       }
 
-       WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
-
        return OPERATOR_FINISHED;
 }
 
 
 void VIEW3D_OT_view_all(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
+
        /* identifiers */
        ot->name = "View All";
        ot->description = "View all objects in scene";
@@ -2279,68 +2336,11 @@
        /* flags */
        ot->flag = 0;
 
+       prop = RNA_def_boolean(ot->srna, "use_all_regions", 0, "All Regions", 
"View selected for all regions");
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
        RNA_def_boolean(ot->srna, "center", 0, "Center", "");
 }
 
-static void viewselected_rv3d_from_minmax(bContext *C, View3D *v3d, ARegion 
*ar,
-                                          const float min[3], const float 
max[3],
-                                          int ok_dist)
-{
-       RegionView3D *rv3d = ar->regiondata;
-       float afm[3];
-       float size;
-
-       /* SMOOTHVIEW */
-       float new_ofs[3];
-       float new_dist;
-
-       sub_v3_v3v3(afm, max, min);
-       size = MAX3(afm[0], afm[1], afm[2]);
-
-       if (ok_dist) {
-               /* fix up zoom distance if needed */
-
-               if (rv3d->is_persp) {
-                       if (size <= v3d->near * 1.5f) {
-                               /* do not zoom closer than the near clipping 
plane */
-                               size = v3d->near * 1.5f;
-                       }
-               }
-               else { /* ortho */
-                       if (size < 0.0001f) {
-                               /* bounding box was a single point so do not 
zoom */
-                               ok_dist = 0;
-                       }
-                       else {
-                               /* adjust zoom so it looks nicer */
-                               size *= 0.7f;
-                       }
-               }
-       }
-
-       add_v3_v3v3(new_ofs, min, max);
-       mul_v3_fl(new_ofs, -0.5f);
-
-       new_dist = size;
-
-       /* correction for window aspect ratio */
-       if (ar->winy > 2 && ar->winx > 2) {
-               size = (float)ar->winx / (float)ar->winy;
-               if (size < 1.0f) size = 1.0f / size;
-               new_dist *= size;
-       }
-
-       if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, 
rv3d)) {
-               rv3d->persp = RV3D_PERSP;
-               view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, 
NULL, ok_dist ? &new_dist : NULL, NULL);
-       }
-       else {
-               view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, 
ok_dist ? &new_dist : NULL, NULL);
-       }
-
-       /* smooth view does viewlock RV3D_BOXVIEW copy */
-}
-
 /* like a localview without local!, was centerview() in 2.4x */
 static int viewselected_exec(bContext *C, wmOperator *op)
 {
@@ -2428,22 +2428,12 @@
        }
 
        if (use_all_regions) {
-               ScrArea *sa = CTX_wm_area(C);
-               ARegion *ar_iter;
-               for (ar_iter = sa->regionbase.first; ar_iter; ar_iter = 
ar_iter->next) {
-                       if (ar_iter->regiontype == RGN_TYPE_WINDOW) {
-                               RegionView3D *rv3d = ar_iter->regiondata;
-                               /* when using all regions, don't jump out of 
camera view */
-                               if (rv3d->persp != RV3D_CAMOB) {
-                                       viewselected_rv3d_from_minmax(C, v3d, 
ar_iter, min, max, ok_dist);
-                               }
-                       }
-               }
+               view3d_from_minmax_multi(C, v3d, min, max, ok_dist);
        }
        else {
-               viewselected_rv3d_from_minmax(C, v3d, ar, min, max, ok_dist);
+               view3d_from_minmax(C, v3d, ar, min, max, ok_dist);
        }
-       
+
 // XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
 
        return OPERATOR_FINISHED;

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

Reply via email to