Example #1
0
void ui_but_anim_flag(uiBut *but, float cfra)
{
	AnimData *adt;
	bAction *act;
	FCurve *fcu;
	bool driven;
	bool special;
	
	but->flag &= ~(UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN);
	
	/* NOTE: "special" is reserved for special F-Curves stored on the animation data
	 *        itself (which are used to animate properties of the animation data).
	 *        We count those as "animated" too for now
	 */
	fcu = ui_but_get_fcurve(but, &adt, &act, &driven, &special);
	
	if (fcu) {
		if (!driven) {
			but->flag |= UI_BUT_ANIMATED;
			
			/* T41525 - When the active action is a NLA strip being edited, 
			 * we need to correct the frame number to "look inside" the
			 * remapped action
			 */
			if (adt)
				cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
			
			if (fcurve_frame_has_keyframe(fcu, cfra, 0))
				but->flag |= UI_BUT_ANIMATED_KEY;
		}
		else {
			but->flag |= UI_BUT_DRIVEN;
		}
	}
}
Example #2
0
bool ui_but_anim_expression_set(uiBut *but, const char *str)
{
	FCurve *fcu;
	ChannelDriver *driver;
	bool driven, special;

	fcu = ui_but_get_fcurve(but, NULL, NULL, &driven, &special);

	if (fcu && driven) {
		driver = fcu->driver;
		
		if (driver && (driver->type == DRIVER_TYPE_PYTHON)) {
			BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
			
			/* tag driver as needing to be recompiled */
			driver->flag |= DRIVER_FLAG_RECOMPILE;
			
			/* clear invalid flags which may prevent this from working */
			driver->flag &= ~DRIVER_FLAG_INVALID;
			fcu->flag &= ~FCURVE_DISABLED;
			
			/* this notifier should update the Graph Editor and trigger depsgraph refresh? */
			WM_event_add_notifier(but->block->evil_C, NC_ANIMATION | ND_KEYFRAME, NULL);
			
			return true;
		}
	}

	return false;
}
Example #3
0
void ui_but_anim_autokey(uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	int driven;

	fcu= ui_but_get_fcurve(but, &action, &driven);

	if(fcu && !driven) {
		id= but->rnapoin.id.data;
		
		// TODO: this should probably respect the keyingset only option for anim
		if(autokeyframe_cfra_can_key(scene, id)) {
			short flag = 0;
			
			if (IS_AUTOKEY_FLAG(INSERTNEEDED))
				flag |= INSERTKEY_NEEDED;
			if (IS_AUTOKEY_FLAG(AUTOMATKEY))
				flag |= INSERTKEY_MATRIX;
			if (IS_AUTOKEY_MODE(scene, EDITKEYS))
				flag |= INSERTKEY_REPLACE;
			
			fcu->flag &= ~FCURVE_SELECTED;
			insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
		}
	}
}
Example #4
0
void ui_but_anim_flag(uiBut *but, float cfra)
{
	AnimData *adt;
	bAction *act;
	FCurve *fcu;
	bool driven;

	but->flag &= ~(UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN);

	fcu = ui_but_get_fcurve(but, &adt, &act, &driven);

	if (fcu) {
		if (!driven) {
			but->flag |= UI_BUT_ANIMATED;
			
			/* T41525 - When the active action is a NLA strip being edited, 
			 * we need to correct the frame number to "look inside" the
			 * remapped action
			 */
			if (adt)
				cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
			
			if (fcurve_frame_has_keyframe(fcu, cfra, 0))
				but->flag |= UI_BUT_ANIMATED_KEY;
		}
		else {
			but->flag |= UI_BUT_DRIVEN;
		}
	}
}
Example #5
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	bool driven;

	fcu = ui_but_get_fcurve(but, NULL, &action, &driven);

	if (fcu && !driven) {
		id = but->rnapoin.id.data;

		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			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(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
			                fcu->rna_path, but->rnaindex, cfra, flag);

			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Example #6
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	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, 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, INSERTKEY_DRIVER);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
	else {
		id = but->rnapoin.id.data;
		
		/* 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(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
			                fcu->rna_path, but->rnaindex, cfra, ts->keyframe_type, flag);
			
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Example #7
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	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);
			PointerRNA ptr = {{NULL}};
			PropertyRNA *prop = NULL;
			int index;
			
			UI_context_active_but_prop_get(C, &ptr, &prop, &index);
			
			insert_keyframe_direct(reports, ptr, prop, fcu, cfra, 0);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
	else if (!driven) {
		id = but->rnapoin.id.data;

		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			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(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
			                fcu->rna_path, but->rnaindex, cfra, flag);

			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Example #8
0
bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen)
{
	FCurve *fcu;
	ChannelDriver *driver;
	bool driven, special;
	
	fcu = ui_but_get_fcurve(but, NULL, NULL, &driven, &special);
	
	if (fcu && driven) {
		driver = fcu->driver;

		if (driver && driver->type == DRIVER_TYPE_PYTHON) {
			BLI_strncpy(str, driver->expression, maxlen);
			return true;
		}
	}

	return false;
}
Example #9
0
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;
}
Example #10
0
void ui_but_anim_flag(uiBut *but, float cfra)
{
	FCurve *fcu;
	bool 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;
		}
	}
}
Example #11
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));
			driver->flag |= DRIVER_FLAG_RECOMPILE;
			WM_event_add_notifier(but->block->evil_C, NC_ANIMATION|ND_KEYFRAME, NULL);
			return 1;
		}
	}

	return 0;
}
Example #12
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	bool driven;

	fcu = ui_but_get_fcurve(but, &action, &driven);

	if (fcu && !driven) {
		id = but->rnapoin.id.data;

		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			short flag = ANIM_get_keyframing_flags(scene, 1);

			fcu->flag &= ~FCURVE_SELECTED;
			insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}