[Bf-blender-cvs] [05e82bf] soc-2016-layer_manager: Allow expanding/collapsing layer groups

Julian Eisel noreply at git.blender.org
Wed Jun 29 17:47:59 CEST 2016


Commit: 05e82bfdea0c08ce8f9a429fd02b69fdd705e094
Author: Julian Eisel
Date:   Wed Jun 29 17:43:00 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rB05e82bfdea0c08ce8f9a429fd02b69fdd705e094

Allow expanding/collapsing layer groups

Had to add a hack to widget drawing to make sure buttons align nicely.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/scene/layer_types.c
M	source/blender/editors/space_layers/layers_draw.c
M	source/blender/editors/space_layers/layers_intern.h
M	source/blender/editors/space_layers/layers_ops.c
M	source/blender/editors/space_layers/layers_util.c
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index a623f5c..fcfe9b3 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -212,6 +212,9 @@ enum {
 	UI_BUT_ALIGN_STITCH_TOP  = (1 << 18),
 	UI_BUT_ALIGN_STITCH_LEFT = (1 << 19),
 	UI_BUT_ALIGN_ALL         = (UI_BUT_ALIGN | UI_BUT_ALIGN_STITCH_TOP | UI_BUT_ALIGN_STITCH_LEFT),
+
+	/* Another hack, in some rare cases we don't want any text margin */
+	UI_BUT_TEXT_NO_MARGIN    = (1 << 20),
 };
 
 /* scale fixed button widths by this to account for DPI */
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 5098e70..e9db39e 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1570,7 +1570,10 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
 		}
 	}
 
-	if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) {
+	if (but->drawflag & UI_BUT_TEXT_NO_MARGIN) {
+		/* skip */
+	}
+	else if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) {
 		rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect;
 	}
 	else if ((but->drawflag & UI_BUT_TEXT_RIGHT)) {
diff --git a/source/blender/editors/scene/layer_types.c b/source/blender/editors/scene/layer_types.c
index c96cb4c..3d0d8d4 100644
--- a/source/blender/editors/scene/layer_types.c
+++ b/source/blender/editors/scene/layer_types.c
@@ -85,9 +85,23 @@ static void LAYERTYPE_object(LayerType *lt)
 }
 
 
-static void layer_group_draw(const bContext *UNUSED(C), LayerTreeItem *litem, uiLayout *layout)
+static void layer_group_draw(const bContext *C, LayerTreeItem *litem, uiLayout *layout)
 {
-	uiItemL(layout, litem->name, ICON_FILE_FOLDER);
+	SpaceLayers *slayer = CTX_wm_space_layers(C);
+	LayerTile *tile = BLI_ghash_lookup(slayer->tiles, litem);
+	uiBlock *block = uiLayoutGetBlock(layout);
+	uiBut *but;
+
+	UI_block_emboss_set(block, UI_EMBOSS_NONE);
+	but = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, 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);
 }
 
 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 8c726ce..5e03db9 100644
--- a/source/blender/editors/space_layers/layers_draw.c
+++ b/source/blender/editors/space_layers/layers_draw.c
@@ -176,6 +176,24 @@ static void layers_tiles_draw_floating(const bContext *C, struct FloatingTileDra
 	UI_block_draw(C, block);
 }
 
+static void layers_tiles_draw_childs(
+        const ListBase *childs, const bContext *C, uiBlock *block,
+        float *r_ofs_y, int *r_idx)
+{
+	SpaceLayers *slayer = CTX_wm_space_layers(C);
+	ARegion *ar = CTX_wm_region(C);
+	uiStyle *style = UI_style_get_dpi();
+
+	for (LayerTreeItem *litem = childs->first; litem; litem = litem->next) {
+		LayerTile *tile = BLI_ghash_lookup(slayer->tiles, litem);
+		*r_ofs_y += layer_tile_draw(tile, C, ar, block, style, *r_ofs_y, *r_idx);
+		(*r_idx)++;
+		if (!BLI_listbase_is_empty(&litem->childs)) {
+			layers_tiles_draw_childs(&litem->childs, C, block, r_ofs_y, r_idx);
+		}
+	}
+}
+
 static void layers_tiles_draw_fixed(
         const bContext *C,
         float *r_ofs_y, int *r_idx,
@@ -189,8 +207,7 @@ static void layers_tiles_draw_fixed(
 	 * fixed tiles are drawn over background of floating ones. */
 	uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
 
-	BKE_LAYERTREE_ITER_START(slayer->act_tree, 0, i, litem)
-	{
+	for (LayerTreeItem *litem = slayer->act_tree->items.last; litem; litem = litem->prev) {
 		LayerTile *tile = BLI_ghash_lookup(slayer->tiles, litem);
 		BLI_assert(tile->litem == litem);
 
@@ -209,9 +226,12 @@ static void layers_tiles_draw_fixed(
 		if (litem->type->draw) {
 			*r_ofs_y += layer_tile_draw(tile, C, ar, block, style, *r_ofs_y, *r_idx);
 			(*r_idx)++;
+			/* draw children */
+			if (!(tile->flag & LAYERTILE_CLOSED)) {
+				layers_tiles_draw_childs(&litem->childs, C, block, r_ofs_y, r_idx);
+			}
 		}
 	}
-	BKE_LAYERTREE_ITER_END;
 
 	UI_block_end(C, block);
 	UI_block_draw(C, block);
diff --git a/source/blender/editors/space_layers/layers_intern.h b/source/blender/editors/space_layers/layers_intern.h
index 34d338c..738e69c 100644
--- a/source/blender/editors/space_layers/layers_intern.h
+++ b/source/blender/editors/space_layers/layers_intern.h
@@ -42,7 +42,7 @@ void       layers_data_refresh(const struct Scene *scene, struct SpaceLayers *sl
 void       layers_tilehash_delete(SpaceLayers *slayer);
 LayerTile *layers_tile_add(const struct SpaceLayers *slayer, struct LayerTreeItem *litem);
 void       layers_tile_remove(const struct SpaceLayers *slayer, LayerTile *tile, const bool remove_children);
-LayerTile *layers_tile_find_at_coordinate(struct SpaceLayers *slayer, struct ARegion *ar, const int co[2]);
+LayerTile *layers_tile_find_at_coordinate(struct SpaceLayers *slayer, const int co[2]);
 bool layers_any_selected(struct SpaceLayers *slayer);
 
 /* layers_ops.c */
diff --git a/source/blender/editors/space_layers/layers_ops.c b/source/blender/editors/space_layers/layers_ops.c
index 6827f84..b6401ec 100644
--- a/source/blender/editors/space_layers/layers_ops.c
+++ b/source/blender/editors/space_layers/layers_ops.c
@@ -462,8 +462,7 @@ static int layer_drag_modal(bContext *C, wmOperator *op, const wmEvent *event)
 static int layer_drag_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	SpaceLayers *slayer = CTX_wm_space_layers(C);
-	ARegion *ar = CTX_wm_region(C);
-	LayerTile *tile = layers_tile_find_at_coordinate(slayer, ar, event->mval);
+	LayerTile *tile = layers_tile_find_at_coordinate(slayer, event->mval);
 
 	if (!tile)
 		return OPERATOR_CANCELLED;
@@ -503,7 +502,7 @@ static int layer_rename_invoke(bContext *C, wmOperator *UNUSED(op), const wmEven
 {
 	SpaceLayers *slayer = CTX_wm_space_layers(C);
 	ARegion *ar = CTX_wm_region(C);
-	LayerTile *tile = layers_tile_find_at_coordinate(slayer, ar, event->mval);
+	LayerTile *tile = layers_tile_find_at_coordinate(slayer, event->mval);
 	if (tile) {
 		tile->flag |= LAYERTILE_RENAME;
 
@@ -585,7 +584,7 @@ static int layer_select_invoke(bContext *C, wmOperator *op, const wmEvent *event
 	const bool toggle = RNA_boolean_get(op->ptr, "toggle");
 	const bool fill = RNA_boolean_get(op->ptr, "fill");
 
-	LayerTile *tile = layers_tile_find_at_coordinate(slayer, ar, event->mval);
+	LayerTile *tile = layers_tile_find_at_coordinate(slayer, event->mval);
 
 	/* little helper for setting/unsetting selection flag */
 #define TILE_SET_SELECTION(enable) layer_selection_set(slayer, tile, enable);
diff --git a/source/blender/editors/space_layers/layers_util.c b/source/blender/editors/space_layers/layers_util.c
index 053562d..f52e3f5 100644
--- a/source/blender/editors/space_layers/layers_util.c
+++ b/source/blender/editors/space_layers/layers_util.c
@@ -27,6 +27,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_rect.h"
 
 #include "BKE_layer.h"
 
@@ -103,17 +104,15 @@ void layers_tile_remove(const SpaceLayers *slayer, LayerTile *tile, const bool r
  * Find the tile at coordinate \a co (regionspace).
  * \note Does *not* account for LayerTile.ofs (could optionally do, layer dragging assumes it doesn't).
  */
-LayerTile *layers_tile_find_at_coordinate(SpaceLayers *slayer, ARegion *ar, const int co[2])
+LayerTile *layers_tile_find_at_coordinate(SpaceLayers *slayer, const int co[2])
 {
 	int ofs_y = 0;
 
 	BKE_LAYERTREE_ITER_START(slayer->act_tree, 0, i, litem)
 	{
 		LayerTile *tile = BLI_ghash_lookup(slayer->tiles, litem);
-		if (co[1] >= -ar->v2d.cur.ymin - (ofs_y + tile->tot_height)) {
-			if ((co[1] >= -ar->v2d.cur.ymin - (ofs_y + LAYERTILE_HEADER_HEIGHT))) {
-				return tile;
-			}
+		if (BLI_rcti_isect_y(&tile->rect, co[1])) {
+			return tile;
 		}
 		ofs_y += tile->tot_height;
 	}
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 2f3aaff..933afb3 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1335,13 +1335,17 @@ typedef enum eSpaceClip_GPencil_Source {
 
 /* Layer Manager ======================================= */
 
+/* XXX LAYERTILE_CLOSED and _EXPANDED could use better names */
 typedef enum eLayerTileFlag {
 	LAYERTILE_SELECTED = (1 << 0),
 	LAYERTILE_RENAME   = (1 << 1),
-	LAYERTILE_EXPANDED = (1 << 2),
+	/* Don't show childs */
+	LAYERTILE_CLOSED   = (1 << 2),
+	/* Show layer settings */
+	LAYERTILE_EXPANDED = (1 << 3),
 	/* Draw the tile as if it was floating above others (for drag and drop).
 	 * Note: Currently only one floating tile at a time allowed. */
-	LAYERTILE_FLOATING = (1 << 3),
+	LAYERTILE_FLOATING = (1 << 4),
 } eLayerTileFlag;
 
 /**




More information about the Bf-blender-cvs mailing list