Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2011-01-03 08:36:52 +0300
committerJoshua Leung <aligorith@gmail.com>2011-01-03 08:36:52 +0300
commitca0b5434fa0f729df57557ff1ec369c9118e2f63 (patch)
tree4b0de0c5e7f3469d81d267d3a8a3253f8baabcb3 /source/blender/editors/animation
parent1ba9dde22d07633d41eea6db10320a14422a2448 (diff)
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.
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r--source/blender/editors/animation/keyframing.c44
-rw-r--r--source/blender/editors/animation/keyingsets.c62
2 files changed, 88 insertions, 18 deletions
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[])
{