Blender V5.3
nla_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <cmath>
11#include <cstdio>
12#include <cstdlib>
13#include <cstring>
14
15#include "DNA_anim_enums.h"
16#include "DNA_anim_types.h"
17#include "DNA_screen_types.h"
18#include "DNA_space_types.h"
19
20#include "BLI_bounds_types.hh"
21#include "BLI_listbase.hh"
22#include "BLI_string_utf8.hh"
23#include "BLI_utildefines.hh"
24
25#include "BLT_translation.hh"
26
27#include "BKE_fcurve.hh"
28#include "BKE_nla.hh"
29
30#include "ED_anim_api.hh"
31#include "ED_keyframes_draw.hh"
33
34#include "GPU_immediate.hh"
35#include "GPU_immediate_util.hh"
36#include "GPU_state.hh"
37
38#include "WM_types.hh"
39
40#include "UI_interface.hh"
41#include "UI_resources.hh"
42#include "UI_view2d.hh"
43
44#include "nla_intern.hh" /* own include */
45#include "nla_private.h"
46
47namespace blender {
48
49/* *********************************************** */
50/* Strips */
51
52/* Action-Line ---------------------- */
53
54void nla_action_get_color(AnimData *adt, bAction *act, float color[4])
55{
56 if (adt && (adt->flag & ADT_NLA_EDIT_ON)) {
57 /* greenish color (same as tweaking strip) */
59 }
60 else {
61 if (act) {
62 /* reddish color - same as dope-sheet summary */
64 }
65 else {
66 /* grayish-red color */
68 }
69 }
70
71 /* when an NLA track is tagged "solo", action doesn't contribute,
72 * so shouldn't be as prominent */
73 if (adt && (adt->flag & ADT_NLA_SOLO_TRACK)) {
74 color[3] *= 0.15f;
75 }
76}
77
78/* draw the keyframes in the specified Action */
80 View2D *v2d, AnimData *adt, bAction *act, float y, float ymin, float ymax)
81{
82 if (act == nullptr) {
83 return;
84 }
85
86 /* get a list of the keyframes with NLA-scaling applied */
87 AnimKeylist *keylist = ED_keylist_create();
88 action_to_keylist(adt, act, keylist, 0, {v2d->cur.xmin, v2d->cur.xmax});
89
90 if (ED_keylist_is_empty(keylist)) {
91 ED_keylist_free(keylist);
92 return;
93 }
94
95 /* draw a darkened region behind the strips
96 * - get and reset the background color, this time without the alpha to stand out better
97 * (amplified alpha is used instead, but clamped to avoid 100% opacity)
98 */
99 float color[4];
100 nla_action_get_color(adt, act, color);
101 color[3] = min_ff(0.7f, color[3] * 2.5f);
102
103 GPUVertFormat *format = immVertexFormat();
104 uint pos_id = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
105
107
109
110 /* - draw a rect from the first to the last frame (no extra overlaps for now)
111 * that is slightly stumpier than the track background (hardcoded 2-units here)
112 */
113
114 Bounds<float> frame_range;
115 ED_keylist_all_keys_frame_range(keylist, &frame_range);
116 immRectf(pos_id, frame_range.min, ymin + 2, frame_range.max, ymax - 2);
118
119 /* Count keys before drawing. */
120 const ListBaseT<ActKeyColumn> *keys = ED_keylist_listbase(keylist);
121 uint key_len = keys->count();
122
123 if (key_len > 0) {
124 format = immVertexFormat();
125 KeyframeShaderBindings sh_bindings;
126 sh_bindings.pos_id = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
127 sh_bindings.size_id = GPU_vertformat_attr_add(format, "size", gpu::VertAttrType::SFLOAT_32);
128 sh_bindings.color_id = GPU_vertformat_attr_add(
129 format, "color", gpu::VertAttrType::UNORM_8_8_8_8);
131 format, "outlineColor", gpu::VertAttrType::UNORM_8_8_8_8);
132 sh_bindings.flags_id = GPU_vertformat_attr_add(format, "flags", gpu::VertAttrType::UINT_32);
133
136 immUniform1f("outline_scale", 1.0f);
137 immUniform2f("ViewportSize", BLI_rcti_size_x(&v2d->mask) + 1, BLI_rcti_size_y(&v2d->mask) + 1);
138 immBegin(GPU_PRIM_POINTS, key_len);
139
140 /* - disregard the selection status of keyframes so they draw a certain way
141 * - size is 6.0f which is smaller than the editable keyframes, so that there is a distinction
142 */
143 for (const ActKeyColumn &ak : *keys) {
144 draw_keyframe_shape(ak.cfra,
145 y,
146 6.0f,
147 false,
148 ak.key_type,
150 1.0f,
151 &sh_bindings,
154 }
155
156 immEnd();
159 }
160
161 /* free icons */
162 ED_keylist_free(keylist);
163}
164
165/* Strip Markers ------------------------ */
166
167/* Markers inside an action strip */
169 NlaStrip *strip, float yminc, float ymaxc, int shade, const bool dashed)
170{
171 const bAction *act = strip->act;
172
173 if (ELEM(nullptr, act, act->markers.first_)) {
174 return;
175 }
176
177 const uint shdr_pos = GPU_vertformat_attr_add(
178 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
179 if (dashed) {
181
182 float viewport_size[4];
183 GPU_viewport_size_get_f(viewport_size);
185 "viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
186
187 immUniform1i("colors_len", 0); /* "simple" mode */
188 immUniform1f("dash_width", 6.0f);
189 immUniform1f("udash_factor", 0.5f);
190 }
191 else {
193 }
195
196 immBeginAtMost(GPU_PRIM_LINES, act->markers.count() * 2);
197 for (TimeMarker &marker : act->markers) {
198 if ((marker.frame > strip->actstart) && (marker.frame < strip->actend)) {
199 float frame = nlastrip_get_frame(strip, marker.frame, NLATIME_CONVERT_MAP);
200
201 /* just a simple line for now */
202 /* XXX: draw a triangle instead... */
203 immVertex2f(shdr_pos, frame, yminc + 1);
204 immVertex2f(shdr_pos, frame, ymaxc - 1);
205 }
206 }
207 immEnd();
208
210}
211
212/* Markers inside a NLA-Strip */
213static void nla_strip_draw_markers(NlaStrip *strip, float yminc, float ymaxc)
214{
215 GPU_line_width(2.0f);
216
217 if (strip->type == NLASTRIP_TYPE_CLIP) {
218 /* try not to be too conspicuous, while being visible enough when transforming */
219 int shade = (strip->flag & NLASTRIP_FLAG_SELECT) ? -60 : -40;
220
221 /* just draw the markers in this clip */
222 nla_actionclip_draw_markers(strip, yminc, ymaxc, shade, true);
223 }
224 else if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
225 /* just a solid color, so that it is very easy to spot */
226 int shade = 20;
227 /* draw the markers in the first level of strips only (if they are actions) */
228 for (NlaStrip &nls : strip->strips) {
229 if (nls.type == NLASTRIP_TYPE_CLIP) {
230 nla_actionclip_draw_markers(&nls, yminc, ymaxc, shade, false);
231 }
232 }
233 }
234
235 GPU_line_width(1.0f);
236}
237
238/* Strips (Proper) ---------------------- */
239
240/* Get colors for drawing NLA Strips. */
241static void nla_strip_get_color_inside(AnimData *adt, NlaStrip *strip, float color[3])
242{
243 const bool is_selected = strip->flag & NLASTRIP_FLAG_SELECT;
244 switch (strip->type) {
246 /* Action Strip. */
247 if (adt && (adt->flag & ADT_NLA_EDIT_ON) && (adt->actstrip == strip)) {
248 /* Active strip tweak - tweak theme is applied only to active edit strip,
249 * not linked-duplicates.
250 */
252 break;
253 }
254
255 if (strip->flag & NLASTRIP_FLAG_TWEAKUSER) {
256 /* Non-active strip tweak - display warning theme
257 * for non active linked-duplicates.
258 */
260 break;
261 }
262 if (strip->flag & NLASTRIP_FLAG_SELECT) {
263 /* selected. */
265 break;
266 }
267
268 /* unselected - use standard strip theme. */
270 break;
271
273 /* Meta Strip. */
275 break;
277 /* Transition Strip. */
279 break;
280 }
282 /* Sound Strip. */
284 break;
285 default: {
286 /* default to unselected theme. */
288 } break;
289 }
290}
291
292/* helper call for drawing influence/time control curves for a given NLA-strip */
293static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc, uint pos)
294{
295 const float yheight = ymaxc - yminc;
296
297 /* draw with AA'd line */
298 GPU_line_smooth(true);
300
301 /* Fully opaque line on selected strips. */
302 if (strip->flag & NLASTRIP_FLAG_SELECT) {
303 /* TODO: Use theme setting. */
304 immUniformColor3f(1.0f, 1.0f, 1.0f);
305 }
306 else {
307 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
308 }
309
310 /* influence -------------------------- */
311 if (strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) {
312 const FCurve *fcu = BKE_fcurve_find(&strip->fcurves, "influence", 0);
313
314 /* plot the curve (over the strip's main region) */
315 if (fcu) {
316 immBegin(GPU_PRIM_LINE_STRIP, abs(int(strip->end - strip->start) + 1));
317
318 /* sample at 1 frame intervals, and draw
319 * - min y-val is yminc, max is y-maxc, so clamp in those regions
320 */
321 for (float cfra = strip->start; cfra <= strip->end; cfra += 1.0f) {
322 float y = evaluate_fcurve(fcu, cfra); /* assume this to be in 0-1 range */
323 CLAMP(y, 0.0f, 1.0f);
324 immVertex2f(pos, cfra, ((y * yheight) + yminc));
325 }
326
327 immEnd();
328 }
329 }
330 else {
331 /* use blend in/out values only if both aren't zero */
332 if ((IS_EQF(strip->blendin, 0.0f) && IS_EQF(strip->blendout, 0.0f)) == 0) {
334
335 /* start of strip - if no blendin, start straight at 1,
336 * otherwise from 0 to 1 over blendin frames */
337 if (IS_EQF(strip->blendin, 0.0f) == 0) {
338 immVertex2f(pos, strip->start, yminc);
339 immVertex2f(pos, strip->start + strip->blendin, ymaxc);
340 }
341 else {
342 immVertex2f(pos, strip->start, ymaxc);
343 }
344
345 /* end of strip */
346 if (IS_EQF(strip->blendout, 0.0f) == 0) {
347 immVertex2f(pos, strip->end - strip->blendout, ymaxc);
348 immVertex2f(pos, strip->end, yminc);
349 }
350 else {
351 immVertex2f(pos, strip->end, ymaxc);
352 }
353
354 immEnd();
355 }
356 }
357
358 /* turn off AA'd lines */
359 GPU_line_smooth(false);
361}
362
363/* helper call to setup dashed-lines for strip outlines */
364static uint nla_draw_use_dashed_outlines(const float color[4], bool muted)
365{
366 /* Note that we use dashed shader here, and make it draw solid lines if not muted... */
367 uint shdr_pos = GPU_vertformat_attr_add(
368 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
370
371 float viewport_size[4];
372 GPU_viewport_size_get_f(viewport_size);
373 immUniform2f("viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
374
375 immUniform1i("colors_len", 0); /* Simple dashes. */
377
378 /* line style: dotted for muted */
379 if (muted) {
380 /* dotted - and slightly thicker for readability of the dashes */
381 immUniform1f("dash_width", 5.0f);
382 immUniform1f("udash_factor", 0.4f);
383 GPU_line_width(1.5f);
384 }
385 else {
386 /* solid line */
387 immUniform1f("udash_factor", 2.0f);
388 GPU_line_width(1.0f);
389 }
390
391 return shdr_pos;
392}
393
398static bool is_nlastrip_enabled(AnimData *adt, NlaTrack *nlt, NlaStrip *strip)
399{
401 BLI_assert(adt);
402 if (!adt) {
403 return true;
404 }
405
406 if ((nlt->flag & NLATRACK_DISABLED) == 0) {
407 return true;
408 }
409
411 return adt->actstrip == strip;
412}
413
414/* main call for drawing a single NLA-strip */
415static void nla_draw_strip(SpaceNla *snla,
416 AnimData *adt,
417 NlaTrack *nlt,
418 NlaStrip *strip,
419 View2D *v2d,
420 float yminc,
421 float ymaxc)
422{
423 /* If there is no 'adt', this strip came from nowhere. */
424 BLI_assert(adt);
425 if (!adt) {
426 return;
427 }
428
429 const bool adt_has_solo_track = (adt->flag & ADT_NLA_SOLO_TRACK);
430 const bool is_track_solo = (nlt->flag & NLATRACK_SOLO);
431 const bool is_other_track_soloed = adt_has_solo_track && !is_track_solo;
432
433 const bool muted = ((nlt->flag & NLATRACK_MUTED) || (strip->flag & NLASTRIP_FLAG_MUTED));
434 float color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
435 uint shdr_pos;
436
437 /* get color of strip */
439
440 shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
442
443 /* draw extrapolation info first (as backdrop)
444 * - but this should only be drawn if track has some contribution
445 */
446 if ((strip->extendmode != NLASTRIP_EXTEND_NOTHING) && !is_other_track_soloed) {
447 /* enable transparency... */
449
450 switch (strip->extendmode) {
451 /* since this does both sides,
452 * only do the 'before' side, and leave the rest to the next case */
454 /* only need to draw here if there's no strip before since
455 * it only applies in such a situation
456 */
457 if (strip->prev == nullptr) {
458 /* set the drawing color to the color of the strip, but with very faint alpha */
460
461 /* draw the rect to the edge of the screen */
462 immRectf(shdr_pos, v2d->cur.xmin, yminc, strip->start, ymaxc);
463 }
465
466 /* this only draws after the strip */
468 /* only need to try and draw if the next strip doesn't occur immediately after */
469 if ((strip->next == nullptr) || (IS_EQF(strip->next->start, strip->end) == 0)) {
470 /* set the drawing color to the color of the strip, but this time less faint */
472
473 /* draw the rect to the next strip or the edge of the screen */
474 float x2 = strip->next ? strip->next->start : v2d->cur.xmax;
475 immRectf(shdr_pos, strip->end, yminc, x2, ymaxc);
476 }
477 break;
479 break;
480 }
481
483 }
484
485 /* draw 'inside' of strip itself */
486 const bool is_invalid_location = (strip->flag & NLASTRIP_FLAG_INVALID_LOCATION);
487 if (!is_other_track_soloed && is_nlastrip_enabled(adt, nlt, strip) && !is_invalid_location) {
489
490 /* strip is in normal track */
491 ui::draw_roundbox_corner_set(ui::CNR_ALL); /* all corners rounded */
492 rctf rect;
493 rect.xmin = strip->start;
494 rect.xmax = strip->end;
495 rect.ymin = yminc;
496 rect.ymax = ymaxc;
497 ui::draw_roundbox_4fv(&rect, true, 0.0f, color);
498
499 /* restore current vertex format & program (roundbox trashes it) */
500 shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
502 }
503 else {
504 /* strip is in disabled track - make less visible */
506
508 immRectf(shdr_pos, strip->start, yminc, strip->end, ymaxc);
510 }
511
512 /* draw strip's control 'curves'
513 * - only if user hasn't hidden them...
514 */
515 if ((snla->flag & SNLA_NOSTRIPCURVES) == 0) {
516 nla_draw_strip_curves(strip, yminc, ymaxc, shdr_pos);
517 }
518
520
521 /* draw markings indicating locations of local markers
522 * (useful for lining up different actions) */
523 if ((snla->flag & SNLA_NOLOCALMARKERS) == 0) {
524 nla_strip_draw_markers(strip, yminc, ymaxc);
525 }
526
527 /* draw strip outline
528 * - color used here is to indicate active vs non-active
529 */
530 if (is_invalid_location) {
531 color[0] = 1.0f;
532 color[1] = color[2] = 0.15f;
533 }
534 else if (strip->flag & NLASTRIP_FLAG_ACTIVE) {
535 /* strip should appear 'sunken', so draw a light border around it */
536 color[0] = color[1] = color[2] = 1.0f; /* FIXME: hardcoded temp-hack colors */
537 }
538 else {
539 /* strip should appear to stand out, so draw a dark border around it */
540 color[0] = color[1] = color[2] = 0.0f; /* FIXME: or 1.0f ?? */
541 }
542
543 /* draw outline
544 * - dashed-line shader is loaded after this block
545 */
546 if (muted) {
547 /* muted - draw dotted, squarish outline (for simplicity) */
548 shdr_pos = nla_draw_use_dashed_outlines(color, muted);
549 imm_draw_box_wire_2d(shdr_pos, strip->start, yminc, strip->end, ymaxc);
550 }
551 else {
552 /* non-muted - draw solid, rounded outline */
553 rctf rect;
554 rect.xmin = strip->start;
555 rect.xmax = strip->end;
556 rect.ymin = yminc;
557 rect.ymax = ymaxc;
558 ui::draw_roundbox_4fv(&rect, false, 0.0f, color);
559
560 /* restore current vertex format & program (roundbox trashes it) */
561 shdr_pos = nla_draw_use_dashed_outlines(color, muted);
562 }
563
564 /* if action-clip strip, draw lines delimiting repeats too (in the same color as outline) */
565 if ((strip->type == NLASTRIP_TYPE_CLIP) && strip->repeat > 1.0f) {
566 float repeatLen = (strip->actend - strip->actstart) * strip->scale;
567
568 /* only draw lines for whole-numbered repeats, starting from the first full-repeat
569 * up to the last full repeat (but not if it lies on the end of the strip)
570 */
572 for (int i = 1; i < strip->repeat; i++) {
573 float repeatPos = strip->start + (repeatLen * i);
574
575 /* don't draw if line would end up on or after the end of the strip */
576 if (repeatPos < strip->end) {
577 immVertex2f(shdr_pos, repeatPos, yminc + 4);
578 immVertex2f(shdr_pos, repeatPos, ymaxc - 4);
579 }
580 }
581 immEnd();
582 }
583 /* or if meta-strip, draw lines delimiting extents of sub-strips
584 * (in same color as outline, if more than 1 exists) */
585 else if ((strip->type == NLASTRIP_TYPE_META) && (strip->strips.first() != strip->strips.last()))
586 {
587 const float y = (ymaxc - yminc) * 0.5f + yminc;
588
589 /* up to 2 lines per strip */
590 immBeginAtMost(GPU_PRIM_LINES, 4 * strip->strips.count());
591
592 /* only draw first-level of child-strips, but don't draw any lines on the endpoints */
593 for (NlaStrip &cs : strip->strips) {
594 /* draw start-line if not same as end of previous (and only if not the first strip)
595 * - on upper half of strip
596 */
597 if ((cs.prev) && IS_EQF(cs.prev->end, cs.start) == 0) {
598 immVertex2f(shdr_pos, cs.start, y);
599 immVertex2f(shdr_pos, cs.start, ymaxc);
600 }
601
602 /* draw end-line if not the last strip
603 * - on lower half of strip
604 */
605 if (cs.next) {
606 immVertex2f(shdr_pos, cs.end, yminc);
607 immVertex2f(shdr_pos, cs.end, y);
608 }
609 }
610
611 immEnd();
612 }
613
615}
616
619 NlaTrack *nlt,
620 NlaStrip *strip,
621 View2D *v2d,
622 float xminc,
623 float xmaxc,
624 float yminc,
625 float ymaxc)
626{
627 const bool solo = !((adt && (adt->flag & ADT_NLA_SOLO_TRACK)) &&
628 (nlt->flag & NLATRACK_SOLO) == 0);
629
630 char str[256];
631 size_t str_len;
632 uchar col[4];
633
634 /* just print the name and the range */
635 if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
636 str_len = STRNCPY_UTF8_RLEN(str, DATA_("Temp-Meta"));
637 }
638 else {
639 str_len = STRNCPY_UTF8_RLEN(str, strip->name);
640 }
641
642 /* set text color - if colors (see above) are light, draw black text, otherwise draw white */
644 col[0] = col[1] = col[2] = 0;
645 }
646 else {
647 col[0] = col[1] = col[2] = 255;
648 }
649 /* Default strip to 100% opacity. */
650 col[3] = 255;
651
652 /* Reduce text opacity if a track is soloed,
653 * and if target track isn't the soloed track. */
654 if (!solo) {
655 col[3] = 128;
656 }
657
658 /* set bounding-box for text
659 * - padding of 2 'units' on either side
660 */
661 /* TODO: make this centered? */
662 rctf rect;
663 rect.xmin = xminc;
664 rect.ymin = yminc;
665 rect.xmax = xmaxc;
666 rect.ymax = ymaxc;
667
668 /* add this string to the cache of texts to draw */
669 ui::view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
670}
671
677 NlaTrack * /*nlt*/, NlaStrip *strip, View2D *v2d, float /*yminc*/, float ymaxc)
678{
679 const float ytol = 1.0f; /* small offset to vertical positioning of text, for legibility */
680 const uchar col[4] = {220, 220, 220, 255}; /* light gray */
681 char numstr[32];
682 size_t numstr_len;
683
684 /* Always draw times above the strip, whereas sequencer drew below + above.
685 * However, we should be fine having everything on top, since these tend to be
686 * quite spaced out.
687 * NOTE: 1 decimal point is a compromise between lack of precision (ints only, as per sequencer)
688 * while also preserving some accuracy, since we do use floats. */
689
690 /* start frame */
691 numstr_len = SNPRINTF_UTF8_RLEN(numstr, "%.1f", strip->start);
692 ui::view2d_text_cache_add(v2d, strip->start - 1.0f, ymaxc + ytol, numstr, numstr_len, col);
693
694 /* end frame */
695 numstr_len = SNPRINTF_UTF8_RLEN(numstr, "%.1f", strip->end);
696 ui::view2d_text_cache_add(v2d, strip->end, ymaxc + ytol, numstr, numstr_len, col);
697}
698
699/* ---------------------- */
700
706static ListBaseT<NlaStrip> get_visible_nla_strips(NlaTrack *nlt, View2D *v2d)
707{
708 if (nlt->strips.is_empty()) {
709 ListBaseT<NlaStrip> empty = {nullptr, nullptr};
710 return empty;
711 }
712
713 NlaStrip *first = nullptr;
714 NlaStrip *last = nullptr;
715
716 /* Find the first strip that is within the bounds of the view. */
717 for (NlaStrip &strip : nlt->strips) {
718 if (BKE_nlastrip_within_bounds(&strip, v2d->cur.xmin, v2d->cur.xmax)) {
719 first = last = &strip;
720 break;
721 }
722 }
723
724 const bool has_strips_within_bounds = first != nullptr;
725
726 if (has_strips_within_bounds) {
727 /* Find the last visible strip. */
728 for (NlaStrip *strip = first->next; strip; strip = strip->next) {
729 if (!BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) {
730 break;
731 }
732 last = strip;
733 }
734 /* Check if the first strip is adjacent to a strip outside the view to the left
735 * that has an extendmode region that should be drawn.
736 * If so, adjust the first strip to include drawing that strip as well.
737 */
738 NlaStrip *prev = first->prev;
739 if (prev && prev->extendmode != NLASTRIP_EXTEND_NOTHING) {
740 first = prev;
741 }
742 }
743 else {
744 /* No immediately visible strips.
745 * Figure out where our view is relative to the strips, then determine
746 * if the view is adjacent to a strip that should have its extendmode
747 * rendered.
748 */
749 NlaStrip *first_strip = nlt->strips.first();
750 NlaStrip *last_strip = nlt->strips.last();
751 if (first_strip && v2d->cur.xmax < first_strip->start &&
752 first_strip->extendmode == NLASTRIP_EXTEND_HOLD)
753 {
754 /* The view is to the left of all strips and the first strip has an
755 * extendmode that should be drawn.
756 */
757 first = last = first_strip;
758 }
759 else if (last_strip && v2d->cur.xmin > last_strip->end &&
760 last_strip->extendmode != NLASTRIP_EXTEND_NOTHING)
761 {
762 /* The view is to the right of all strips and the last strip has an
763 * extendmode that should be drawn.
764 */
765 first = last = last_strip;
766 }
767 else {
768 /* The view is in the middle of two strips. */
769 for (NlaStrip &strip : nlt->strips) {
770 /* Find the strip to the left by finding the strip to the right and getting its prev. */
771 if (v2d->cur.xmax < strip.start) {
772 /* If the strip to the left has an extendmode, set that as the only visible strip. */
773 if (strip.prev && strip.prev->extendmode != NLASTRIP_EXTEND_NOTHING) {
774 first = last = strip.prev;
775 }
776 break;
777 }
778 }
779 }
780 }
781
782 ListBaseT<NlaStrip> visible_strips = {first, last};
783 return visible_strips;
784}
785
787{
788 View2D *v2d = &region->v2d;
789 const float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
790 const float text_margin_x = (8 * UI_SCALE_FAC) * pixelx;
791
792 /* build list of tracks to draw */
793 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
796 size_t items = ANIM_animdata_filter(
797 ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype));
798
799 /* Update max-extent of tracks here (taking into account scrollers):
800 * - this is done to allow the track list to be scrollable, but must be done here
801 * to avoid regenerating the list again and/or also because tracks list is drawn first
802 * - offset of NLATRACK_HEIGHT*2 is added to the height of the tracks, as first is for
803 * start of list offset, and the second is as a correction for the scrollers.
804 */
805 int height = NLATRACK_TOT_HEIGHT(ac, items);
806 v2d->tot.ymin = -height;
807
808 /* Loop through tracks, and set up drawing depending on their type. */
809 float ymax = NLATRACK_FIRST_TOP(ac);
810
811 for (bAnimListElem *ale = anim_data.first(); ale; ale = ale->next, ymax -= NLATRACK_STEP(snla)) {
812 float ymin = ymax - NLATRACK_HEIGHT(snla);
813 float ycenter = (ymax + ymin + 2 * NLATRACK_SKIP - 1) / 2.0f;
814
815 /* check if visible */
816 if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
817 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax))
818 {
819 /* data to draw depends on the type of track */
820 switch (ale->type) {
821 case ANIMTYPE_NLATRACK: {
822 AnimData *adt = ale->adt;
823 NlaTrack *nlt = static_cast<NlaTrack *>(ale->data);
824 ListBaseT<NlaStrip> visible_nla_strips = get_visible_nla_strips(nlt, v2d);
825
826 /* Draw each visible strip in the track. */
827 for (NlaStrip &strip : visible_nla_strips) {
828 const float xminc = strip.start + text_margin_x;
829 const float xmaxc = strip.end - text_margin_x;
830
831 /* draw the visualization of the strip */
832 nla_draw_strip(snla, adt, nlt, &strip, v2d, ymin, ymax);
833
834 /* add the text for this strip to the cache */
835 if (xminc < xmaxc) {
836 nla_draw_strip_text(adt, nlt, &strip, v2d, xminc, xmaxc, ymin, ymax);
837 }
838
839 /* if transforming strips (only real reason for temp-metas currently),
840 * add to the cache the frame numbers of the strip's extents
841 */
842 if (strip.flag & NLASTRIP_FLAG_TEMP_META) {
843 nla_draw_strip_frames_text(nlt, &strip, v2d, ymin, ymax);
844 }
845 }
846 break;
847 }
848 case ANIMTYPE_NLAACTION: {
849 AnimData *adt = ale->adt;
850
851 /* Draw the manually set intended playback frame range highlight. */
852 if (ale->data) {
853 ANIM_draw_action_framerange(adt, static_cast<bAction *>(ale->data), v2d, ymin, ymax);
854 }
855
857 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
859
860 /* just draw a semi-shaded rect spanning the width of the viewable area, based on if
861 * there's data and the action's extrapolation mode. Draw a second darker rect within
862 * which we draw keyframe indicator dots if there's data.
863 */
865
866 /* get colors for drawing */
867 float color[4];
868 nla_action_get_color(adt, static_cast<bAction *>(ale->data), color);
870
871 /* draw slightly shifted up for greater separation from standard tracks,
872 * but also slightly shorter for some more contrast when viewing the strips
873 */
874 switch (adt->act_extendmode) {
876 immRectf(pos,
877 v2d->cur.xmin,
878 ymin + NLATRACK_SKIP,
879 v2d->cur.xmax,
880 ymax + NLATRACK_SKIP - 1);
881 break;
882 }
884 if (ale->data == nullptr) {
885 /* This can happen if the object itself has no action attached anymore (e.g. after
886 * using "push down"). */
887 break;
888 }
889 const animrig::Action &action = static_cast<bAction *>(ale->data)->wrap();
890 float2 frame_range = action.get_frame_range();
891 BKE_nla_clip_length_ensure_nonzero(&frame_range[0], &frame_range[1]);
892
893 immRectf(
894 pos, frame_range[1], ymin + NLATRACK_SKIP, v2d->cur.xmax, ymax - NLATRACK_SKIP);
895 break;
896 }
898 break;
899 }
900
902
903 /* draw keyframes in the action */
905 adt,
906 static_cast<bAction *>(ale->data),
907 ycenter,
908 ymin + NLATRACK_SKIP,
909 ymax + NLATRACK_SKIP - 1);
910
912 break;
913 }
914 case ANIMTYPE_NONE:
917 case ANIMTYPE_SUMMARY:
918 case ANIMTYPE_SCENE:
919 case ANIMTYPE_OBJECT:
920 case ANIMTYPE_GROUP:
921 case ANIMTYPE_FCURVE:
928 case ANIMTYPE_DSMAT:
929 case ANIMTYPE_DSLAM:
930 case ANIMTYPE_DSCAM:
932 case ANIMTYPE_DSCUR:
933 case ANIMTYPE_DSSKEY:
934 case ANIMTYPE_DSWOR:
935 case ANIMTYPE_DSNTREE:
936 case ANIMTYPE_DSPART:
937 case ANIMTYPE_DSMBALL:
938 case ANIMTYPE_DSARM:
939 case ANIMTYPE_DSMESH:
940 case ANIMTYPE_DSTEX:
941 case ANIMTYPE_DSLAT:
943 case ANIMTYPE_DSSPK:
945 case ANIMTYPE_DSMCLIP:
946 case ANIMTYPE_DSHAIR:
951 case ANIMTYPE_GPLAYER:
957 case ANIMTYPE_PALETTE:
959 break;
960 }
961 }
962 }
963
964 /* Free temporary tracks. */
965 ANIM_animdata_freelist(&anim_data);
966}
967
968/* *********************************************** */
969/* Track List */
970
972 bAnimContext *ac,
973 ARegion *region,
974 const ListBaseT<bAnimListElem> &anim_data)
975{
976
977 SpaceNla *snla = reinterpret_cast<SpaceNla *>(ac->sl);
978 View2D *v2d = &region->v2d;
979
980 /* need to do a view-sync here, so that the keys area doesn't jump around
981 * (it must copy this) */
982 ui::view2d_sync(nullptr, ac->area, v2d, V2D_LOCK_COPY);
983
984 /* draw tracks */
985 { /* first pass: just the standard GL-drawing for backdrop + text */
986 size_t track_index = 0;
987 float ymax = NLATRACK_FIRST_TOP(ac);
988
989 for (bAnimListElem *ale = anim_data.first(); ale;
990 ale = ale->next, ymax -= NLATRACK_STEP(snla), track_index++)
991 {
992 float ymin = ymax - NLATRACK_HEIGHT(snla);
993
994 /* check if visible */
995 if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
996 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax))
997 {
998 /* draw all tracks using standard channel-drawing API */
999 ANIM_channel_draw(ac, ale, ymin, ymax, track_index);
1000 }
1001 }
1002 }
1003 { /* second pass: UI widgets */
1004 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
1005 size_t track_index = 0;
1006 float ymax = NLATRACK_FIRST_TOP(ac);
1007
1008 /* set blending again, as may not be set in previous step */
1010
1011 /* Loop through tracks, and set up drawing depending on their type. */
1012 for (bAnimListElem *ale = anim_data.first(); ale;
1013 ale = ale->next, ymax -= NLATRACK_STEP(snla), track_index++)
1014 {
1015 float ymin = ymax - NLATRACK_HEIGHT(snla);
1016
1017 /* check if visible */
1018 if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
1019 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax))
1020 {
1021 /* draw all tracks using standard channel-drawing API */
1022 rctf track_rect;
1023 BLI_rctf_init(&track_rect, 0, v2d->cur.xmax, ymin, ymax);
1024 ANIM_channel_draw_widgets(C, ac, ale, block, &track_rect, track_index);
1025 }
1026 }
1027
1028 block_end(C, block);
1029 block_draw(C, block);
1030
1032 }
1033}
1034
1035/* *********************************************** */
1036
1037} // namespace blender
#define ATTR_FALLTHROUGH
#define SNPRINTF_UTF8_RLEN(dst, format,...)
#define STRNCPY_UTF8_RLEN(dst, src)
#define DATA_(msgid)
#define UI_SCALE_FAC
#define NLATRACK_SKIP
#define NLATRACK_FIRST_TOP(ac)
#define NLATRACK_TOT_HEIGHT(ac, item_amount)
#define NLATRACK_STEP(snla)
#define NLATRACK_HEIGHT(snla)
#define C
Definition RandGen.cpp:29
#define V2D_LOCK_COPY
Definition UI_view2d.hh:110
#define CLAMP(a, b, c)
#define IN_RANGE(a, b, c)
#define ELEM(...)
#define IS_EQF(a, b)
float2 get_frame_range() const ATTR_WARN_UNUSED_RESULT
#define str(s)
#define abs
BLI_INLINE Texture * wrap(MTLTexture *texture)
void get_color_3fv(int colorid, float col[3])
void get_color_4fv(int colorid, float col[4])
char char char char void view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, size_t str_len, const unsigned char col[4])
Definition view2d.cc:2079
void view2d_text_cache_add_rectf(View2D *v2d, const rctf *rect_view, const char *str, size_t str_len, const unsigned char col[4])
Definition view2d.cc:2109
void draw_roundbox_corner_set(int type)
void view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
Definition view2d.cc:850
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
BMesh Iterators.
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode)
MINLINE float min_ff(float a, float b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc, size_t channel_index)
void action_to_keylist(AnimData *adt, bAction *dna_action, AnimKeylist *keylist, const int saction_flag, float2 range)
static void nla_draw_strip(SpaceNla *snla, AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2D *v2d, float yminc, float ymaxc)
Definition nla_draw.cc:415
void draw_nla_track_list(const bContext *C, bAnimContext *ac, ARegion *region, const ListBaseT< bAnimListElem > &anim_data)
Definition nla_draw.cc:971
void immEnd()
void immUniformColor3f(float r, float g, float b)
unsigned int uint
Definition BKE_text.h:55
void ANIM_draw_action_framerange(AnimData *adt, bAction *action, View2D *v2d, float ymin, float ymax)
Definition anim_draw.cc:212
@ NLASTRIP_FLAG_USR_INFLUENCE
@ NLASTRIP_FLAG_SELECT
@ NLASTRIP_FLAG_TWEAKUSER
@ NLASTRIP_FLAG_ACTIVE
@ NLASTRIP_FLAG_MUTED
@ NLASTRIP_FLAG_INVALID_LOCATION
@ NLASTRIP_FLAG_TEMP_META
void draw_keyframe_shape(const float x, const float y, float size, const bool sel, const eBezTriple_KeyframeType key_type, const eKeyframeShapeDrawOpts mode, const float alpha, const KeyframeShaderBindings *sh_bindings, const short handle_type, const short extreme_type)
static void nla_draw_strip_frames_text(NlaTrack *, NlaStrip *strip, View2D *v2d, float, float ymaxc)
Definition nla_draw.cc:676
void immUniform2f(const char *name, float x, float y)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
@ NLASTRIP_EXTEND_NOTHING
@ NLASTRIP_EXTEND_HOLD_FORWARD
@ NLASTRIP_EXTEND_HOLD
GPUVertFormat * immVertexFormat()
static uint nla_draw_use_dashed_outlines(const float color[4], bool muted)
Definition nla_draw.cc:364
@ NLATIME_CONVERT_MAP
Definition BKE_nla.hh:563
void immBegin(GPUPrimType, uint vertex_len)
static bool is_nlastrip_enabled(AnimData *adt, NlaTrack *nlt, NlaStrip *strip)
Definition nla_draw.cc:398
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
@ GPU_PRIM_LINE_STRIP
@ TH_NLA_TRANSITION_SEL
@ TH_NLA_TRANSITION
@ TH_NLA_TWEAK_DUPLI
static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc, uint pos)
Definition nla_draw.cc:293
bool ED_keylist_is_empty(const AnimKeylist *keylist)
void immUniformColor4fv(const float rgba[4])
static ListBaseT< NlaStrip > get_visible_nla_strips(NlaTrack *nlt, View2D *v2d)
Definition nla_draw.cc:706
@ ANIMTYPE_MASKDATABLOCK
@ ANIMTYPE_NLAACTION
@ ANIMTYPE_NLACURVE
@ ANIMTYPE_GREASE_PENCIL_LAYER_GROUP
@ ANIMTYPE_DSPOINTCLOUD
@ ANIMTYPE_DSMCLIP
@ ANIMTYPE_DSLIGHTPROBE
@ ANIMTYPE_DSNTREE
@ ANIMTYPE_GREASE_PENCIL_DATABLOCK
@ ANIMTYPE_FCURVE
@ ANIMTYPE_ANIMDATA
@ ANIMTYPE_DSVOLUME
@ ANIMTYPE_NLATRACK
@ ANIMTYPE_OBJECT
@ ANIMTYPE_GPLAYER
@ ANIMTYPE_GREASE_PENCIL_LAYER
@ ANIMTYPE_DSMBALL
@ ANIMTYPE_DSMESH
@ ANIMTYPE_NUM_TYPES
@ ANIMTYPE_NLACONTROLS
@ ANIMTYPE_DSHAIR
@ ANIMTYPE_FILLDRIVERS
@ ANIMTYPE_SUMMARY
@ ANIMTYPE_FILLACT_LAYERED
@ ANIMTYPE_SHAPEKEY
@ ANIMTYPE_SPECIALDATA__UNUSED
@ ANIMTYPE_ACTION_SLOT
@ ANIMTYPE_DSCACHEFILE
@ ANIMTYPE_MASKLAYER
@ ANIMTYPE_DSGPENCIL
@ ANIMTYPE_DSPART
@ ANIMTYPE_FILLACTD
@ ANIMTYPE_DSSKEY
@ ANIMTYPE_DSLINESTYLE
@ ANIMTYPE_PALETTE
void immUnbindProgram()
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
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void BKE_nla_clip_length_ensure_nonzero(const float *actstart, float *r_actend)
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_LIST_VISIBLE
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_LIST_CHANNELS
static void nla_strip_get_color_inside(AnimData *adt, NlaStrip *strip, float color[3])
Definition nla_draw.cc:241
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ NLASTRIP_TYPE_SOUND
@ NLASTRIP_TYPE_TRANSITION
static void nla_strip_draw_markers(NlaStrip *strip, float yminc, float ymaxc)
Definition nla_draw.cc:213
void immUniformThemeColorShade(int color_id, int offset)
void immUniformColor4f(float r, float g, float b, float a)
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
AnimKeylist * ED_keylist_create()
void nla_action_get_color(AnimData *adt, bAction *act, float color[4])
Definition nla_draw.cc:54
void ANIM_channel_draw_widgets(const bContext *C, bAnimContext *ac, bAnimListElem *ale, ui::Block *block, const rctf *rect, size_t channel_index)
bool BKE_nlastrip_within_bounds(NlaStrip *strip, float min, float max)
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 imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *region)
Definition nla_draw.cc:786
void ED_keylist_free(AnimKeylist *keylist)
void immUniformColor3fv(const float rgb[3])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
const ListBaseT< ActKeyColumn > * ED_keylist_listbase(const AnimKeylist *keylist)
void immUniform1i(const char *name, int x)
FCurve * BKE_fcurve_find(ListBaseT< FCurve > *list, const char rna_path[], int array_index)
void immUniformColor3fvAlpha(const float rgb[3], float a)
static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float ymaxc, int shade, const bool dashed)
Definition nla_draw.cc:168
void immRectf(uint pos, float x1, float y1, float x2, float y2)
bool ED_keylist_all_keys_frame_range(const AnimKeylist *keylist, Bounds< float > *r_frame_range)
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
float evaluate_fcurve(const FCurve *fcu, float evaltime)
static void nla_draw_strip_text(AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2D *v2d, float xminc, float xmaxc, float yminc, float ymaxc)
Definition nla_draw.cc:618
static void nla_action_draw_keyframes(View2D *v2d, AnimData *adt, bAction *act, float y, float ymin, float ymax)
Definition nla_draw.cc:79
#define floorf
eNlaStrip_Extrapolate_Mode act_extendmode
eAnimData_Flag flag
struct NlaStrip * next
ListBaseT< FCurve > fcurves
eNlaStrip_Extrapolate_Mode extendmode
eNlaStrip_Flag flag
ListBaseT< NlaStrip > strips
eNlaStrip_Type type
struct NlaStrip * prev
eNlaTrack_Flag flag
ListBaseT< NlaStrip > strips
eSpaceNla_Flag flag
ListBaseT< struct TimeMarker > markers
eAnimCont_Types datatype
bAnimListElem * next