[Bf-blender-cvs] [028daaf8172] temp-outliner-visibility: Outliner: Implement 3 levels of viewport visibility

Dalai Felinto noreply at git.blender.org
Fri Nov 30 05:36:42 CET 2018


Commit: 028daaf8172161df2ff620d7b24551d5ef910c0a
Author: Dalai Felinto
Date:   Fri Nov 30 02:24:06 2018 -0200
Branches: temp-outliner-visibility
https://developer.blender.org/rB028daaf8172161df2ff620d7b24551d5ef910c0a

Outliner: Implement 3 levels of viewport visibility

Now collection and objects can be either:
* Hidden for all the view layers.
* Hidden for a view layer but not necessarily for all others.
* Visible for a view layer but not necessarily for all others.

Regarding icons: Whatever we decide to use for the "Hidden for all view
layers" needs to be a toggle-like icon. Because when viewing "Scenes"
instead of "View Layer" in the outliner we should be able to edit the
collection "Hidden for all the view layers" as an on/off option.

See T57857 for discussion.

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

M	source/blender/blenkernel/intern/layer.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_intern.h

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 7f36af40e0b..9d27cda9984 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -677,7 +677,9 @@ static short layer_collection_sync(
 			lc->runtime_flag = child_runtime_flag;
 		}
 
-		if ((child_layer_restrict & LAYER_COLLECTION_RESTRICT_VIEW) == 0) {
+		if (((child_restrict & COLLECTION_RESTRICT_VIEW) == 0) &&
+		    ((child_layer_restrict & LAYER_COLLECTION_RESTRICT_VIEW) == 0))
+		{
 			lc->runtime_flag |= LAYER_COLLECTION_VISIBLE;
 		}
 
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 59523feabc5..41052215a8b 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -276,24 +276,38 @@ static void restrictbutton_id_user_toggle(bContext *UNUSED(C), void *poin, void
 
 static void hidebutton_base_flag_cb(bContext *C, void *poin, void *poin2)
 {
+	Main *bmain = CTX_data_main(C);
 	Scene *scene = CTX_data_scene(C);
 	ViewLayer *view_layer = poin;
 	Base *base = poin2;
-	bool extend = (CTX_wm_window(C)->eventstate->ctrl == 0);
-
-	/* Undo button toggle, let function do it. */
-	base->flag ^= BASE_HIDDEN;
-
-	BKE_base_set_visible(scene, view_layer, base, extend);
+	Object *ob = base->object;
+	bool freeze = (CTX_wm_window(C)->eventstate->ctrl != 0);
+	bool changed_restrict_view = false;
 
-	if (!extend && (base->flag & BASE_VISIBLE)) {
-		/* Auto select solo-ed object. */
-		ED_object_base_select(base, BA_SELECT);
-		view_layer->basact = base;
+	if (freeze) {
+		ob->restrictflag |= OB_RESTRICT_VIEW;
+		changed_restrict_view = true;
+	}
+	else if (ob->restrictflag & OB_RESTRICT_VIEW) {
+		ob->restrictflag &= ~OB_RESTRICT_VIEW;
+		base->flag &= ~BASE_HIDDEN;
+		changed_restrict_view = true;
+	}
+	else {
+		base->flag ^= BASE_HIDDEN;
 	}
 
-	DEG_id_tag_update(&scene->id, DEG_TAG_BASE_FLAGS_UPDATE);
-	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
+	if (changed_restrict_view) {
+		BKE_main_collection_sync(bmain);
+		DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
+		DEG_relations_tag_update(bmain);
+		WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
+	}
+	if (!freeze) {
+		BKE_layer_collection_sync(scene, view_layer);
+		DEG_id_tag_update(&scene->id, DEG_TAG_BASE_FLAGS_UPDATE);
+		WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
+	}
 }
 
 static void hidebutton_layer_collection_flag_cb(bContext *C, void *poin, void *poin2)
@@ -301,16 +315,25 @@ static void hidebutton_layer_collection_flag_cb(bContext *C, void *poin, void *p
 	Scene *scene = CTX_data_scene(C);
 	ViewLayer *view_layer = poin;
 	LayerCollection *lc = poin2;
-	bool extend = (CTX_wm_window(C)->eventstate->ctrl == 0);
+	Collection *collection = lc->collection;
+	bool freeze = (CTX_wm_window(C)->eventstate->ctrl != 0);
 
-	/* Undo button toggle, let function do it. */
-	lc->flag ^= LAYER_COLLECTION_RESTRICT_VIEW;
+	if (freeze) {
+		collection->flag |= COLLECTION_RESTRICT_VIEW;
+	}
+	else if (collection->flag & COLLECTION_RESTRICT_VIEW) {
+		collection->flag &= ~COLLECTION_RESTRICT_VIEW;
+		lc->flag &= ~LAYER_COLLECTION_RESTRICT_VIEW;
+	}
+	else {
+		lc->flag ^= LAYER_COLLECTION_RESTRICT_VIEW;
+	}
 
-	BKE_layer_collection_set_visible(scene, view_layer, lc, extend);
+	BKE_layer_collection_sync(scene, view_layer);
 
+	DEG_id_tag_update(&scene->id, DEG_TAG_BASE_FLAGS_UPDATE);
 	DEG_relations_tag_update(CTX_data_main(C));
-	DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE);
-	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
+	WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, NULL);
 }
 
 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
@@ -525,27 +548,32 @@ static void outliner_draw_restrictbuts(
 				UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
 			}
 			else if (tselem->type == 0 && te->idcode == ID_OB) {
+				PointerRNA ptr;
 				Object *ob = (Object *)tselem->id;
+				RNA_pointer_create(&ob->id, &RNA_Object, ob, &ptr);
 				Base *base = BKE_view_layer_base_find(view_layer, ob);
 
 				if (base) {
-					bt = uiDefIconButBitS(
-					        block, UI_BTYPE_ICON_TOGGLE, BASE_HIDDEN, 0, ICON_HIDE_OFF,
-					        (int)(ar->v2d.cur.xmax - OL_TOG_HIDEX), te->ys, UI_UNIT_X,
-					        UI_UNIT_Y, &base->flag, 0, 0, 0, 0,
-					        TIP_("Hide object in viewport (Ctrl to isolate)"));
+					int icon = ICON_RESTRICT_VIEW_ON;
+					if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0) {
+						icon = (base->flag & BASE_HIDDEN) != 0 ?
+						       ICON_HIDE_ON :
+						       ICON_HIDE_OFF;
+					}
+					bt = uiDefIconBut(
+					        block, UI_BTYPE_ICON_TOGGLE, 0, icon,
+					        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
+					        NULL, 0, 0, 0, 0,
+					        TIP_("Hide object in viewport (Ctrl to hide for all viewports)"));
 					UI_but_func_set(bt, hidebutton_base_flag_cb, view_layer, base);
 					UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-					UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
 				}
-
-				PointerRNA ptr;
-				RNA_pointer_create(&ob->id, &RNA_Object, ob, &ptr);
-
-				bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, 0,
-				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-				                        &ptr, props.object_hide_viewport, -1, 0, 0, -1, -1, NULL);
-				UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+				else {
+					bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, 0,
+					        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
+					        &ptr, props.object_hide_viewport, -1, 0, 0, -1, -1, NULL);
+					UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+				}
 
 				bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, 0,
 				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
@@ -649,23 +677,31 @@ static void outliner_draw_restrictbuts(
 				if ((!lc || !(lc->flag & LAYER_COLLECTION_EXCLUDE)) &&
 				    !(collection->flag & COLLECTION_IS_MASTER))
 				{
-					bt = uiDefIconButBitS(
-					        block, UI_BTYPE_ICON_TOGGLE, LAYER_COLLECTION_RESTRICT_VIEW, 0, ICON_HIDE_OFF,
-					        (int)(ar->v2d.cur.xmax - OL_TOG_HIDEX), te->ys, UI_UNIT_X,
-					        UI_UNIT_Y, &lc->flag, 0, 0, 0, 0,
-					        TIP_("Hide collection in viewport (Ctrl to isolate)"));
-					UI_but_func_set(bt, hidebutton_layer_collection_flag_cb, view_layer, lc);
-					UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-					UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
-
 					PointerRNA collection_ptr;
 					RNA_id_pointer_create(&collection->id, &collection_ptr);
 
-					bt = uiDefIconButR_prop(
-					        block, UI_BTYPE_ICON_TOGGLE, 0, 0,
-					        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
-					        UI_UNIT_Y, &collection_ptr, props.collection_hide_viewport, -1, 0, 0, 0, 0, NULL);
-					UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+					if (lc != NULL) {
+						int icon = ICON_RESTRICT_VIEW_ON;
+						if ((collection->flag & COLLECTION_RESTRICT_VIEW) == 0) {
+							icon = (lc->flag & LAYER_COLLECTION_RESTRICT_VIEW) != 0 ?
+								ICON_HIDE_ON :
+								ICON_HIDE_OFF;
+						}
+						bt = uiDefIconBut(
+						        block, UI_BTYPE_ICON_TOGGLE, 0, icon,
+						        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
+						        NULL, 0, 0, 0, 0,
+						        TIP_("Hide collection in viewport (Ctrl to hide for all viewports)"));
+						UI_but_func_set(bt, hidebutton_layer_collection_flag_cb, view_layer, lc);
+						UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+					}
+					else {
+						bt = uiDefIconButR_prop(
+						        block, UI_BTYPE_ICON_TOGGLE, 0, 0,
+						        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
+						        UI_UNIT_Y, &collection_ptr, props.collection_hide_viewport, -1, 0, 0, 0, 0, NULL);
+						UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+					}
 
 					bt = uiDefIconButR_prop(
 					        block, UI_BTYPE_ICON_TOGGLE, 0, 0,
@@ -2119,10 +2155,7 @@ static void outliner_draw_restrictcols(ARegion *ar)
 	uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
 	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 	immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
-	immBegin(GPU_PRIM_LINES, 8);
-
-	immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_HIDEX), (int)ar->v2d.cur.ymax);
-	immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_HIDEX), (int)ar->v2d.cur.ymin);
+	immBegin(GPU_PRIM_LINES, 6);
 
 	immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymax);
 	immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymin);
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 41a0dce7a38..0110b8e9fdc 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -129,12 +129,11 @@ typedef enum {
 /* size constants */
 #define OL_Y_OFFSET 2
 
-#define OL_TOG_HIDEX            (UI_UNIT_X * 4.0f + V2D_SCROLL_WIDTH)
-#define OL_TOG_RESTRICT_SELECTX (UI_UNIT_X * 3.0f + V2D_SCROLL_WIDTH)
-#define OL_TOG_RESTRICT_VIEWX   (UI_UNIT_X * 2.0f + V2D_SCROLL_WIDTH)
+#define OL_TOG_RESTRICT_VIEWX   (UI_UNIT_X * 3.0f + V2D_SCROLL_WIDTH)
+#define OL_TOG_RESTRICT_SELECTX (UI_UNIT_X * 2.0f + V2D_SCROLL_WIDTH)
 #define OL_TOG_RESTRICT_RENDERX (UI_UNIT_X + V2D_SCROLL_WIDTH)
 
-#define OL_TOGW OL_TOG_HIDEX
+#define OL_TOGW OL_TOG_RESTRICT_VIEWX
 
 #define OL_RNA_COLX         (UI_UNIT_X * 15)
 #define OL_RNA_COL_SIZEX    (UI_UNIT_X * 7.5f)



More information about the Bf-blender-cvs mailing list