2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* ***** END GPL LICENSE BLOCK *****
23
/** \file blender/editors/interface/interface_anim.c
24
* \ingroup edinterface
79
108
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));
111
fcu = ui_but_get_fcurve(but, NULL, &driven);
114
driver = fcu->driver;
116
if (driver && driver->type == DRIVER_TYPE_PYTHON) {
117
BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
118
driver->flag |= DRIVER_FLAG_RECOMPILE;
119
WM_event_add_notifier(but->block->evil_C, NC_ANIMATION | ND_KEYFRAME, NULL);
127
/* create new expression for button (i.e. a "scripted driver"), if it can be created... */
128
int ui_but_anim_expression_create(uiBut *but, const char *str)
130
bContext *C = but->block->evil_C;
136
/* button must have RNA-pointer to a numeric-capable property */
137
if (ELEM(NULL, but->rnapoin.data, but->rnaprop)) {
138
if (G.debug & G_DEBUG)
139
printf("ERROR: create expression failed - button has no RNA info attached\n");
143
/* make sure we have animdata for this */
144
// FIXME: until materials can be handled by depsgraph, don't allow drivers to be created for them
145
id = (ID *)but->rnapoin.id.data;
146
if ((id == NULL) || (GS(id->name) == ID_MA) || (GS(id->name) == ID_TE)) {
147
if (G.debug & G_DEBUG)
148
printf("ERROR: create expression failed - invalid id-datablock for adding drivers (%p)\n", id);
153
path = RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
156
fcu = verify_driver_fcurve(id, path, but->rnaindex, 1);
158
ChannelDriver *driver = fcu->driver;
161
/* set type of driver */
162
driver->type = DRIVER_TYPE_PYTHON;
164
/* set the expression */
165
// TODO: need some way of identifying variables used
166
BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
169
driver->flag |= DRIVER_FLAG_RECOMPILE;
170
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, NULL);
96
179
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
103
fcu= ui_but_get_fcurve(but, &action, &driven);
186
fcu = ui_but_get_fcurve(but, &action, &driven);
106
id= but->rnapoin.id.data;
188
if (fcu && !driven) {
189
id = but->rnapoin.id.data;
108
191
// TODO: this should probably respect the keyingset only option for anim
109
if(autokeyframe_cfra_can_key(scene, id)) {
192
if (autokeyframe_cfra_can_key(scene, id)) {
193
ReportList *reports = CTX_wm_reports(C);
110
194
short flag = ANIM_get_keyframing_flags(scene, 1);
112
196
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|NA_EDITED, 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;
197
insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
198
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
143
203
void ui_but_anim_insert_keyframe(bContext *C)
145
/* this operator calls uiAnimContextProperty above */
205
/* this operator calls uiContextActiveProperty */
146
206
WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
149
209
void ui_but_anim_delete_keyframe(bContext *C)
151
/* this operator calls uiAnimContextProperty above */
211
/* this operator calls uiContextActiveProperty */
152
212
WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
155
215
void ui_but_anim_add_driver(bContext *C)
157
/* this operator calls uiAnimContextProperty above */
217
/* this operator calls uiContextActiveProperty */
158
218
WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
161
221
void ui_but_anim_remove_driver(bContext *C)
163
/* this operator calls uiAnimContextProperty above */
223
/* this operator calls uiContextActiveProperty */
164
224
WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
167
227
void ui_but_anim_copy_driver(bContext *C)
169
/* this operator calls uiAnimContextProperty above */
229
/* this operator calls uiContextActiveProperty */
170
230
WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
173
233
void ui_but_anim_paste_driver(bContext *C)
175
/* this operator calls uiAnimContextProperty above */
235
/* this operator calls uiContextActiveProperty */
176
236
WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
179
239
void ui_but_anim_add_keyingset(bContext *C)
181
/* this operator calls uiAnimContextProperty above */
241
/* this operator calls uiContextActiveProperty */
182
242
WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
185
245
void ui_but_anim_remove_keyingset(bContext *C)
187
/* this operator calls uiAnimContextProperty above */
247
/* this operator calls uiContextActiveProperty */
188
248
WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);