/* 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;
/* 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;
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;
/* 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;
}
/* 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;
/* ************************************************************************** */
/* 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 */
/* ******************** 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", ""},
{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};
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 */