[Bf-blender-cvs] [5cd39ced650] greasepencil-object: Add new parameter to template_ID to use live icon in button

Antonio Vazquez noreply at git.blender.org
Mon Jul 16 13:54:30 CEST 2018


Commit: 5cd39ced650add98b7599d438563aa92e0247bca
Author: Antonio Vazquez
Date:   Mon Jul 16 13:51:40 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5cd39ced650add98b7599d438563aa92e0247bca

Add new parameter to template_ID to use live icon in button

By default, the button uses a predefined fixed icon, but in some situations it's better to show the preview (materials)

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_clip/clip_buttons.c
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/editors/space_nla/nla_buttons.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 1d8f0ce00e9..4ad604c8acc 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1021,7 +1021,8 @@ uiLayout *uiLayoutRadial(uiLayout *layout);
 void uiTemplateHeader(uiLayout *layout, struct bContext *C);
 void uiTemplateID(
         uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname,
-        const char *newop, const char *openop, const char *unlinkop, int filter);
+        const char *newop, const char *openop, const char *unlinkop,
+		int filter, const bool live_icon);
 void uiTemplateIDBrowse(
         uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname,
         const char *newop, const char *openop, const char *unlinkop, int filter);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 0a7c14e31c1..8c1c0d90e99 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -114,7 +114,7 @@ static void template_add_button_search_menu(
         const bContext *C, uiLayout *layout, uiBlock *block,
         PointerRNA *ptr, PropertyRNA *prop,
         uiBlockCreateFunc block_func, void *block_argN, const char * const tip,
-        const bool use_previews, const bool editable)
+        const bool use_previews, const bool editable, const bool live_icon)
 {
 	PointerRNA active_ptr = RNA_property_pointer_get(ptr, prop);
 	ID *id = (active_ptr.data && RNA_struct_is_ID(active_ptr.type)) ? active_ptr.data : NULL;
@@ -150,7 +150,14 @@ static void template_add_button_search_menu(
 	}
 	else {
 		but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y, tip);
-		ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON);
+
+		if (live_icon) {
+			int icon = id ? ui_id_icon_get(C, id, false) : RNA_struct_ui_icon(type);
+			ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+		}
+		else {
+			ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON);
+		}
 		if (id) {
 			/* default dragging of icon for id browse buttons */
 			UI_but_drag_set_id(but, id);
@@ -636,7 +643,8 @@ static uiBut *template_id_def_new_but(
 
 static void template_ID(
         bContext *C, uiLayout *layout, TemplateID *template_ui, StructRNA *type, int flag,
-        const char *newop, const char *openop, const char *unlinkop, float scale)
+        const char *newop, const char *openop, const char *unlinkop,
+		float scale, const bool live_icon)
 {
 	uiBut *but;
 	uiBlock *block;
@@ -661,7 +669,7 @@ static void template_ID(
 		template_add_button_search_menu(
 		        C, layout, block, &template_ui->ptr, template_ui->prop,
 		        id_search_menu, MEM_dupallocN(template_ui), TIP_(template_id_browse_tip(type)),
-		        use_previews, editable);
+		        use_previews, editable, live_icon);
 	}
 
 	/* text button with name */
@@ -867,7 +875,7 @@ static void ui_template_id(
         PointerRNA *ptr, const char *propname,
         const char *newop, const char *openop, const char *unlinkop,
         int flag, int prv_rows, int prv_cols, int filter, bool use_tabs,
-		float scale)
+		float scale, bool live_icon)
 {
 	TemplateID *template_ui;
 	PropertyRNA *prop;
@@ -915,7 +923,7 @@ static void ui_template_id(
 		}
 		else {
 			uiLayoutRow(layout, true);
-			template_ID(C, layout, template_ui, type, flag, newop, openop, unlinkop, scale);
+			template_ID(C, layout, template_ui, type, flag, newop, openop, unlinkop, scale, live_icon);
 		}
 	}
 
@@ -924,13 +932,14 @@ static void ui_template_id(
 
 void uiTemplateID(
         uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
-        const char *openop, const char *unlinkop, int filter)
+        const char *openop, const char *unlinkop,
+		int filter, const bool live_icon)
 {
 	ui_template_id(
 	        layout, C, ptr, propname,
 	        newop, openop, unlinkop,
 	        UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE,
-	        0, 0, filter, false, 1.0f);
+	        0, 0, filter, false, 1.0f, live_icon);
 }
 
 void uiTemplateIDBrowse(
@@ -941,7 +950,7 @@ void uiTemplateIDBrowse(
 	        layout, C, ptr, propname,
 	        newop, openop, unlinkop,
 	        UI_ID_BROWSE | UI_ID_RENAME,
-	        0, 0, filter, false, 1.0f);
+	        0, 0, filter, false, 1.0f, false);
 }
 
 void uiTemplateIDPreview(
@@ -952,7 +961,7 @@ void uiTemplateIDPreview(
 	        layout, C, ptr, propname,
 	        newop, openop, unlinkop,
 	        UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS,
-	        rows, cols, filter, false, 1.0f);
+	        rows, cols, filter, false, 1.0f, false);
 }
 
 void uiTemplateGpencilColorPreview(
@@ -963,7 +972,7 @@ void uiTemplateGpencilColorPreview(
 		layout, C, ptr, propname,
 		NULL, NULL, NULL,
 		UI_ID_BROWSE | UI_ID_PREVIEWS,
-		rows, cols, filter, false, scale < 0.5f ? 0.5f : scale);
+		rows, cols, filter, false, scale < 0.5f ? 0.5f : scale, false);
 }
 
 /**
@@ -979,7 +988,7 @@ void uiTemplateIDTabs(
 	        layout, C, ptr, propname,
 	        newop, openop, unlinkop,
 	        UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE,
-	        0, 0, filter, true, 1.0f);
+	        0, 0, filter, true, 1.0f, false);
 }
 
 /************************ ID Chooser Template ***************************/
@@ -1081,7 +1090,7 @@ static uiBlock *template_search_menu(bContext *C, ARegion *region, void *arg_tem
 
 static void template_search_add_button_searchmenu(
         const bContext *C, uiLayout *layout, uiBlock *block,
-        TemplateSearch *template_search, const bool editable)
+        TemplateSearch *template_search, const bool editable, const bool live_icon)
 {
 	const char *ui_description = RNA_property_ui_description(template_search->search_data.target_prop);
 
@@ -1089,7 +1098,7 @@ static void template_search_add_button_searchmenu(
 	        C, layout, block,
 	        &template_search->search_data.target_ptr, template_search->search_data.target_prop,
 	        template_search_menu, MEM_dupallocN(template_search), ui_description,
-	        template_search->use_previews, editable);
+	        template_search->use_previews, editable, live_icon);
 }
 
 static void template_search_add_button_name(
@@ -1135,7 +1144,7 @@ static void template_search_buttons(
 	uiLayoutRow(layout, true);
 	UI_block_align_begin(block);
 
-	template_search_add_button_searchmenu(C, layout, block, template_search, editable);
+	template_search_add_button_searchmenu(C, layout, block, template_search, editable, false);
 	template_search_add_button_name(block, &active_ptr, type);
 	template_search_add_button_operator(block, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN, editable);
 	template_search_add_button_operator(block, unlinkop, WM_OP_INVOKE_REGION_WIN, ICON_X, editable);
@@ -4847,7 +4856,7 @@ void uiTemplateCacheFile(uiLayout *layout, bContext *C, PointerRNA *ptr, const c
 
 	uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr);
 
-	uiTemplateID(layout, C, ptr, propname, NULL, "CACHEFILE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL);
+	uiTemplateID(layout, C, ptr, propname, NULL, "CACHEFILE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
 
 	if (!file) {
 		return;
diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c
index db5f6c2451c..6953b7cfb71 100644
--- a/source/blender/editors/space_clip/clip_buttons.c
+++ b/source/blender/editors/space_clip/clip_buttons.c
@@ -107,7 +107,7 @@ void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const c
 	uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
 
 	if (!compact)
-		uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL);
+		uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
 
 	if (clip) {
 		uiLayout *col;
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 1d8c6721b64..afcae7a27ab 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -876,7 +876,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char
 	if (!compact) {
 		uiTemplateID(
 		        layout, C, ptr, propname,
-		        ima ? NULL : "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL);
+		        ima ? NULL : "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
 	}
 
 	if (ima) {
diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c
index 174737df58f..40caf919848 100644
--- a/source/blender/editors/space_nla/nla_buttons.c
+++ b/source/blender/editors/space_nla/nla_buttons.c
@@ -288,7 +288,7 @@ static void nla_panel_animdata(const bContext *C, Panel *pa)
 	row = uiLayoutRow(layout, true);
 	uiTemplateID(
 	        row, (bContext *)C, &adt_ptr, "action",
-	        "ACTION_OT_new", NULL, "NLA_OT_action_unlink", UI_TEMPLATE_ID_FILTER_ALL);
+	        "ACTION_OT_new", NULL, "NLA_OT_action_unlink", UI_TEMPLATE_ID_FILTER_ALL, false);
 
 	/* extrapolation */
 	row = uiLayoutRow(layout, true);
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index dfb85d3c8a4..3e1315e1ede 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -744,7 +744,7 @@ static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA
 	PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
 
 	uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
-	uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL);
+	uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
 	uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
 	uiItemR(layout, ptr, "interpolation", 0, "", ICON_NONE);
 	uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
@@ -775,7

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list