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:
authorCampbell Barton <ideasman42@gmail.com>2020-01-14 08:32:14 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-01-14 09:05:59 +0300
commitfffba2b6530e3bc94db3f27a8912ca112d5e7706 (patch)
tree40a0510256101e41fbee86bf109c836ead2cb24c /source/blender/editors
parentc56526d8b68abdd4feb0367c716e713966b8de0f (diff)
Cleanup: move property auto-keyframing to a generic API function
Prepare to call this from gizmos.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/animation/keyframing.c76
-rw-r--r--source/blender/editors/include/ED_keyframing.h6
-rw-r--r--source/blender/editors/interface/interface_anim.c75
3 files changed, 84 insertions, 73 deletions
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 8203a9131fa..14b1f6523d9 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -2964,6 +2964,82 @@ bool ED_autokeyframe_pchan(
}
}
+/**
+ * Use for auto-keyframing from the UI.
+ */
+bool ED_autokeyframe_property(
+ bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra)
+{
+ Main *bmain = CTX_data_main(C);
+ ID *id;
+ bAction *action;
+ FCurve *fcu;
+ bool driven;
+ bool special;
+ bool changed = false;
+
+ fcu = rna_get_fcurve_context_ui(C, ptr, prop, rnaindex, NULL, &action, &driven, &special);
+
+ if (fcu == NULL) {
+ return changed;
+ }
+
+ if (special) {
+ /* NLA Strip property */
+ if (IS_AUTOKEY_ON(scene)) {
+ ReportList *reports = CTX_wm_reports(C);
+ ToolSettings *ts = scene->toolsettings;
+
+ changed = insert_keyframe_direct(reports, *ptr, prop, fcu, cfra, ts->keyframe_type, NULL, 0);
+ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ }
+ }
+ else if (driven) {
+ /* Driver - Try to insert keyframe using the driver's input as the frame,
+ * making it easier to set up corrective drivers
+ */
+ if (IS_AUTOKEY_ON(scene)) {
+ ReportList *reports = CTX_wm_reports(C);
+ ToolSettings *ts = scene->toolsettings;
+
+ changed = insert_keyframe_direct(
+ reports, *ptr, prop, fcu, cfra, ts->keyframe_type, NULL, INSERTKEY_DRIVER);
+ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ }
+ }
+ else {
+ id = ptr->owner_id;
+
+ /* TODO: this should probably respect the keyingset only option for anim */
+ if (autokeyframe_cfra_can_key(scene, id)) {
+ ReportList *reports = CTX_wm_reports(C);
+ ToolSettings *ts = scene->toolsettings;
+ short flag = ANIM_get_keyframing_flags(scene, 1);
+
+ fcu->flag &= ~FCURVE_SELECTED;
+
+ /* Note: We use rnaindex instead of fcu->array_index,
+ * because a button may control all items of an array at once.
+ * E.g., color wheels (see T42567). */
+ BLI_assert((fcu->array_index == rnaindex) || (rnaindex == -1));
+ changed = insert_keyframe(bmain,
+ reports,
+ id,
+ action,
+ ((fcu->grp) ? (fcu->grp->name) : (NULL)),
+ fcu->rna_path,
+ rnaindex,
+ cfra,
+ ts->keyframe_type,
+ NULL,
+ flag) != 0;
+
+ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ }
+ }
+ return changed;
+}
+
/* -------------------------------------------------------------------- */
/** \name Internal Utilities
* \{ */
diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h
index 16b3c9c240a..ac3007afe5d 100644
--- a/source/blender/editors/include/ED_keyframing.h
+++ b/source/blender/editors/include/ED_keyframing.h
@@ -492,6 +492,12 @@ bool ED_autokeyframe_pchan(struct bContext *C,
struct Object *ob,
struct bPoseChannel *pchan,
struct KeyingSet *ks);
+bool ED_autokeyframe_property(struct bContext *C,
+ struct Scene *scene,
+ PointerRNA *ptr,
+ PropertyRNA *prop,
+ int rnaindex,
+ float cfra);
/* Names for builtin keying sets so we don't confuse these with labels/text,
* defined in python script: keyingsets_builtins.py */
diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c
index c8baa1a7c7b..15fc23bc539 100644
--- a/source/blender/editors/interface/interface_anim.c
+++ b/source/blender/editors/interface/interface_anim.c
@@ -270,79 +270,8 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str)
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
- Main *bmain = CTX_data_main(C);
- ID *id;
- bAction *action;
- FCurve *fcu;
- bool driven;
- bool special;
-
- fcu = ui_but_get_fcurve(but, NULL, &action, &driven, &special);
-
- if (fcu == NULL) {
- return;
- }
-
- if (special) {
- /* NLA Strip property */
- if (IS_AUTOKEY_ON(scene)) {
- ReportList *reports = CTX_wm_reports(C);
- ToolSettings *ts = scene->toolsettings;
-
- insert_keyframe_direct(
- reports, but->rnapoin, but->rnaprop, fcu, cfra, ts->keyframe_type, NULL, 0);
- WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
- }
- }
- else if (driven) {
- /* Driver - Try to insert keyframe using the driver's input as the frame,
- * making it easier to set up corrective drivers
- */
- if (IS_AUTOKEY_ON(scene)) {
- ReportList *reports = CTX_wm_reports(C);
- ToolSettings *ts = scene->toolsettings;
-
- insert_keyframe_direct(reports,
- but->rnapoin,
- but->rnaprop,
- fcu,
- cfra,
- ts->keyframe_type,
- NULL,
- INSERTKEY_DRIVER);
- WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
- }
- }
- else {
- id = but->rnapoin.owner_id;
-
- /* TODO: this should probably respect the keyingset only option for anim */
- if (autokeyframe_cfra_can_key(scene, id)) {
- ReportList *reports = CTX_wm_reports(C);
- ToolSettings *ts = scene->toolsettings;
- short flag = ANIM_get_keyframing_flags(scene, 1);
-
- fcu->flag &= ~FCURVE_SELECTED;
-
- /* Note: We use but->rnaindex instead of fcu->array_index,
- * because a button may control all items of an array at once.
- * E.g., color wheels (see T42567). */
- BLI_assert((fcu->array_index == but->rnaindex) || (but->rnaindex == -1));
- insert_keyframe(bmain,
- reports,
- id,
- action,
- ((fcu->grp) ? (fcu->grp->name) : (NULL)),
- fcu->rna_path,
- but->rnaindex,
- cfra,
- ts->keyframe_type,
- NULL,
- flag);
-
- WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
- }
- }
+ const int rnaindex = (but->rnaindex == -1) ? 0 : but->rnaindex;
+ ED_autokeyframe_property(C, scene, &but->rnapoin, but->rnaprop, rnaindex, cfra);
}
void ui_but_anim_copy_driver(bContext *C)