Blender V5.3
keyframes_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <cmath>
11#include <cstdlib>
12#include <cstring>
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_function_ref.hh"
17#include "BLI_lasso_2d.hh"
18#include "BLI_listbase.hh"
19#include "BLI_math_vector_c.hh"
20#include "BLI_rect.hh"
21#include "BLI_utildefines.hh"
22
23#include "DNA_anim_types.h"
24#include "DNA_layer_types.h"
25#include "DNA_object_types.h"
26#include "DNA_scene_types.h"
27
28#include "BKE_fcurve.hh"
29#include "BKE_nla.hh"
30
31#include "ED_anim_api.hh"
32#include "ED_keyframes_edit.hh"
33#include "ED_markers.hh"
34
35#include "ANIM_action.hh"
36
37namespace blender {
38
39/* This file defines an API and set of callback-operators for
40 * non-destructive editing of keyframe data.
41 *
42 * Two API functions are defined for actually performing the operations on the data:
43 * ANIM_fcurve_keyframes_loop()
44 * which take the data they operate on, a few callbacks defining what operations to perform.
45 *
46 * As operators which work on keyframes usually apply the same operation on all BezTriples in
47 * every channel, the code has been optimized providing a set of functions which will get the
48 * appropriate bezier-modify function to set. These functions (ANIM_editkeyframes_*) will need
49 * to be called before getting any channels.
50 *
51 * A set of 'validation' callbacks are provided for checking if a BezTriple should be operated on.
52 * These should only be used when using a 'general' BezTriple editor (i.e. selection setters which
53 * don't check existing selection status).
54 *
55 * - Joshua Leung, Dec 2008
56 */
57
58/* ************************************************************************** */
59/* Keyframe Editing Loops - Exposed API */
60
61/* --------------------------- Base Functions ------------------------------------ */
62
64 FCurve *fcu,
65 KeyframeEditFunc key_ok,
66 KeyframeEditFunc key_cb,
67 FcuEditFunc fcu_cb)
68{
69 BezTriple *bezt;
70 short ok = 0;
71 uint i;
72
73 /* sanity check */
74 if (ELEM(nullptr, fcu, fcu->bezt)) {
75 return 0;
76 }
77
78 /* Set the F-Curve into the edit-data so that it can be accessed. */
79 if (ked) {
80 ked->fcu = fcu;
81 ked->curIndex = 0;
83 }
84
85 /* if function to apply to bezier curves is set, then loop through executing it on beztriples */
86 if (key_cb) {
87 /* if there's a validation func, include that check in the loop
88 * (this is should be more efficient than checking for it in every loop)
89 */
90 if (key_ok) {
91 for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) {
92 if (ked) {
93 /* advance the index, and reset the ok flags (to not influence the result) */
94 ked->curIndex = i;
96 }
97
98 /* Only operate on this BezTriple if it fulfills the criteria of the validation func */
99 if ((ok = key_ok(ked, bezt))) {
100 if (ked) {
101 ked->curflags = eKeyframeVertOk(ok);
102 }
103
104 /* Exit with return-code '1' if function returns positive
105 * This is useful if finding if some BezTriple satisfies a condition.
106 */
107 if (key_cb(ked, bezt)) {
108 return 1;
109 }
110 }
111 }
112 }
113 else {
114 for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) {
115 if (ked) {
116 ked->curIndex = i;
117 }
118
119 /* Exit with return-code '1' if function returns positive
120 * This is useful if finding if some BezTriple satisfies a condition.
121 */
122 if (key_cb(ked, bezt)) {
123 return 1;
124 }
125 }
126 }
127 }
128
129 /* Unset the F-Curve from the edit-data now that it's done. */
130 if (ked) {
131 ked->fcu = nullptr;
132 ked->curIndex = 0;
133 ked->curflags = KEYFRAME_NONE;
134 }
135
136 /* if fcu_cb (F-Curve post-editing callback) has been specified then execute it */
137 if (fcu_cb) {
138 fcu_cb(*fcu);
139 }
140
141 /* done */
142 return 0;
143}
144
145/* --------------------- Further Abstracted (Not Exposed Directly) ----------------------------- */
146
147/* This function is used to loop over the keyframe data in an Action Group */
149 bActionGroup *agrp,
150 KeyframeEditFunc key_ok,
151 KeyframeEditFunc key_cb,
152 FcuEditFunc fcu_cb)
153{
154 /* sanity check */
155 if (agrp == nullptr) {
156 return 0;
157 }
158
159 /* Layered actions. */
160 animrig::Channelbag &channelbag = agrp->channelbag->wrap();
161 Span<FCurve *> fcurves = channelbag.fcurves().slice(agrp->fcurve_range_start,
162 agrp->fcurve_range_length);
163 for (FCurve *fcurve : fcurves) {
164 if (ANIM_fcurve_keyframes_loop(ked, fcurve, key_ok, key_cb, fcu_cb)) {
165 return 1;
166 }
167 }
168
169 return 0;
170}
171
172/* Loop over all keyframes in the layered Action. */
174 animrig::Action &action,
175 animrig::Slot *slot,
176 KeyframeEditFunc key_ok,
177 KeyframeEditFunc key_cb,
178 FcuEditFunc fcu_cb)
179{
180 if (!slot) {
181 /* Valid situation, and will not have any FCurves. */
182 return 0;
183 }
184
186 for (FCurve *fcurve : fcurves) {
187 if (ANIM_fcurve_keyframes_loop(ked, fcurve, key_ok, key_cb, fcu_cb)) {
188 return 1;
189 }
190 }
191 return 0;
192}
193
194/* This function is used to loop over the keyframe data in an Action */
196 bAction *act,
197 KeyframeEditFunc key_ok,
198 KeyframeEditFunc key_cb,
199 FcuEditFunc fcu_cb)
200{
201 /* sanity check */
202 if (act == nullptr) {
203 return 0;
204 }
205
206 /* just loop through all F-Curves */
207 for (FCurve &fcu : act->curves) {
208 if (ANIM_fcurve_keyframes_loop(ked, &fcu, key_ok, key_cb, fcu_cb)) {
209 return 1;
210 }
211 }
212
213 return 0;
214}
215
216/* This function is used to loop over the keyframe data in an Object */
218 bDopeSheet *ads,
219 Object *ob,
220 KeyframeEditFunc key_ok,
221 KeyframeEditFunc key_cb,
222 FcuEditFunc fcu_cb)
223{
224 bAnimContext ac = {nullptr};
225 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
226 int filter;
227 int ret = 0;
228
229 bAnimListElem dummy_chan = {nullptr};
230 Base dummy_base = {nullptr};
231
232 if (ob == nullptr) {
233 return 0;
234 }
235
236 /* create a dummy wrapper data to work with */
237 dummy_base.object = ob;
238
239 dummy_chan.type = ANIMTYPE_OBJECT;
240 dummy_chan.data = &dummy_base;
241 dummy_chan.id = &ob->id;
242 dummy_chan.adt = ob->adt;
243
244 ac.ads = ads;
245 ac.data = &dummy_chan;
249
250 /* get F-Curves to take keyframes from */
253 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
254
255 /* Loop through each F-Curve, applying the operation as required,
256 * but stopping on the first one. */
257 for (bAnimListElem &ale : anim_data) {
258 if (ANIM_fcurve_keyframes_loop(ked, static_cast<FCurve *>(ale.data), key_ok, key_cb, fcu_cb)) {
259 ret = 1;
260 break;
261 }
262 }
263
264 ANIM_animdata_freelist(&anim_data);
265
266 /* Return the return code (defaults to zero if nothing happened). */
267 return ret;
268}
269
270/* This function is used to loop over the keyframe data in a Scene */
272 bDopeSheet *ads,
273 Scene *sce,
274 KeyframeEditFunc key_ok,
275 KeyframeEditFunc key_cb,
276 FcuEditFunc fcu_cb)
277{
278 bAnimContext ac = {nullptr};
279 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
280 int filter;
281 int ret = 0;
282
283 bAnimListElem dummy_chan = {nullptr};
284
285 if (sce == nullptr) {
286 return 0;
287 }
288
289 /* create a dummy wrapper data to work with */
290 dummy_chan.type = ANIMTYPE_SCENE;
291 dummy_chan.data = sce;
292 dummy_chan.id = &sce->id;
293 dummy_chan.adt = sce->adt;
294
295 ac.ads = ads;
296 ac.data = &dummy_chan;
300
301 /* get F-Curves to take keyframes from */
304 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
305
306 /* Loop through each F-Curve, applying the operation as required,
307 * but stopping on the first one. */
308 for (bAnimListElem &ale : anim_data) {
309 if (ANIM_fcurve_keyframes_loop(ked, static_cast<FCurve *>(ale.data), key_ok, key_cb, fcu_cb)) {
310 ret = 1;
311 break;
312 }
313 }
314
315 ANIM_animdata_freelist(&anim_data);
316
317 /* Return the return code (defaults to zero if nothing happened). */
318 return ret;
319}
320
321/* This function is used to loop over the keyframe data in a DopeSheet summary */
323 bAnimContext *ac,
324 KeyframeEditFunc key_ok,
325 KeyframeEditFunc key_cb,
326 FcuEditFunc fcu_cb)
327{
328 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
329 int filter, ret_code = 0;
330
331 /* sanity check */
332 if (ac == nullptr) {
333 return 0;
334 }
335
336 /* get F-Curves to take keyframes from */
339 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
340
341 /* loop through each F-Curve, working on the keyframes until the first curve aborts */
342 for (bAnimListElem &ale : anim_data) {
343 switch (ale.datatype) {
344 case ALE_MASKLAY:
345 case ALE_GPFRAME:
347 break;
348
349 case ALE_FCURVE:
350 default: {
351 if (ked && ked->iterflags) {
352 /* make backups of the current values, so that a localized fix
353 * (e.g. NLA time remapping) can be applied to these values
354 */
355 float f1 = ked->f1;
356 float f2 = ked->f2;
357
358 if (ked->iterflags & KED_F1_NLA_UNMAP) {
360 }
361 if (ked->iterflags & KED_F2_NLA_UNMAP) {
363 }
364
365 /* now operate on the channel as per normal */
367 ked, static_cast<FCurve *>(ale.data), key_ok, key_cb, fcu_cb);
368
369 /* reset */
370 ked->f1 = f1;
371 ked->f2 = f2;
372 }
373 else {
374 /* no special handling required... */
376 ked, static_cast<FCurve *>(ale.data), key_ok, key_cb, fcu_cb);
377 }
378 break;
379 }
380 }
381
382 if (ret_code) {
383 break;
384 }
385 }
386
387 ANIM_animdata_freelist(&anim_data);
388
389 return ret_code;
390}
391
392/* --- */
393
395 bDopeSheet *ads,
396 bAnimListElem *ale,
397 KeyframeEditFunc key_ok,
398 KeyframeEditFunc key_cb,
399 FcuEditFunc fcu_cb)
400{
401 /* sanity checks */
402 if (ale == nullptr) {
403 return 0;
404 }
405
406 /* method to use depends on the type of keyframe data */
407 switch (ale->datatype) {
408 /* direct keyframe data (these loops are exposed) */
409 case ALE_FCURVE: /* F-Curve */
411 ked, static_cast<FCurve *>(ale->key_data), key_ok, key_cb, fcu_cb);
412
413 /* indirect 'summaries' (these are not exposed directly)
414 * NOTE: must keep this code in sync with the drawing code and also the filtering code!
415 */
416 case ALE_GROUP: /* action group */
417 return agrp_keyframes_loop(
418 ked, static_cast<bActionGroup *>(ale->data), key_ok, key_cb, fcu_cb);
419 case ALE_ACTION_LAYERED: { /* Layered Action. */
420 /* This assumes that the ALE_ACTION_LAYERED channel is shown in the dope-sheet context,
421 * underneath the data-block that owns `ale->adt`. So that means that the loop is limited to
422 * the keys that belong to that slot. */
423 animrig::Action &action = static_cast<bAction *>(ale->key_data)->wrap();
424 animrig::Slot *slot = action.slot_for_handle(ale->adt->slot_handle);
425 return action_layered_keyframes_loop(ked, action, slot, key_ok, key_cb, fcu_cb);
426 }
427 case ALE_ACTION_SLOT: {
428 animrig::Action *action = static_cast<animrig::Action *>(ale->key_data);
429 BLI_assert(action);
430 animrig::Slot *slot = static_cast<animrig::Slot *>(ale->data);
431 return action_layered_keyframes_loop(ked, *action, slot, key_ok, key_cb, fcu_cb);
432 }
433
434 case ALE_ACT: /* Legacy Action. */
436 ked, static_cast<bAction *>(ale->key_data), key_ok, key_cb, fcu_cb);
437 case ALE_OB: /* object */
438 return ob_keyframes_loop(
439 ked, ads, static_cast<Object *>(ale->key_data), key_ok, key_cb, fcu_cb);
440 case ALE_SCE: /* scene */
442 ked, ads, static_cast<Scene *>(ale->data), key_ok, key_cb, fcu_cb);
443 case ALE_ALL: /* 'all' (DopeSheet summary) */
445 ked, static_cast<bAnimContext *>(ale->data), key_ok, key_cb, fcu_cb);
446
447 case ALE_NONE:
448 case ALE_GPFRAME:
449 case ALE_MASKLAY:
450 case ALE_NLASTRIP:
454 break;
455 }
456
457 return 0;
458}
459
462 KeyframeEditFunc callback_fn)
463{
464 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
465
467 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
468
469 for (bAnimListElem &ale : anim_data) {
471 static_cast<FCurve *>(ale.key_data),
472 nullptr,
473 callback_fn,
475 ale.update |= ANIM_UPDATE_DEFAULT;
476 }
477
478 ANIM_animdata_update(ac, &anim_data);
479 ANIM_animdata_freelist(&anim_data);
480}
481
482/* ************************************************************************** */
483/* Keyframe Integrity Tools */
484
486{
487 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
488 int filter;
489
490 /* filter animation data */
493 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
494
495 /* Loop over F-Curves that are likely to have been edited, and tag them to
496 * ensure the keyframes are in order and handles are in a valid position. */
497 for (bAnimListElem &ale : anim_data) {
499 }
500
501 /* free temp data */
502 ANIM_animdata_update(ac, &anim_data);
503 ANIM_animdata_freelist(&anim_data);
504}
505
506/* ************************************************************************** */
507/* BezTriple Validation Callbacks */
508
509/* ------------------------ */
510
512{
513 const bool handles_shown = (ked->iterflags & KEYFRAME_ITER_HANDLES_INVISIBLE) == 0;
514 if (!handles_shown) {
515 return false;
516 }
517 const bool handles_shown_only_selected = ked->iterflags &
519
520 return handles_shown_only_selected ? BEZT_ISSEL_ANY(bezt) : true;
521}
522
524 KeyframeEditData *ked,
525 BezTriple *bezt,
526 FunctionRef<bool(KeyframeEditData *ked, BezTriple *bezt, const int index)> check)
527{
528 short ok = 0;
529 if (check(ked, bezt, 1)) {
530 ok |= KEYFRAME_OK_KEY;
531 }
532 /* Only act on visible items, so check handle visibility state. */
533 if (ked && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) {
534 if (handles_visible(ked, bezt)) {
535 if (check(ked, bezt, 0)) {
536 ok |= KEYFRAME_OK_H1;
537 }
538 if (check(ked, bezt, 2)) {
539 ok |= KEYFRAME_OK_H2;
540 }
541 }
542 }
543 return ok;
544}
545
546/* ------------------------ */
547
549{
550 /* frame is stored in f1 property (this float accuracy check may need to be dropped?) */
551 const short ok = keyframe_ok_checks(
552 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
553 return IS_EQF(bezt->vec[index][0], ked->f1);
554 });
555
556 return ok;
557}
558
560{
561 const short ok = keyframe_ok_checks(
562 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
563 return (bezt->vec[index][0] > ked->f1) && (bezt->vec[index][0] < ked->f2);
564 });
565
566 return ok;
567}
568
569static short ok_bezier_selected(KeyframeEditData * /*ked*/, BezTriple *bezt)
570{
571 /* this macro checks all beztriple handles for selection...
572 * only one of the verts has to be selected for this to be ok...
573 */
574 if (BEZT_ISSEL_ANY(bezt)) {
575 return KEYFRAME_OK_ALL;
576 }
577 return 0;
578}
579
581{
582 /* This macro checks the beztriple key (f2) selection. */
583 if (BEZT_ISSEL_IDX(bezt, 1)) {
584 return KEYFRAME_OK_KEY;
585 }
586 return 0;
587}
588
590{
591 /* Value is stored in f1 property:
592 * - This float accuracy check may need to be dropped?
593 * - Should value be stored in f2 instead
594 * so that we won't have conflicts when using f1 for frames too?
595 */
596 const short ok = keyframe_ok_checks(
597 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
598 return IS_EQF(bezt->vec[index][1], ked->f1);
599 });
600
601 return ok;
602}
603
605{
606 /* value range is stored in float properties */
607 const short ok = keyframe_ok_checks(
608 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
609 return (bezt->vec[index][1] > ked->f1) && (bezt->vec[index][1] < ked->f2);
610 });
611
612 return ok;
613}
614
616{
617 /* rect is stored in data property (it's of type rectf, but may not be set) */
618 if (!ked->data) {
619 return 0;
620 }
621
622 const short ok = keyframe_ok_checks(
623 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
624 return BLI_rctf_isect_pt_v(static_cast<rctf *>(ked->data), bezt->vec[index]);
625 });
626
627 return ok;
628}
629
630bool keyframe_region_lasso_test(const KeyframeEdit_LassoData *data_lasso, const float xy[2])
631{
632 if (BLI_rctf_isect_pt_v(data_lasso->rectf_scaled, xy)) {
633 float xy_view[2];
634
635 BLI_rctf_transform_pt_v(data_lasso->rectf_view, data_lasso->rectf_scaled, xy_view, xy);
636
637 if (BLI_lasso_is_point_inside(data_lasso->mcoords, xy_view[0], xy_view[1], INT_MAX)) {
638 return true;
639 }
640 }
641
642 return false;
643}
644
646{
647 /* check for lasso customdata (KeyframeEdit_LassoData) */
648 if (!ked->data) {
649 return 0;
650 }
651
652 const short ok = keyframe_ok_checks(
653 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
654 return keyframe_region_lasso_test(static_cast<KeyframeEdit_LassoData *>(ked->data),
655 bezt->vec[index]);
656 });
657
658 return ok;
659}
660
662{
663 /* check for lasso customdata (KeyframeEdit_LassoData) */
664 if (ked->data) {
666 float pt[2];
667
668 /* late-binding remap of the x values (for summary channels) */
669 /* XXX: Ideally we reset, but it should be fine just leaving it as-is
670 * as the next channel will reset it properly, while the next summary-channel
671 * curve will also reset by itself...
672 */
674 data->rectf_scaled->xmin = ked->f1;
675 data->rectf_scaled->xmax = ked->f2;
676 }
677
678 /* only use the x-coordinate of the point; the y is the channel range... */
679 pt[0] = bezt->vec[1][0];
680 pt[1] = ked->channel_y;
681
683 return KEYFRAME_OK_KEY;
684 }
685 }
686 return 0;
687}
688
689bool keyframe_region_circle_test(const KeyframeEdit_CircleData *data_circle, const float xy[2])
690{
691 if (BLI_rctf_isect_pt_v(data_circle->rectf_scaled, xy)) {
692 float xy_view[2];
693
694 BLI_rctf_transform_pt_v(data_circle->rectf_view, data_circle->rectf_scaled, xy_view, xy);
695
696 xy_view[0] = xy_view[0] - data_circle->mval[0];
697 xy_view[1] = xy_view[1] - data_circle->mval[1];
698 return len_squared_v2(xy_view) < data_circle->radius_squared;
699 }
700
701 return false;
702}
703
705{
706 /* check for circle select customdata (KeyframeEdit_CircleData) */
707 if (!ked->data) {
708 return 0;
709 }
710
711 const short ok = keyframe_ok_checks(
712 ked, bezt, [](KeyframeEditData *ked, BezTriple *bezt, int index) -> bool {
713 return keyframe_region_circle_test(static_cast<KeyframeEdit_CircleData *>(ked->data),
714 bezt->vec[index]);
715 });
716
717 return ok;
718}
719
721{
722 /* check for circle select customdata (KeyframeEdit_CircleData) */
723 if (ked->data) {
725 float pt[2];
726
727 /* late-binding remap of the x values (for summary channels) */
728 /* XXX: Ideally we reset, but it should be fine just leaving it as-is
729 * as the next channel will reset it properly, while the next summary-channel
730 * curve will also reset by itself...
731 */
733 data->rectf_scaled->xmin = ked->f1;
734 data->rectf_scaled->xmax = ked->f2;
735 }
736
737 /* only use the x-coordinate of the point; the y is the channel range... */
738 pt[0] = bezt->vec[1][0];
739 pt[1] = ked->channel_y;
740
742 return KEYFRAME_OK_KEY;
743 }
744 }
745 return 0;
746}
747
749{
750 /* eEditKeyframes_Validate */
751 switch (mode) {
752 case BEZT_OK_FRAME:
753 /* only if bezt falls on the right frame (float) */
754 return ok_bezier_frame;
756 /* only if bezt falls within the specified frame range (floats) */
758 case BEZT_OK_SELECTED:
759 /* only if bezt is selected (any of f1, f2, f3) */
760 return ok_bezier_selected;
762 /* only if bezt is selected (f2 is enough) */
764 case BEZT_OK_VALUE:
765 /* only if bezt value matches (float) */
766 return ok_bezier_value;
768 /* only if bezier falls within the specified value range (floats) */
770 case BEZT_OK_REGION:
771 /* only if bezier falls within the specified rect (data -> rectf) */
772 return ok_bezier_region;
774 /* only if the point falls within KeyframeEdit_LassoData defined data */
777 /* only if the point falls within KeyframeEdit_CircleData defined data */
780 /* same as BEZT_OK_REGION_LASSO, but we're only using the x-value of the points */
783 /* same as BEZT_OK_REGION_CIRCLE, but we're only using the x-value of the points */
785 default: /* nothing was ok */
786 return nullptr;
787 }
788}
789
790/* ******************************************* */
791/* Assorted Utility Functions */
792
794{
795 /* only if selected */
796 if (bezt->f2 & SELECT) {
797 /* store average time in float 1 (only do rounding at last step) */
798 ked->f1 += bezt->vec[1][0];
799
800 /* store average value in float 2 (only do rounding at last step)
801 * - this isn't always needed, but some operators may also require this
802 */
803 ked->f2 += bezt->vec[1][1];
804
805 /* increment number of items */
806 ked->i1++;
807 }
808
809 return 0;
810}
811
813{
814 /* only if selected */
815 if ((bezt->f2 & SELECT) == 0) {
816 return 0;
817 }
818
819 CfraElem *ce = MEM_new_zeroed<CfraElem>("cfraElem");
820 BLI_addtail(&ked->cfra_elem_list, ce);
821
822 /* bAnimListElem so we can do NLA mapping, we want the cfra to be in "global" time */
823 bAnimListElem *ale = static_cast<bAnimListElem *>(ked->data);
824 if (ale != nullptr) {
825 ce->cfra = ANIM_nla_tweakedit_remap(ale, bezt->vec[1][0], NLATIME_CONVERT_MAP);
826 }
827 else {
828 ce->cfra = bezt->vec[1][0];
829 }
830
831 return 0;
832}
833
835{
836 KeyframeEditCD_Remap *rmap = static_cast<KeyframeEditCD_Remap *>(ked->data);
837 const float scale = (rmap->newMax - rmap->newMin) / (rmap->oldMax - rmap->oldMin);
838
839 /* perform transform on all three handles unless indicated otherwise */
840 /* TODO: need to include some checks for that */
841
842 bezt->vec[0][0] = scale * (bezt->vec[0][0] - rmap->oldMin) + rmap->newMin;
843 bezt->vec[1][0] = scale * (bezt->vec[1][0] - rmap->oldMin) + rmap->newMin;
844 bezt->vec[2][0] = scale * (bezt->vec[2][0] - rmap->oldMin) + rmap->newMin;
845}
846
847/* ******************************************* */
848/* Transform */
849
850/* snaps the keyframe to the nearest frame */
851static short snap_bezier_nearest(KeyframeEditData * /*ked*/, BezTriple *bezt)
852{
853 if (bezt->f2 & SELECT) {
854 BKE_fcurve_keyframe_move_time_with_handles(bezt, floorf(bezt->vec[1][0] + 0.5f));
855 }
856 return 0;
857}
858
859/* snaps the keyframe to the nearest second */
861{
862 const Scene *scene = ked->scene;
863 const float secf = float(scene->frames_per_second());
864
865 if (bezt->f2 & SELECT) {
866 BKE_fcurve_keyframe_move_time_with_handles(bezt, floorf(bezt->vec[1][0] / secf + 0.5f) * secf);
867 }
868 return 0;
869}
870
871/* snaps the keyframe to the current frame */
873{
874 const Scene *scene = ked->scene;
875 if (bezt->f2 & SELECT) {
877 }
878 return 0;
879}
880
881/* snaps the keyframe time to the nearest marker's frame */
883{
884 if (bezt->f2 & SELECT) {
886 bezt, float(ED_markers_find_nearest_marker_time(&ked->time_marker_list, bezt->vec[1][0])));
887 }
888 return 0;
889}
890
891/* make the handles have the same value as the key */
893{
894 if (bezt->f2 & SELECT) {
895 bezt->vec[0][1] = bezt->vec[2][1] = bezt->vec[1][1];
896
897 if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) {
898 bezt->h1 = HD_ALIGN;
899 }
900 if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) {
901 bezt->h2 = HD_ALIGN;
902 }
903 }
904 return 0;
905}
906
907/* frame to snap to is stored in the custom data -> first float value slot */
909{
910 if (bezt->f2 & SELECT) {
912 }
913 return 0;
914}
915
916/* value to snap to is stored in the custom data -> first float value slot */
918{
919 if (bezt->f2 & SELECT) {
921 }
922 return 0;
923}
924
926{
927 /* eEditKeyframes_Snap */
928 switch (mode) {
929 case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */
930 return snap_bezier_nearest;
931 case SNAP_KEYS_CURFRAME: /* snap to current frame */
932 return snap_bezier_cframe;
933 case SNAP_KEYS_NEARMARKER: /* snap to nearest marker */
935 case SNAP_KEYS_NEARSEC: /* snap to nearest second */
937 case SNAP_KEYS_HORIZONTAL: /* snap handles to same value */
939 case SNAP_KEYS_TIME: /* snap to given frame/time */
940 return snap_bezier_time;
941 case SNAP_KEYS_VALUE: /* snap to given value */
942 return snap_bezier_value;
943 default: /* just in case */
944 return snap_bezier_nearest;
945 }
946}
947
948/* --------- */
949
950static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center)
951{
952 for (int i = 0; i < 3; i++) {
953 float diff = (center - bezt->vec[i][0]);
954 bezt->vec[i][0] = (center + diff);
955 }
956 swap_v3_v3(bezt->vec[0], bezt->vec[2]);
957
958 std::swap(bezt->h1, bezt->h2);
959 std::swap(bezt->f1, bezt->f3);
960}
961
962static void mirror_bezier_yaxis_ex(BezTriple *bezt, const float center)
963{
964 for (int i = 0; i < 3; i++) {
965 float diff = (center - bezt->vec[i][1]);
966 bezt->vec[i][1] = (center + diff);
967 }
968}
969
971{
972 const Scene *scene = ked->scene;
973
974 if (bezt->f2 & SELECT) {
975 mirror_bezier_xaxis_ex(bezt, scene->r.cfra);
976 }
977
978 return 0;
979}
980
981static short mirror_bezier_yaxis(KeyframeEditData * /*ked*/, BezTriple *bezt)
982{
983 if (bezt->f2 & SELECT) {
984 /* Yes, names are inverted, we are mirroring across y axis, hence along x axis... */
985 mirror_bezier_xaxis_ex(bezt, 0.0f);
986 }
987
988 return 0;
989}
990
991static short mirror_bezier_xaxis(KeyframeEditData * /*ked*/, BezTriple *bezt)
992{
993 if (bezt->f2 & SELECT) {
994 /* Yes, names are inverted, we are mirroring across x axis, hence along y axis... */
995 mirror_bezier_yaxis_ex(bezt, 0.0f);
996 }
997
998 return 0;
999}
1000
1002{
1003 /* mirroring time stored in f1 */
1004 if (bezt->f2 & SELECT) {
1005 mirror_bezier_xaxis_ex(bezt, ked->f1);
1006 }
1007
1008 return 0;
1009}
1010
1012{
1013 /* value to mirror over is stored in f1 */
1014 if (bezt->f2 & SELECT) {
1015 mirror_bezier_xaxis_ex(bezt, ked->f1);
1016 }
1017
1018 return 0;
1019}
1020
1022{
1023 /* value to mirror over is stored in the custom data -> first float value slot */
1024 if (bezt->f2 & SELECT) {
1025 mirror_bezier_yaxis_ex(bezt, ked->f1);
1026 }
1027
1028 return 0;
1029}
1030
1032{
1033 switch (mode) {
1034 case MIRROR_KEYS_CURFRAME: /* mirror over current frame */
1035 return mirror_bezier_cframe;
1036 case MIRROR_KEYS_YAXIS: /* mirror over frame 0 */
1037 return mirror_bezier_yaxis;
1038 case MIRROR_KEYS_XAXIS: /* mirror over value 0 */
1039 return mirror_bezier_xaxis;
1040 case MIRROR_KEYS_MARKER: /* mirror over marker */
1041 return mirror_bezier_marker;
1042 case MIRROR_KEYS_TIME: /* mirror over frame/time */
1043 return mirror_bezier_time;
1044 case MIRROR_KEYS_VALUE: /* mirror over given value */
1045 return mirror_bezier_value;
1046 default: /* just in case */
1047 return mirror_bezier_yaxis;
1048 }
1049}
1050
1051/* ******************************************* */
1052/* Settings */
1053
1059#define ENSURE_HANDLES_MATCH(bezt) \
1060 if (bezt->h1 != bezt->h2) { \
1061 if (ELEM(bezt->h1, HD_ALIGN, HD_AUTO, HD_AUTO_ANIM)) { \
1062 bezt->h1 = HD_FREE; \
1063 } \
1064 if (ELEM(bezt->h2, HD_ALIGN, HD_AUTO, HD_AUTO_ANIM)) { \
1065 bezt->h2 = HD_FREE; \
1066 } \
1067 } \
1068 (void)0
1069
1070/* Sets the selected bezier handles to type 'auto' */
1071static short set_bezier_auto(KeyframeEditData * /*ked*/, BezTriple *bezt)
1072{
1073 if (BEZT_ISSEL_ANY(bezt)) {
1074 /* Setting one handle to `HD_AUTO` is not a valid state. Both need to be the same. */
1075 bezt->h1 = bezt->h2 = HD_AUTO;
1076 }
1077 return 0;
1078}
1079
1080/* Sets the selected bezier handles to type 'auto-clamped'
1081 * NOTE: this is like auto above, but they're handled a bit different
1082 */
1084{
1085 if (BEZT_ISSEL_ANY(bezt)) {
1086 /* Setting one handle to `HD_AUTO_ANIM` is not a valid state. Both need to be the same. */
1087 bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
1088 }
1089 return 0;
1090}
1091
1092/* Sets the selected bezier handles to type 'vector'. */
1093static short set_bezier_vector(KeyframeEditData * /*ked*/, BezTriple *bezt)
1094{
1095 /* If the key is selected, always apply to both handles. */
1096 if (bezt->f2 & SELECT) {
1097 bezt->h1 = bezt->h2 = HD_VECT;
1098 }
1099 else {
1100 if (bezt->f1 & SELECT) {
1101 bezt->h1 = HD_VECT;
1103 }
1104 if (bezt->f3 & SELECT) {
1105 bezt->h2 = HD_VECT;
1107 }
1108 }
1109
1110 return 0;
1111}
1112
1119static short bezier_isfree(KeyframeEditData * /*ked*/, BezTriple *bezt)
1120{
1121 if ((bezt->f1 & SELECT) && (bezt->h1)) {
1122 return 1;
1123 }
1124 if ((bezt->f3 & SELECT) && (bezt->h2)) {
1125 return 1;
1126 }
1127 return 0;
1128}
1129
1130/* Sets selected bezier handles to type 'align' */
1131static short set_bezier_align(KeyframeEditData * /*ked*/, BezTriple *bezt)
1132{
1133 if (bezt->f2 & SELECT) {
1134 bezt->h1 = bezt->h2 = HD_ALIGN;
1135 }
1136 else {
1137 if (bezt->f1 & SELECT) {
1138 bezt->h1 = HD_ALIGN;
1140 }
1141 if (bezt->f3 & SELECT) {
1142 bezt->h2 = HD_ALIGN;
1144 }
1145 }
1146 return 0;
1147}
1148
1149/* Sets selected bezier handles to type 'free'. */
1150static short set_bezier_free(KeyframeEditData * /*ked*/, BezTriple *bezt)
1151{
1152 /* If the key is selected, always apply to both handles. */
1153 if (bezt->f2 & SELECT) {
1154 bezt->h1 = bezt->h2 = HD_FREE;
1155 }
1156 else {
1157 if (bezt->f1 & SELECT) {
1158 bezt->h1 = HD_FREE;
1160 }
1161 if (bezt->f3 & SELECT) {
1162 bezt->h2 = HD_FREE;
1164 }
1165 }
1166
1167 return 0;
1168}
1169
1171{
1172 switch (mode) {
1173 case HD_AUTO: /* auto */
1174 return set_bezier_auto;
1175 case HD_AUTO_ANIM: /* auto clamped */
1177
1178 case HD_VECT: /* vector */
1179 return set_bezier_vector;
1180 case HD_FREE: /* free */
1181 return set_bezier_free;
1182 case HD_ALIGN: /* align */
1183 return set_bezier_align;
1184
1185 default: /* check for toggle free or align? */
1186 return bezier_isfree;
1187 }
1188}
1189
1190/* ------- */
1191
1192static short set_bezt_constant(KeyframeEditData * /*ked*/, BezTriple *bezt)
1193{
1194 if (bezt->f2 & SELECT) {
1195 bezt->ipo = BEZT_IPO_CONST;
1196 }
1197 return 0;
1198}
1199
1200static short set_bezt_linear(KeyframeEditData * /*ked*/, BezTriple *bezt)
1201{
1202 if (bezt->f2 & SELECT) {
1203 bezt->ipo = BEZT_IPO_LIN;
1204 }
1205 return 0;
1206}
1207
1208static short set_bezt_bezier(KeyframeEditData * /*ked*/, BezTriple *bezt)
1209{
1210 if (bezt->f2 & SELECT) {
1211 bezt->ipo = BEZT_IPO_BEZ;
1212 }
1213 return 0;
1214}
1215
1216static short set_bezt_back(KeyframeEditData * /*ked*/, BezTriple *bezt)
1217{
1218 if (bezt->f2 & SELECT) {
1219 bezt->ipo = BEZT_IPO_BACK;
1220 }
1221 return 0;
1222}
1223
1224static short set_bezt_bounce(KeyframeEditData * /*ked*/, BezTriple *bezt)
1225{
1226 if (bezt->f2 & SELECT) {
1227 bezt->ipo = BEZT_IPO_BOUNCE;
1228 }
1229 return 0;
1230}
1231
1232static short set_bezt_circle(KeyframeEditData * /*ked*/, BezTriple *bezt)
1233{
1234 if (bezt->f2 & SELECT) {
1235 bezt->ipo = BEZT_IPO_CIRC;
1236 }
1237 return 0;
1238}
1239
1240static short set_bezt_cubic(KeyframeEditData * /*ked*/, BezTriple *bezt)
1241{
1242 if (bezt->f2 & SELECT) {
1243 bezt->ipo = BEZT_IPO_CUBIC;
1244 }
1245 return 0;
1246}
1247
1248static short set_bezt_elastic(KeyframeEditData * /*ked*/, BezTriple *bezt)
1249{
1250 if (bezt->f2 & SELECT) {
1251 bezt->ipo = BEZT_IPO_ELASTIC;
1252 }
1253 return 0;
1254}
1255
1256static short set_bezt_expo(KeyframeEditData * /*ked*/, BezTriple *bezt)
1257{
1258 if (bezt->f2 & SELECT) {
1259 bezt->ipo = BEZT_IPO_EXPO;
1260 }
1261 return 0;
1262}
1263
1264static short set_bezt_quad(KeyframeEditData * /*ked*/, BezTriple *bezt)
1265{
1266 if (bezt->f2 & SELECT) {
1267 bezt->ipo = BEZT_IPO_QUAD;
1268 }
1269 return 0;
1270}
1271
1272static short set_bezt_quart(KeyframeEditData * /*ked*/, BezTriple *bezt)
1273{
1274 if (bezt->f2 & SELECT) {
1275 bezt->ipo = BEZT_IPO_QUART;
1276 }
1277 return 0;
1278}
1279
1280static short set_bezt_quint(KeyframeEditData * /*ked*/, BezTriple *bezt)
1281{
1282 if (bezt->f2 & SELECT) {
1283 bezt->ipo = BEZT_IPO_QUINT;
1284 }
1285 return 0;
1286}
1287
1288static short set_bezt_sine(KeyframeEditData * /*ked*/, BezTriple *bezt)
1289{
1290 if (bezt->f2 & SELECT) {
1291 bezt->ipo = BEZT_IPO_SINE;
1292 }
1293 return 0;
1294}
1295
1296static void handle_flatten(float vec[3][3], const int idx, const float direction[2])
1297{
1298 BLI_assert_msg(idx == 0 || idx == 2, "handle_flatten() expects a handle index");
1299
1300 add_v2_v2v2(vec[idx], vec[1], direction);
1301}
1302
1303static void handle_set_length(float vec[3][3], const int idx, const float handle_length)
1304{
1305 BLI_assert_msg(idx == 0 || idx == 2, "handle_set_length() expects a handle index");
1306
1307 float handle_direction[2];
1308 sub_v2_v2v2(handle_direction, vec[idx], vec[1]);
1309 normalize_v2_length(handle_direction, handle_length);
1310 add_v2_v2v2(vec[idx], vec[1], handle_direction);
1311}
1312
1314 const eEditKeyframes_Equalize mode,
1315 const float handle_length,
1316 const bool flatten)
1317{
1318 uint i;
1319 BezTriple *bezt;
1320 const float flat_direction_left[2] = {-handle_length, 0.0f};
1321 const float flat_direction_right[2] = {handle_length, 0.0f};
1322
1323 /* Loop through an F-Curves keyframes. */
1324 for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) {
1325 if ((bezt->f2 & SELECT) == 0) {
1326 continue;
1327 }
1328
1329 /* Perform handle equalization if mode is 'Both' or 'Left'. */
1330 if (mode & EQUALIZE_HANDLES_LEFT) {
1331 /* If left handle type is 'Auto', 'Auto Clamped', or 'Vector', convert handles to
1332 * 'Aligned'.
1333 */
1334 if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) {
1335 bezt->h1 = HD_ALIGN;
1336 bezt->h2 = HD_ALIGN;
1337 }
1338
1339 if (flatten) {
1340 handle_flatten(bezt->vec, 0, flat_direction_left);
1341 }
1342 else {
1343 handle_set_length(bezt->vec, 0, handle_length);
1344 }
1345 }
1346
1347 /* Perform handle equalization if mode is 'Both' or 'Right'. */
1348 if (mode & EQUALIZE_HANDLES_RIGHT) {
1349 /* If right handle type is 'Auto', 'Auto Clamped', or 'Vector', convert handles to
1350 * 'Aligned'. */
1351 if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) {
1352 bezt->h1 = HD_ALIGN;
1353 bezt->h2 = HD_ALIGN;
1354 }
1355
1356 if (flatten) {
1357 handle_flatten(bezt->vec, 2, flat_direction_right);
1358 }
1359 else {
1360 handle_set_length(bezt->vec, 2, handle_length);
1361 }
1362 }
1363 }
1364}
1365
1367{
1368 switch (mode) {
1369 /* interpolation */
1370 case BEZT_IPO_CONST: /* constant */
1371 return set_bezt_constant;
1372 case BEZT_IPO_LIN: /* linear */
1373 return set_bezt_linear;
1374
1375 /* easing */
1376 case BEZT_IPO_BACK:
1377 return set_bezt_back;
1378 case BEZT_IPO_BOUNCE:
1379 return set_bezt_bounce;
1380 case BEZT_IPO_CIRC:
1381 return set_bezt_circle;
1382 case BEZT_IPO_CUBIC:
1383 return set_bezt_cubic;
1384 case BEZT_IPO_ELASTIC:
1385 return set_bezt_elastic;
1386 case BEZT_IPO_EXPO:
1387 return set_bezt_expo;
1388 case BEZT_IPO_QUAD:
1389 return set_bezt_quad;
1390 case BEZT_IPO_QUART:
1391 return set_bezt_quart;
1392 case BEZT_IPO_QUINT:
1393 return set_bezt_quint;
1394 case BEZT_IPO_SINE:
1395 return set_bezt_sine;
1396
1397 default: /* bezier */
1398 return set_bezt_bezier;
1399 }
1400}
1401
1402/* ------- */
1403
1405{
1406 if (bezt->f2 & SELECT) {
1408 }
1409 return 0;
1410}
1411
1413{
1414 if (bezt->f2 & SELECT) {
1416 }
1417 return 0;
1418}
1419
1420static short set_keytype_extreme(KeyframeEditData * /*ked*/, BezTriple *bezt)
1421{
1422 if (bezt->f2 & SELECT) {
1424 }
1425 return 0;
1426}
1427
1428static short set_keytype_jitter(KeyframeEditData * /*ked*/, BezTriple *bezt)
1429{
1430 if (bezt->f2 & SELECT) {
1432 }
1433 return 0;
1434}
1435
1437{
1438 if (bezt->f2 & SELECT) {
1440 }
1441 return 0;
1442}
1443
1445{
1446 if (bezt->f2 & SELECT) {
1448 }
1449 return 0;
1450}
1451
1453{
1454 switch (keyframe_type) {
1456 return set_keytype_breakdown;
1457
1459 return set_keytype_extreme;
1460
1462 return set_keytype_jitter;
1463
1466
1468 return set_keytype_keyframe;
1469
1471 return set_keytype_generated;
1472 }
1473
1475 return nullptr;
1476}
1477
1478/* ------- */
1479
1481{
1482 if (bezt->f2 & SELECT) {
1483 bezt->easing = BEZT_IPO_EASE_IN;
1484 }
1485 return 0;
1486}
1487
1489{
1490 if (bezt->f2 & SELECT) {
1491 bezt->easing = BEZT_IPO_EASE_OUT;
1492 }
1493 return 0;
1494}
1495
1497{
1498 if (bezt->f2 & SELECT) {
1500 }
1501 return 0;
1502}
1503
1505{
1506 if (bezt->f2 & SELECT) {
1507 bezt->easing = BEZT_IPO_EASE_AUTO;
1508 }
1509 return 0;
1510}
1511
1513{
1514 switch (mode) {
1515 case BEZT_IPO_EASE_IN: /* ease in */
1516 return set_easingtype_easein;
1517
1518 case BEZT_IPO_EASE_OUT: /* ease out */
1520
1521 case BEZT_IPO_EASE_IN_OUT: /* both */
1523
1524 default: /* auto */
1526 }
1527}
1528
1529/* ******************************************* */
1530/* Selection */
1531
1533{
1534 /* Only act on visible items, so check handle visibility state. */
1535 /* if we've got info on what to select, use it, otherwise select all */
1536 if ((ked) && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES) && handles_visible(ked, bezt)) {
1537 if (ked->curflags & KEYFRAME_OK_KEY) {
1538 bezt->f2 |= BEZT_FLAG_SELECT;
1539 }
1540 if (ked->curflags & KEYFRAME_OK_H1) {
1541 bezt->f1 |= BEZT_FLAG_SELECT;
1542 }
1543 if (ked->curflags & KEYFRAME_OK_H2) {
1544 bezt->f3 |= BEZT_FLAG_SELECT;
1545 }
1546 }
1547 else {
1548 BEZT_SEL_ALL(bezt);
1549 }
1550
1551 return 0;
1552}
1553
1555{
1556 /* Only act on visible items, so check handle visibility state. */
1557 /* if we've got info on what to deselect, use it, otherwise deselect all */
1558 if ((ked) && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES) && handles_visible(ked, bezt)) {
1559 if (ked->curflags & KEYFRAME_OK_KEY) {
1560 bezt->f2 &= ~BEZT_FLAG_SELECT;
1561 }
1562 if (ked->curflags & KEYFRAME_OK_H1) {
1563 bezt->f1 &= ~BEZT_FLAG_SELECT;
1564 }
1565 if (ked->curflags & KEYFRAME_OK_H2) {
1566 bezt->f3 &= ~BEZT_FLAG_SELECT;
1567 }
1568 }
1569 else {
1570 BEZT_DESEL_ALL(bezt);
1571 }
1572
1573 return 0;
1574}
1575
1577{
1578 /* Invert the selection for the whole bezier triple */
1579 bezt->f2 ^= BEZT_FLAG_SELECT;
1580 if (bezt->f2 & SELECT) {
1581 bezt->f1 |= BEZT_FLAG_SELECT;
1582 bezt->f3 |= BEZT_FLAG_SELECT;
1583 }
1584 else {
1585 bezt->f1 &= ~BEZT_FLAG_SELECT;
1586 bezt->f3 &= ~BEZT_FLAG_SELECT;
1587 }
1588 return 0;
1589}
1590
1592{
1593 switch (selectmode) {
1594 case SELECT_ADD: /* add */
1595 return select_bezier_add;
1596 case SELECT_SUBTRACT: /* subtract */
1598 case SELECT_INVERT: /* invert */
1599 return select_bezier_invert;
1600 default: /* replace (need to clear all, then add) */
1601 return select_bezier_add;
1602 }
1603}
1604
1605/* ******************************************* */
1606/* Selection Maps */
1607
1608/* Selection maps are simply fancy names for char arrays that store on/off
1609 * info for whether the selection status. The main purpose for these is to
1610 * allow extra info to be tagged to the keyframes without influencing their
1611 * values or having to be removed later.
1612 */
1613
1614/* ----------- */
1615
1617{
1618 const FCurve *fcu = ked->fcu;
1619 char *map = static_cast<char *>(ked->data);
1620 int i = ked->curIndex;
1621
1622 /* if current is selected, just make sure it stays this way */
1623 if (BEZT_ISSEL_ANY(bezt)) {
1624 map[i] = 1;
1625 return 0;
1626 }
1627
1628 /* if previous is selected, that means that selection should extend across */
1629 if (i > 0) {
1630 BezTriple *prev = bezt - 1;
1631
1632 if (BEZT_ISSEL_ANY(prev)) {
1633 map[i] = 1;
1634 return 0;
1635 }
1636 }
1637
1638 /* if next is selected, that means that selection should extend across */
1639 if (i < (fcu->totvert - 1)) {
1640 BezTriple *next = bezt + 1;
1641
1642 if (BEZT_ISSEL_ANY(next)) {
1643 map[i] = 1;
1644 return 0;
1645 }
1646 }
1647
1648 return 0;
1649}
1650
1652{
1653 const FCurve *fcu = ked->fcu;
1654 char *map = static_cast<char *>(ked->data);
1655 int i = ked->curIndex;
1656
1657 /* if current is selected, check the left/right keyframes
1658 * since it might need to be deselected (but otherwise no)
1659 */
1660 if (BEZT_ISSEL_ANY(bezt)) {
1661 /* if previous is not selected, we're on the tip of an iceberg */
1662 if (i > 0) {
1663 BezTriple *prev = bezt - 1;
1664
1665 if (BEZT_ISSEL_ANY(prev) == 0) {
1666 return 0;
1667 }
1668 }
1669 else if (i == 0) {
1670 /* current keyframe is selected at an endpoint, so should get deselected */
1671 return 0;
1672 }
1673
1674 /* if next is not selected, we're on the tip of an iceberg */
1675 if (i < (fcu->totvert - 1)) {
1676 BezTriple *next = bezt + 1;
1677
1678 if (BEZT_ISSEL_ANY(next) == 0) {
1679 return 0;
1680 }
1681 }
1682 else if (i == (fcu->totvert - 1)) {
1683 /* current keyframe is selected at an endpoint, so should get deselected */
1684 return 0;
1685 }
1686
1687 /* if we're still here, that means that keyframe should remain untouched */
1688 map[i] = 1;
1689 }
1690
1691 return 0;
1692}
1693
1695{
1696 switch (mode) {
1697 case SELMAP_LESS: /* less */
1699
1700 case SELMAP_MORE: /* more */
1701 default:
1703 }
1704}
1705
1706/* ----------- */
1707
1709{
1710 const char *map = static_cast<char *>(ked->data);
1711 short on = map[ked->curIndex];
1712
1713 /* select or deselect based on whether the map allows it or not */
1714 if (on) {
1715 BEZT_SEL_ALL(bezt);
1716 }
1717 else {
1718 BEZT_DESEL_ALL(bezt);
1719 }
1720
1721 return 0;
1722}
1723
1724} // namespace blender
Functions and classes to work with Actions.
#define SELECT
Definition BKE_mask.hh:19
#define BEZT_ISSEL_IDX(bezt, i)
#define BEZT_SEL_ALL(bezt)
#define BEZT_ISSEL_ANY(bezt)
#define BEZT_DESEL_ALL(bezt)
#define BEZKEYTYPE_LVALUE(bezt)
Object is a sort of wrapper for general info.
#define ANIM_UPDATE_DEFAULT
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define ELEM(...)
#define IS_EQF(a, b)
#define BLI_assert_msg(a, msg)
Slot * slot_for_handle(slot_handle_t handle)
Span< const FCurve * > fcurves() const
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
Definition frames.inl:1166
#define INT_MAX
float3x3 scale(float3x3 mat, float2 scale)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
BLI_INLINE Texture * wrap(MTLTexture *texture)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static short snap_bezier_cframe(KeyframeEditData *ked, BezTriple *bezt)
@ BEZT_KEYTYPE_MOVEHOLD
@ BEZT_KEYTYPE_GENERATED
@ BEZT_KEYTYPE_KEYFRAME
@ BEZT_KEYTYPE_BREAKDOWN
static short set_keytype_keyframe(KeyframeEditData *, BezTriple *bezt)
KeyframeEditFunc ANIM_editkeyframes_ok(short mode)
static short set_keytype_jitter(KeyframeEditData *, BezTriple *bezt)
void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value)
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
static short summary_keyframes_loop(KeyframeEditData *ked, bAnimContext *ac, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static short select_bezier_add(KeyframeEditData *ked, BezTriple *bezt)
KeyframeEditFunc ANIM_editkeyframes_ipo(short mode)
static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center)
unsigned int uint
Definition BKE_text.h:55
short bezt_to_cfraelem(KeyframeEditData *ked, BezTriple *bezt)
@ ANIMCONT_CHANNEL
static short ok_bezier_selected(KeyframeEditData *, BezTriple *bezt)
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
KeyframeEditFunc ANIM_editkeyframes_handles(short mode)
static short set_bezt_circle(KeyframeEditData *, BezTriple *bezt)
void BKE_fcurve_update_handle_flag_from_opposite(BezTriple &key, HandleSide source_side)
static bool handles_visible(KeyframeEditData *ked, BezTriple *bezt)
static short bezier_isfree(KeyframeEditData *, BezTriple *bezt)
static short snap_bezier_nearestsec(KeyframeEditData *ked, BezTriple *bezt)
static short mirror_bezier_xaxis(KeyframeEditData *, BezTriple *bezt)
static short action_layered_keyframes_loop(KeyframeEditData *ked, animrig::Action &action, animrig::Slot *slot, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
@ NLATIME_CONVERT_MAP
Definition BKE_nla.hh:563
static short ok_bezier_valuerange(KeyframeEditData *ked, BezTriple *bezt)
static short snap_bezier_time(KeyframeEditData *ked, BezTriple *bezt)
MINLINE float normalize_v2_length(float n[2], float unit_length)
float ANIM_nla_tweakedit_remap(bAnimListElem *ale, const float cframe, const eNlaTime_ConvertModes mode)
Definition anim_draw.cc:329
static short selmap_build_bezier_less(KeyframeEditData *ked, BezTriple *bezt)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
static short set_bezt_quad(KeyframeEditData *, BezTriple *bezt)
static short snap_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
@ ANIMTYPE_OBJECT
bool BLI_lasso_is_point_inside(Span< int2 > mcoords, int sx, int sy, int error_value)
Definition lasso_2d.cc:42
short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, FCurve *fcu, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static void mirror_bezier_yaxis_ex(BezTriple *bezt, const float center)
static short ok_bezier_framerange(KeyframeEditData *ked, BezTriple *bezt)
static short mirror_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
void ANIM_animdata_update(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:365
static short select_bezier_invert(KeyframeEditData *, BezTriple *bezt)
static short ok_bezier_channel_circle(KeyframeEditData *ked, BezTriple *bezt)
static short ok_bezier_channel_lasso(KeyframeEditData *ked, BezTriple *bezt)
bool keyframe_region_lasso_test(const KeyframeEdit_LassoData *data_lasso, const float xy[2])
static short set_keytype_extreme(KeyframeEditData *, BezTriple *bezt)
static short set_bezt_constant(KeyframeEditData *, BezTriple *bezt)
void BKE_fcurve_keyframe_move_time_with_handles(BezTriple *keyframe, const float new_time)
static short set_bezt_sine(KeyframeEditData *, BezTriple *bezt)
@ ALE_GREASE_PENCIL_GROUP
@ ALE_ACTION_LAYERED
@ ALE_GREASE_PENCIL_DATA
@ ALE_ACTION_SLOT
@ ALE_GREASE_PENCIL_CEL
static short mirror_bezier_marker(KeyframeEditData *ked, BezTriple *bezt)
static short set_easingtype_easein(KeyframeEditData *, BezTriple *bezt)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void ANIM_fcurve_equalize_keyframes_loop(FCurve *fcu, const eEditKeyframes_Equalize mode, const float handle_length, const bool flatten)
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_NODUPLIS
void BKE_fcurve_handles_recalc(FCurve &fcu)
static short ok_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
void bezt_remap_times(KeyframeEditData *ked, BezTriple *bezt)
MINLINE void swap_v3_v3(float a[3], float b[3])
static short ok_bezier_selected_key(KeyframeEditData *, BezTriple *bezt)
BMesh const char void * data
static short set_easingtype_easeinout(KeyframeEditData *, BezTriple *bezt)
static short agrp_keyframes_loop(KeyframeEditData *ked, bActionGroup *agrp, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static short ok_bezier_region_lasso(KeyframeEditData *ked, BezTriple *bezt)
static short set_bezier_auto(KeyframeEditData *, BezTriple *bezt)
static short set_bezt_bounce(KeyframeEditData *, BezTriple *bezt)
static short set_bezt_back(KeyframeEditData *, BezTriple *bezt)
void ANIM_editkeyframes_refresh(bAnimContext *ac)
KeyframeEditFunc ANIM_editkeyframes_select(const eEditKeyframes_Select selectmode)
static short set_bezt_bezier(KeyframeEditData *, BezTriple *bezt)
static short snap_bezier_horizontal(KeyframeEditData *, BezTriple *bezt)
static short keyframe_ok_checks(KeyframeEditData *ked, BezTriple *bezt, FunctionRef< bool(KeyframeEditData *ked, BezTriple *bezt, const int index)> check)
static short snap_bezier_nearest(KeyframeEditData *, BezTriple *bezt)
static short ob_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, Object *ob, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static short scene_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, Scene *sce, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static short set_keytype_breakdown(KeyframeEditData *, BezTriple *bezt)
KeyframeEditFunc ANIM_editkeyframes_buildselmap(short mode)
static short set_bezier_align(KeyframeEditData *, BezTriple *bezt)
short(*)(KeyframeEditData *ked, BezTriple *bezt) KeyframeEditFunc
static short set_bezt_linear(KeyframeEditData *, BezTriple *bezt)
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void(*)(FCurve &fcu) FcuEditFunc
static short ok_bezier_region_circle(KeyframeEditData *ked, BezTriple *bezt)
static short set_easingtype_easeauto(KeyframeEditData *, BezTriple *bezt)
static void handle_flatten(float vec[3][3], const int idx, const float direction[2])
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, float xy_dst[2], const float xy_src[2])
Definition rct.cc:540
bool keyframe_region_circle_test(const KeyframeEdit_CircleData *data_circle, const float xy[2])
int ED_markers_find_nearest_marker_time(ListBaseT< TimeMarker > *markers, float x)
static short ok_bezier_region(KeyframeEditData *ked, BezTriple *bezt)
static short selmap_build_bezier_more(KeyframeEditData *ked, BezTriple *bezt)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
KeyframeEditFunc ANIM_editkeyframes_snap(short mode)
static short set_keytype_generated(KeyframeEditData *, BezTriple *bezt)
KeyframeEditFunc ANIM_editkeyframes_keytype(const eBezTriple_KeyframeType keyframe_type)
static short set_bezt_expo(KeyframeEditData *, BezTriple *bezt)
static void handle_set_length(float vec[3][3], const int idx, const float handle_length)
static short ok_bezier_frame(KeyframeEditData *ked, BezTriple *bezt)
static short set_bezier_vector(KeyframeEditData *, BezTriple *bezt)
short bezt_selmap_flush(KeyframeEditData *ked, BezTriple *bezt)
static short set_bezier_free(KeyframeEditData *, BezTriple *bezt)
KeyframeEditFunc ANIM_editkeyframes_easing(short mode)
static short set_bezt_quint(KeyframeEditData *, BezTriple *bezt)
short bezt_calc_average(KeyframeEditData *ked, BezTriple *bezt)
static short mirror_bezier_yaxis(KeyframeEditData *, BezTriple *bezt)
static short set_bezt_quart(KeyframeEditData *, BezTriple *bezt)
static short set_keytype_moving_hold(KeyframeEditData *, BezTriple *bezt)
void ANIM_animdata_keyframe_callback(bAnimContext *ac, eAnimFilter_Flags filter, KeyframeEditFunc callback_fn)
static short set_easingtype_easeout(KeyframeEditData *, BezTriple *bezt)
static short mirror_bezier_time(KeyframeEditData *ked, BezTriple *bezt)
static short select_bezier_subtract(KeyframeEditData *ked, BezTriple *bezt)
static short set_bezt_cubic(KeyframeEditData *, BezTriple *bezt)
static short mirror_bezier_cframe(KeyframeEditData *ked, BezTriple *bezt)
@ KEYFRAME_ITER_HANDLES_INVISIBLE
@ KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE
@ ANIM_UPDATE_ORDER
@ ANIM_UPDATE_DEPS
@ ANIM_UPDATE_HANDLES
short ANIM_animchannel_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, bAnimListElem *ale, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static short set_bezier_auto_clamped(KeyframeEditData *, BezTriple *bezt)
static short action_legacy_keyframes_loop(KeyframeEditData *ked, bAction *act, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
KeyframeEditFunc ANIM_editkeyframes_mirror(short mode)
static short snap_bezier_nearmarker(KeyframeEditData *ked, BezTriple *bezt)
static short set_bezt_elastic(KeyframeEditData *, BezTriple *bezt)
#define floorf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct Object * object
eBezTriple_Flag f2
eBezTriple_Easing easing
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Interpolation ipo
eBezTriple_Handle h1
unsigned int totvert
ListBaseT< TimeMarker > time_marker_list
ListBaseT< CfraElem > cfra_elem_list
struct AnimData * adt
struct AnimData * adt
struct RenderData r
struct ActionChannelbag * channelbag
ListBaseT< FCurve > curves
struct blender::bAnimContext::@354357007254244122245111034311231000121111260015 filters
eAnimCont_Types datatype
eAnim_ChannelType type
eDopeSheet_FilterFlag2 filterflag2
eDopeSheet_FilterFlag filterflag