4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2009 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation, Joshua Leung
26 * ***** END GPL LICENSE BLOCK *****
29 /** \file blender/editors/space_nla/nla_buttons.c
39 #include "DNA_anim_types.h"
41 #include "BLI_utildefines.h"
43 #include "MEM_guardedalloc.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_editVert.h"
51 #include "BKE_context.h"
52 #include "BKE_screen.h"
58 #include "RNA_access.h"
60 #include "ED_anim_api.h"
61 #include "ED_screen.h"
63 #include "UI_interface.h"
64 #include "UI_resources.h"
66 #include "nla_intern.h" // own include
69 /* ******************* nla editor space & buttons ************** */
76 static void do_nla_region_buttons(bContext *C, void *UNUSED(arg), int event)
78 //Scene *scene= CTX_data_scene(C);
85 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
86 WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM, NULL);
89 static int nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr)
92 bAnimListElem *ale= NULL;
93 ListBase anim_data = {NULL, NULL};
97 /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools)
98 * to work correctly is able to be correctly retrieved. There's no point showing empty panels?
100 if (ANIM_animdata_get_context(C, &ac) == 0)
103 /* extract list of active channel(s), of which we should only take the first one
104 * - we need the channels flag to get the active AnimData block when there are no NLA Tracks
106 // XXX: double-check active!
107 filter= (ANIMFILTER_DATA_VISIBLE|ANIMFILTER_LIST_VISIBLE|ANIMFILTER_ACTIVE|ANIMFILTER_LIST_CHANNELS);
108 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
110 for (ale= anim_data.first; ale; ale= ale->next) {
112 case ANIMTYPE_NLATRACK: /* NLA Track - The primary data type which should get caught */
114 NlaTrack *nlt= (NlaTrack *)ale->data;
115 AnimData *adt= ale->adt;
117 /* found it, now set the pointers */
119 /* AnimData pointer */
120 RNA_pointer_create(ale->id, &RNA_AnimData, adt, adt_ptr);
123 /* NLA-Track pointer */
124 RNA_pointer_create(ale->id, &RNA_NlaTrack, nlt, nlt_ptr);
127 /* NLA-Strip pointer */
128 NlaStrip *strip= BKE_nlastrip_find_active(nlt);
129 RNA_pointer_create(ale->id, &RNA_NlaStrip, strip, strip_ptr);
136 case ANIMTYPE_SCENE: /* Top-Level Widgets doubling up as datablocks */
137 case ANIMTYPE_OBJECT:
138 case ANIMTYPE_FILLACTD: /* Action Expander */
139 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
143 case ANIMTYPE_DSSKEY:
145 case ANIMTYPE_DSNTREE:
146 case ANIMTYPE_DSPART:
147 case ANIMTYPE_DSMBALL:
151 /* for these channels, we only do AnimData */
152 if (ale->id && ale->adt) {
154 /* AnimData pointer */
155 RNA_pointer_create(ale->id, &RNA_AnimData, ale->adt, adt_ptr);
157 /* set found status to -1, since setting to 1 would break the loop
158 * and potentially skip an active NLA-Track in some cases...
172 BLI_freelistN(&anim_data);
178 static int nla_panel_poll(const bContext *C, PanelType *pt)
180 return nla_panel_context(C, NULL, NULL);
184 static int nla_animdata_panel_poll(const bContext *C, PanelType *UNUSED(pt))
187 return (nla_panel_context(C, &ptr, NULL, NULL) && (ptr.data != NULL));
190 static int nla_track_panel_poll(const bContext *C, PanelType *UNUSED(pt))
193 return (nla_panel_context(C, NULL, &ptr, NULL) && (ptr.data != NULL));
196 static int nla_strip_panel_poll(const bContext *C, PanelType *UNUSED(pt))
199 return (nla_panel_context(C, NULL, NULL, &ptr) && (ptr.data != NULL));
202 static int nla_strip_actclip_panel_poll(const bContext *C, PanelType *UNUSED(pt))
207 if (!nla_panel_context(C, NULL, NULL, &ptr))
209 if (ptr.data == NULL)
213 return (strip->type == NLASTRIP_TYPE_CLIP);
216 static int nla_strip_eval_panel_poll(const bContext *C, PanelType *UNUSED(pt))
221 if (!nla_panel_context(C, NULL, NULL, &ptr))
223 if (ptr.data == NULL)
228 if (strip->type == NLASTRIP_TYPE_SOUND)
236 /* active AnimData */
237 static void nla_panel_animdata (const bContext *C, Panel *pa)
241 uiLayout *layout= pa->layout;
245 /* check context and also validity of pointer */
246 if (!nla_panel_context(C, &adt_ptr, NULL, NULL))
249 /* adt= adt_ptr.data; */
251 block= uiLayoutGetBlock(layout);
252 uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
254 /* Active Action Properties ------------------------------------- */
256 row= uiLayoutRow(layout, 1);
257 uiTemplateID(row, (bContext *)C, &adt_ptr, "action", "ACTION_OT_new", NULL, NULL /*"ACTION_OT_unlink"*/); // XXX: need to make these operators
260 row= uiLayoutRow(layout, 1);
261 uiItemR(row, &adt_ptr, "action_extrapolation", 0, NULL, ICON_NONE);
264 row= uiLayoutRow(layout, 1);
265 uiItemR(row, &adt_ptr, "action_blend_type", 0, NULL, ICON_NONE);
268 row= uiLayoutRow(layout, 1);
269 uiItemR(row, &adt_ptr, "action_influence", 0, NULL, ICON_NONE);
272 /* active NLA-Track */
273 static void nla_panel_track (const bContext *C, Panel *pa)
276 uiLayout *layout= pa->layout;
280 /* check context and also validity of pointer */
281 if (!nla_panel_context(C, NULL, &nlt_ptr, NULL))
284 block= uiLayoutGetBlock(layout);
285 uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
287 /* Info - Active NLA-Context:Track ---------------------- */
288 row= uiLayoutRow(layout, 1);
289 uiItemR(row, &nlt_ptr, "name", 0, NULL, ICON_NLA);
292 /* generic settings for active NLA-Strip */
293 static void nla_panel_properties(const bContext *C, Panel *pa)
295 PointerRNA strip_ptr;
296 uiLayout *layout= pa->layout;
297 uiLayout *column, *row, *subcol;
299 short showEvalProps = 1;
301 if (!nla_panel_context(C, NULL, NULL, &strip_ptr))
304 block= uiLayoutGetBlock(layout);
305 uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
307 /* Strip Properties ------------------------------------- */
309 row= uiLayoutColumn(layout, 1);
310 uiItemR(row, &strip_ptr, "name", 0, NULL, ICON_NLA); // XXX icon?
311 uiItemR(row, &strip_ptr, "type", 0, NULL, ICON_NONE);
314 column= uiLayoutColumn(layout, 1);
315 uiItemL(column, "Strip Extents:", ICON_NONE);
316 uiItemR(column, &strip_ptr, "frame_start", 0, NULL, ICON_NONE);
317 uiItemR(column, &strip_ptr, "frame_end", 0, NULL, ICON_NONE);
319 /* Evaluation-Related Strip Properties ------------------ */
321 /* sound properties strips don't have these settings */
322 if (RNA_enum_get(&strip_ptr, "type") == NLASTRIP_TYPE_SOUND)
325 /* only show if allowed to... */
328 row= uiLayoutRow(layout, 1);
329 uiItemR(row, &strip_ptr, "extrapolation", 0, NULL, ICON_NONE);
332 row= uiLayoutRow(layout, 1);
333 uiItemR(row, &strip_ptr, "blend_type", 0, NULL, ICON_NONE);
335 /* blend in/out + autoblending
336 * - blend in/out can only be set when autoblending is off
338 column= uiLayoutColumn(layout, 1);
339 uiLayoutSetActive(column, RNA_boolean_get(&strip_ptr, "use_animated_influence")==0);
340 uiItemR(column, &strip_ptr, "use_auto_blend", 0, NULL, ICON_NONE); // XXX as toggle?
342 subcol= uiLayoutColumn(column, 1);
343 uiLayoutSetActive(subcol, RNA_boolean_get(&strip_ptr, "use_auto_blend")==0);
344 uiItemR(subcol, &strip_ptr, "blend_in", 0, NULL, ICON_NONE);
345 uiItemR(subcol, &strip_ptr, "blend_out", 0, NULL, ICON_NONE);
348 column= uiLayoutColumn(layout, 1);
349 uiLayoutSetActive(column, !(RNA_boolean_get(&strip_ptr, "use_animated_influence") || RNA_boolean_get(&strip_ptr, "use_animated_time")));
350 uiItemL(column, "Playback Settings:", ICON_NONE);
351 uiItemR(column, &strip_ptr, "mute", 0, NULL, ICON_NONE);
352 uiItemR(column, &strip_ptr, "use_reverse", 0, NULL, ICON_NONE);
357 /* action-clip only settings for active NLA-Strip */
358 static void nla_panel_actclip(const bContext *C, Panel *pa)
360 PointerRNA strip_ptr;
361 uiLayout *layout= pa->layout;
362 uiLayout *column, *row;
365 /* check context and also validity of pointer */
366 if (!nla_panel_context(C, NULL, NULL, &strip_ptr))
369 block= uiLayoutGetBlock(layout);
370 uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
372 /* Strip Properties ------------------------------------- */
374 row= uiLayoutRow(layout, 1);
375 uiItemR(row, &strip_ptr, "action", 0, NULL, ICON_ACTION);
378 // XXX custom names were used here (to avoid the prefixes)... probably not necessary in future?
379 column= uiLayoutColumn(layout, 1);
380 uiItemL(column, "Action Extents:", ICON_NONE);
381 uiItemR(column, &strip_ptr, "action_frame_start", 0, "Start Frame", ICON_NONE);
382 uiItemR(column, &strip_ptr, "action_frame_end", 0, "End Frame", ICON_NONE);
383 uiItemO(column, NULL, ICON_NONE, "NLA_OT_action_sync_length");
386 column= uiLayoutColumn(layout, 1);
387 uiLayoutSetActive(column, RNA_boolean_get(&strip_ptr, "use_animated_time")==0);
388 uiItemL(column, "Playback Settings:", ICON_NONE);
389 uiItemR(column, &strip_ptr, "scale", 0, NULL, ICON_NONE);
390 uiItemR(column, &strip_ptr, "repeat", 0, NULL, ICON_NONE);
393 /* evaluation settings for active NLA-Strip */
394 static void nla_panel_evaluation(const bContext *C, Panel *pa)
396 PointerRNA strip_ptr;
397 uiLayout *layout= pa->layout;
398 uiLayout *column, *subcolumn, *subrow;
401 /* check context and also validity of pointer */
402 if (!nla_panel_context(C, NULL, NULL, &strip_ptr))
405 block= uiLayoutGetBlock(layout);
406 uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
408 column= uiLayoutColumn(layout, 1);
409 uiItemR(column, &strip_ptr, "use_animated_influence", 0, NULL, ICON_NONE);
411 subcolumn= uiLayoutColumn(column, 1);
412 uiLayoutSetEnabled(subcolumn, RNA_boolean_get(&strip_ptr, "use_animated_influence"));
413 uiItemR(subcolumn, &strip_ptr, "influence", 0, NULL, ICON_NONE);
416 column= uiLayoutColumn(layout, 1);
417 subrow= uiLayoutRow(column, 0);
418 uiItemR(subrow, &strip_ptr, "use_animated_time", 0, NULL, ICON_NONE);
419 uiItemR(subrow, &strip_ptr, "use_animated_time_cyclic", 0, NULL, ICON_NONE);
421 subcolumn= uiLayoutColumn(column, 1);
422 subrow= uiLayoutRow(subcolumn, 0);
423 uiLayoutSetEnabled(subrow, RNA_boolean_get(&strip_ptr, "use_animated_time"));
424 uiItemR(subcolumn, &strip_ptr, "strip_time", 0, NULL, ICON_NONE);
427 /* F-Modifiers for active NLA-Strip */
428 static void nla_panel_modifiers(const bContext *C, Panel *pa)
430 PointerRNA strip_ptr;
436 /* check context and also validity of pointer */
437 if (!nla_panel_context(C, NULL, NULL, &strip_ptr))
439 strip= strip_ptr.data;
441 block= uiLayoutGetBlock(pa->layout);
442 uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL);
444 /* 'add modifier' button at top of panel */
446 row= uiLayoutRow(pa->layout, 0);
447 block= uiLayoutGetBlock(row);
449 // XXX for now, this will be a operator button which calls a temporary 'add modifier' operator
450 // FIXME: we need to set the only-active property so that this will only add modifiers for the active strip (not all selected)
451 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");
453 /* copy/paste (as sub-row)*/
454 row= uiLayoutRow(row, 1);
455 uiItemO(row, "", ICON_COPYDOWN, "NLA_OT_fmodifier_copy");
456 uiItemO(row, "", ICON_PASTEDOWN, "NLA_OT_fmodifier_paste");
459 /* draw each modifier */
460 for (fcm= strip->modifiers.first; fcm; fcm= fcm->next) {
461 col= uiLayoutColumn(pa->layout, 1);
463 ANIM_uiTemplate_fmodifier_draw(col, strip_ptr.id.data, &strip->modifiers, fcm);
467 /* ******************* general ******************************** */
470 void nla_buttons_register(ARegionType *art)
474 pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel animdata");
475 strcpy(pt->idname, "NLA_PT_animdata");
476 strcpy(pt->label, "Animation Data");
477 pt->draw= nla_panel_animdata;
478 pt->poll= nla_animdata_panel_poll;
479 pt->flag= PNL_DEFAULT_CLOSED;
480 BLI_addtail(&art->paneltypes, pt);
482 pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel track");
483 strcpy(pt->idname, "NLA_PT_track");
484 strcpy(pt->label, "Active Track");
485 pt->draw= nla_panel_track;
486 pt->poll= nla_track_panel_poll;
487 BLI_addtail(&art->paneltypes, pt);
489 pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel properties");
490 strcpy(pt->idname, "NLA_PT_properties");
491 strcpy(pt->label, "Active Strip");
492 pt->draw= nla_panel_properties;
493 pt->poll= nla_strip_panel_poll;
494 BLI_addtail(&art->paneltypes, pt);
496 pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel properties");
497 strcpy(pt->idname, "NLA_PT_actionclip");
498 strcpy(pt->label, "Action Clip");
499 pt->draw= nla_panel_actclip;
500 pt->poll= nla_strip_actclip_panel_poll;
501 BLI_addtail(&art->paneltypes, pt);
503 pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel evaluation");
504 strcpy(pt->idname, "NLA_PT_evaluation");
505 strcpy(pt->label, "Evaluation");
506 pt->draw= nla_panel_evaluation;
507 pt->poll= nla_strip_eval_panel_poll;
508 BLI_addtail(&art->paneltypes, pt);
510 pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel modifiers");
511 strcpy(pt->idname, "NLA_PT_modifiers");
512 strcpy(pt->label, "Modifiers");
513 pt->draw= nla_panel_modifiers;
514 pt->poll= nla_strip_eval_panel_poll;
515 BLI_addtail(&art->paneltypes, pt);
518 static int nla_properties(bContext *C, wmOperator *UNUSED(op))
520 ScrArea *sa= CTX_wm_area(C);
521 ARegion *ar= nla_has_buttons_region(sa);
524 ED_region_toggle_hidden(C, ar);
526 return OPERATOR_FINISHED;
529 void NLA_OT_properties(wmOperatorType *ot)
531 ot->name= "Properties";
532 ot->idname= "NLA_OT_properties";
533 ot->description= "Toggle display properties panel";
535 ot->exec= nla_properties;
536 ot->poll= ED_operator_nla_active;