Commit: f5dde1d4a1f8b8afed97a9e09f583b3424e36955
Author: Julian Eisel
Date:   Tue Jul 12 23:14:22 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rBf5dde1d4a1f8b8afed97a9e09f583b3424e36955

Add layer visibility toggle

Currently only affects drawing, need to check all object iterations if they 
need a visibility check individually.

Alignment need to be improved, didn't find a quick solution though. Would need 
to be solved differently when moving to outliner anyway.

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

M       source/blender/blenkernel/BKE_layer.h
M       source/blender/blenkernel/intern/layer.c
M       source/blender/editors/scene/CMakeLists.txt
M       source/blender/editors/scene/layer_types.c
M       source/blender/editors/space_layers/layers_draw.c
M       source/blender/editors/space_view3d/view3d_draw.c
M       source/blender/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/blenkernel/BKE_layer.h 
b/source/blender/blenkernel/BKE_layer.h
index 1a5f137..4198d5f 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -121,5 +121,7 @@ bool BKE_layeritem_iterate_childs(
         LayerTreeItem *litem, LayerTreeIterFunc foreach, void *customdata,
         const bool inverse);
 
+bool BKE_layeritem_is_visible(LayerTreeItem *litem);
+
 #endif  /* __BKE_LAYER_H__ */
 
diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index 97164fb..930ed5c 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -410,4 +410,20 @@ bool BKE_layeritem_iterate_childs(
        return layertree_iterate_list(&litem->childs, foreach, customdata, 
inverse);
 }
 
+/**
+ * Check if \a litem and all of its parents are visible.
+ */
+bool BKE_layeritem_is_visible(LayerTreeItem *litem)
+{
+       if (litem->is_hidden)
+               return false;
+
+       for (LayerTreeItem *parent = litem->parent; parent; parent = 
parent->parent) {
+               if (parent->is_hidden)
+                       return false;
+       }
+
+       return true;
+}
+
 /** \} */ /* Layer Tree Item */
diff --git a/source/blender/editors/scene/CMakeLists.txt 
b/source/blender/editors/scene/CMakeLists.txt
index a324c27..354b154 100644
--- a/source/blender/editors/scene/CMakeLists.txt
+++ b/source/blender/editors/scene/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
        ../../blentranslation
        ../../makesdna
        ../../makesrna
+       ../../windowmanager
        ../../../../intern/guardedalloc
 )
 
diff --git a/source/blender/editors/scene/layer_types.c 
b/source/blender/editors/scene/layer_types.c
index ae50410..9b7b494 100644
--- a/source/blender/editors/scene/layer_types.c
+++ b/source/blender/editors/scene/layer_types.c
@@ -45,6 +45,23 @@
 #include "UI_interface_icons.h"
 #include "UI_resources.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
+
+static void layer_visibility_update_cb(bContext *C, void *UNUSED(arg1), void 
*UNUSED(arg2))
+{
+       WM_event_add_notifier(C, NC_SCENE | ND_LAYER, NULL);
+}
+
+static void layer_visibility_but_draw(uiBlock *block, uiLayout *layout, 
LayerTreeItem *litem)
+{
+       BLI_assert(uiLayoutGetBlock(layout) == block);
+
+       uiBut *but = uiDefIconButBitC(block, UI_BTYPE_ICON_TOGGLE_N, 1, 0, 
ICON_VISIBLE_IPO_OFF, 0, 0, UI_UNIT_X, UI_UNIT_Y,
+                        &litem->is_hidden, 0.0f, 0.0f, 0.0f, 0.0f, "Layer 
Visibility");
+       UI_but_func_set(but, layer_visibility_update_cb, NULL, NULL);
+}
 
 static void object_layer_draw(const bContext *C, LayerTreeItem *litem, 
uiLayout *layout)
 {
@@ -57,13 +74,20 @@ static void object_layer_draw(const bContext *C, 
LayerTreeItem *litem, uiLayout
        const int col_icon = UI_colorset_icon_get(RNA_enum_get(litem->ptr, 
"color_set"));
        uiItemL(layout, litem->name, col_icon);
 
+       uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_RIGHT);
+
        if (draw_settingbut) {
-               UI_block_emboss_set(block, UI_EMBOSS_NONE);
                uiDefIconButBitI(block, UI_BTYPE_TOGGLE, LAYERTILE_EXPANDED, 0,
                                 ICON_SCRIPTWIN, 0, 0, UI_UNIT_X, UI_UNIT_Y, 
(int *)&tile->flag,
                                 0.0f, 0.0f, 0.0f, 0.0f, TIP_("Toggle layer 
settings"));
-               UI_block_emboss_set(block, UI_EMBOSS);
        }
+       else {
+               /* dummy button for alignment */
+               uiDefIconBut(block, UI_BTYPE_LABEL, 0, ICON_NONE, 0, 0, 
UI_UNIT_X, UI_UNIT_Y,
+                            NULL, 0.0f, 0.0f, 0.0f, 0.0f, "");
+       }
+
+       layer_visibility_but_draw(block, layout, litem);
 }
 
 static void object_layer_draw_settings(const bContext *UNUSED(C), 
LayerTreeItem *litem, uiLayout *layout)
@@ -93,16 +117,17 @@ static void layer_group_draw(const bContext *C, 
LayerTreeItem *litem, uiLayout *
        uiBlock *block = uiLayoutGetBlock(layout);
        uiBut *but;
 
-       UI_block_emboss_set(block, UI_EMBOSS_NONE);
        but = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE_N, LAYERTILE_CLOSED, 
0,
                         ICON_TRIA_RIGHT, 0, 0, UI_UNIT_X, UI_UNIT_Y, 
&tile->flag,
                         0.0f, 0.0f, 0.0f, 0.0f, TIP_("Toggle display of layer 
children"));
-       UI_block_emboss_set(block, UI_EMBOSS);
        UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT); /* doesn't align nicely 
without this */
 
        but = uiDefBut(block, UI_BTYPE_LABEL, 0, litem->name, 0, 0, UI_UNIT_X * 
10, UI_UNIT_Y,
                       NULL, 0.0f, 0.0f, 0.0f, 0.0f, "");
        UI_but_drawflag_enable(but, UI_BUT_TEXT_NO_MARGIN);
+
+       uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_RIGHT);
+       layer_visibility_but_draw(block, layout, litem);
 }
 
 static void LAYERTYPE_group(LayerType *lt)
diff --git a/source/blender/editors/space_layers/layers_draw.c 
b/source/blender/editors/space_layers/layers_draw.c
index 137aeb0..1cab0b0 100644
--- a/source/blender/editors/space_layers/layers_draw.c
+++ b/source/blender/editors/space_layers/layers_draw.c
@@ -104,10 +104,17 @@ static float layer_tile_draw(
        }
        else {
                uiLayout *layout = UI_block_layout(
-                       block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
-                       rect.xmin, rect.ymax, BLI_rctf_size_y(&rect), 0, 0, 
style);
-               litem->type->draw(C, litem, layout);
-               uiItemL(layout, "", 0); /* XXX without this editing last item 
causes crashes */
+                       block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
+                       rect.xmin, rect.ymax, 0, 0, 0, style);
+               uiLayout *row = uiLayoutRow(layout, false);
+
+               /* un-embossed by default */
+               UI_block_emboss_set(block, UI_EMBOSS_NONE);
+
+               litem->type->draw(C, litem, row);
+
+               UI_block_emboss_set(block, UI_EMBOSS);
+               uiItemL(row, "", 0); /* XXX without this editing last item 
causes crashes */
                UI_block_layout_resolve(block, NULL, NULL);
        }
        tile_size_y = header_y;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c 
b/source/blender/editors/space_view3d/view3d_draw.c
index 27991f6..3e217a0 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2829,11 +2829,18 @@ static void view3d_objectlayers_drawstep_draw(
         unsigned int *r_lay_used)
 {
 #ifdef WITH_ADVANCED_LAYERS
-       BKE_BASES_ITER_START(scene)
+       BKE_LAYERTREE_ITER_START(scene->object_layers, 0, i, litem)
        {
-               view3d_object_drawstep_draw(scene, v3d, ar, base, drawstep, 
drawflag, r_lay_used);
+               if (BKE_layeritem_is_visible(litem) && litem->type->type == 
LAYER_ITEMTYPE_LAYER) {
+                       LayerTypeObject *oblayer = (LayerTypeObject *)litem;
+                       BKE_OBJECTLAYER_BASES_ITER_START(oblayer, j, base)
+                       {
+                               view3d_object_drawstep_draw(scene, v3d, ar, 
base, drawstep, drawflag, r_lay_used);
+                       }
+                       BKE_OBJECTLAYER_BASES_ITER_END;
+               }
        }
-       BKE_BASES_ITER_END;
+       BKE_LAYERTREE_ITER_END;
 
 #else
        BKE_BASES_ITER_START(scene)
diff --git a/source/blender/makesdna/DNA_scene_types.h 
b/source/blender/makesdna/DNA_scene_types.h
index 0e708a8..49408f7 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -110,9 +110,14 @@ typedef struct LayerTreeItem {
        struct LayerType *type;
        char idname[64]; /* LayerType.idname, for finding type on file read */
 
-       int pad, index; /* index of the item - stored to avoid loockups */
+       int index; /* index of the item - stored to avoid loockups */
        char name[64];  /* MAX_NAME */
 
+       /* Such stuff should usually be handled using custom props but this is
+        * an exception: We access it a lot and it's useful for all layer types.
+        * Will/should stay the only exception so not using bit flags. */
+       char is_hidden, pad[3];
+
        LayerTree *tree; /* pointer back to layer tree - TODO check if needed */
        struct LayerTreeItem *parent; /* the group this item belongs to */
        ListBase childs; /* LayerTreeItem */

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

Reply via email to