1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/**
* $Id:
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation, Joshua Leung
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include "DNA_anim_types.h"
#include "DNA_action_types.h"
#include "DNA_object_types.h"
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"
#include "BLI_blenlib.h"
#include "BLI_editVert.h"
#include "BLI_rand.h"
#include "BKE_animsys.h"
#include "BKE_nla.h"
#include "BKE_action.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_object.h"
#include "BKE_global.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_utildefines.h"
#include "BIF_gl.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "ED_anim_api.h"
#include "ED_keyframing.h"
#include "ED_screen.h"
#include "ED_types.h"
#include "ED_util.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "nla_intern.h" // own include
/* ******************* nla editor space & buttons ************** */
#define B_NOP 1
#define B_REDR 2
/* -------------- */
static void do_nla_region_buttons(bContext *C, void *arg, int event)
{
//Scene *scene= CTX_data_scene(C);
switch(event) {
}
/* default for now */
WM_event_add_notifier(C, NC_SCENE|NC_OBJECT|ND_TRANSFORM, NULL);
}
static int nla_panel_context(const bContext *C, PointerRNA *nlt_ptr, PointerRNA *strip_ptr)
{
bAnimContext ac;
bAnimListElem *ale= NULL;
ListBase anim_data = {NULL, NULL};
short found=0;
int filter;
/* for now, only draw if we could init the anim-context info (necessary for all animation-related tools)
* to work correctly is able to be correctly retrieved. There's no point showing empty panels?
*/
if (ANIM_animdata_get_context(C, &ac) == 0)
return 0;
/* extract list of active channel(s), of which we should only take the first one (expecting it to be an NLA track) */
filter= (ANIMFILTER_VISIBLE|ANIMFILTER_ACTIVE);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
for (ale= anim_data.first; ale; ale= ale->next) {
if (ale->type == ANIMTYPE_NLATRACK) {
NlaTrack *nlt= (NlaTrack *)ale->data;
/* found it, now set the pointers */
if (nlt_ptr) {
/* NLA-Track pointer */
RNA_pointer_create(ale->id, &RNA_NlaTrack, nlt, nlt_ptr);
}
if (strip_ptr) {
/* NLA-Strip pointer */
NlaStrip *strip= BKE_nlastrip_find_active(nlt);
RNA_pointer_create(ale->id, &RNA_NlaStrip, strip, strip_ptr);
}
found= 1;
break;
}
}
/* free temp data */
BLI_freelistN(&anim_data);
return found;
}
#if 0
static int nla_panel_poll(const bContext *C, PanelType *pt)
{
return nla_panel_context(C, NULL, NULL);
}
#endif
static int nla_track_panel_poll(const bContext *C, PanelType *pt)
{
PointerRNA ptr;
return (nla_panel_context(C, &ptr, NULL) && (ptr.data != NULL));
}
static int nla_strip_panel_poll(const bContext *C, PanelType *pt)
{
PointerRNA ptr;
return (nla_panel_context(C, NULL, &ptr) && (ptr.data != NULL));
}
static int nla_strip_actclip_panel_poll(const bContext *C, PanelType *pt)
{
PointerRNA ptr;
NlaStrip *strip;
if (!nla_panel_context(C, NULL, &ptr))
return 0;
if (ptr.data == NULL)
return 0;
strip= ptr.data;
return (strip->type == NLASTRIP_TYPE_CLIP);
}
/* -------------- */
/* active NLA-Track */
static void nla_panel_track (const bContext *C, Panel *pa)
{
PointerRNA nlt_ptr;
uiLayout *layout= pa->layout;
uiLayout *row;
uiBlock *block;
/* check context and also validity of pointer */
if (!nla_panel_context(C, &nlt_ptr, NULL))
return;
block= uiLayoutGetBlock(layout);
uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
/* Info - Active NLA-Context:Track ---------------------- */
row= uiLayoutRow(layout, 1);
uiItemR(row, NULL, ICON_NLA, &nlt_ptr, "name", 0, 0, 0);
}
/* generic settings for active NLA-Strip */
static void nla_panel_properties(const bContext *C, Panel *pa)
{
PointerRNA strip_ptr;
uiLayout *layout= pa->layout;
uiLayout *column, *row, *subcol;
uiBlock *block;
if (!nla_panel_context(C, NULL, &strip_ptr))
return;
block= uiLayoutGetBlock(layout);
uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
/* Strip Properties ------------------------------------- */
/* strip type */
row= uiLayoutRow(layout, 1);
uiItemR(row, NULL, 0, &strip_ptr, "type", 0, 0, 0);
/* strip extents */
column= uiLayoutColumn(layout, 1);
uiItemL(column, "Strip Extents:", 0);
uiItemR(column, NULL, 0, &strip_ptr, "start_frame", 0, 0, 0);
uiItemR(column, NULL, 0, &strip_ptr, "end_frame", 0, 0, 0);
/* extrapolation */
row= uiLayoutRow(layout, 1);
uiItemR(row, NULL, 0, &strip_ptr, "extrapolation", 0, 0, 0);
/* blending */
row= uiLayoutRow(layout, 1);
uiItemR(row, NULL, 0, &strip_ptr, "blending", 0, 0, 0);
/* blend in/out + autoblending
* - blend in/out can only be set when autoblending is off
*/
column= uiLayoutColumn(layout, 1);
uiItemR(column, NULL, 0, &strip_ptr, "auto_blending", 0, 0, 0); // XXX as toggle?
subcol= uiLayoutColumn(column, 1);
uiLayoutSetActive(subcol, RNA_boolean_get(&strip_ptr, "auto_blending")==0);
uiItemR(subcol, NULL, 0, &strip_ptr, "blend_in", 0, 0, 0);
uiItemR(subcol, NULL, 0, &strip_ptr, "blend_out", 0, 0, 0);
/* settings */
column= uiLayoutColumn(layout, 1);
uiItemL(column, "Playback Settings:", 0);
uiItemR(column, NULL, 0, &strip_ptr, "muted", 0, 0, 0);
uiItemR(column, NULL, 0, &strip_ptr, "reversed", 0, 0, 0);
}
/* action-clip only settings for active NLA-Strip */
static void nla_panel_actclip(const bContext *C, Panel *pa)
{
PointerRNA strip_ptr;
uiLayout *layout= pa->layout;
uiLayout *column, *row;
uiBlock *block;
/* check context and also validity of pointer */
if (!nla_panel_context(C, NULL, &strip_ptr))
return;
block= uiLayoutGetBlock(layout);
uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
/* Strip Properties ------------------------------------- */
/* action pointer */
row= uiLayoutRow(layout, 1);
uiItemR(row, NULL, ICON_ACTION, &strip_ptr, "action", 0, 0, 0);
/* action extents */
// XXX custom names were used here (to avoid the prefixes)... probably not necessary in future?
column= uiLayoutColumn(layout, 1);
uiItemL(column, "Action Extents:", 0);
uiItemR(column, "Start Frame", 0, &strip_ptr, "action_start_frame", 0, 0, 0);
uiItemR(column, "End Frame", 0, &strip_ptr, "action_end_frame", 0, 0, 0);
/* action usage */
column= uiLayoutColumn(layout, 1);
uiItemL(column, "Playback Settings:", 0);
uiItemR(column, NULL, 0, &strip_ptr, "scale", 0, 0, 0);
uiItemR(column, NULL, 0, &strip_ptr, "repeat", 0, 0, 0);
}
/* evaluation settings for active NLA-Strip */
static void nla_panel_evaluation(const bContext *C, Panel *pa)
{
PointerRNA strip_ptr;
uiLayout *layout= pa->layout;
uiLayout *column, *subcolumn;
uiBlock *block;
/* check context and also validity of pointer */
if (!nla_panel_context(C, NULL, &strip_ptr))
return;
block= uiLayoutGetBlock(layout);
uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
column= uiLayoutColumn(layout, 1);
uiItemR(column, NULL, 0, &strip_ptr, "animated_influence", 0, 0, 0);
subcolumn= uiLayoutColumn(column, 1);
uiLayoutSetEnabled(subcolumn, RNA_boolean_get(&strip_ptr, "animated_influence"));
uiItemR(subcolumn, NULL, 0, &strip_ptr, "influence", 0, 0, 0);
column= uiLayoutColumn(layout, 1);
uiItemR(column, NULL, 0, &strip_ptr, "animated_time", 0, 0, 0);
subcolumn= uiLayoutColumn(column, 1);
uiLayoutSetEnabled(subcolumn, RNA_boolean_get(&strip_ptr, "animated_time"));
uiItemR(subcolumn, NULL, 0, &strip_ptr, "strip_time", 0, 0, 0);
}
/* F-Modifiers for active NLA-Strip */
static void nla_panel_modifiers(const bContext *C, Panel *pa)
{
PointerRNA strip_ptr;
NlaStrip *strip;
FModifier *fcm;
uiLayout *col, *row;
uiBlock *block;
/* check context and also validity of pointer */
if (!nla_panel_context(C, NULL, &strip_ptr))
return;
strip= strip_ptr.data;
block= uiLayoutGetBlock(pa->layout);
uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
/* 'add modifier' button at top of panel */
{
row= uiLayoutRow(pa->layout, 0);
block= uiLayoutGetBlock(row);
// XXX for now, this will be a operator button which calls a temporary 'add modifier' operator
// FIXME: we need to set the only-active property so that this will only add modifiers for the active strip (not all selected)
uiDefButO(block, BUT, "NLA_OT_fmodifier_add", WM_OP_INVOKE_REGION_WIN, "Add Modifier", 10, 0, 150, 20, "Adds a new F-Modifier for the active NLA Strip");
}
/* draw each modifier */
for (fcm= strip->modifiers.first; fcm; fcm= fcm->next) {
col= uiLayoutColumn(pa->layout, 1);
ANIM_uiTemplate_fmodifier_draw(col, strip_ptr.id.data, &strip->modifiers, fcm);
}
}
/* ******************* general ******************************** */
void nla_buttons_register(ARegionType *art)
{
PanelType *pt;
pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel track");
strcpy(pt->idname, "NLA_PT_track");
strcpy(pt->label, "Active Track");
pt->draw= nla_panel_track;
pt->poll= nla_track_panel_poll;
BLI_addtail(&art->paneltypes, pt);
pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel properties");
strcpy(pt->idname, "NLA_PT_properties");
strcpy(pt->label, "Active Strip");
pt->draw= nla_panel_properties;
pt->poll= nla_strip_panel_poll;
BLI_addtail(&art->paneltypes, pt);
pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel properties");
strcpy(pt->idname, "NLA_PT_actionclip");
strcpy(pt->label, "Action Clip");
pt->draw= nla_panel_actclip;
pt->poll= nla_strip_actclip_panel_poll;
BLI_addtail(&art->paneltypes, pt);
pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel evaluation");
strcpy(pt->idname, "NLA_PT_evaluation");
strcpy(pt->label, "Evaluation");
pt->draw= nla_panel_evaluation;
pt->poll= nla_strip_panel_poll;
BLI_addtail(&art->paneltypes, pt);
pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel modifiers");
strcpy(pt->idname, "NLA_PT_modifiers");
strcpy(pt->label, "Modifiers");
pt->draw= nla_panel_modifiers;
pt->poll= nla_strip_panel_poll;
BLI_addtail(&art->paneltypes, pt);
}
static int nla_properties(bContext *C, wmOperator *op)
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= nla_has_buttons_region(sa);
if(ar) {
ar->flag ^= RGN_FLAG_HIDDEN;
ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
ED_area_tag_redraw(sa);
}
return OPERATOR_FINISHED;
}
void NLA_OT_properties(wmOperatorType *ot)
{
ot->name= "Properties";
ot->idname= "NLA_OT_properties";
ot->exec= nla_properties;
ot->poll= ED_operator_nla_active;
/* flags */
ot->flag= 0;
}
|