Blender V5.3
anim_draw.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 "BLI_sys_types.hh"
10
11#include "DNA_anim_types.h"
14#include "DNA_object_types.h"
15#include "DNA_scene_types.h"
16#include "DNA_screen_types.h"
17#include "DNA_sequence_types.h"
18#include "DNA_space_types.h"
19#include "DNA_userdef_types.h"
20#include "DNA_workspace_types.h"
21
22#include "BLI_listbase.hh"
24#include "BLI_math_vector_c.hh"
25#include "BLI_rect.hh"
26#include "BLI_utildefines.hh"
27
28#include "BKE_context.hh"
29#include "BKE_curve.hh"
30#include "BKE_fcurve.hh"
31#include "BKE_global.hh"
32#include "BKE_mask.hh"
33#include "BKE_nla.hh"
34#include "BKE_scene_context.hh"
35#include "BKE_unit.hh"
36
37#include "ED_anim_api.hh"
38#include "ED_keyframes_edit.hh"
40#include "ED_sequencer.hh"
41
42#include "RNA_access.hh"
43#include "RNA_path.hh"
44
45#include "UI_resources.hh"
46#include "UI_view2d.hh"
47
48#include "GPU_immediate.hh"
49#include "GPU_state.hh"
50
51#include "SEQ_time.hh"
52
53#include <utility>
54
55namespace blender {
56
57/* *************************************************** */
58/* CURRENT FRAME DRAWING */
59
60void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag)
61{
62 Scene *scene = CTX_data_scene(C);
63
64 const float time = scene->r.cfra + scene->r.subframe;
65 const float x = float(time * scene->r.framelen);
66
67 GPU_line_width((flag & DRAWCFRA_WIDE) ? 3.0 : 2.0);
68
70 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
71
73
74 /* Draw a light green line to indicate current frame */
76
78 immVertex2f(pos, x, v2d->cur.ymin - 500.0f); /* XXX arbitrary... want it go to bottom */
79 immVertex2f(pos, x, v2d->cur.ymax);
80 immEnd();
82}
83
84/* *************************************************** */
85/* PREVIEW RANGE 'CURTAINS' */
86/* NOTE: 'Preview Range' tools are defined in `anim_ops.cc`. */
87
88void ANIM_draw_previewrange(const Scene *scene, View2D *v2d, int end_frame_width)
89{
90 /* Only draw this if preview range is set. */
91 if (PRVRANGEON) {
93
95 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
96
99
100 /* Only draw two separate 'curtains' if there's no overlap between them. */
101 if (scene->r.psfra < scene->r.pefra + end_frame_width) {
102 immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, float(scene->r.psfra), v2d->cur.ymax);
103 immRectf(pos,
104 float(scene->r.pefra + end_frame_width),
105 v2d->cur.ymin,
106 v2d->cur.xmax,
107 v2d->cur.ymax);
108 }
109 else {
110 immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
111 }
112
114
116 }
117}
118
120{
121 SpaceAction *space_action = CTX_wm_space_action(C);
122 if (!space_action || (space_action->overlays.flag & ADS_OVERLAY_SHOW_OVERLAYS) == 0 ||
123 (space_action->overlays.flag & ADS_SHOW_SCENE_STRIP_FRAME_RANGE) == 0)
124 {
125 return;
126 }
127 WorkSpace *workspace = CTX_wm_workspace(C);
128 if (!workspace) {
129 return;
130 }
131 if ((workspace->flags & WORKSPACE_SYNC_SCENE_TIME) == 0) {
132 return;
133 }
134 const Scene *sequencer_scene = workspace->sequencer_scene;
135 if (!sequencer_scene) {
136 return;
137 }
138 const Strip *scene_strip = ed::vse::get_scene_strip_for_time_sync(sequencer_scene);
139 if (!scene_strip || !scene_strip->scene) {
140 return;
141 }
143
144 GPUVertFormat *format = immVertexFormat();
145 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
146
149
150 /* ..._handle are frames in "sequencer logic", meaning that on the right_handle point in time,
151 * the strip is not visible any more. The last visible frame of the strip is actually on
152 * (right_handle-1), hence the -1 when computing the end_frame. */
153 const float left_handle = scene_strip->left_handle();
154 const float right_handle = scene_strip->right_handle(sequencer_scene);
155 float start_frame = seq::give_frame_index(sequencer_scene, scene_strip, left_handle) +
156 scene_strip->scene->r.sfra + scene_strip->anim_startofs;
157 float end_frame = seq::give_frame_index(sequencer_scene, scene_strip, right_handle - 1) +
158 scene_strip->scene->r.sfra + scene_strip->anim_startofs;
159
160 /* This can happen when the strip time is reversed. */
161 if (start_frame > end_frame) {
162 std::swap(start_frame, end_frame);
163 }
164
165 immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, start_frame, v2d->cur.ymax);
166 immRectf(pos, end_frame, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
167
169
171}
172
173/* *************************************************** */
174/* SCENE FRAME RANGE */
175
177{
178 /* draw darkened area outside of active timeline frame range */
180
181 GPUVertFormat *format = immVertexFormat();
182 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
183
186
187 if (scene->r.sfra < scene->r.efra) {
188 immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, float(scene->r.sfra), v2d->cur.ymax);
189 immRectf(pos, float(scene->r.efra), v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
190 }
191 else {
192 immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
193 }
194
196
197 /* thin lines where the actual frames are */
199
201
202 immVertex2f(pos, float(scene->r.sfra), v2d->cur.ymin);
203 immVertex2f(pos, float(scene->r.sfra), v2d->cur.ymax);
204
205 immVertex2f(pos, float(scene->r.efra), v2d->cur.ymin);
206 immVertex2f(pos, float(scene->r.efra), v2d->cur.ymax);
207
208 immEnd();
210}
211
213 AnimData *adt, bAction *action, View2D *v2d, float ymin, float ymax)
214{
215 if ((action->flag & ACT_FRAME_RANGE) == 0) {
216 return;
217 }
218
219 /* Compute the dimensions. */
220 CLAMP_MIN(ymin, v2d->cur.ymin);
221 CLAMP_MAX(ymax, v2d->cur.ymax);
222
223 if (ymin > ymax) {
224 return;
225 }
226
227 const float sfra = BKE_nla_tweakedit_remap(adt, action->frame_start, NLATIME_CONVERT_MAP);
228 const float efra = BKE_nla_tweakedit_remap(adt, action->frame_end, NLATIME_CONVERT_MAP);
229
230 /* Diagonal stripe filled area outside of the frame range. */
232
233 GPUVertFormat *format = immVertexFormat();
234 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
235
237
238 float color[4];
240
241 immUniform4f("color1", color[0], color[1], color[2], color[3]);
242 immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
243 immUniform1i("size1", 2 * UI_SCALE_FAC);
244 immUniform1i("size2", 4 * UI_SCALE_FAC);
245
246 if (sfra < efra) {
247 immRectf(pos, v2d->cur.xmin, ymin, sfra, ymax);
248 immRectf(pos, efra, ymin, v2d->cur.xmax, ymax);
249 }
250 else {
251 immRectf(pos, v2d->cur.xmin, ymin, v2d->cur.xmax, ymax);
252 }
253
255
257
258 /* Thin lines where the actual frames are. */
261
262 GPU_line_width(1.0f);
263
265
266 immVertex2f(pos, sfra, ymin);
267 immVertex2f(pos, sfra, ymax);
268
269 immVertex2f(pos, efra, ymin);
270 immVertex2f(pos, efra, ymax);
271
272 immEnd();
274}
275
276/* *************************************************** */
277/* NLA-MAPPING UTILITIES (required for drawing and also editing keyframes). */
278
280{
281 /* Historically, there was another check in the code that this function replaced:
282 * if (!ELEM(ac->datatype,
283 * ANIMCONT_ACTION,
284 * ANIMCONT_SHAPEKEY,
285 * ANIMCONT_DOPESHEET,
286 * ANIMCONT_FCURVES,
287 * ANIMCONT_NLA,
288 * ANIMCONT_CHANNEL,
289 * ANIMCONT_TIMELINE))
290 * {
291 * ... prevent NLA-remapping ...
292 * }
293 *
294 * I (Sybren) suspect that this was actually hiding some animation type check. When that code was
295 * written, I think there was no GreasePencil data showing in the regular Dope Sheet editor.
296 */
297
298 switch (ale->type) {
300 /* NLA Control Curves occur on NLA strips,
301 * and shouldn't be subjected to this kind of mapping. */
302 return false;
303 case ANIMTYPE_FCURVE: {
304 /* The F-Curve data of a driver should never get NLA-remapped. */
305 FCurve *fcurve = static_cast<FCurve *>(ale->key_data);
306 return !fcurve->driver;
307 }
309 case ANIMTYPE_GPLAYER:
313 /* Grease Pencil doesn't use the NLA, so don't bother remapping. */
314 return false;
317 /* I (Sybren) don't _think_ masks can use the NLA. */
318 return false;
319 case ANIMTYPE_SUMMARY:
320 /* The summary line cannot do NLA remapping since it may contain multiple actions. */
321 return false;
322 default:
323 /* NLA time remapping is the default behavior, and only should be
324 * prohibited for the above types. */
325 return true;
326 }
327}
328
330 const float cframe,
331 const eNlaTime_ConvertModes mode)
332{
333 if (!ANIM_nla_mapping_allowed(ale)) {
334 return cframe;
335 }
336 return BKE_nla_tweakedit_remap(ale->adt, cframe, mode);
337}
338
339/* ------------------- */
340
341/* Helper function for ANIM_nla_mapping_apply_fcurve() -> "restore",
342 * i.e. mapping points back to action-time. */
344{
345 /* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */
346 AnimData *adt = static_cast<AnimData *>(ked->data);
347 short only_keys = short(ked->i1);
348
349 /* adjust BezTriple handles only if allowed to */
350 if (only_keys == 0) {
351 bezt->vec[0][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_UNMAP);
352 bezt->vec[2][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_UNMAP);
353 }
354
355 bezt->vec[1][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_UNMAP);
356
357 return 0;
358}
359
360/* helper function for ANIM_nla_mapping_apply_fcurve() -> "apply",
361 * i.e. mapping points to NLA-mapped global time */
363{
364 /* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */
365 AnimData *adt = static_cast<AnimData *>(ked->data);
366 short only_keys = short(ked->i1);
367
368 /* adjust BezTriple handles only if allowed to */
369 if (only_keys == 0) {
370 bezt->vec[0][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_MAP);
371 bezt->vec[2][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_MAP);
372 }
373
374 bezt->vec[1][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_MAP);
375
376 return 0;
377}
378
379void ANIM_nla_mapping_apply_fcurve(AnimData *adt, FCurve *fcu, bool restore, bool only_keys)
380{
381 if (adt == nullptr || adt->nla_tracks.is_empty()) {
382 return;
383 }
384 KeyframeEditData ked = {{nullptr}};
385 KeyframeEditFunc map_cb;
386
387 /* init edit data
388 * - AnimData is stored in 'data'
389 * - only_keys is stored in 'i1'
390 */
391 ked.data = static_cast<void *>(adt);
392 ked.i1 = int(only_keys);
393
394 /* get editing callback */
395 if (restore) {
397 }
398 else {
399 map_cb = bezt_nlamapping_apply;
400 }
401
402 /* apply to F-Curve */
403 ANIM_fcurve_keyframes_loop(&ked, fcu, nullptr, map_cb, nullptr);
404}
405
407 FCurve *fcu,
408 const bool restore,
409 const bool only_keys)
410{
411 if (!ANIM_nla_mapping_allowed(ale)) {
412 return;
413 }
414 ANIM_nla_mapping_apply_fcurve(ale->adt, fcu, restore, only_keys);
415}
416
417/* *************************************************** */
418/* UNITS CONVERSION MAPPING (required for drawing and editing keyframes) */
419
421{
422 if (space_link->spacetype == SPACE_GRAPH) {
423 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(space_link);
424 bool use_normalization = (sipo->flag & SIPO_NORMALIZE) != 0;
425 bool freeze_normalization = (sipo->flag & SIPO_NORMALIZE_FREEZE) != 0;
426 return use_normalization ? (ANIM_UNITCONV_NORMALIZE |
427 (freeze_normalization ? ANIM_UNITCONV_NORMALIZE_FREEZE : 0)) :
428 0;
429 }
430
431 return 0;
432}
433
435 const FCurve *fcu,
436 float *r_min_coord,
437 float *r_max_coord)
438{
439 float min_coord = FLT_MAX;
440 float max_coord = -FLT_MAX;
441 const bool use_preview_only = PRVRANGEON;
442
443 if (fcu->bezt || fcu->fpt) {
444 int start = 0;
445 int end = fcu->totvert;
446
447 if (use_preview_only) {
448 if (fcu->bezt) {
449 /* Preview frame ranges need to be converted to bezt array indices. */
450 bool replace = false;
452 fcu->bezt, scene->r.psfra, fcu->totvert, &replace);
453
455 fcu->bezt, scene->r.pefra + 1, fcu->totvert, &replace);
456 }
457 else if (fcu->fpt) {
458 const int unclamped_start = int(scene->r.psfra - fcu->fpt[0].vec[0]);
459 start = max_ii(unclamped_start, 0);
460 end = min_ii(unclamped_start + (scene->r.pefra - scene->r.psfra) + 1, fcu->totvert);
461 }
462 }
463
464 if (fcu->bezt) {
465 const BezTriple *bezt = fcu->bezt + start;
466 for (int i = start; i < end; i++, bezt++) {
467
468 if (i == 0) {
469 /* We ignore extrapolation flags and handle here, and use the
470 * control point position only. so we normalize "interesting"
471 * part of the curve.
472 *
473 * Here we handle left extrapolation.
474 */
475 max_coord = max_ff(max_coord, bezt->vec[1][1]);
476 min_coord = min_ff(min_coord, bezt->vec[1][1]);
477 }
478 else {
479 const BezTriple *prev_bezt = bezt - 1;
480 if (!ELEM(prev_bezt->ipo, BEZT_IPO_BEZ, BEZT_IPO_BACK, BEZT_IPO_ELASTIC)) {
481 /* The points on the curve will lie inside the start and end points.
482 * Calculate min/max using both previous and current CV.
483 */
484 max_coord = max_ff(max_coord, bezt->vec[1][1]);
485 min_coord = min_ff(min_coord, bezt->vec[1][1]);
486 max_coord = max_ff(max_coord, prev_bezt->vec[1][1]);
487 min_coord = min_ff(min_coord, prev_bezt->vec[1][1]);
488 }
489 else {
490 const int resol = fcu->driver ?
491 32 :
492 min_ii(int(5.0f * len_v2v2(bezt->vec[1], prev_bezt->vec[1])),
493 32);
494 if (resol < 2) {
495 max_coord = max_ff(max_coord, prev_bezt->vec[1][1]);
496 min_coord = min_ff(min_coord, prev_bezt->vec[1][1]);
497 }
498 else {
499 if (!ELEM(prev_bezt->ipo, BEZT_IPO_BACK, BEZT_IPO_ELASTIC)) {
500 /* Calculate min/max using bezier forward differencing. */
501 float data[120];
502 float v1[2], v2[2], v3[2], v4[2];
503
504 v1[0] = prev_bezt->vec[1][0];
505 v1[1] = prev_bezt->vec[1][1];
506 v2[0] = prev_bezt->vec[2][0];
507 v2[1] = prev_bezt->vec[2][1];
508
509 v3[0] = bezt->vec[0][0];
510 v3[1] = bezt->vec[0][1];
511 v4[0] = bezt->vec[1][0];
512 v4[1] = bezt->vec[1][1];
513
514 BKE_fcurve_correct_bezpart(v1, v2, v3, v4);
515
517 v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float[3]));
519 v1[1], v2[1], v3[1], v4[1], data + 1, resol, sizeof(float[3]));
520
521 for (int j = 0; j <= resol; ++j) {
522 const float *fp = &data[j * 3];
523 max_coord = max_ff(max_coord, fp[1]);
524 min_coord = min_ff(min_coord, fp[1]);
525 }
526 }
527 else {
528 /* Calculate min/max using full fcurve evaluation.
529 * [slower than bezier forward differencing but evaluates Back/Elastic
530 * interpolation as well]. */
531 float step_size = (bezt->vec[1][0] - prev_bezt->vec[1][0]) / resol;
532 for (int j = 0; j <= resol; j++) {
533 float eval_time = prev_bezt->vec[1][0] + step_size * j;
534 float eval_value = evaluate_fcurve_only_curve(fcu, eval_time);
535 max_coord = max_ff(max_coord, eval_value);
536 min_coord = min_ff(min_coord, eval_value);
537 }
538 }
539 }
540 }
541 }
542 }
543 }
544 else if (fcu->fpt) {
545 const FPoint *fpt = fcu->fpt + start;
546 for (int i = start; i < end; ++i, ++fpt) {
547 min_coord = min_ff(min_coord, fpt->vec[1]);
548 max_coord = max_ff(max_coord, fpt->vec[1]);
549 }
550 }
551 }
552
553 if (r_min_coord) {
554 *r_min_coord = min_coord;
555 }
556 if (r_max_coord) {
557 *r_max_coord = max_coord;
558 }
559}
560
561static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, float *r_offset)
562{
563 float factor = 1.0f, offset = 0.0f;
564
565 if (flag & ANIM_UNITCONV_RESTORE) {
566 if (r_offset) {
567 *r_offset = fcu->prev_offset;
568 }
569
570 return 1.0f / fcu->prev_norm_factor;
571 }
572
574 if (r_offset) {
575 *r_offset = fcu->prev_offset;
576 }
577 if (fcu->prev_norm_factor == 0.0f) {
578 /* Happens when Auto Normalize was disabled before
579 * any curves were displayed.
580 */
581 return 1.0f;
582 }
583 return fcu->prev_norm_factor;
584 }
585
586 if (G.moving & G_TRANSFORM_FCURVES) {
587 if (r_offset) {
588 *r_offset = fcu->prev_offset;
589 }
590 if (fcu->prev_norm_factor == 0.0f) {
591 /* Same as above. */
592 return 1.0f;
593 }
594 return fcu->prev_norm_factor;
595 }
596
597 fcu->prev_norm_factor = 1.0f;
598
599 float max_coord = -FLT_MAX;
600 float min_coord = FLT_MAX;
601 fcurve_scene_coord_range_get(scene, fcu, &min_coord, &max_coord);
602
603 /* We use an ULPS-based floating point comparison here, with the
604 * rationale that if there are too few possible values between
605 * `min_coord` and `max_coord`, then after display normalization it
606 * will certainly be a weird quantized experience for the user anyway. */
607 if (min_coord < max_coord && ulp_diff_ff(min_coord, max_coord) > 256) {
608 /* Normalize. */
609 const float range = max_coord - min_coord;
610 factor = 2.0f / range;
611 offset = -min_coord - range / 2.0f;
612 }
613 else {
614 /* Skip normalization in 2 cases. Either the y difference of all keyframes is too small to
615 * normalize or there are no keys at all in the range. In the first case, the curve should be
616 * brought to the 0 line. In the second case we cannot do that since we have no information. */
617 factor = 1.0f;
618 if (min_coord == FLT_MAX) {
619 offset = 0.0f;
620 }
621 else {
622 offset = -min_coord;
623 }
624 }
625
626 BLI_assert(factor != 0.0f);
627 if (r_offset) {
628 *r_offset = offset;
629 }
630
631 fcu->prev_norm_factor = factor;
632 fcu->prev_offset = offset;
633 return factor;
634}
635
636float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
637{
638 if (flag & ANIM_UNITCONV_NORMALIZE) {
639 return normalization_factor_get(scene, fcu, flag, r_offset);
640 }
641
642 if (r_offset) {
643 *r_offset = 0.0f;
644 }
645
646 /* TODO: change the pointer parameters to references, as this function should not be called
647 * without an animated ID or a scene (to get the preferred units). */
648
649 if (!id || !fcu || !scene) {
650 /* Not enough information to do the remapping, so just show the data as-is. */
651 return 1.0f;
652 }
653
654 const ParsedRNAPathRef rna_path = fcu->rna_path_parsed();
655 if (rna_path.is_empty()) {
656 return 1.0f;
657 }
658
659 PointerRNA ptr;
660 PropertyRNA *prop;
662 if (!RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) {
663 /* Without resolving the property, its type & subtype are unknown; remapping is impossible. */
664 return 1.0f;
665 }
666
668
669 UnitConversion unit_conversion;
670 const int b_unit = RNA_SUBTYPE_UNIT_VALUE(prop_unit);
671
672 switch (prop_unit) {
673 /* Units not affected by the scene's unit scale. */
675 case PROP_UNIT_TIME:
676 unit_conversion = BKE_unit_preferred_conversion_get(scene->unit, b_unit);
677 break;
678 /* Units that BKE_unit_value_scale() also scales by the scene's unit scale.
679 * Assumption: BKE_unit_value_scale() is linear and zero maps to zero for these
680 * unit types, so the scaled value can be used as a scaler factor. */
681 case PROP_UNIT_LENGTH:
682 case PROP_UNIT_MASS: {
683 unit_conversion = BKE_unit_preferred_conversion_get(scene->unit, b_unit);
684 const double scene_scale = BKE_unit_value_scale(scene->unit, b_unit, 1.0);
685 if (scene_scale != 0.0) {
686 unit_conversion.scalar /= scene_scale;
687 }
688 break;
689 }
690 default:
691 /* Other units are not scaled. */
692 break;
693 }
694 BLI_assert_msg(unit_conversion.bias == 0.0,
695 "Only linear units (without bias) are supported for now.");
696 BLI_assert(unit_conversion.scalar != 0.0);
697
698 if (flag & ANIM_UNITCONV_RESTORE) {
699 return float(unit_conversion.scalar);
700 }
701 return float(1.0 / unit_conversion.scalar);
702}
703
704static bool find_prev_next_keyframes(bContext *C, int *r_nextfra, int *r_prevfra)
705{
706 Scene *scene = CTX_data_scene(C);
709 bDopeSheet ads = {nullptr};
710 AnimKeylist *keylist = ED_keylist_create();
711 const ActKeyColumn *aknext, *akprev;
712 float cfranext, cfraprev;
713 bool donenext = false, doneprev = false;
714 int nextcount = 0, prevcount = 0;
715
716 cfranext = cfraprev = float(scene->r.cfra);
717
718 /* Seed up dummy dope-sheet context with flags to perform necessary filtering. */
719 if ((scene->flag & SCE_KEYS_NO_SELONLY) == 0) {
720 /* only selected channels are included */
722 }
723
724 /* populate tree with keyframe nodes */
725 scene_to_keylist(&ads, scene, keylist, 0, {-FLT_MAX, FLT_MAX});
726 gpencil_to_keylist(&ads, scene->gpd, keylist, false);
727
728 if (ob) {
729 ob_to_keylist(&ads, ob, keylist, 0, {-FLT_MAX, FLT_MAX});
730 gpencil_to_keylist(&ads, id_cast<bGPdata *>(ob->data), keylist, false);
731 }
732
733 if (mask) {
735 mask_to_keylist(&ads, masklay, keylist);
736 }
738
739 /* TODO(jbakker): Key-lists are ordered, no need to do any searching at all. */
740 /* find matching keyframe in the right direction */
741 do {
742 aknext = ED_keylist_find_next(keylist, cfranext);
743
744 if (aknext) {
745 if (scene->r.cfra == int(aknext->cfra)) {
746 /* make this the new starting point for the search and ignore */
747 cfranext = aknext->cfra;
748 }
749 else {
750 /* this changes the frame, so set the frame and we're done */
751 if (++nextcount == U.view_frame_keyframes) {
752 donenext = true;
753 }
754 }
755 cfranext = aknext->cfra;
756 }
757 } while ((aknext != nullptr) && (donenext == false));
758
759 do {
760 akprev = ED_keylist_find_prev(keylist, cfraprev);
761
762 if (akprev) {
763 if (scene->r.cfra == int(akprev->cfra)) {
764 /* make this the new starting point for the search */
765 }
766 else {
767 /* this changes the frame, so set the frame and we're done */
768 if (++prevcount == U.view_frame_keyframes) {
769 doneprev = true;
770 }
771 }
772 cfraprev = akprev->cfra;
773 }
774 } while ((akprev != nullptr) && (doneprev == false));
775
776 /* free temp stuff */
777 ED_keylist_free(keylist);
778
779 /* any success? */
780 if (doneprev || donenext) {
781 if (doneprev) {
782 *r_prevfra = cfraprev;
783 }
784 else {
785 *r_prevfra = scene->r.cfra - (cfranext - scene->r.cfra);
786 }
787
788 if (donenext) {
789 *r_nextfra = cfranext;
790 }
791 else {
792 *r_nextfra = scene->r.cfra + (scene->r.cfra - cfraprev);
793 }
794
795 return true;
796 }
797
798 return false;
799}
800
801void ANIM_center_frame(bContext *C, int smooth_viewtx)
802{
804 if (!scene) {
805 return;
806 }
807
808 ARegion *region = CTX_wm_region(C);
809 float w = BLI_rctf_size_x(&region->v2d.cur);
810 rctf newrct;
811 int nextfra, prevfra;
812
813 switch (U.view_frame_type) {
815 const float fps = scene->frames_per_second();
816 newrct.xmax = scene->r.cfra + U.view_frame_seconds * fps + 1;
817 newrct.xmin = scene->r.cfra - U.view_frame_seconds * fps - 1;
818 newrct.ymax = region->v2d.cur.ymax;
819 newrct.ymin = region->v2d.cur.ymin;
820 break;
821 }
822
823 /* hardest case of all, look for all keyframes around frame and display those */
825 if (find_prev_next_keyframes(C, &nextfra, &prevfra)) {
826 newrct.xmax = nextfra;
827 newrct.xmin = prevfra;
828 newrct.ymax = region->v2d.cur.ymax;
829 newrct.ymin = region->v2d.cur.ymin;
830 break;
831 }
832 /* else drop through, keep range instead */
834
836 default:
837 newrct.xmax = scene->r.cfra + (w / 2);
838 newrct.xmin = scene->r.cfra - (w / 2);
839 newrct.ymax = region->v2d.cur.ymax;
840 newrct.ymin = region->v2d.cur.ymin;
841 break;
842 }
843
844 ui::view2d_smooth_view(C, region, &newrct, smooth_viewtx);
845}
846/* *************************************************** */
847
848rctf ANIM_frame_range_view2d_add_xmargin(const View2D &view_2d, const rctf view_rect)
849{
850 /* Keyframe diamonds seem to be drawn at 10 pixels wide, multiplied by the UI scale. */
851 const float keyframe_size = 10 * UI_SCALE_FAC;
852 const float margin_in_px = 4 * keyframe_size;
853
854 /* This cannot use view2d_scale_get_x(view_2d) because that would use the
855 * current scale of the view, and not the one we'd get once `view_rect` is
856 * applied. And this function should not assume that view_2d.cur == view_rect.
857 *
858 * As an added bonus, the division is inverted (compared to
859 * view2d_scale_get_x()) so that we can multiply with the result instead of
860 * doing yet another division. */
861 const float target_scale = BLI_rctf_size_x(&view_rect) / BLI_rcti_size_x(&view_2d.mask);
862 const float margin_in_frames = margin_in_px * target_scale;
863
864 /* Limit the margin to a maximum of 12.5% of the available size. This will
865 * make the margins smaller when the view gets smaller, but for large views
866 * still retain the fixed size calculated above */
867 const float margin_max = 0.125f * BLI_rctf_size_x(&view_rect);
868 const float margin = std::min(margin_in_frames, margin_max);
869
870 rctf rect_with_margin = view_rect;
871 rect_with_margin.xmin -= margin;
872 rect_with_margin.xmax += margin;
873
874 return rect_with_margin;
875}
876
877} // namespace blender
#define ATTR_FALLTHROUGH
Object is a sort of wrapper for general info.
#define PRVRANGEON
#define UI_SCALE_FAC
#define RNA_SUBTYPE_UNIT_VALUE(subtype)
Definition RNA_types.hh:268
#define RNA_SUBTYPE_UNIT(subtype)
Definition RNA_types.hh:266
#define C
Definition RandGen.cpp:29
#define CLAMP_MAX(a, c)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define CLAMP_MIN(a, b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define FLT_MAX
Scene * scene_or_sequencer_scene_from_context(const bContext &C)
const Strip * get_scene_strip_for_time_sync(const Scene *sequencer_scene)
float give_frame_index(const Scene *scene, const Strip *strip, float timeline_frame)
Definition strip_time.cc:43
void get_color_shade_alpha_4fv(int colorid, int coloffset, int alphaoffset, float col[4])
void view2d_smooth_view(const bContext *C, ARegion *region, const rctf *cur, int smooth_viewtx)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ANIM_draw_framerange(Scene *scene, View2D *v2d)
Definition anim_draw.cc:176
double BKE_unit_value_scale(const UnitSettings &settings, int unit_type, double value)
Definition unit.cc:1963
SpaceAction * CTX_wm_space_action(const bContext *C)
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
void immEnd()
unsigned int uint
Definition BKE_text.h:55
WorkSpace * CTX_wm_workspace(const bContext *C)
void ANIM_draw_action_framerange(AnimData *adt, bAction *action, View2D *v2d, float ymin, float ymax)
Definition anim_draw.cc:212
PointerRNA RNA_id_pointer_create(ID *id)
@ ANIM_UNITCONV_RESTORE
@ ANIM_UNITCONV_NORMALIZE_FREEZE
@ ANIM_UNITCONV_NORMALIZE
GPUVertFormat * immVertexFormat()
void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag)
Definition anim_draw.cc:60
eNlaTime_ConvertModes
Definition BKE_nla.hh:555
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
@ NLATIME_CONVERT_MAP
Definition BKE_nla.hh:563
@ PROP_UNIT_LENGTH
Definition RNA_types.hh:222
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:226
@ PROP_UNIT_MASS
Definition RNA_types.hh:225
@ PROP_UNIT_TIME
Definition RNA_types.hh:227
const ActKeyColumn * ED_keylist_find_prev(const AnimKeylist *keylist, const float cfra)
void immBegin(GPUPrimType, uint vertex_len)
float ANIM_nla_tweakedit_remap(bAnimListElem *ale, const float cframe, const eNlaTime_ConvertModes mode)
Definition anim_draw.cc:329
UnitConversion BKE_unit_preferred_conversion_get(const UnitSettings &settings, int unit_type)
Definition unit.cc:2658
MINLINE int max_ii(int a, int b)
@ TH_ANIM_PREVIEW_RANGE
@ TH_ANIM_SCENE_STRIP_RANGE
rctf ANIM_frame_range_view2d_add_xmargin(const View2D &view_2d, const rctf view_rect)
Definition anim_draw.cc:848
bool ANIM_nla_mapping_allowed(const bAnimListElem *ale)
Definition anim_draw.cc:279
Span< rna_path::Item > ParsedRNAPathRef
Definition RNA_path.hh:113
@ ANIMTYPE_MASKDATABLOCK
@ ANIMTYPE_NLACURVE
@ ANIMTYPE_GREASE_PENCIL_LAYER_GROUP
@ ANIMTYPE_GREASE_PENCIL_DATABLOCK
@ ANIMTYPE_FCURVE
@ ANIMTYPE_GPLAYER
@ ANIMTYPE_GREASE_PENCIL_LAYER
@ ANIMTYPE_SUMMARY
@ ANIMTYPE_MASKLAYER
@ ANIMTYPE_DSGPENCIL
MINLINE uint ulp_diff_ff(float a, float b)
short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, FCurve *fcu, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
void immUnbindProgram()
const ActKeyColumn * ED_keylist_find_next(const AnimKeylist *keylist, const float cfra)
void ANIM_nla_mapping_apply_if_needed_fcurve(bAnimListElem *ale, FCurve *fcu, const bool restore, const bool only_keys)
Definition anim_draw.cc:406
@ ADS_OVERLAY_SHOW_OVERLAYS
@ ADS_SHOW_SCENE_STRIP_FRAME_RANGE
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
Global G
Definition blender.cc:57
static short bezt_nlamapping_apply(KeyframeEditData *ked, BezTriple *bezt)
Definition anim_draw.cc:362
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void immUniformThemeColor(int color_id)
void ANIM_center_frame(bContext *C, int smooth_viewtx)
Definition anim_draw.cc:801
void gpencil_to_keylist(bDopeSheet *ads, bGPdata *gpd, AnimKeylist *keylist, const bool active)
void immVertex2f(uint attr_id, float x, float y)
static bool find_prev_next_keyframes(bContext *C, int *r_nextfra, int *r_prevfra)
Definition anim_draw.cc:704
BMesh const char void * data
void immUniformThemeColorShade(int color_id, int offset)
MaskLayer * BKE_mask_layer_active(Mask *mask)
void ED_keylist_prepare_for_direct_access(AnimKeylist *keylist)
AnimKeylist * ED_keylist_create()
Mask * CTX_data_edit_mask(const bContext *C)
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
static void fcurve_scene_coord_range_get(Scene *scene, const FCurve *fcu, float *r_min_coord, float *r_max_coord)
Definition anim_draw.cc:434
void ANIM_draw_previewrange(const Scene *scene, View2D *v2d, int end_frame_width)
Definition anim_draw.cc:88
static short bezt_nlamapping_restore(KeyframeEditData *ked, BezTriple *bezt)
Definition anim_draw.cc:343
@ SIPO_NORMALIZE_FREEZE
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void ob_to_keylist(bDopeSheet *ads, Object *ob, AnimKeylist *keylist, const int saction_flag, float2 range)
void scene_to_keylist(bDopeSheet *ads, Scene *sce, AnimKeylist *keylist, const int saction_flag, float2 range)
short(*)(KeyframeEditData *ked, BezTriple *bezt) KeyframeEditFunc
PropertySubType RNA_property_subtype(PropertyRNA *prop)
void BKE_fcurve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2])
float evaluate_fcurve_only_curve(const FCurve *fcu, float evaltime)
void immUniform4f(const char *name, float x, float y, float z, float w)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
MINLINE float max_ff(float a, float b)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
Definition anim_draw.cc:636
void ANIM_nla_mapping_apply_fcurve(AnimData *adt, FCurve *fcu, bool restore, bool only_keys)
Definition anim_draw.cc:379
@ G_TRANSFORM_FCURVES
void mask_to_keylist(bDopeSheet *, MaskLayer *masklay, AnimKeylist *keylist)
void ED_keylist_free(AnimKeylist *keylist)
Scene * CTX_data_scene(const bContext *C)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void immUniform1i(const char *name, int x)
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
Definition curve.cc:1696
@ ZOOM_FRAME_MODE_KEEP_RANGE
@ ZOOM_FRAME_MODE_KEYFRAMES
MINLINE int min_ii(int a, int b)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
Object * CTX_data_active_object(const bContext *C)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
ARegion * CTX_wm_region(const bContext *C)
void ANIM_draw_scene_strip_range(const bContext *C, View2D *v2d)
Definition anim_draw.cc:119
static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, float *r_offset)
Definition anim_draw.cc:561
short ANIM_get_normalization_flags(SpaceLink *space_link)
Definition anim_draw.cc:420
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< NlaTrack > nla_tracks
eBezTriple_Interpolation ipo
ChannelDriver * driver
unsigned int totvert
struct UnitSettings unit
struct bGPdata * gpd
struct RenderData r
SpaceActionOverlays_Flag flag
SpaceActionOverlays overlays
eGraphEdit_Flag flag
struct Scene * sequencer_scene
eAnim_ChannelType type
eDopeSheet_FilterFlag filterflag