[Bf-blender-cvs] [8df8824] pie-menus: Change enum behaviour:

Antony Riakiotakis noreply at git.blender.org
Tue Jul 8 16:55:52 CEST 2014


Commit: 8df8824f3ae51ef716d58d9e8a24c14eb6f089a7
Author: Antony Riakiotakis
Date:   Tue Jul 8 17:50:54 2014 +0300
https://developer.blender.org/rB8df8824f3ae51ef716d58d9e8a24c14eb6f089a7

Change enum behaviour:

Enums now get completely expanded and any items not present in a dynamic
enum are filled by separators. This makes it possible to have
predictable positions even if some items are missing.

The iteration code expects that the dynamic and initial enum lists have
the same ordering of items, which is not unreasonable.

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

M	source/blender/editors/interface/interface_layout.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 83c30f9..8ef5d12 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -560,11 +560,15 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt
 	const char *name;
 	int itemw, icon, value;
 	bool free;
+	bool radial = (layout->root->type == UI_LAYOUT_PIEMENU);
 
-	RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item_array, NULL, &free);
+	if (radial)
+		RNA_property_enum_items_gettexted_all(block->evil_C, ptr, prop, &item_array, NULL, &free);
+	else
+		RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item_array, NULL, &free);
 
 	/* we dont want nested rows, cols in menus */
-	if (layout->root->type == UI_LAYOUT_PIEMENU) {
+	if (radial) {
 		uiBlockSetCurLayout(block, uiLayoutRadial(layout));
 	}
 	else if (layout->root->type != UI_LAYOUT_MENU) {
@@ -575,8 +579,11 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt
 	}
 
 	for (item = item_array; item->identifier; item++) {
-		if (!item->identifier[0])
+		if (!item->identifier[0]) {
+			if (radial)
+				uiItemS(layout);
 			continue;
+		}
 
 		name = (!uiname || uiname[0]) ? item->name : "";
 		icon = item->icon;
@@ -905,7 +912,11 @@ void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname
 			target = uiLayoutColumn(split, layout->align);
 		}
 
-		RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item_array, NULL, &free);
+		if (radial)
+			RNA_property_enum_items_gettexted_all(block->evil_C, &ptr, prop, &item_array, NULL, &free);
+		else
+			RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item_array, NULL, &free);
+
 		for (item = item_array; item->identifier; item++) {
 			if (item->identifier[0]) {
 				PointerRNA tptr;
@@ -947,11 +958,12 @@ void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname
 					}
 					ui_but_tip_from_enum_item(but, item);
 				}
-				else {  /* XXX bug here, colums draw bottom item badly */
+				else {
 					if (radial) {
-						/* pass */
+						uiItemS(target);
 					}
 					else {
+						/* XXX bug here, colums draw bottom item badly */
 						uiItemS(target);
 					}
 				}
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 6e1bb49..f180e21 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -792,6 +792,8 @@ void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *p
                              EnumPropertyItem **item, int *r_totitem, bool *r_free);
 void RNA_property_enum_items_gettexted(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop,
                                        EnumPropertyItem **r_item, int *r_totitem, bool *r_free);
+void RNA_property_enum_items_gettexted_all(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop,
+                                       EnumPropertyItem **r_item, int *r_totitem, bool *r_free);
 bool RNA_property_enum_value(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value);
 bool RNA_property_enum_identifier(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier);
 bool RNA_property_enum_name(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index ded0278..c16f19d 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1249,12 +1249,9 @@ void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, En
 	}
 }
 
-void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop,
-                                       EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
-{
-	RNA_property_enum_items(C, ptr, prop, r_item, r_totitem, r_free);
-
 #ifdef WITH_INTERNATIONAL
+static void property_enum_translate(PropertyRNA *prop, EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
+{
 	if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
 		int i;
 
@@ -1300,9 +1297,75 @@ void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA
 
 		*r_item = nitem;
 	}
+}
+#endif
+
+void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop,
+                                       EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
+{
+	RNA_property_enum_items(C, ptr, prop, r_item, r_totitem, r_free);
+
+#ifdef WITH_INTERNATIONAL
+	property_enum_translate(prop, r_item, r_totitem, r_free);
 #endif
 }
 
+void RNA_property_enum_items_gettexted_all(bContext *C, PointerRNA *ptr, PropertyRNA *prop,
+                                       EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
+{
+	EnumPropertyRNA *eprop = (EnumPropertyRNA *)rna_ensure_property(prop);
+	int mem_size = sizeof(EnumPropertyItem) * (eprop->totitem + 1);
+	/* first return all items */
+	*r_free = true;
+	*r_item = MEM_mallocN(mem_size, "enum_gettext_all");
+	 memcpy(*r_item, eprop->item, mem_size);
+
+	if (r_totitem)
+		*r_totitem = eprop->totitem;
+
+	if (eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
+		EnumPropertyItem *item;
+		int i, i_fixed;
+		bool free;
+
+		if (prop->flag & PROP_ENUM_NO_CONTEXT)
+			item = eprop->itemf(NULL, ptr, prop, &free);
+		else
+			item = eprop->itemf(C, ptr, prop, &free);
+
+		/* any callbacks returning NULL should be fixed */
+		BLI_assert(item != NULL);
+
+		for (i = 0, i_fixed = 0; i < eprop->totitem; i++, i_fixed++) {
+			/* ran out ouf valid entries, NULL out the rest*/
+			if (!item[i_fixed].identifier) {
+				while (i < eprop->totitem) {
+					(*r_item)[i].name = NULL;
+					(*r_item)[i].identifier = "";
+					i++;
+				}
+				break;
+			}
+
+			/* items that do not exist on list are returned, but have their names/identifiers NULLed out */
+			while ((strcmp(item[i_fixed].identifier, (*r_item)[i].identifier) != 0) && i < eprop->totitem)
+			{
+				(*r_item)[i].name = NULL;
+				(*r_item)[i].identifier = "";
+				i++;
+			}
+		}
+
+		fflush(stdout);
+
+		if (free)
+			MEM_freeN(item);
+	}
+
+#ifdef WITH_INTERNATIONAL
+	property_enum_translate(prop, r_item, r_totitem, r_free);
+#endif
+}
 
 bool RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
 {
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 5d10a0a..216a998 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -61,12 +61,12 @@
 EnumPropertyItem object_mode_items[] = {
 	{OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object Mode", ""},
 	{OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit Mode", ""},
+	{OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""},
 	{OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""},
 	{OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
 	{OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
 	{OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
 	{OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", ICON_PARTICLEMODE, "Particle Edit", ""},
-	{OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""},
 	{0, NULL, 0, NULL, NULL}
 };




More information about the Bf-blender-cvs mailing list