adjust view3d api function for getting user region to also return view3d since most...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 14 Jan 2012 12:24:25 +0000 (12:24 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 14 Jan 2012 12:24:25 +0000 (12:24 +0000)
source/blender/editors/include/ED_view3d.h
source/blender/editors/render/render_opengl.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_view.c

index 438646feaa48bee8ab267b8d4b0e67adefcbb21b..2148b0d04a69a1f4094eb166753d111f924a7e14 100644 (file)
@@ -266,8 +266,8 @@ int lasso_inside_edge(int mcords[][2], short moves, int x0, int y0, int x1, int
 
 /* get 3d region from context, also if mouse is in header or toolbar */
 struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C);
-struct ARegion *ED_view3d_context_region_unlock(struct bContext *C);
-int ED_operator_rv3d_unlock_poll(struct bContext *C);
+int ED_view3d_context_user_region(struct bContext *C, struct View3D **v3d_r, struct ARegion **ar_r);
+int ED_operator_rv3d_user_region_poll(struct bContext *C);
 
 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d);
 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d);
index d26915cc04691095c30428b0b8d3721de7fe0bb7..06e15f4a5f676dee7d9cdcd7c9338988eb428d3f 100644 (file)
@@ -327,8 +327,7 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op)
        oglrender->prevar= prevar;
 
        if(is_view_context) {
-               oglrender->v3d= CTX_wm_view3d(C);
-               oglrender->ar= ED_view3d_context_region_unlock(C); /* so quad view renders camera */
+               ED_view3d_context_user_region(C, &oglrender->v3d, &oglrender->ar); /* so quad view renders camera */
                oglrender->rv3d= oglrender->ar->regiondata;
 
                /* MUST be cleared on exit */
index 196af34137a8d7e1b40f620eb26b01c2b0b4e70b..f2906ca9559bafaf2c5006800e8a08d2b8e9d0fd 100644 (file)
@@ -154,15 +154,23 @@ RegionView3D *ED_view3d_context_rv3d(bContext *C)
 
 /* ideally would return an rv3d but in some cases the region is needed too
  * so return that, the caller can then access the ar->regiondata */
-ARegion *ED_view3d_context_region_unlock(bContext *C)
+int ED_view3d_context_user_region(bContext *C, View3D **v3d_r, ARegion **ar_r)
 {
        ScrArea *sa= CTX_wm_area(C);
+
+       *v3d_r = NULL;
+       *ar_r = NULL;
+
        if(sa && sa->spacetype==SPACE_VIEW3D) {
                ARegion *ar= CTX_wm_region(C);
+               View3D *v3d = (View3D *)sa->spacedata.first;
+
                if(ar) {
                        RegionView3D *rv3d= ar->regiondata;
                        if(rv3d && rv3d->viewlock == 0) {
-                               return ar;
+                               *v3d_r = v3d;
+                               *ar_r = ar;
+                               return 1;
                        }
                        else {
                                ARegion *ar_unlock_user= NULL;
@@ -182,12 +190,22 @@ ARegion *ED_view3d_context_region_unlock(bContext *C)
                                }
 
                                /* camera/perspective view get priority when the active region is locked */
-                               if(ar_unlock_user) return ar_unlock_user;
-                               if(ar_unlock) return ar_unlock;
+                               if(ar_unlock_user) {
+                                       *v3d_r = v3d;
+                                       *ar_r = ar_unlock_user;
+                                       return 1;
+                               }
+
+                               if(ar_unlock) {
+                                       *v3d_r = v3d;
+                                       *ar_r = ar_unlock;
+                                       return 1;
+                               }
                        }
                }
        }
-       return NULL;
+
+       return 0;
 }
 
 /* Most of the time this isn't needed since you could assume the view matrix was
index 8a0fa5324be66fe474f75a5300ab65a90c8d38c4..224df5b9f806812a2e751332addd590db2dfc9e4 100644 (file)
@@ -2653,13 +2653,16 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, float q1, float
 
 static int viewnumpad_exec(bContext *C, wmOperator *op)
 {
-       View3D *v3d = CTX_wm_view3d(C);
-       ARegion *ar= ED_view3d_context_region_unlock(C);
-       RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
+       View3D *v3d;
+       ARegion *ar;
+       RegionView3D *rv3d;
        Scene *scene= CTX_data_scene(C);
-       static int perspo=RV3D_PERSP;
+       static int perspo = RV3D_PERSP;
        int viewnum, align_active, nextperspo;
 
+       ED_view3d_context_user_region(C, &v3d, &ar);
+       rv3d = ar->regiondata;
+
        viewnum = RNA_enum_get(op->ptr, "type");
        align_active = RNA_boolean_get(op->ptr, "align_active");
 
@@ -2783,7 +2786,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= viewnumpad_exec;
-       ot->poll= ED_operator_rv3d_unlock_poll;
+       ot->poll= ED_operator_rv3d_user_region_poll;
 
        /* flags */
        ot->flag= 0;
@@ -2801,12 +2804,16 @@ static EnumPropertyItem prop_view_orbit_items[] = {
 
 static int vieworbit_exec(bContext *C, wmOperator *op)
 {
-       View3D *v3d= CTX_wm_view3d(C);
-       ARegion *ar= ED_view3d_context_region_unlock(C);
-       RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
+       View3D *v3d;
+       ARegion *ar;
+       RegionView3D *rv3d;
        float phi, q1[4], new_quat[4];
        int orbitdir;
 
+       /* no NULL check is needed, poll checks */
+       ED_view3d_context_user_region(C, &v3d, &ar);
+       rv3d = ar->regiondata;
+
        orbitdir = RNA_enum_get(op->ptr, "type");
 
        if(rv3d->viewlock==0) {
@@ -2852,7 +2859,7 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= vieworbit_exec;
-       ot->poll= ED_operator_rv3d_unlock_poll;
+       ot->poll= ED_operator_rv3d_user_region_poll;
 
        /* flags */
        ot->flag= 0;
@@ -2909,8 +2916,13 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot)
 
 static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       ARegion *ar= ED_view3d_context_region_unlock(C);
-       RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
+       View3D *v3d_dummy;
+       ARegion *ar;
+       RegionView3D *rv3d;
+
+       /* no NULL check is needed, poll checks */
+       ED_view3d_context_user_region(C, &v3d_dummy, &ar);
+       rv3d = ar->regiondata;
 
        if(rv3d->viewlock==0) {
                if(rv3d->persp!=RV3D_ORTHO)
@@ -2932,7 +2944,7 @@ void VIEW3D_OT_view_persportho(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= viewpersportho_exec;
-       ot->poll= ED_operator_rv3d_unlock_poll;
+       ot->poll= ED_operator_rv3d_user_region_poll;
 
        /* flags */
        ot->flag= 0;
index aa444125287104e87f11a246fb716da286e8955f..11492ee78042d3e1e083bd26d84c647bb6e98d13 100644 (file)
@@ -466,13 +466,18 @@ void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
 
 
 static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       View3D *v3d = CTX_wm_view3d(C);
-       ARegion *ar= ED_view3d_context_region_unlock(C);
-       RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
+{      
+       View3D *v3d;
+       ARegion *ar;
+       RegionView3D *rv3d;
+
        Scene *scene= CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
 
+       /* no NULL check is needed, poll checks */
+       ED_view3d_context_user_region(C, &v3d, &ar);
+       rv3d = ar->regiondata;
+
        if(ob) {
                Object *camera_old= (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL;
                rv3d->persp= RV3D_CAMOB;
@@ -489,9 +494,12 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op))
        return OPERATOR_FINISHED;
 }
 
-int ED_operator_rv3d_unlock_poll(bContext *C)
+int ED_operator_rv3d_user_region_poll(bContext *C)
 {
-       return ED_view3d_context_region_unlock(C) != NULL;
+       View3D *v3d_dummy;
+       ARegion *ar_dummy;
+
+       return ED_view3d_context_user_region(C, &v3d_dummy, &ar_dummy);
 }
 
 void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
@@ -504,7 +512,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= view3d_setobjectascamera_exec;
-       ot->poll= ED_operator_rv3d_unlock_poll;
+       ot->poll= ED_operator_rv3d_user_region_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;