adjust view3d api function for getting user region to also return view3d since most callers need this too.

This commit is contained in:
Campbell Barton
2012-01-14 12:24:25 +00:00
parent fca385ca9a
commit 4f3de6a741
5 changed files with 65 additions and 28 deletions

View 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);

View 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 */

View 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

View 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;

View 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;