forked from bartvdbraak/blender
Keyframing Operator Code Cleanup:
Keyframing operators now use a dynamically-generated enum for their "type" property, which determines the Keying Set to use for keyframing instead of the obscure "index" values which were determined internally. Internally though, these same indices are still being used :) Notes: - I've kept the menu-building function and the special "menu" operator for now, since it's better to not "pollute" the actual insert keyframes operator with hardcoded menu-showing logic. Instead, the menu operator does that, so that if you like, you could write another such wrapper that works differently. - The 'type' properties could have the PROP_HIDDEN flags removed, though I think it's cleaner to leave these without this option for now.
This commit is contained in:
parent
1ba9dde22d
commit
ca0b5434fa
@ -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
|
||||
*/
|
||||
|
@ -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[])
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user