[Bf-blender-cvs] [d8c39b8] master: FCurve: move add modifiers logic from menu into dynamic enum

Campbell Barton noreply at git.blender.org
Wed May 14 06:42:44 CEST 2014


Commit: d8c39b878945ce48d731fe86b6843725ba7bc3f0
Author: Campbell Barton
Date:   Wed May 14 14:41:43 2014 +1000
https://developer.blender.org/rBd8c39b878945ce48d731fe86b6843725ba7bc3f0

FCurve: move add modifiers logic from menu into dynamic enum

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

M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/makesrna/intern/rna_fcurve.c

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

diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 364dd1d..3d9b23d 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -2217,39 +2217,33 @@ void GRAPH_OT_smooth(wmOperatorType *ot)
 
 /* ******************** Add F-Modifier Operator *********************** */
 
-/* present a special customised popup menu for this, with some filtering */
-static int graph_fmodifier_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static EnumPropertyItem *graph_fmodifier_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
-	wmOperatorType *ot = WM_operatortype_find("GRAPH_OT_fmodifier_add", 1);
-	uiPopupMenu *pup;
-	uiLayout *layout;
-	int i;
-	
-	pup = uiPupMenuBegin(C, IFACE_("Add F-Curve Modifier"), ICON_NONE);
-	layout = uiPupMenuLayout(pup);
-	
+	EnumPropertyItem *item = NULL;
+	int totitem = 0;
+	int i = 0;
+
+	if (C == NULL) {
+		return fmodifier_type_items;
+	}
+
 	/* start from 1 to skip the 'Invalid' modifier type */
 	for (i = 1; i < FMODIFIER_NUM_TYPES; i++) {
 		FModifierTypeInfo *fmi = get_fmodifier_typeinfo(i);
-		PointerRNA props_ptr;
-		
+		int index;
+
 		/* check if modifier is valid for this context */
 		if (fmi == NULL)
 			continue;
-		
-		/* create operator menu item with relevant properties filled in */
-		props_ptr = uiItemFullO_ptr(layout, ot, IFACE_(fmi->name), ICON_NONE,
-		                            NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
-		/* the only thing that gets set from the menu is the type of F-Modifier to add */
-		RNA_enum_set(&props_ptr, "type", i);
-		/* the following properties are just repeats of existing ones... */
-		RNA_boolean_set(&props_ptr, "only_active", RNA_boolean_get(op->ptr, "only_active"));
+
+		index = RNA_enum_from_value(fmodifier_type_items, fmi->type);
+		RNA_enum_item_add(&item, &totitem, &fmodifier_type_items[index]);
 	}
-	uiItemS(layout);
-	
-	uiPupMenuEnd(C, pup);
-	
-	return OPERATOR_CANCELLED;
+
+	RNA_enum_item_end(&item, &totitem);
+	*r_free = true;
+
+	return item;
 }
 
 static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
@@ -2304,13 +2298,15 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
  
 void GRAPH_OT_fmodifier_add(wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name = "Add F-Curve Modifier";
 	ot->idname = "GRAPH_OT_fmodifier_add";
 	ot->description = "Add F-Modifiers to the selected F-Curves";
 	
 	/* api callbacks */
-	ot->invoke = graph_fmodifier_add_invoke;
+	ot->invoke = WM_menu_invoke;
 	ot->exec = graph_fmodifier_add_exec;
 	ot->poll = graphop_selected_fcurve_poll; 
 	
@@ -2318,7 +2314,10 @@ void GRAPH_OT_fmodifier_add(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 	
 	/* id-props */
-	ot->prop = RNA_def_enum(ot->srna, "type", fmodifier_type_items, 0, "Type", "");
+	prop = RNA_def_enum(ot->srna, "type", fmodifier_type_items, 0, "Type", "");
+	RNA_def_enum_funcs(prop, graph_fmodifier_itemf);
+	ot->prop = prop;
+
 	RNA_def_boolean(ot->srna, "only_active", 1, "Only Active", "Only add F-Modifier to active F-Curve");
 }
 
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index 2dad2c1..9f9cc57 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -61,7 +61,7 @@ EnumPropertyItem fmodifier_type_items[] = {
 	{FMODIFIER_TYPE_NOISE, "NOISE", 0, "Noise",
 	                       "Add pseudo-random noise on top of F-Curves"},
 	/*{FMODIFIER_TYPE_FILTER, "FILTER", 0, "Filter", ""},*/ /* FIXME: not implemented yet! */
-	/*{FMODIFIER_TYPE_PYTHON, "PYTHON", 0, "Python", ""},	 *//* FIXME: not implemented yet! */
+	{FMODIFIER_TYPE_PYTHON, "PYTHON", 0, "Python", ""},
 	{FMODIFIER_TYPE_LIMITS, "LIMITS", 0, "Limits",
 	                        "Restrict maximum and minimum values of F-Curve"},
 	{FMODIFIER_TYPE_STEPPED, "STEPPED", 0, "Stepped Interpolation",




More information about the Bf-blender-cvs mailing list