diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index e588a3610d8..e31af91cce0 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -72,6 +72,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "anim_intern.h" @@ -1074,7 +1075,7 @@ static int insert_key_exec (bContext *C, wmOperator *op) Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); KeyingSet *ks= NULL; - int type= RNA_int_get(op->ptr, "type"); + int type= RNA_enum_get(op->ptr, "type"); float cfra= (float)CFRA; // XXX for now, don't bother about all the yucky offset crap short success; @@ -1139,11 +1140,12 @@ void ANIM_OT_keyframe_insert (wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - /* keyingset to use - * - here the type is int not enum, since many of the indicies here are determined dynamically - */ - prop= RNA_def_int(ot->srna, "type", 0, INT_MIN, INT_MAX, "Keying Set Number", "Index (determined internally) of the Keying Set to use", 0, 1); + /* keyingset to use (dynamic enum) */ + prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use"); + RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf); RNA_def_property_flag(prop, PROP_HIDDEN); + ot->prop= prop; + /* confirm whether a keyframe was added by showing a popup * - by default, this is enabled, since this operator is assumed to be called independently */ @@ -1168,7 +1170,7 @@ static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *UNUSED( } else { /* just call the exec() on the active keyingset */ - RNA_int_set(op->ptr, "type", 0); + RNA_enum_set(op->ptr, "type", 0); RNA_boolean_set(op->ptr, "confirm_success", 1); return op->type->exec(C, op); @@ -1192,17 +1194,19 @@ void ANIM_OT_keyframe_insert_menu (wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - /* keyingset to use - * - here the type is int not enum, since many of the indicies here are determined dynamically - */ - prop= RNA_def_int(ot->srna, "type", 0, INT_MIN, INT_MAX, "Keying Set Number", "Index (determined internally) of the Keying Set to use", 0, 1); + /* keyingset to use (dynamic enum) */ + prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use"); + RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf); RNA_def_property_flag(prop, PROP_HIDDEN); + ot->prop= prop; + /* confirm whether a keyframe was added by showing a popup * - by default, this is disabled so that if a menu is shown, this doesn't come up too */ // XXX should this just be always on? prop= RNA_def_boolean(ot->srna, "confirm_success", 0, "Confirm Successful Insert", "Show a popup when the keyframes get successfully added"); RNA_def_property_flag(prop, PROP_HIDDEN); + /* whether the menu should always be shown * - by default, the menu should only be shown when there is no active Keying Set (2.5 behaviour), * although in some cases it might be useful to always shown (pre 2.5 behaviour) @@ -1218,7 +1222,7 @@ static int delete_key_exec (bContext *C, wmOperator *op) Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); KeyingSet *ks= NULL; - int type= RNA_int_get(op->ptr, "type"); + int type= RNA_enum_get(op->ptr, "type"); float cfra= (float)CFRA; // XXX for now, don't bother about all the yucky offset crap short success; @@ -1269,6 +1273,8 @@ static int delete_key_exec (bContext *C, wmOperator *op) void ANIM_OT_keyframe_delete (wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name= "Delete Keyframe"; ot->idname= "ANIM_OT_keyframe_delete"; @@ -1281,10 +1287,12 @@ void ANIM_OT_keyframe_delete (wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - /* keyingset to use - * - here the type is int not enum, since many of the indicies here are determined dynamically - */ - RNA_def_int(ot->srna, "type", 0, INT_MIN, INT_MAX, "Keying Set Number", "Index (determined internally) of the Keying Set to use", 0, 1); + /* keyingset to use (dynamic enum) */ + prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use"); + RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf); + RNA_def_property_flag(prop, PROP_HIDDEN); + ot->prop= prop; + /* confirm whether a keyframe was added by showing a popup * - by default, this is enabled, since this operator is assumed to be called independently */ @@ -1407,7 +1415,7 @@ static int insert_key_button_exec (bContext *C, wmOperator *op) } else if (G.f & G_DEBUG) { printf("ptr.data = %p, prop = %p,", (void *)ptr.data, (void *)prop); - if(prop) + if (prop) printf("animateable = %d \n", RNA_property_animateable(&ptr, prop)); else printf("animateable = NULL \n"); @@ -1416,7 +1424,7 @@ static int insert_key_button_exec (bContext *C, wmOperator *op) if (success) { /* send updates */ uiContextAnimUpdate(C); - + DAG_ids_flush_update(bmain, 0); /* send notifiers that keyframes have been changed */ @@ -1488,7 +1496,7 @@ static int delete_key_button_exec (bContext *C, wmOperator *op) if (success) { /* send updates */ uiContextAnimUpdate(C); - + DAG_ids_flush_update(bmain, 0); /* send notifiers that keyframes have been changed */ diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index d0e7d8be769..09128672df8 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -59,6 +59,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "anim_intern.h" @@ -691,6 +692,67 @@ KeyingSet *ANIM_get_keyingset_for_autokeying(Scene *scene, const char *tranformK /* Menu of All Keying Sets ----------------------------- */ +/* Dynamically populate an enum of Keying Sets */ +EnumPropertyItem *ANIM_keying_sets_enum_itemf (bContext *C, PointerRNA *UNUSED(ptr), int *free) +{ + Scene *scene = CTX_data_scene(C); + KeyingSet *ks; + EnumPropertyItem *item= NULL, item_tmp= {0}; + int totitem= 0; + int i= 0; + + if (C == NULL) { + return DummyRNA_DEFAULT_items; + } + + /* active Keying Set + * - only include entry if it exists + */ + if (scene->active_keyingset) { + /* active Keying Set */ + item_tmp.identifier= item_tmp.name= "Active Keying Set"; + item_tmp.value= i++; + RNA_enum_item_add(&item, &totitem, &item_tmp); + + /* separator */ + RNA_enum_item_add_separator(&item, &totitem); + } + else + i++; + + /* user-defined Keying Sets + * - these are listed in the order in which they were defined for the active scene + */ + if (scene->keyingsets.first) { + for (ks= scene->keyingsets.first; ks; ks= ks->next) { + if (ANIM_keyingset_context_ok_poll(C, ks)) { + item_tmp.identifier= item_tmp.name= ks->name; + item_tmp.value= i++; + RNA_enum_item_add(&item, &totitem, &item_tmp); + } + } + + /* separator */ + RNA_enum_item_add_separator(&item, &totitem); + } + + /* builtin Keying Sets */ + i= -1; + for (ks= builtin_keyingsets.first; ks; ks= ks->next) { + /* only show KeyingSet if context is suitable */ + if (ANIM_keyingset_context_ok_poll(C, ks)) { + item_tmp.identifier= item_tmp.name= ks->name; + item_tmp.value= i--; + RNA_enum_item_add(&item, &totitem, &item_tmp); + } + } + + RNA_enum_item_end(&item, &totitem); + *free= 1; + + return item; +} + /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */ void ANIM_keying_sets_menu_setup (bContext *C, const char title[], const char op_name[]) { diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index 6dc2fe04227..72e87e2c9bc 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -51,6 +51,7 @@ struct ReportList; struct PointerRNA; struct PropertyRNA; +struct EnumPropertyItem; #include "RNA_types.h" @@ -204,6 +205,9 @@ struct KeyingSet *ANIM_get_keyingset_for_autokeying(struct Scene *scene, const c /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */ void ANIM_keying_sets_menu_setup(struct bContext *C, const char title[], const char op_name[]); +/* Dynamically populate an enum of Keying Sets */ +struct EnumPropertyItem *ANIM_keying_sets_enum_itemf(struct bContext *C, struct PointerRNA *ptr, int *free); + /* Check if KeyingSet can be used in the current context */ short ANIM_keyingset_context_ok_poll(struct bContext *C, struct KeyingSet *ks);