diff options
Diffstat (limited to 'source/blender/editors/space_nla/nla_draw.c')
-rw-r--r-- | source/blender/editors/space_nla/nla_draw.c | 129 |
1 files changed, 104 insertions, 25 deletions
diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 6c631f46069..bb9e201d94a 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -621,7 +621,6 @@ static void nla_draw_strip(SpaceNla *snla, static void nla_draw_strip_text(AnimData *adt, NlaTrack *nlt, NlaStrip *strip, - int index, View2D *v2d, float xminc, float xmaxc, @@ -636,7 +635,7 @@ static void nla_draw_strip_text(AnimData *adt, /* just print the name and the range */ if (strip->flag & NLASTRIP_FLAG_TEMP_META) { - str_len = BLI_snprintf_rlen(str, sizeof(str), "%d) Temp-Meta", index); + str_len = BLI_snprintf_rlen(str, sizeof(str), "Temp-Meta"); } else { str_len = BLI_strncpy_rlen(str, strip->name, sizeof(str)); @@ -702,6 +701,89 @@ static void nla_draw_strip_frames_text( /* ---------------------- */ +/** + * Gets the first and last visible NLA strips on a track. + * Note that this also includes tracks that might only be + * visible because of their extendmode. + */ +static ListBase get_visible_nla_strips(NlaTrack *nlt, View2D *v2d) +{ + if (BLI_listbase_is_empty(&nlt->strips)) { + ListBase empty = {NULL, NULL}; + return empty; + } + + NlaStrip *first = NULL; + NlaStrip *last = NULL; + + /* Find the first strip that is within the bounds of the view. */ + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { + if (BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) { + first = last = strip; + break; + } + } + + const bool has_strips_within_bounds = first != NULL; + + if (has_strips_within_bounds) { + /* Find the last visible strip. */ + for (NlaStrip *strip = first->next; strip; strip = strip->next) { + if (!BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) { + break; + } + last = strip; + } + /* Check if the first strip is adjacent to a strip outside the view to the left + * that has an extendmode region that should be drawn. + * If so, adjust the first strip to include drawing that strip as well. + */ + NlaStrip *prev = first->prev; + if (prev && prev->extendmode != NLASTRIP_EXTEND_NOTHING) { + first = prev; + } + } + else { + /* No immediately visible strips. + * Figure out where our view is relative to the strips, then determine + * if the view is adjacent to a strip that should have its extendmode + * rendered. + */ + NlaStrip *first_strip = nlt->strips.first; + NlaStrip *last_strip = nlt->strips.last; + if (first_strip && v2d->cur.xmax < first_strip->start && + first_strip->extendmode == NLASTRIP_EXTEND_HOLD) { + /* The view is to the left of all strips and the first strip has an + * extendmode that should be drawn. + */ + first = last = first_strip; + } + else if (last_strip && v2d->cur.xmin > last_strip->end && + last_strip->extendmode != NLASTRIP_EXTEND_NOTHING) { + /* The view is to the right of all strips and the last strip has an + * extendmode that should be drawn. + */ + first = last = last_strip; + } + else { + /* The view is in the middle of two strips. */ + LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { + /* Find the strip to the left by finding the strip to the right and getting its prev. */ + if (v2d->cur.xmax < strip->start) { + /* If the strip to the left has an extendmode, set that as the only visible strip. */ + if (strip->prev && strip->prev->extendmode != NLASTRIP_EXTEND_NOTHING) { + first = last = strip->prev; + } + break; + } + } + } + } + + ListBase visible_strips = {first, last}; + return visible_strips; +} + void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *region) { View2D *v2d = ®ion->v2d; @@ -737,29 +819,26 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *region) case ANIMTYPE_NLATRACK: { AnimData *adt = ale->adt; NlaTrack *nlt = (NlaTrack *)ale->data; - NlaStrip *strip; - int index; - - /* draw each strip in the track (if visible) */ - for (strip = nlt->strips.first, index = 1; strip; strip = strip->next, index++) { - if (BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) { - const float xminc = strip->start + text_margin_x; - const float xmaxc = strip->end - text_margin_x; - - /* draw the visualization of the strip */ - nla_draw_strip(snla, adt, nlt, strip, v2d, ymin, ymax); - - /* add the text for this strip to the cache */ - if (xminc < xmaxc) { - nla_draw_strip_text(adt, nlt, strip, index, v2d, xminc, xmaxc, ymin, ymax); - } - - /* if transforming strips (only real reason for temp-metas currently), - * add to the cache the frame numbers of the strip's extents - */ - if (strip->flag & NLASTRIP_FLAG_TEMP_META) { - nla_draw_strip_frames_text(nlt, strip, v2d, ymin, ymax); - } + ListBase visible_nla_strips = get_visible_nla_strips(nlt, v2d); + + /* Draw each visible strip in the track. */ + LISTBASE_FOREACH (NlaStrip *, strip, &visible_nla_strips) { + const float xminc = strip->start + text_margin_x; + const float xmaxc = strip->end - text_margin_x; + + /* draw the visualization of the strip */ + nla_draw_strip(snla, adt, nlt, strip, v2d, ymin, ymax); + + /* add the text for this strip to the cache */ + if (xminc < xmaxc) { + nla_draw_strip_text(adt, nlt, strip, v2d, xminc, xmaxc, ymin, ymax); + } + + /* if transforming strips (only real reason for temp-metas currently), + * add to the cache the frame numbers of the strip's extents + */ + if (strip->flag & NLASTRIP_FLAG_TEMP_META) { + nla_draw_strip_frames_text(nlt, strip, v2d, ymin, ymax); } } break; |