6 #include "MEM_guardedalloc.h"
8 #include "DNA_anim_types.h"
9 #include "DNA_scene_types.h"
10 #include "DNA_screen_types.h"
12 #include "BLI_listbase.h"
13 #include "BLI_string.h"
15 #include "BKE_animsys.h"
16 #include "BKE_context.h"
17 #include "BKE_fcurve.h"
20 #include "ED_keyframing.h"
22 #include "UI_interface.h"
27 #include "interface_intern.h"
29 static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven)
31 return rna_get_fcurve(&but->rnapoin, but->rnaprop, but->rnaindex, action, driven);
34 void ui_but_anim_flag(uiBut *but, float cfra)
39 but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
41 fcu= ui_but_get_fcurve(but, NULL, &driven);
45 but->flag |= UI_BUT_ANIMATED;
47 if(fcurve_frame_has_keyframe(fcu, cfra, 0))
48 but->flag |= UI_BUT_ANIMATED_KEY;
51 but->flag |= UI_BUT_DRIVEN;
56 int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen)
59 ChannelDriver *driver;
62 fcu= ui_but_get_fcurve(but, NULL, &driven);
67 if(driver && driver->type == DRIVER_TYPE_PYTHON) {
68 BLI_strncpy(str, driver->expression, maxlen);
76 int ui_but_anim_expression_set(uiBut *but, const char *str)
79 ChannelDriver *driver;
82 fcu= ui_but_get_fcurve(but, NULL, &driven);
87 if(driver && driver->type == DRIVER_TYPE_PYTHON) {
88 BLI_strncpy(driver->expression, str, sizeof(driver->expression));
96 void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
103 fcu= ui_but_get_fcurve(but, &action, &driven);
106 id= but->rnapoin.id.data;
108 // TODO: this should probably respect the keyingset only option for anim
109 if(autokeyframe_cfra_can_key(scene, id)) {
110 short flag = ANIM_get_keyframing_flags(scene, 1);
112 fcu->flag &= ~FCURVE_SELECTED;
113 insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
114 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
119 void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index)
121 ARegion *ar= CTX_wm_region(C);
125 memset(ptr, 0, sizeof(*ptr));
130 for(block=ar->uiblocks.first; block; block=block->next) {
131 for(but=block->buttons.first; but; but= but->next) {
132 if((but->active || but->flag & UI_BUT_LAST_ACTIVE) && but->rnapoin.id.data) {
135 *index= but->rnaindex;
143 void ui_but_anim_insert_keyframe(bContext *C)
145 /* this operator calls uiAnimContextProperty above */
146 WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
149 void ui_but_anim_delete_keyframe(bContext *C)
151 /* this operator calls uiAnimContextProperty above */
152 WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
155 void ui_but_anim_add_driver(bContext *C)
157 /* this operator calls uiAnimContextProperty above */
158 WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
161 void ui_but_anim_remove_driver(bContext *C)
163 /* this operator calls uiAnimContextProperty above */
164 WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
167 void ui_but_anim_copy_driver(bContext *C)
169 /* this operator calls uiAnimContextProperty above */
170 WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
173 void ui_but_anim_paste_driver(bContext *C)
175 /* this operator calls uiAnimContextProperty above */
176 WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
179 void ui_but_anim_add_keyingset(bContext *C)
181 /* this operator calls uiAnimContextProperty above */
182 WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
185 void ui_but_anim_remove_keyingset(bContext *C)
187 /* this operator calls uiAnimContextProperty above */
188 WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);