Fix gizmos showing for non-visible objects
authorCampbell Barton <ideasman42@gmail.com>
Tue, 18 Dec 2018 00:57:12 +0000 (11:57 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 18 Dec 2018 00:59:29 +0000 (11:59 +1100)
Active object gizmos were showing even when the object wasn't visible
(local view or with their object type disabled).

source/blender/editors/space_view3d/view3d_gizmo_armature.c
source/blender/editors/space_view3d/view3d_gizmo_camera.c
source/blender/editors/space_view3d/view3d_gizmo_empty.c
source/blender/editors/space_view3d/view3d_gizmo_forcefield.c
source/blender/editors/space_view3d/view3d_gizmo_lamp.c

index 0a3d20979a0e1f0b2b095e637306c4424b94911d..9766e8f7ff92462946524a7eb5a66d1e863194a4 100644 (file)
@@ -129,19 +129,22 @@ static void gizmo_bbone_offset_set(
 
 static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt))
 {
-       Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
-       if (ob != NULL) {
-               const bArmature *arm = ob->data;
-               if (arm->drawtype == ARM_B_BONE) {
-                       bPoseChannel *pchan = BKE_pose_channel_active(ob);
-                       if (pchan && pchan->bone->segments > 1) {
-                               View3D *v3d = CTX_wm_view3d(C);
-                               if ((v3d->flag2 & V3D_RENDER_OVERRIDE) ||
-                                   (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_CONTEXT)))
-                               {
-                                       /* pass */
-                               }
-                               else {
+       View3D *v3d = CTX_wm_view3d(C);
+       if ((v3d->flag2 & V3D_RENDER_OVERRIDE) ||
+           (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_CONTEXT)))
+       {
+               return false;
+       }
+
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (base && BASE_VISIBLE(v3d, base)) {
+               Object *ob = BKE_object_pose_armature_get(base->object);
+               if (ob) {
+                       const bArmature *arm = ob->data;
+                       if (arm->drawtype == ARM_B_BONE) {
+                               bPoseChannel *pchan = BKE_pose_channel_active(ob);
+                               if (pchan && pchan->bone->segments > 1) {
                                        return true;
                                }
                        }
@@ -153,7 +156,8 @@ static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType
 
 static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *gzgroup)
 {
-       Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = BKE_object_pose_armature_get(OBACT(view_layer));
        bPoseChannel *pchan = BKE_pose_channel_active(ob);
 
        const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true);
@@ -183,7 +187,8 @@ static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *g
 
 static void WIDGETGROUP_armature_spline_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 {
-       Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = BKE_object_pose_armature_get(OBACT(view_layer));
 
        if (!gzgroup->customdata)
                return;
index 3c29d4c407ba8fe9645c76a4065f112f23d64ec7..ace22094e530eb334b40971694ea299f9506626a 100644 (file)
@@ -70,12 +70,16 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED(
                return false;
        }
 
-       Object *ob = CTX_data_active_object(C);
-       if (ob && ob->type == OB_CAMERA) {
-               Camera *camera = ob->data;
-               /* TODO: support overrides. */
-               if (camera->id.lib == NULL) {
-                       return true;
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (base && BASE_VISIBLE(v3d, base)) {
+               Object *ob = base->object;
+               if (ob->type == OB_CAMERA) {
+                       Camera *camera = ob->data;
+                       /* TODO: support overrides. */
+                       if (camera->id.lib == NULL) {
+                               return true;
+                       }
                }
        }
        return false;
@@ -83,7 +87,8 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED(
 
 static void WIDGETGROUP_camera_setup(const bContext *C, wmGizmoGroup *gzgroup)
 {
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        float dir[3];
 
        const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
@@ -132,7 +137,8 @@ static void WIDGETGROUP_camera_refresh(const bContext *C, wmGizmoGroup *gzgroup)
                return;
 
        struct CameraWidgetGroup *cagzgroup = gzgroup->customdata;
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        Camera *ca = ob->data;
        PointerRNA camera_ptr;
        float dir[3];
@@ -234,7 +240,8 @@ static void WIDGETGROUP_camera_message_subscribe(
         const bContext *C, wmGizmoGroup *gzgroup, struct wmMsgBus *mbus)
 {
        ARegion *ar = CTX_wm_region(C);
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        Camera *ca = ob->data;
 
        wmMsgSubscribeValue msg_sub_value_gz_tag_refresh = {
index df1ae8c82e9bac66ba0b1934e81f1d98edab7a39..695ffc1d7ef7c885fce667a931bff684a0e72dfc 100644 (file)
@@ -118,11 +118,14 @@ static bool WIDGETGROUP_empty_image_poll(const bContext *C, wmGizmoGroupType *UN
                return false;
        }
 
-       Object *ob = CTX_data_active_object(C);
-
-       if (ob && ob->type == OB_EMPTY) {
-               if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
-                       return BKE_object_empty_image_is_visible_in_view3d(ob, rv3d);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (BASE_VISIBLE(v3d, base)) {
+               Object *ob = base->object;
+               if (ob->type == OB_EMPTY) {
+                       if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
+                               return BKE_object_empty_image_is_visible_in_view3d(ob, rv3d);
+                       }
                }
        }
        return false;
@@ -147,8 +150,9 @@ static void WIDGETGROUP_empty_image_setup(const bContext *UNUSED(C), wmGizmoGrou
 static void WIDGETGROUP_empty_image_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 {
        struct EmptyImageWidgetGroup *igzgroup = gzgroup->customdata;
-       Object *ob = CTX_data_active_object(C);
        wmGizmo *gz = igzgroup->gizmo;
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
 
        copy_m4_m4(gz->matrix_basis, ob->obmat);
 
index e2a8d2802e78c8222d3fb02b7717c2d7d4187d27..0e3d214ae3c57c73c8ecb448e8aea6be30e05bb4 100644 (file)
@@ -62,9 +62,15 @@ static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType *UNU
                return false;
        }
 
-       Object *ob = CTX_data_active_object(C);
-
-       return (ob && ob->pd && ob->pd->forcefield);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (base && BASE_VISIBLE(v3d, base)) {
+               Object *ob = base->object;
+               if (ob->pd && ob->pd->forcefield) {
+                       return true;
+               }
+       }
+       return false;
 }
 
 static void WIDGETGROUP_forcefield_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
@@ -87,7 +93,8 @@ static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmGizmoGroup *gzgr
 {
        wmGizmoWrapper *wwrapper = gzgroup->customdata;
        wmGizmo *gz = wwrapper->gizmo;
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        PartDeflect *pd = ob->pd;
 
        if (pd->forcefield == PFIELD_WIND) {
index b50f69950fb4cef585db5ed3514e11d4faef48dd..88da7d0b4f4642300f26af1fe1a1de7643ab59d1 100644 (file)
@@ -63,11 +63,14 @@ static bool WIDGETGROUP_lamp_spot_poll(const bContext *C, wmGizmoGroupType *UNUS
                return false;
        }
 
-       Object *ob = CTX_data_active_object(C);
-
-       if (ob && ob->type == OB_LAMP) {
-               Lamp *la = ob->data;
-               return (la->type == LA_SPOT);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (base && BASE_VISIBLE(v3d, base)) {
+               Object *ob = base->object;
+               if (ob->type == OB_LAMP) {
+                       Lamp *la = ob->data;
+                       return (la->type == LA_SPOT);
+               }
        }
        return false;
 }
@@ -91,7 +94,8 @@ static void WIDGETGROUP_lamp_spot_refresh(const bContext *C, wmGizmoGroup *gzgro
 {
        wmGizmoWrapper *wwrapper = gzgroup->customdata;
        wmGizmo *gz = wwrapper->gizmo;
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        Lamp *la = ob->data;
        float dir[3];
 
@@ -168,10 +172,14 @@ static bool WIDGETGROUP_lamp_area_poll(const bContext *C, wmGizmoGroupType *UNUS
                return false;
        }
 
-       Object *ob = CTX_data_active_object(C);
-       if (ob && ob->type == OB_LAMP) {
-               Lamp *la = ob->data;
-               return (la->type == LA_AREA);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (base && BASE_VISIBLE(v3d, base)) {
+               Object *ob = base->object;
+               if (ob->type == OB_LAMP) {
+                       Lamp *la = ob->data;
+                       return (la->type == LA_AREA);
+               }
        }
        return false;
 }
@@ -195,7 +203,8 @@ static void WIDGETGROUP_lamp_area_setup(const bContext *UNUSED(C), wmGizmoGroup
 static void WIDGETGROUP_lamp_area_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 {
        wmGizmoWrapper *wwrapper = gzgroup->customdata;
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        Lamp *la = ob->data;
        wmGizmo *gz = wwrapper->gizmo;
 
@@ -247,9 +256,10 @@ static bool WIDGETGROUP_lamp_target_poll(const bContext *C, wmGizmoGroupType *UN
                return false;
        }
 
-       Object *ob = CTX_data_active_object(C);
-
-       if (ob != NULL) {
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *base = BASACT(view_layer);
+       if (base && BASE_VISIBLE(v3d, base)) {
+               Object *ob = base->object;
                if (ob->type == OB_LAMP) {
                        Lamp *la = ob->data;
                        return (ELEM(la->type, LA_SUN, LA_SPOT, LA_AREA));
@@ -287,7 +297,8 @@ static void WIDGETGROUP_lamp_target_setup(const bContext *UNUSED(C), wmGizmoGrou
 static void WIDGETGROUP_lamp_target_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
 {
        wmGizmoWrapper *wwrapper = gzgroup->customdata;
-       Object *ob = CTX_data_active_object(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        wmGizmo *gz = wwrapper->gizmo;
 
        copy_m4_m4(gz->matrix_basis, ob->obmat);