diff options
-rw-r--r-- | source/blender/editors/animation/anim_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/animation/keyframes_edit.c | 69 | ||||
-rw-r--r-- | source/blender/editors/include/ED_keyframes_edit.h | 4 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_edit_keyframes.c | 188 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_ops.c | 10 |
6 files changed, 221 insertions, 55 deletions
diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index d31764a2cd3..f9247579c06 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -368,7 +368,7 @@ void ED_keymap_anim(wmWindowManager *wm) ListBase *keymap= WM_keymap_listbase(wm, "Animation", 0, 0); WM_keymap_verify_item(keymap, "ANIM_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0); - WM_keymap_verify_item(keymap, "ANIM_OT_toggle_time", TKEY, KM_PRESS, 0, 0); + WM_keymap_verify_item(keymap, "ANIM_OT_toggle_time", TKEY, KM_PRESS, KM_CTRL, 0); /* preview range */ WM_keymap_verify_item(keymap, "ANIM_OT_previewrange_define", PKEY, KM_PRESS, KM_CTRL, 0); diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index e58516bf1b8..f905496cb25 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -398,7 +398,6 @@ void snap_cfra_ipo_keys(BeztEditData *bed, Ipo *ipo, short mode) /* Sets the selected bezier handles to type 'auto' */ static short set_bezier_auto(BeztEditData *bed, BezTriple *bezt) { - /* is a handle selected? If so set it to type auto */ if((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { if (bezt->f1 & SELECT) bezt->h1= 1; /* the secret code for auto */ if (bezt->f3 & SELECT) bezt->h2= 1; @@ -417,7 +416,6 @@ static short set_bezier_auto(BeztEditData *bed, BezTriple *bezt) /* Sets the selected bezier handles to type 'vector' */ static short set_bezier_vector(BeztEditData *bed, BezTriple *bezt) { - /* is a handle selected? If so set it to type vector */ if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { if (bezt->f1 & SELECT) bezt->h1= HD_VECT; if (bezt->f3 & SELECT) bezt->h2= HD_VECT; @@ -433,29 +431,25 @@ static short set_bezier_vector(BeztEditData *bed, BezTriple *bezt) return 0; } -#if 0 // xxx currently not used (only used by old code as a check) +/* Queries if the handle should be set to 'free' or 'align' */ static short bezier_isfree(BeztEditData *bed, BezTriple *bezt) { - /* queries whether the handle should be set - * to type 'free' or 'align' - */ if ((bezt->f1 & SELECT) && (bezt->h1)) return 1; if ((bezt->f3 & SELECT) && (bezt->h2)) return 1; return 0; } +/* Sets selected bezier handles to type 'align' */ static short set_bezier_align(BeztEditData *bed, BezTriple *bezt) -{ - /* Sets selected bezier handles to type 'align' */ +{ if (bezt->f1 & SELECT) bezt->h1= HD_ALIGN; if (bezt->f3 & SELECT) bezt->h2= HD_ALIGN; return 0; } -#endif // xxx currently not used (only used by old code as a check, but can't replicate that now) +/* Sets selected bezier handles to type 'free' */ static short set_bezier_free(BeztEditData *bed, BezTriple *bezt) { - /* Sets selected bezier handles to type 'free' */ if (bezt->f1 & SELECT) bezt->h1= HD_FREE; if (bezt->f3 & SELECT) bezt->h2= HD_FREE; return 0; @@ -463,54 +457,31 @@ static short set_bezier_free(BeztEditData *bed, BezTriple *bezt) /* Set all Bezier Handles to a single type */ // calchandles_ipocurve -BeztEditFunc ANIM_editkeyframes_sethandles(short code) +BeztEditFunc ANIM_editkeyframes_handles(short code) { switch (code) { - case 1: /* auto */ + case HD_AUTO: /* auto */ return set_bezier_auto; - case 2: /* vector */ + case HD_VECT: /* vector */ return set_bezier_vector; - + case HD_FREE: /* free */ + return set_bezier_free; + case HD_ALIGN: /* align */ + return set_bezier_align; + default: /* free or align? */ - return set_bezier_free; // err.. to set align, we need 'align' to be set + return bezier_isfree; } } -#if 0 -void sethandles_ipo_keys(Ipo *ipo, int code) -{ - /* this function lets you set bezier handles all to - * one type for some Ipo's (e.g. with hotkeys through - * the action window). - */ - - /* code==1: set autohandle */ - /* code==2: set vectorhandle */ - /* als code==3 (HD_ALIGN) toggelt het, vectorhandles worden HD_FREE */ - - switch (code) { - case 1: /* auto */ - ipo_keys_bezier_loop(ipo, set_bezier_auto, calchandles_ipocurve); - break; - case 2: /* vector */ - ipo_keys_bezier_loop(ipo, set_bezier_vector, calchandles_ipocurve); - break; - default: /* free or align? */ - if (ipo_keys_bezier_loop(ipo, bezier_isfree, NULL)) /* free */ - ipo_keys_bezier_loop(ipo, set_bezier_free, calchandles_ipocurve); - else /* align */ - ipo_keys_bezier_loop(ipo, set_bezier_align, calchandles_ipocurve); - break; - } -} -#endif - /* ------- */ -void set_ipocurve_mixed(IpoCurve *icu) +/* IPO-curve sanity callback - the name of this is a bit unwieldy, by is best to keep this in style... */ +// was called set_ipocurve_mixed() +void ANIM_editkeyframes_ipocurve_ipotype(IpoCurve *icu) { /* Sets the type of the IPO curve to mixed, as some (selected) - * keyframes were set to other interpolation modes + * keyframes were set to other interpolation types */ icu->ipo= IPO_MIXED; @@ -540,13 +511,13 @@ static short set_bezt_bezier(BeztEditData *bed, BezTriple *bezt) } /* Set the interpolation type of the selected BezTriples in each IPO curve to the specified one */ -// set_ipocurve_mixed() ! +// ANIM_editkeyframes_ipocurve_ipotype() ! BeztEditFunc ANIM_editkeyframes_ipo(short code) { switch (code) { - case 1: /* constant */ + case IPO_CONST: /* constant */ return set_bezt_constant; - case 2: /* linear */ + case IPO_LIN: /* linear */ return set_bezt_linear; default: /* bezier */ return set_bezt_bezier; diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 36ec834635e..787e206b434 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -124,6 +124,10 @@ BeztEditFunc ANIM_editkeyframes_select(short mode); BeztEditFunc ANIM_editkeyframes_handles(short mode); BeztEditFunc ANIM_editkeyframes_ipo(short mode); +/* ---------- IpoCurve Callbacks ------------ */ + +void ANIM_editkeyframes_ipocurve_ipotype(struct IpoCurve *icu); + /* ************************************************ */ // XXX all of these funcs will be depreceated! diff --git a/source/blender/editors/space_action/action_edit_keyframes.c b/source/blender/editors/space_action/action_edit_keyframes.c index d421b2a8b8c..22603a7dc9a 100644 --- a/source/blender/editors/space_action/action_edit_keyframes.c +++ b/source/blender/editors/space_action/action_edit_keyframes.c @@ -91,6 +91,188 @@ /* ************************************************************************** */ /* SETTINGS STUFF */ +/* ******************** Set Interpolation-Type Operator *********************** */ + +/* defines for set ipo-type for selected keyframes tool */ +EnumPropertyItem prop_actkeys_ipo_types[] = { + {IPO_CONST, "CONSTANT", "Constant Interpolation", ""}, + {IPO_LIN, "LINEAR", "Linear Interpolation", ""}, + {IPO_BEZ, "BEZIER", "Bezier Interpolation", ""}, + {0, NULL, NULL, NULL} +}; + +/* this function is responsible for setting interpolation mode for keyframes */ +static void setipo_action_keys(bAnimContext *ac, short mode) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + BeztEditFunc set_cb= ANIM_editkeyframes_ipo(mode); + + /* filter data */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_IPOKEYS); + ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype); + + /* loop through setting flags for handles + * Note: we do not supply BeztEditData to the looper yet. Currently that's not necessary here... + */ + for (ale= anim_data.first; ale; ale= ale->next) + ipo_keys_bezier_loop(NULL, ale->key_data, NULL, set_cb, ANIM_editkeyframes_ipocurve_ipotype); + + /* cleanup */ + BLI_freelistN(&anim_data); +} + +/* ------------------- */ + +static int actkeys_ipo_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + short mode; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + if (ac.datatype == ANIMCONT_GPENCIL) + return OPERATOR_PASS_THROUGH; + + /* get handle setting mode */ + mode= RNA_enum_get(op->ptr, "type"); + + /* set handle type */ + setipo_action_keys(&ac, mode); + + /* validate keyframes after editing */ + ANIM_editkeyframes_refresh(&ac); + + /* set notifier tha things have changed */ + ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 'keyframes' data context or so instead! + + return OPERATOR_FINISHED; +} + +void ACT_OT_keyframes_ipotype (wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name= "Set Keyframe Interpolation"; + ot->idname= "ACT_OT_keyframes_ipotype"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= actkeys_ipo_exec; + ot->poll= ED_operator_areaactive; + + /* flags */ + ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/; + + /* id-props */ + prop= RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, prop_actkeys_ipo_types); +} + +/* ******************** Set Handle-Type Operator *********************** */ + +/* defines for set handle-type for selected keyframes tool */ +EnumPropertyItem prop_actkeys_handletype_types[] = { + {HD_AUTO, "AUTO", "Auto Handles", ""}, + {HD_VECT, "VECTOR", "Vector Handles", ""}, + {HD_FREE, "FREE", "Free Handles", ""}, + {HD_ALIGN, "ALIGN", "Aligned Handles", ""}, +// {-1, "TOGGLE", "Toggle between Free and Aligned Handles", ""}, + {0, NULL, NULL, NULL} +}; + +/* this function is responsible for setting handle-type of selected keyframes */ +static void sethandles_action_keys(bAnimContext *ac, short mode) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + BeztEditFunc set_cb= ANIM_editkeyframes_handles(mode); + + /* filter data */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_IPOKEYS); + ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype); + + /* loop through setting flags for handles + * Note: we do not supply BeztEditData to the looper yet. Currently that's not necessary here... + */ + for (ale= anim_data.first; ale; ale= ale->next) { + if (mode == -1) { + BeztEditFunc toggle_cb; + + /* check which type of handle to set (free or aligned) + * - check here checks for handles with free alignment already + */ + if (ipo_keys_bezier_loop(NULL, ale->key_data, NULL, set_cb, NULL)) + toggle_cb= ANIM_editkeyframes_handles(HD_FREE); + else + toggle_cb= ANIM_editkeyframes_handles(HD_ALIGN); + + /* set handle-type */ + ipo_keys_bezier_loop(NULL, ale->key_data, NULL, toggle_cb, calchandles_ipocurve); + } + else { + /* directly set handle-type */ + ipo_keys_bezier_loop(NULL, ale->key_data, NULL, set_cb, calchandles_ipocurve); + } + } + + /* cleanup */ + BLI_freelistN(&anim_data); +} + +/* ------------------- */ + +static int actkeys_handletype_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + short mode; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + if (ac.datatype == ANIMCONT_GPENCIL) + return OPERATOR_PASS_THROUGH; + + /* get handle setting mode */ + mode= RNA_enum_get(op->ptr, "type"); + + /* set handle type */ + sethandles_action_keys(&ac, mode); + + /* validate keyframes after editing */ + ANIM_editkeyframes_refresh(&ac); + + /* set notifier tha things have changed */ + ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 'keyframes' data context or so instead! + + return OPERATOR_FINISHED; +} + +void ACT_OT_keyframes_handletype (wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name= "Set Keyframe Handle Type"; + ot->idname= "ACT_OT_keyframes_handletype"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= actkeys_handletype_exec; + ot->poll= ED_operator_areaactive; + + /* flags */ + ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/; + + /* id-props */ + prop= RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, prop_actkeys_handletype_types); +} + /* ************************************************************************** */ /* TRANSFORM STUFF */ @@ -263,7 +445,7 @@ void ACT_OT_keyframes_snap (wmOperatorType *ot) /* ******************** Mirror Keyframes Operator *********************** */ -/* defines for snap keyframes tool */ +/* defines for mirror keyframes tool */ EnumPropertyItem prop_actkeys_mirror_types[] = { {ACTKEYS_MIRROR_CFRA, "CFRA", "Current frame", ""}, {ACTKEYS_MIRROR_YAXIS, "YAXIS", "Vertical Axis", ""}, @@ -272,7 +454,7 @@ EnumPropertyItem prop_actkeys_mirror_types[] = { {0, NULL, NULL, NULL} }; -/* this function is responsible for snapping keyframes to frame-times */ +/* this function is responsible for mirroring keyframes */ static void mirror_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {NULL, NULL}; @@ -343,7 +525,7 @@ static int actkeys_mirror_exec(bContext *C, wmOperator *op) if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; - /* get snapping mode */ + /* get mirroring mode */ mode= RNA_enum_get(op->ptr, "type"); /* mirror keyframes */ diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h index d95322d80de..8655315ccfb 100644 --- a/source/blender/editors/space_action/action_intern.h +++ b/source/blender/editors/space_action/action_intern.h @@ -73,6 +73,9 @@ enum { /* ***************************************** */ /* action_edit_keyframes.c */ +void ACT_OT_keyframes_handletype(struct wmOperatorType *ot); +void ACT_OT_keyframes_ipotype(struct wmOperatorType *ot); + void ACT_OT_keyframes_cfrasnap(struct wmOperatorType *ot); void ACT_OT_keyframes_snap(struct wmOperatorType *ot); void ACT_OT_keyframes_mirror(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_action/action_ops.c b/source/blender/editors/space_action/action_ops.c index 63de5d147e9..ad42173be41 100644 --- a/source/blender/editors/space_action/action_ops.c +++ b/source/blender/editors/space_action/action_ops.c @@ -69,9 +69,11 @@ void action_operatortypes(void) WM_operatortype_append(ACT_OT_keyframes_columnselect); /* editing */ - WM_operatortype_append(ACT_OT_keyframes_cfrasnap); WM_operatortype_append(ACT_OT_keyframes_snap); WM_operatortype_append(ACT_OT_keyframes_mirror); + WM_operatortype_append(ACT_OT_keyframes_cfrasnap); + WM_operatortype_append(ACT_OT_keyframes_handletype); + WM_operatortype_append(ACT_OT_keyframes_ipotype); } /* ************************** registration - keymaps **********************************/ @@ -103,9 +105,13 @@ static void action_keymap_keyframes (ListBase *keymap) /* snap - current frame to selected keys */ WM_keymap_add_item(keymap, "ACT_OT_keyframes_cfrasnap", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); - /* menu+1-step transform */ + /* menu + single-step transform */ WM_keymap_add_item(keymap, "ACT_OT_keyframes_snap", SKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "ACT_OT_keyframes_mirror", MKEY, KM_PRESS, KM_SHIFT, 0); + + /* menu + set setting */ + WM_keymap_add_item(keymap, "ACT_OT_keyframes_handletype", HKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "ACT_OT_keyframes_ipotype", TKEY, KM_PRESS, KM_SHIFT, 0); } /* --------------- */ |