[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47814] branches/soc-2012-bratwurst/source /blender: Add X buttons in the material slots list box to delete a specific material slot without selecting it .

Jorge Rodriguez bs.vino at gmail.com
Wed Jun 13 08:36:01 CEST 2012


Revision: 47814
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47814
Author:   vino
Date:     2012-06-13 06:35:50 +0000 (Wed, 13 Jun 2012)
Log Message:
-----------
Add X buttons in the material slots list box to delete a specific material slot without selecting it.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_material.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/material.c
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c
    branches/soc-2012-bratwurst/source/blender/editors/render/render_shading.c

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_material.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_material.h	2012-06-12 23:19:52 UTC (rev 47813)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_material.h	2012-06-13 06:35:50 UTC (rev 47814)
@@ -75,7 +75,7 @@
 short find_material_index(struct Object *ob, struct Material *ma);
 
 int object_add_material_slot(struct Object *ob);
-int object_remove_material_slot(struct Object *ob);
+int object_remove_material_slot(struct Object *ob, int slot);
 
 /* rna api */
 void material_append_id(struct ID *id, struct Material *ma);

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/material.c	2012-06-12 23:19:52 UTC (rev 47813)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/material.c	2012-06-13 06:35:50 UTC (rev 47814)
@@ -840,7 +840,7 @@
 	int actcol_orig = ob->actcol;
 	short i;
 
-	while (object_remove_material_slot(ob)) {}
+	while (object_remove_material_slot(ob, -1)) {}
 
 	/* now we have the right number of slots */
 	for (i = 0; i < totcol; i++)
@@ -1100,7 +1100,7 @@
 }
 #endif
 
-int object_remove_material_slot(Object *ob)
+int object_remove_material_slot(Object *ob, int slot)
 {
 	Material *mao, ***matarar;
 	Object *obt;
@@ -1111,9 +1111,12 @@
 		return FALSE;
 	}
 
+	if (slot < 0)
+		slot = ob->actcol;
+
 	/* this should never happen and used to crash */
-	if (ob->actcol <= 0) {
-		printf("%s: invalid material index %d, report a bug!\n", __func__, ob->actcol);
+	if (slot <= 0) {
+		printf("%s: invalid material index %d, report a bug!\n", __func__, slot);
 		BLI_assert(0);
 		return FALSE;
 	}
@@ -1130,10 +1133,10 @@
 	if (*matarar == NULL) return FALSE;
 
 	/* we delete the actcol */
-	mao = (*matarar)[ob->actcol - 1];
+	mao = (*matarar)[slot - 1];
 	if (mao) mao->id.us--;
 	
-	for (a = ob->actcol; a < ob->totcol; a++)
+	for (a = slot; a < ob->totcol; a++)
 		(*matarar)[a - 1] = (*matarar)[a];
 	(*totcolp)--;
 	
@@ -1142,7 +1145,7 @@
 		*matarar = NULL;
 	}
 	
-	actcol = ob->actcol;
+	actcol = slot;
 	obt = G.main->object.first;
 	while (obt) {
 	

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c	2012-06-12 23:19:52 UTC (rev 47813)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_templates.c	2012-06-13 06:35:50 UTC (rev 47814)
@@ -2150,9 +2150,13 @@
 		Scene *scene = CTX_data_scene(C);
 		Object *ob = (Object *)ptr->id.data;
 		int index = (Material **)itemptr->data - ob->mat;
+		PointerRNA remove_rna;
 		
 		/* default item with material base name */
-		uiItemL(sub, name, icon);
+		if (!name || name[0] == '\0')
+			uiItemL(sub, "<Unassigned>", icon);
+		else
+			uiItemL(sub, name, icon);
 		
 		ma = give_current_material(ob, index + 1);
 		if (ma && !BKE_scene_use_new_shading_nodes(scene)) {
@@ -2166,6 +2170,10 @@
 				uiItemL(sub, IFACE_("Node <none>"), ICON_NONE);
 			}
 		}
+
+		WM_operator_properties_create(&remove_rna, "OBJECT_OT_material_slot_remove");
+		RNA_int_set(&remove_rna, "slot", i+1);
+		uiItemFullO(sub, "object.material_slot_remove", "", ICON_X, remove_rna.data, uiLayoutGetOperatorContext(layout), UI_ITEM_O_RETURN_PROPS|UI_ITEM_R_NO_BG);
 	}
 	else if (itemptr->type == &RNA_ShapeKey) {
 		Object *ob = (Object *)activeptr->data;

Modified: branches/soc-2012-bratwurst/source/blender/editors/render/render_shading.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/render/render_shading.c	2012-06-12 23:19:52 UTC (rev 47813)
+++ branches/soc-2012-bratwurst/source/blender/editors/render/render_shading.c	2012-06-13 06:35:50 UTC (rev 47814)
@@ -133,7 +133,7 @@
 		return OPERATOR_CANCELLED;
 	}
 
-	object_remove_material_slot(ob);
+	object_remove_material_slot(ob, RNA_int_get(op->ptr, "slot"));
 	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 	WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
@@ -154,6 +154,8 @@
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	RNA_def_int(ot->srna, "slot", -1, INT_MIN, INT_MAX, "Slot to remove", "< 0 means selection", INT_MIN, INT_MAX);
 }
 
 static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))




More information about the Bf-blender-cvs mailing list