WIP: uv-simple-select #1

Closed
Chris Blackbourn wants to merge 182 commits from uv-simple-select into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
7 changed files with 90 additions and 39 deletions
Showing only changes of commit 22f8f944fe - Show all commits

View File

@ -36,10 +36,10 @@ struct PropertyRNA;
/* Data Management */
/**
* Remove the given NLA strip from the NLA track it occupies, free the strip's data,
* and the strip itself.
* Frees the given NLA strip, and calls #BKE_nlastrip_remove_and_free to
* remove and free all children strips.
*/
void BKE_nlastrip_free(ListBase *strips, struct NlaStrip *strip, bool do_id_user);
void BKE_nlastrip_free(struct NlaStrip *strip, bool do_id_user);
/**
* Remove the given NLA track from the set of NLA tracks, free the track's data,
* and the track itself.
@ -94,10 +94,22 @@ void BKE_nla_tracks_copy_from_adt(struct Main *bmain,
struct NlaTrack *BKE_nlatrack_add(struct AnimData *adt,
struct NlaTrack *prev,
bool is_liboverride);
/**
* Create a NLA Strip referencing the given Action.
*/
struct NlaStrip *BKE_nlastrip_new(struct bAction *act);
/*
* Removes the given NLA strip from the list of strips provided.
*/
void BKE_nlastrip_remove(ListBase *strips, struct NlaStrip *strip);
/*
* Removes the given NLA strip from the list of strips provided, and frees it's memory.
*/
void BKE_nlastrip_remove_and_free(ListBase *strips, struct NlaStrip *strip, const bool do_id_user);
/**
* Add new NLA-strip to the top of the NLA stack - i.e.
* into the last track if space, or a new one otherwise.
@ -139,13 +151,9 @@ void BKE_nlastrips_sort_strips(ListBase *strips);
void BKE_nlastrips_add_strip_unsafe(ListBase *strips, struct NlaStrip *strip);
/**
* \brief NULL checks incoming strip and verifies no overlap / invalid
* configuration against other strips in NLA Track.
*
* \param strips:
* \param strip:
* \return true
* \return false
* NULL checks incoming strip and verifies no overlap / invalid
* configuration against other strips in NLA Track before calling
* #BKE_nlastrips_add_strip_unsafe.
*/
bool BKE_nlastrips_add_strip(ListBase *strips, struct NlaStrip *strip);
@ -215,11 +223,16 @@ bool BKE_nlatrack_has_space(struct NlaTrack *nlt, float start, float end);
void BKE_nlatrack_sort_strips(struct NlaTrack *nlt);
/**
* Add the given NLA-Strip to the given NLA-Track, assuming that it
* isn't currently attached to another one.
* Add the given NLA-Strip to the given NLA-Track.
* Calls #BKE_nlastrips_add_strip to check if strip can be added.
*/
bool BKE_nlatrack_add_strip(struct NlaTrack *nlt, struct NlaStrip *strip, bool is_liboverride);
/**
* Remove the NLA-Strip from the given NLA-Track.
*/
void BKE_nlatrack_remove_strip(struct NlaTrack *track, struct NlaStrip *strip);
/**
* Get the extents of the given NLA-Track including gaps between strips,
* returning whether this succeeded or not

View File

@ -61,7 +61,7 @@ static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks,
/* Freeing ------------------------------------------- */
void BKE_nlastrip_free(ListBase *strips, NlaStrip *strip, bool do_id_user)
void BKE_nlastrip_free(NlaStrip *strip, const bool do_id_user)
{
NlaStrip *cs, *csn;
@ -73,7 +73,7 @@ void BKE_nlastrip_free(ListBase *strips, NlaStrip *strip, bool do_id_user)
/* free child-strips */
for (cs = strip->strips.first; cs; cs = csn) {
csn = cs->next;
BKE_nlastrip_free(&strip->strips, cs, do_id_user);
BKE_nlastrip_remove_and_free(&strip->strips, cs, do_id_user);
}
/* remove reference to action */
@ -81,10 +81,6 @@ void BKE_nlastrip_free(ListBase *strips, NlaStrip *strip, bool do_id_user)
id_us_min(&strip->act->id);
}
/* free remapping info */
// if (strip->remap)
// BKE_animremap_free();
/* free own F-Curves */
BKE_fcurves_free(&strip->fcurves);
@ -92,13 +88,8 @@ void BKE_nlastrip_free(ListBase *strips, NlaStrip *strip, bool do_id_user)
free_fmodifiers(&strip->modifiers);
/* free the strip itself */
if (strips) {
BLI_freelinkN(strips, strip);
}
else {
MEM_freeN(strip);
}
}
void BKE_nlatrack_free(ListBase *tracks, NlaTrack *nlt, bool do_id_user)
{
@ -112,7 +103,7 @@ void BKE_nlatrack_free(ListBase *tracks, NlaTrack *nlt, bool do_id_user)
/* free strips */
for (strip = nlt->strips.first; strip; strip = stripn) {
stripn = strip->next;
BKE_nlastrip_free(&nlt->strips, strip, do_id_user);
BKE_nlastrip_remove_and_free(&nlt->strips, strip, do_id_user);
}
/* free NLA track itself now */
@ -875,7 +866,7 @@ void BKE_nlastrips_clear_metastrip(ListBase *strips, NlaStrip *strip)
}
/* free the meta-strip now */
BKE_nlastrip_free(strips, strip, true);
BKE_nlastrip_remove_and_free(strips, strip, true);
}
void BKE_nlastrips_clear_metas(ListBase *strips, bool only_sel, bool only_temp)
@ -1190,6 +1181,12 @@ bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip, const bool is_libove
return BKE_nlastrips_add_strip(&nlt->strips, strip);
}
void BKE_nlatrack_remove_strip(NlaTrack *track, NlaStrip *strip)
{
BLI_assert(track);
BKE_nlastrip_remove(&track->strips, strip);
}
bool BKE_nlatrack_get_bounds(NlaTrack *nlt, float bounds[2])
{
NlaStrip *strip;
@ -1318,6 +1315,18 @@ NlaStrip *BKE_nlastrip_find_active(NlaTrack *nlt)
return nlastrip_find_active(&nlt->strips);
}
void BKE_nlastrip_remove(ListBase *strips, NlaStrip *strip)
{
BLI_assert(strips);
BLI_remlink(strips, strip);
}
void BKE_nlastrip_remove_and_free(ListBase *strips, NlaStrip *strip, const bool do_id_user)
{
BKE_nlastrip_remove(strips, strip);
BKE_nlastrip_free(strip, do_id_user);
}
void BKE_nlastrip_set_active(AnimData *adt, NlaStrip *strip)
{
NlaTrack *nlt;

View File

@ -1,6 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2023 Blender Foundation. All rights reserved. */
#include "BLI_listbase.h"
#include "BKE_nla.h"
#include "DNA_anim_types.h"
@ -20,19 +22,19 @@ TEST(nla_strip, BKE_nlastrip_recalculate_blend)
strip.start = 1;
strip.end = 10;
/* Scaling a strip up doesn't affect the blend in/out value */
/* Scaling a strip up doesn't affect the blend in/out value. */
strip.end = 20;
BKE_nlastrip_recalculate_blend(&strip);
EXPECT_FLOAT_EQ(strip.blendin, 4.0);
EXPECT_FLOAT_EQ(strip.blendout, 5.0);
/* Scaling a strip down affects the blend-in value before the blend-out value */
/* Scaling a strip down affects the blend-in value before the blend-out value. */
strip.end = 7;
BKE_nlastrip_recalculate_blend(&strip);
EXPECT_FLOAT_EQ(strip.blendin, 1.0);
EXPECT_FLOAT_EQ(strip.blendout, 5.0);
/* Scaling a strip down to nothing updates the blend in/out values accordingly */
/* Scaling a strip down to nothing updates the blend in/out values accordingly. */
strip.end = 1.1;
BKE_nlastrip_recalculate_blend(&strip);
EXPECT_FLOAT_EQ(strip.blendin, 0.0);
@ -63,4 +65,31 @@ TEST(nla_strip, BKE_nlastrips_add_strip)
EXPECT_TRUE(BKE_nlastrips_add_strip(&strips, &strip2));
}
TEST(nla_track, BKE_nlatrack_remove_strip)
{
NlaTrack track{};
ListBase strips{};
NlaStrip strip1{};
strip1.start = 0;
strip1.end = 10;
NlaStrip strip2{};
strip2.start = 11;
strip2.end = 20;
// Add NLA strips to the NLATrack.
BKE_nlastrips_add_strip(&strips, &strip1);
BKE_nlastrips_add_strip(&strips, &strip2);
track.strips = strips;
// ensure we have 2 strips in the track.
EXPECT_EQ(2, BLI_listbase_count(&track.strips));
BKE_nlatrack_remove_strip(&track, &strip2);
EXPECT_EQ(1, BLI_listbase_count(&track.strips));
// ensure the correct strip was removed.
EXPECT_EQ(-1, BLI_findindex(&track.strips, &strip2));
}
} // namespace blender::bke::tests

View File

@ -586,7 +586,7 @@ void ED_animedit_unlink_action(
if (strip->act == act) {
/* Remove this strip, and the track too if it doesn't have anything else */
BKE_nlastrip_free(&nlt->strips, strip, true);
BKE_nlastrip_remove_and_free(&nlt->strips, strip, true);
if (nlt->strips.first == NULL) {
BLI_assert(nstrip == NULL);

View File

@ -1305,15 +1305,15 @@ static int nlaedit_delete_exec(bContext *C, wmOperator *UNUSED(op))
if (strip->flag & NLASTRIP_FLAG_SELECT) {
/* if a strip either side of this was a transition, delete those too */
if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION)) {
BKE_nlastrip_free(&nlt->strips, strip->prev, true);
BKE_nlastrip_remove_and_free(&nlt->strips, strip->prev, true);
}
if ((nstrip) && (nstrip->type == NLASTRIP_TYPE_TRANSITION)) {
nstrip = nstrip->next;
BKE_nlastrip_free(&nlt->strips, strip->next, true);
BKE_nlastrip_remove_and_free(&nlt->strips, strip->next, true);
}
/* finally, delete this strip */
BKE_nlastrip_free(&nlt->strips, strip, true);
BKE_nlastrip_remove_and_free(&nlt->strips, strip, true);
}
}
}
@ -1824,7 +1824,7 @@ static int nlaedit_move_up_exec(bContext *C, wmOperator *UNUSED(op))
if (BKE_nlatrack_has_space(nltn, strip->start, strip->end)) {
/* remove from its current track, and add to the one above
* (it 'should' work, so no need to worry) */
BLI_remlink(&nlt->strips, strip);
BKE_nlatrack_remove_strip(nlt, strip);
BKE_nlatrack_add_strip(nltn, strip, is_liboverride);
}
}
@ -1916,7 +1916,7 @@ static int nlaedit_move_down_exec(bContext *C, wmOperator *UNUSED(op))
if (BKE_nlatrack_has_space(nltp, strip->start, strip->end)) {
/* remove from its current track, and add to the one above
* (it 'should' work, so no need to worry) */
BLI_remlink(&nlt->strips, strip);
BKE_nlatrack_remove_strip(nlt, strip);
BKE_nlatrack_add_strip(nltp, strip, is_liboverride);
}
}

View File

@ -457,7 +457,7 @@ static void recalcData_nla(TransInfo *t)
if (BKE_nlatrack_has_space(track, strip->start, strip->end) &&
!BKE_nlatrack_is_nonlocal_in_liboverride(tdn->id, track)) {
/* move strip to this track */
BLI_remlink(&tdn->nlt->strips, strip);
BKE_nlatrack_remove_strip(tdn->nlt, strip);
BKE_nlatrack_add_strip(track, strip, is_liboverride);
tdn->nlt = track;
@ -477,7 +477,7 @@ static void recalcData_nla(TransInfo *t)
if (BKE_nlatrack_has_space(track, strip->start, strip->end) &&
!BKE_nlatrack_is_nonlocal_in_liboverride(tdn->id, track)) {
/* move strip to this track */
BLI_remlink(&tdn->nlt->strips, strip);
BKE_nlatrack_remove_strip(tdn->nlt, strip);
BKE_nlatrack_add_strip(track, strip, is_liboverride);
tdn->nlt = track;

View File

@ -544,7 +544,7 @@ static NlaStrip *rna_NlaStrip_new(ID *id,
reports,
RPT_ERROR,
"Unable to add strip (the track does not have any space to accommodate this new strip)");
BKE_nlastrip_free(NULL, strip, true);
BKE_nlastrip_free(strip, true);
return NULL;
}
@ -595,7 +595,7 @@ static void rna_NlaStrip_remove(
return;
}
BKE_nlastrip_free(&track->strips, strip, true);
BKE_nlastrip_remove_and_free(&track->strips, strip, true);
RNA_POINTER_INVALIDATE(strip_ptr);
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_REMOVED, NULL);