void fcurve_to_keylist(AnimData *adt, FCurve *fcu, DLRBT_Tree *keys, DLRBT_Tree *blocks) { BezTriple *bezt; unsigned int v; if (fcu && fcu->totvert && fcu->bezt) { /* apply NLA-mapping (if applicable) */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 0); /* loop through beztriples, making ActKeysColumns and ActKeyBlocks */ for (v = 0, bezt = fcu->bezt; v < fcu->totvert; v++, bezt++) { add_bezt_to_keycolumns_list(keys, bezt); if (blocks) add_bezt_to_keyblocks_list(blocks, fcu->bezt, bezt); } /* update the number of curves that elements have appeared in */ if (keys) set_touched_actkeycolumn(keys->root); if (blocks) set_touched_actkeyblock(blocks->root); /* unapply NLA-mapping if applicable */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, fcu, 1, 0); } }
/* this function is responsible for mirroring keyframes */ static void mirror_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; BeztEditData bed; BeztEditFunc edit_cb; /* get beztriple editing callbacks */ edit_cb= ANIM_editkeyframes_mirror(mode); memset(&bed, 0, sizeof(BeztEditData)); bed.scene= ac->scene; /* for 'first selected marker' mode, need to find first selected marker first! */ // XXX should this be made into a helper func in the API? if (mode == ACTKEYS_MIRROR_MARKER) { TimeMarker *marker= NULL; /* find first selected marker */ if (ac->markers) { for (marker= ac->markers->first; marker; marker=marker->next) { if (marker->flag & SELECT) { break; } } } /* store marker's time (if available) */ if (marker) bed.f1= (float)marker->frame; else return; } /* filter data */ if (ac->datatype == ANIMCONT_GPENCIL) filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT); else filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* mirror keyframes */ for (ale= anim_data.first; ale; ale= ale->next) { AnimData *adt= ANIM_nla_mapping_get(ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } //else if (ale->type == ACTTYPE_GPLAYER) // snap_gplayer_frames(ale->data, mode); else ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve); } BLI_freelistN(&anim_data); }
static void graphkeys_select_leftright(bAnimContext *ac, short leftright, short select_mode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditFunc ok_cb, select_cb; KeyframeEditData ked = {{NULL}}; Scene *scene = ac->scene; /* if select mode is replace, deselect all keyframes (and channels) first */ if (select_mode == SELECT_REPLACE) { select_mode = SELECT_ADD; /* - deselect all other keyframes, so that just the newly selected remain * - channels aren't deselected, since we don't re-select any as a consequence */ deselect_graph_keys(ac, 0, SELECT_SUBTRACT, false); } /* set callbacks and editing data */ ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); select_cb = ANIM_editkeyframes_select(select_mode); if (leftright == GRAPHKEYS_LRSEL_LEFT) { ked.f1 = MINAFRAMEF; ked.f2 = (float)(CFRA + 0.1f); } else { ked.f1 = (float)(CFRA - 0.1f); ked.f2 = MAXFRAMEF; } /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* select keys */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); } /* Cleanup */ BLI_freelistN(&anim_data); }
/* this function is responsible for mirroring keyframes */ static void mirror_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditData ked = {{NULL}}; KeyframeEditFunc edit_cb; /* get beztriple editing callbacks */ edit_cb = ANIM_editkeyframes_mirror(mode); ked.scene = ac->scene; /* for 'first selected marker' mode, need to find first selected marker first! */ /* XXX should this be made into a helper func in the API? */ if (mode == ACTKEYS_MIRROR_MARKER) { TimeMarker *marker = ED_markers_get_first_selected(ac->markers); if (marker) ked.f1 = (float)marker->frame; else return; } /* filter data */ if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); else filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* mirror keyframes */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } //else if (ale->type == ACTTYPE_GPLAYER) // snap_gplayer_frames(ale->data, mode); else ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); ale->update |= ANIM_UPDATE_DEFAULT; } ANIM_animdata_update(ac, &anim_data); ANIM_animdata_freelist(&anim_data); }
/* this function is responsible for snapping keyframes to frame-times */ static void snap_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditData ked = {{NULL}}; KeyframeEditFunc edit_cb; /* filter data */ if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); else filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* get beztriple editing callbacks */ edit_cb = ANIM_editkeyframes_snap(mode); ked.scene = ac->scene; if (mode == ACTKEYS_SNAP_NEAREST_MARKER) { ked.list.first = (ac->markers) ? ac->markers->first : NULL; ked.list.last = (ac->markers) ? ac->markers->last : NULL; } /* snap keyframes */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (ale->type == ANIMTYPE_GPLAYER) { ED_gplayer_snap_frames(ale->data, ac->scene, mode); } else if (ale->type == ANIMTYPE_MASKLAYER) { ED_masklayer_snap_frames(ale->data, ac->scene, mode); } else if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); } ale->update |= ANIM_UPDATE_DEFAULT; } ANIM_animdata_update(ac, &anim_data); ANIM_animdata_freelist(&anim_data); }
/* TODO, this is almost an _exact_ duplicate of a function of the same name in graph_select.c * should de-duplicate - campbell */ static void markers_selectkeys_between(bAnimContext *ac) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditFunc ok_cb, select_cb; KeyframeEditData ked = {{NULL}}; float min, max; /* get extreme markers */ ED_markers_get_minmax(ac->markers, 1, &min, &max); min -= 0.5f; max += 0.5f; /* get editing funcs + data */ ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); select_cb = ANIM_editkeyframes_select(SELECT_ADD); ked.f1 = min; ked.f2 = max; /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* select keys in-between */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else if (ale->type == ANIMTYPE_GPLAYER) { ED_gplayer_frames_select_border(ale->data, min, max, SELECT_ADD); } else if (ale->type == ANIMTYPE_MASKLAYER) { ED_masklayer_frames_select_border(ale->data, min, max, SELECT_ADD); } else { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); } } /* Cleanup */ ANIM_animdata_freelist(&anim_data); }
/* snap current-frame indicator to 'average time' of selected keyframe */ static int actkeys_framejump_exec(bContext *C, wmOperator *op) { bAnimContext ac; ListBase anim_data= {NULL, NULL}; bAnimListElem *ale; int filter; BeztEditData bed; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* init edit data */ memset(&bed, 0, sizeof(BeztEditData)); /* loop over action data, averaging values */ filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVESONLY); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); for (ale= anim_data.first; ale; ale= ale->next) { AnimData *adt= ANIM_nla_mapping_get(&ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL); } BLI_freelistN(&anim_data); /* set the new current frame value, based on the average time */ if (bed.i1) { Scene *scene= ac.scene; CFRA= (int)floor((bed.f1 / bed.i1) + 0.5f); } /* set notifier that things have changed */ WM_event_add_notifier(C, NC_SCENE|ND_FRAME, ac.scene); return OPERATOR_FINISHED; }
/* snap current-frame indicator to 'average time' of selected keyframe */ static int actkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) { bAnimContext ac; ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditData ked = {{NULL}}; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* init edit data */ /* loop over action data, averaging values */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL); } ANIM_animdata_freelist(&anim_data); /* set the new current frame value, based on the average time */ if (ked.i1) { Scene *scene = ac.scene; CFRA = iroundf(ked.f1 / ked.i1); SUBFRA = 0.f; } /* set notifier that things have changed */ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene); return OPERATOR_FINISHED; }
/* this function is responsible for snapping keyframes to frame-times */ static void snap_action_keys(bAnimContext *ac, short mode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; BeztEditData bed; BeztEditFunc edit_cb; /* filter data */ if (ac->datatype == ANIMCONT_GPENCIL) filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT); else filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* get beztriple editing callbacks */ edit_cb= ANIM_editkeyframes_snap(mode); memset(&bed, 0, sizeof(BeztEditData)); bed.scene= ac->scene; if (mode == ACTKEYS_SNAP_NEAREST_MARKER) { bed.list.first= (ac->markers) ? ac->markers->first : NULL; bed.list.last= (ac->markers) ? ac->markers->last : NULL; } /* snap keyframes */ for (ale= anim_data.first; ale; ale= ale->next) { AnimData *adt= ANIM_nla_mapping_get(ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } //else if (ale->type == ACTTYPE_GPLAYER) // snap_gplayer_frames(ale->data, mode); else ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve); } BLI_freelistN(&anim_data); }
/* This is called twice from space_graph.c -> graph_main_area_draw() * Unselected then selected F-Curves are drawn so that they do not occlude each other. */ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid, short sel) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; /* build list of curves to draw */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE); filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL)); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* for each curve: * draw curve, then handle-lines, and finally vertices in this order so that * the data will be layered correctly */ for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; FModifier *fcm = find_active_fmodifier(&fcu->modifiers); AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* map keyframes for drawing if scaled F-Curve */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); /* draw curve: * - curve line may be result of one or more destructive modifiers or just the raw data, * so we need to check which method should be used * - controls from active modifier take precedence over keyframes * (XXX! editing tools need to take this into account!) */ /* 1) draw curve line */ { /* set color/drawing style for curve itself */ if (BKE_fcurve_is_protected(fcu)) { /* protected curves (non editable) are drawn with dotted lines */ setlinestyle(2); } if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) { /* muted curves are drawn in a grayish hue */ /* XXX should we have some variations? */ UI_ThemeColorShade(TH_HEADER, 50); } else { /* set whatever color the curve has set * - unselected curves draw less opaque to help distinguish the selected ones */ glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], fcurve_display_alpha(fcu)); } /* draw active F-Curve thicker than the rest to make it stand out */ if (fcu->flag & FCURVE_ACTIVE) { glLineWidth(2.0); } /* anti-aliased lines for less jagged appearance */ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); /* draw F-Curve */ if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) { /* draw a curve affected by modifiers or only allowed to have integer values * by sampling it at various small-intervals over the visible region */ draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid); } else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { /* just draw curve based on defined data (i.e. no modifiers) */ if (fcu->bezt) //draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d); draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid); // XXX: better to do an optimised integration here instead, but for now, this works else if (fcu->fpt) draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d); } /* restore settings */ setlinestyle(0); glLineWidth(1.0); if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); } /* 2) draw handles and vertices as appropriate based on active * - if the option to only show controls if the F-Curve is selected is enabled, we must obey this */ if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) { if (fcurve_are_keyframes_usable(fcu) == 0) { /* only draw controls if this is the active modifier */ if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) { switch (fcm->type) { case FMODIFIER_TYPE_ENVELOPE: /* envelope */ draw_fcurve_modifier_controls_envelope(fcm, &ar->v2d); break; } } } else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { short mapping_flag = ANIM_get_normalization_flags(ac); float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag); glPushMatrix(); glScalef(1.0f, unit_scale, 1.0f); if (fcu->bezt) { int do_handles = draw_fcurve_handles_check(sipo, fcu); if (do_handles) { /* only draw handles/vertices on keyframes */ glEnable(GL_BLEND); draw_fcurve_handles(sipo, fcu); glDisable(GL_BLEND); } draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY), unit_scale); } else { /* samples: only draw two indicators at either end as indicators */ draw_fcurve_samples(sipo, ar, fcu); } glPopMatrix(); } } /* 3) draw driver debugging stuff */ if ((ac->datatype == ANIMCONT_DRIVERS) && (fcu->flag & FCURVE_ACTIVE)) { graph_draw_driver_debug(ac, ale->id, fcu); } /* undo mapping of keyframes for drawing if scaled F-Curve */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); } /* free list of curves */ BLI_freelistN(&anim_data); }
/* Borderselect only selects keyframes now, as overshooting handles often get caught too, * which means that they may be inadvertently moved as well. However, incl_handles overrides * this, and allow handles to be considered independently too. * Also, for convenience, handles should get same status as keyframe (if it was within bounds). */ static void borderselect_graphkeys( bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, bool incl_handles, struct KeyframeEdit_LassoData *data_lasso) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter, mapping_flag; SpaceIpo *sipo = (SpaceIpo *)ac->sl; KeyframeEditData ked; KeyframeEditFunc ok_cb, select_cb; View2D *v2d = &ac->ar->v2d; rctf rectf, scaled_rectf; /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* get beztriple editing/validation funcs */ select_cb = ANIM_editkeyframes_select(selectmode); ok_cb = ANIM_editkeyframes_ok(mode); /* init editing data */ memset(&ked, 0, sizeof(KeyframeEditData)); if (data_lasso) { data_lasso->rectf_scaled = &scaled_rectf; ked.data = data_lasso; } else { ked.data = &scaled_rectf; } /* treat handles separately? */ if (incl_handles) { ked.iterflags |= KEYFRAME_ITER_INCL_HANDLES; mapping_flag = 0; } else mapping_flag = ANIM_UNITCONV_ONLYKEYS; mapping_flag |= ANIM_get_normalization_flags(ac); /* loop over data, doing border select */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->key_data; float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag); /* apply NLA mapping to all the keyframes, since it's easier than trying to * guess when a callback might use something different */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0); scaled_rectf.xmin = rectf.xmin; scaled_rectf.xmax = rectf.xmax; scaled_rectf.ymin = rectf.ymin / unit_scale; scaled_rectf.ymax = rectf.ymax / unit_scale; /* set horizontal range (if applicable) * NOTE: these values are only used for x-range and y-range but not region * (which uses ked.data, i.e. rectf) */ if (mode != BEZT_OK_VALUERANGE) { ked.f1 = rectf.xmin; ked.f2 = rectf.xmax; } else { ked.f1 = rectf.ymin; ked.f2 = rectf.ymax; } /* firstly, check if any keyframes will be hit by this */ if (ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, ok_cb, NULL)) { /* select keyframes that are in the appropriate places */ ANIM_fcurve_keyframes_loop(&ked, fcu, ok_cb, select_cb, NULL); /* only change selection of channel when the visibility of keyframes doesn't depend on this */ if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { /* select the curve too now that curve will be touched */ if (selectmode == SELECT_ADD) fcu->flag |= FCURVE_SELECTED; } } /* un-apply NLA mapping from all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0); } /* cleanup */ BLI_freelistN(&anim_data); }
/* helper for find_nearest_fcurve_vert() - build the list of nearest matches */ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], ListBase *matches) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; SpaceIpo *sipo = (SpaceIpo *)ac->sl; View2D *v2d = &ac->ar->v2d; short mapping_flag = 0; /* get curves to search through * - if the option to only show keyframes that belong to selected F-Curves is enabled, * include the 'only selected' flag... */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); if (sipo->flag & SIPO_SELCUVERTSONLY) // FIXME: this should really be check for by the filtering code... filter |= ANIMFILTER_SEL; mapping_flag |= ANIM_get_normalization_flags(ac); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; AnimData *adt = ANIM_nla_mapping_get(ac, ale); float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag); /* apply NLA mapping to all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); if (fcu->bezt) { BezTriple *bezt1 = fcu->bezt, *prevbezt = NULL; int i; for (i = 0; i < fcu->totvert; i++, prevbezt = bezt1, bezt1++) { /* keyframe */ nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_KEY, mval, unit_scale); /* handles - only do them if they're visible */ if (fcurve_handle_sel_check(sipo, bezt1) && (fcu->totvert > 1)) { /* first handle only visible if previous segment had handles */ if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_LEFT, mval, unit_scale); } /* second handle only visible if this segment is bezier */ if (bezt1->ipo == BEZT_IPO_BEZ) { nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_RIGHT, mval, unit_scale); } } } } else if (fcu->fpt) { // TODO; do this for samples too } /* un-apply NLA mapping from all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); } /* free channels */ BLI_freelistN(&anim_data); }
static void actkeys_select_leftright(bAnimContext *ac, short leftright, short select_mode) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; KeyframeEditFunc ok_cb, select_cb; KeyframeEditData ked = {{NULL}}; Scene *scene = ac->scene; /* if select mode is replace, deselect all keyframes (and channels) first */ if (select_mode == SELECT_REPLACE) { select_mode = SELECT_ADD; /* - deselect all other keyframes, so that just the newly selected remain * - channels aren't deselected, since we don't re-select any as a consequence */ deselect_action_keys(ac, 0, SELECT_SUBTRACT); } /* set callbacks and editing data */ ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); select_cb = ANIM_editkeyframes_select(select_mode); if (leftright == ACTKEYS_LRSEL_LEFT) { ked.f1 = MINAFRAMEF; ked.f2 = (float)(CFRA + 0.1f); } else { ked.f1 = (float)(CFRA - 0.1f); ked.f2 = MAXFRAMEF; } /* filter data */ if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS); else filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* select keys */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else if (ale->type == ANIMTYPE_GPLAYER) ED_gplayer_frames_select_border(ale->data, ked.f1, ked.f2, select_mode); else if (ale->type == ANIMTYPE_MASKLAYER) ED_masklayer_frames_select_border(ale->data, ked.f1, ked.f2, select_mode); else ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); } /* Sync marker support */ if (select_mode == SELECT_ADD) { SpaceAction *saction = (SpaceAction *)ac->sl; if ((saction) && (saction->flag & SACTION_MARKERS_MOVE)) { ListBase *markers = ED_animcontext_get_markers(ac); TimeMarker *marker; for (marker = markers->first; marker; marker = marker->next) { if (((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) || ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA))) { marker->flag |= SELECT; } else { marker->flag &= ~SELECT; } } } } /* Cleanup */ ANIM_animdata_freelist(&anim_data); }
/** * This function pastes data from the keyframes copy/paste buffer * * \return Status code is whether the method FAILED to do anything */ short paste_animedit_keys(bAnimContext *ac, ListBase *anim_data, const eKeyPasteOffset offset_mode, const eKeyMergeMode merge_mode, bool flip) { bAnimListElem *ale; const Scene *scene = (ac->scene); const bool from_single = BLI_listbase_is_single(&animcopybuf); const bool to_simple = BLI_listbase_is_single(anim_data); float offset = 0.0f; int pass; /* check if buffer is empty */ if (BLI_listbase_is_empty(&animcopybuf)) { BKE_report(ac->reports, RPT_ERROR, "No animation data in buffer to paste"); return -1; } if (BLI_listbase_is_empty(anim_data)) { BKE_report(ac->reports, RPT_ERROR, "No selected F-Curves to paste into"); return -1; } /* methods of offset */ switch (offset_mode) { case KEYFRAME_PASTE_OFFSET_CFRA_START: offset = (float)(CFRA - animcopy_firstframe); break; case KEYFRAME_PASTE_OFFSET_CFRA_END: offset = (float)(CFRA - animcopy_lastframe); break; case KEYFRAME_PASTE_OFFSET_CFRA_RELATIVE: offset = (float)(CFRA - animcopy_cfra); break; case KEYFRAME_PASTE_OFFSET_NONE: offset = 0.0f; break; } if (from_single && to_simple) { /* 1:1 match, no tricky checking, just paste */ FCurve *fcu; tAnimCopybufItem *aci; ale = anim_data->first; fcu = (FCurve *)ale->data; /* destination F-Curve */ aci = animcopybuf.first; paste_animedit_keys_fcurve(fcu, aci, offset, merge_mode, false); ale->update |= ANIM_UPDATE_DEFAULT; } else { /* from selected channels * This "passes" system aims to try to find "matching" channels to paste keyframes * into with increasingly loose matching heuristics. The process finishes when at least * one F-Curve has been pasted into. */ for (pass = 0; pass < 3; pass++) { unsigned int totmatch = 0; for (ale = anim_data->first; ale; ale = ale->next) { /* find buffer item to paste from * - if names don't matter (i.e. only 1 channel in buffer), don't check id/group * - if names do matter, only check if id-type is ok for now (group check is not that important) * - most importantly, rna-paths should match (array indices are unimportant for now) */ AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->data; /* destination F-Curve */ tAnimCopybufItem *aci = NULL; switch (pass) { case 0: /* most strict, must be exact path match data_path & index */ aci = pastebuf_match_path_full(fcu, from_single, to_simple, flip); break; case 1: /* less strict, just compare property names */ aci = pastebuf_match_path_property(fcu, from_single, to_simple); break; case 2: /* Comparing properties gave no results, so just do index comparisons */ aci = pastebuf_match_index_only(fcu, from_single, to_simple); break; } /* copy the relevant data from the matching buffer curve */ if (aci) { totmatch++; if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); paste_animedit_keys_fcurve(fcu, aci, offset, merge_mode, flip); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else { paste_animedit_keys_fcurve(fcu, aci, offset, merge_mode, flip); } } ale->update |= ANIM_UPDATE_DEFAULT; } /* don't continue if some fcurves were pasted */ if (totmatch) break; } } ANIM_animdata_update(ac, anim_data); return 0; }