2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/interface/interface_anim.c
|
|
|
|
* \ingroup edinterface
|
|
|
|
*/
|
2009-04-03 23:30:32 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "DNA_anim_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
2009-07-12 02:06:15 +00:00
|
|
|
#include "BLI_string.h"
|
2009-04-03 23:30:32 +00:00
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_fcurve.h"
|
|
|
|
|
|
|
|
|
2009-07-08 12:30:09 +00:00
|
|
|
#include "ED_keyframing.h"
|
|
|
|
|
2009-04-03 23:30:32 +00:00
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "interface_intern.h"
|
|
|
|
|
2009-07-12 02:06:15 +00:00
|
|
|
static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven)
|
2009-04-03 23:30:32 +00:00
|
|
|
{
|
2010-01-27 05:42:17 +00:00
|
|
|
return rna_get_fcurve(&but->rnapoin, but->rnaprop, but->rnaindex, action, driven);
|
2009-07-12 02:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_flag(uiBut *but, float cfra)
|
|
|
|
{
|
|
|
|
FCurve *fcu;
|
|
|
|
int driven;
|
|
|
|
|
|
|
|
but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
|
|
|
|
|
|
|
|
fcu= ui_but_get_fcurve(but, NULL, &driven);
|
|
|
|
|
|
|
|
if(fcu) {
|
|
|
|
if(!driven) {
|
|
|
|
but->flag |= UI_BUT_ANIMATED;
|
|
|
|
|
|
|
|
if(fcurve_frame_has_keyframe(fcu, cfra, 0))
|
|
|
|
but->flag |= UI_BUT_ANIMATED_KEY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
but->flag |= UI_BUT_DRIVEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen)
|
|
|
|
{
|
|
|
|
FCurve *fcu;
|
|
|
|
ChannelDriver *driver;
|
|
|
|
int driven;
|
|
|
|
|
|
|
|
fcu= ui_but_get_fcurve(but, NULL, &driven);
|
|
|
|
|
|
|
|
if(fcu && driven) {
|
|
|
|
driver= fcu->driver;
|
|
|
|
|
|
|
|
if(driver && driver->type == DRIVER_TYPE_PYTHON) {
|
|
|
|
BLI_strncpy(str, driver->expression, maxlen);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_but_anim_expression_set(uiBut *but, const char *str)
|
|
|
|
{
|
|
|
|
FCurve *fcu;
|
|
|
|
ChannelDriver *driver;
|
|
|
|
int driven;
|
|
|
|
|
|
|
|
fcu= ui_but_get_fcurve(but, NULL, &driven);
|
|
|
|
|
|
|
|
if(fcu && driven) {
|
|
|
|
driver= fcu->driver;
|
|
|
|
|
|
|
|
if(driver && driver->type == DRIVER_TYPE_PYTHON) {
|
|
|
|
BLI_strncpy(driver->expression, str, sizeof(driver->expression));
|
2010-12-13 19:10:35 +00:00
|
|
|
driver->flag |= DRIVER_FLAG_RECOMPILE;
|
|
|
|
WM_event_add_notifier(but->block->evil_C, NC_ANIMATION|ND_KEYFRAME, NULL);
|
2009-07-12 02:06:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-12 03:01:19 +00:00
|
|
|
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
|
2009-07-12 02:06:15 +00:00
|
|
|
{
|
|
|
|
ID *id;
|
|
|
|
bAction *action;
|
|
|
|
FCurve *fcu;
|
|
|
|
int driven;
|
|
|
|
|
|
|
|
fcu= ui_but_get_fcurve(but, &action, &driven);
|
|
|
|
|
|
|
|
if(fcu && !driven) {
|
|
|
|
id= but->rnapoin.id.data;
|
2009-07-31 07:43:47 +00:00
|
|
|
|
2009-10-27 09:38:15 +00:00
|
|
|
// TODO: this should probably respect the keyingset only option for anim
|
2009-07-12 02:06:15 +00:00
|
|
|
if(autokeyframe_cfra_can_key(scene, id)) {
|
2010-11-17 12:02:36 +00:00
|
|
|
ReportList *reports = CTX_wm_reports(C);
|
2009-12-14 12:09:20 +00:00
|
|
|
short flag = ANIM_get_keyframing_flags(scene, 1);
|
2009-07-12 02:06:15 +00:00
|
|
|
|
|
|
|
fcu->flag &= ~FCURVE_SELECTED;
|
2010-11-17 12:02:36 +00:00
|
|
|
insert_keyframe(reports, id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
|
2010-06-18 04:39:32 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
|
2009-07-12 02:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_insert_keyframe(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-11-28 14:37:21 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_delete_keyframe(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-11-28 14:37:21 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 13:08:12 +00:00
|
|
|
void ui_but_anim_add_driver(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-11-28 14:37:21 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
|
2009-04-10 13:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_remove_driver(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-11-28 14:37:21 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
|
2009-04-10 13:08:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 04:51:04 +00:00
|
|
|
void ui_but_anim_copy_driver(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-09-25 04:51:04 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_paste_driver(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-09-25 04:51:04 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
2009-09-04 07:26:32 +00:00
|
|
|
void ui_but_anim_add_keyingset(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-11-28 14:37:21 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
|
2009-09-04 07:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ui_but_anim_remove_keyingset(bContext *C)
|
|
|
|
{
|
2010-09-25 14:32:26 +00:00
|
|
|
/* this operator calls uiContextActiveProperty */
|
2009-11-28 14:37:21 +00:00
|
|
|
WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
|
2009-09-04 07:26:32 +00:00
|
|
|
}
|