diff options
author | Joshua Leung <aligorith@gmail.com> | 2010-03-18 16:04:46 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2010-03-18 16:04:46 +0300 |
commit | 618b459e8b3630eea747523febec666889a364f7 (patch) | |
tree | 481c530e96e9e77ae09029f35a436475921bea39 /source/blender/editors | |
parent | 148985edf03814b26f99bf4ae883c83db216ccf3 (diff) |
F-Modifier Goodies (as requested by @ndy):
* Copy/Paste operators for F-Modifiers
Available in Graph and NLA Editors. Use the Copy/Paste buttons beside the 'Add Modifier' buttons.
Copy copies all the modifiers of the ACTIVE F-Curve or Strip depending on the editor.
Paste pastes modifiers from the buffer to all the selected F-Curves or Strips, adding the new modifiers to the ends of each list.
* 'Stepped Interpolation' F-Modifier
This modifier holds each interpolated value from the F-Curve for several frames without changing the timing.
This allows to preview motions 'on-twos' for example without altering the timing, or having to go through setting heaps of keyframes. In this case, Andy wanted to use this for CG <-> StopMo.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/animation/fmodifier_ui.c | 108 | ||||
-rw-r--r-- | source/blender/editors/include/ED_anim_api.h | 19 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_buttons.c | 7 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 117 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_buttons.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 124 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_ops.c | 2 |
10 files changed, 382 insertions, 7 deletions
diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 9d0fe99976b..22bb5317383 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -30,6 +30,9 @@ * This file defines the (C-Coded) templates + editing callbacks needed * by the interface stuff or F-Modifiers, as used by F-Curves in the Graph Editor, * and NLA-Strips in the NLA Editor. + * + * Copy/Paste Buffer for F-Modifiers: + * For now, this is also defined in this file so that it can be shared between the */ #include <string.h> @@ -47,15 +50,18 @@ #include "RNA_access.h" +#include "ED_anim_api.h" + #include "UI_interface.h" #include "UI_resources.h" +/* ********************************************** */ +/* UI STUFF */ + // XXX! -------------------------------- /* temporary definition for limits of float number buttons (FLT_MAX tends to infinity with old system) */ #define UI_FLT_MAX 10000.0f -/* ********************************************** */ - #define B_REDR 1 #define B_FMODIFIER_REDRAW 20 @@ -549,6 +555,22 @@ static void draw_modifier__limits(uiLayout *layout, ID *id, FModifier *fcm, shor /* --------------- */ +/* draw settings for stepped interpolation modifier */ +static void draw_modifier__stepped(uiLayout *layout, ID *id, FModifier *fcm, short width) +{ + uiLayout *col; + PointerRNA ptr; + + /* init the RNA-pointer */ + RNA_pointer_create(id, &RNA_FModifierStepped, fcm, &ptr); + + col= uiLayoutColumn(layout, 0); + + uiItemR(col, NULL, 0, &ptr, "step_size", 0); + uiItemR(col, NULL, 0, &ptr, "start_offset", 0); +} + +/* --------------- */ void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm) { @@ -635,6 +657,10 @@ void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifie case FMODIFIER_TYPE_NOISE: /* Noise */ draw_modifier__noise(box, id, fcm, width); break; + + case FMODIFIER_TYPE_STEPPED: /* Stepped */ + draw_modifier__stepped(box, id, fcm, width); + break; default: /* unknown type */ break; @@ -643,3 +669,81 @@ void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifie } /* ********************************************** */ +/* COPY/PASTE BUFFER STUFF */ + +/* Copy/Paste Buffer itself (list of FModifier 's) */ +static ListBase fmodifier_copypaste_buf = {NULL, NULL}; + +/* ---------- */ + +/* free the copy/paste buffer */ +void free_fmodifiers_copybuf (void) +{ + /* just free the whole buffer */ + free_fmodifiers(&fmodifier_copypaste_buf); +} + +/* copy the given F-Modifiers to the buffer, returning whether anything was copied or not + * assuming that the buffer has been cleared already with free_fmodifiers_copybuf() + * - active: only copy the active modifier + */ +short ANIM_fmodifiers_copy_to_buf (ListBase *modifiers, short active) +{ + short ok = 1; + + /* sanity checks */ + if ELEM(NULL, modifiers, modifiers->first) + return 0; + + /* copy the whole list, or just the active one? */ + if (active) { + FModifier *fcm = find_active_fmodifier(modifiers); + + if (fcm) { + FModifier *fcmN = copy_fmodifier(fcm); + BLI_addtail(&fmodifier_copypaste_buf, fcmN); + } + else + ok = 0; + } + else + copy_fmodifiers(&fmodifier_copypaste_buf, modifiers); + + /* did we succeed? */ + return ok; +} + +/* 'Paste' the F-Modifier(s) from the buffer to the specified list + * - replace: free all the existing modifiers to leave only the pasted ones + */ +short ANIM_fmodifiers_paste_from_buf (ListBase *modifiers, short replace) +{ + FModifier *fcm; + short ok = 0; + + /* sanity checks */ + if (modifiers == NULL) + return 0; + + /* if replacing the list, free the existing modifiers */ + if (replace) + free_fmodifiers(modifiers); + + /* now copy over all the modifiers in the buffer to the end of the list */ + for (fcm= fmodifier_copypaste_buf.first; fcm; fcm= fcm->next) { + /* make a copy of it */ + FModifier *fcmN = copy_fmodifier(fcm); + + /* make sure the new one isn't active, otherwise the list may get several actives */ + fcmN->flag &= ~FMODIFIER_FLAG_ACTIVE; + + /* now add it to the end of the list */ + BLI_addtail(modifiers, fcmN); + ok = 1; + } + + /* did we succeed? */ + return ok; +} + +/* ********************************************** */ diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 2f089a41a3f..3892770c1f4 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -452,9 +452,28 @@ void ANIM_draw_previewrange(const struct bContext *C, struct View2D *v2d); /* ************************************************* */ /* F-MODIFIER TOOLS */ +/* ------------- UI Panel Drawing -------------- */ + /* draw a given F-Modifier for some layout/UI-Block */ void ANIM_uiTemplate_fmodifier_draw(struct uiLayout *layout, struct ID *id, ListBase *modifiers, struct FModifier *fcm); +/* ------------- Copy/Paste Buffer -------------- */ + + +/* free the copy/paste buffer */ +void free_fmodifiers_copybuf(void); + +/* copy the given F-Modifiers to the buffer, returning whether anything was copied or not + * assuming that the buffer has been cleared already with free_fmodifiers_copybuf() + * - active: only copy the active modifier + */ +short ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, short active); + +/* 'Paste' the F-Modifier(s) from the buffer to the specified list + * - replace: free all the existing modifiers to leave only the pasted ones + */ +short ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, short replace); + /* ************************************************* */ /* ASSORTED TOOLS */ diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index 3975c88fe5c..78fd2e06683 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -610,8 +610,13 @@ static void graph_panel_modifiers(const bContext *C, Panel *pa) row= uiLayoutRow(pa->layout, 0); block= uiLayoutGetBlock(row); - // XXX for now, this will be a operator button which calls a temporary 'add modifier' operator + // XXX for now, this will be a operator button which calls a 'add modifier' operator uiDefButO(block, BUT, "GRAPH_OT_fmodifier_add", WM_OP_INVOKE_REGION_WIN, "Add Modifier", 10, 0, 150, 20, "Adds a new F-Curve Modifier for the active F-Curve"); + + /* copy/paste (as sub-row)*/ + row= uiLayoutRow(row, 1); + uiItemO(row, "", ICON_COPYDOWN, "GRAPH_OT_fmodifier_copy"); + uiItemO(row, "", ICON_PASTEDOWN, "GRAPH_OT_fmodifier_paste"); } /* draw each modifier */ diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 485c9ab8bf4..d23bafbc001 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1971,7 +1971,7 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op) filter |= (ANIMFILTER_SEL|ANIMFILTER_CURVEVISIBLE); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); - /* smooth keyframes */ + /* add f-modifier to each curve */ for (ale= anim_data.first; ale; ale= ale->next) { FCurve *fcu= (FCurve *)ale->data; FModifier *fcm; @@ -2017,4 +2017,119 @@ void GRAPH_OT_fmodifier_add (wmOperatorType *ot) RNA_def_boolean(ot->srna, "only_active", 1, "Only Active", "Only add F-Modifier to active F-Curve."); } +/* ******************** Copy F-Modifiers Operator *********************** */ + +static int graph_fmodifier_copy_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + bAnimListElem *ale; + short ok = 0; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* clear buffer first */ + free_fmodifiers_copybuf(); + + /* get the active F-Curve */ + ale= get_active_fcurve_channel(&ac); + + /* if this exists, call the copy F-Modifiers API function */ + if (ale && ale->data) { + FCurve *fcu= (FCurve *)ale->data; + + // TODO: when 'active' vs 'all' boolean is added, change last param! + ok= ANIM_fmodifiers_copy_to_buf(&fcu->modifiers, 0); + + /* free temp data now */ + MEM_freeN(ale); + } + + /* successful or not? */ + if (ok == 0) { + BKE_report(op->reports, RPT_ERROR, "No F-Modifiers available to be copied"); + return OPERATOR_CANCELLED; + } + else + return OPERATOR_FINISHED; +} + +void GRAPH_OT_fmodifier_copy (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Copy F-Modifiers"; + ot->idname= "GRAPH_OT_fmodifier_copy"; + ot->description= "Copy the F-Modifier(s) of the active F-Curve."; + + /* api callbacks */ + ot->exec= graph_fmodifier_copy_exec; + ot->poll= graphop_active_fcurve_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* id-props */ + //ot->prop = RNA_def_boolean(ot->srna, "all", 1, "All F-Modifiers", "Copy all the F-Modifiers, instead of just the active one"); +} + +/* ******************** Paste F-Modifiers Operator *********************** */ + +static int graph_fmodifier_paste_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter, ok=0; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* filter data */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* paste modifiers */ + for (ale = anim_data.first; ale; ale = ale->next) { + FCurve *fcu= (FCurve *)ale->data; + + // TODO: do we want to replace existing modifiers? add user pref for that! + ok += ANIM_fmodifiers_paste_from_buf(&fcu->modifiers, 0); + } + + /* clean up */ + BLI_freelistN(&anim_data); + + /* successful or not? */ + if (ok) { + /* validate keyframes after editing */ + ANIM_editkeyframes_refresh(&ac); + + /* set notifier that keyframes have changed */ + WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL); + + return OPERATOR_FINISHED; + } + else { + BKE_report(op->reports, RPT_ERROR, "No F-Modifiers to paste"); + return OPERATOR_CANCELLED; + } +} + +void GRAPH_OT_fmodifier_paste (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Paste F-Modifiers"; + ot->idname= "GRAPH_OT_fmodifier_paste"; + ot->description= "Add copied F-Modifiers to the selected F-Curves"; + + /* api callbacks */ + ot->exec= graph_fmodifier_paste_exec; + ot->poll= graphop_editable_keyframes_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ************************************************************************** */ diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 696d31e22e1..356cd05b509 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -139,6 +139,8 @@ enum { /* ----------- */ void GRAPH_OT_fmodifier_add(struct wmOperatorType *ot); +void GRAPH_OT_fmodifier_copy(struct wmOperatorType *ot); +void GRAPH_OT_fmodifier_paste(struct wmOperatorType *ot); /* ----------- */ diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 7c1ac14027a..63c877e7402 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -262,8 +262,9 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_click_insert); /* F-Curve Modifiers */ - // XXX temporary? WM_operatortype_append(GRAPH_OT_fmodifier_add); + WM_operatortype_append(GRAPH_OT_fmodifier_copy); + WM_operatortype_append(GRAPH_OT_fmodifier_paste); } /* ************************** registration - keymaps **********************************/ diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c index 4f944d1b855..944a93a713f 100644 --- a/source/blender/editors/space_nla/nla_buttons.c +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -430,6 +430,11 @@ static void nla_panel_modifiers(const bContext *C, Panel *pa) // 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"); + + /* copy/paste (as sub-row)*/ + row= uiLayoutRow(row, 1); + uiItemO(row, "", ICON_COPYDOWN, "NLA_OT_fmodifier_copy"); + uiItemO(row, "", ICON_PASTEDOWN, "NLA_OT_fmodifier_paste"); } /* draw each modifier */ diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 543fa1dfed7..bc99ded4db6 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -1633,8 +1633,7 @@ static int nla_fmodifier_add_exec(bContext *C, wmOperator *op) BLI_freelistN(&anim_data); /* set notifier that things have changed */ - // FIXME: this doesn't really do it justice... - WM_event_add_notifier(C, NC_ANIMATION, NULL); + WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL); /* done */ return OPERATOR_FINISHED; @@ -1659,4 +1658,125 @@ void NLA_OT_fmodifier_add (wmOperatorType *ot) RNA_def_boolean(ot->srna, "only_active", 0, "Only Active", "Only add F-Modifier of the specified type to the active strip."); } +/* ******************** Copy F-Modifiers Operator *********************** */ + +static int nla_fmodifier_copy_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter, ok=0; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* clear buffer first */ + free_fmodifiers_copybuf(); + + /* get a list of the editable tracks being shown in the NLA */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each NLA-Track, add the specified modifier to all selected strips */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + NlaStrip *strip; + + for (strip= nlt->strips.first; strip; strip=strip->next) { + /* only add F-Modifier if on active strip? */ + if ((strip->flag & NLASTRIP_FLAG_ACTIVE)==0) + continue; + + // TODO: when 'active' vs 'all' boolean is added, change last param! + ok += ANIM_fmodifiers_copy_to_buf(&strip->modifiers, 0); + } + } + + /* successful or not? */ + if (ok == 0) { + BKE_report(op->reports, RPT_ERROR, "No F-Modifiers available to be copied"); + return OPERATOR_CANCELLED; + } + else + return OPERATOR_FINISHED; +} + +void NLA_OT_fmodifier_copy (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Copy F-Modifiers"; + ot->idname= "NLA_OT_fmodifier_copy"; + ot->description= "Copy the F-Modifier(s) of the active NLA-Strip."; + + /* api callbacks */ + ot->exec= nla_fmodifier_copy_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* id-props */ + //ot->prop = RNA_def_boolean(ot->srna, "all", 1, "All F-Modifiers", "Copy all the F-Modifiers, instead of just the active one"); +} + +/* ******************** Paste F-Modifiers Operator *********************** */ + +static int nla_fmodifier_paste_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter, ok=0; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* get a list of the editable tracks being shown in the NLA */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_SEL | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each NLA-Track, add the specified modifier to all selected strips */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + NlaStrip *strip; + + for (strip= nlt->strips.first; strip; strip=strip->next) { + // TODO: do we want to replace existing modifiers? add user pref for that! + ok += ANIM_fmodifiers_paste_from_buf(&strip->modifiers, 0); + } + } + + /* clean up */ + BLI_freelistN(&anim_data); + + /* successful or not? */ + if (ok) { + /* set notifier that things have changed */ + /* set notifier that things have changed */ + WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL); + return OPERATOR_FINISHED; + } + else { + BKE_report(op->reports, RPT_ERROR, "No F-Modifiers to paste"); + return OPERATOR_CANCELLED; + } +} + +void NLA_OT_fmodifier_paste (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Paste F-Modifiers"; + ot->idname= "NLA_OT_fmodifier_paste"; + ot->description= "Add copied F-Modifiers to the selected NLA-Strips"; + + /* api callbacks */ + ot->exec= nla_fmodifier_paste_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* *********************************************** */ diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 1af2d2a1635..18ef91220f9 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -111,6 +111,8 @@ void NLA_OT_clear_scale(wmOperatorType *ot); void NLA_OT_snap(wmOperatorType *ot); void NLA_OT_fmodifier_add(wmOperatorType *ot); +void NLA_OT_fmodifier_copy(wmOperatorType *ot); +void NLA_OT_fmodifier_paste(wmOperatorType *ot); /* **************************************** */ diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 10ff10f46fd..249256a47f9 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -165,6 +165,8 @@ void nla_operatortypes(void) WM_operatortype_append(NLA_OT_snap); WM_operatortype_append(NLA_OT_fmodifier_add); + WM_operatortype_append(NLA_OT_fmodifier_copy); + WM_operatortype_append(NLA_OT_fmodifier_paste); } /* ************************** registration - keymaps **********************************/ |