diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2016-12-03 03:39:09 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2016-12-03 04:23:44 +0300 |
commit | 89d20732a1fc279e9fcd531491ca5cc578bdf7e0 (patch) | |
tree | da9c76b1e2980fe56e3532cc0c9a8be195c06ce9 /source/blender/blenkernel/intern/layer.c | |
parent | bc2321025beec65c26a661908a9049fee1d80454 (diff) |
layer.active_collection
This one is straight from the "layers" branch. I nailed it quite nicely there, so it was simply a matter of bringing it over :)
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 5022f4e9737..924a6b28dcb 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -157,6 +157,81 @@ void BKE_layer_collection_free(SceneLayer *sl, LayerCollection *lc) } } +/* Recursively get the collection for a given index */ +static LayerCollection *collection_from_index(ListBase *lb, const int number, int *i) +{ + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + if (*i == number) { + return lc; + } + + (*i)++; + + LayerCollection *lc_nested = collection_from_index(&lc->collections, number, i); + if (lc_nested) { + return lc_nested; + } + } + return NULL; +} + +/* + * Get the active collection +*/ +LayerCollection *BKE_layer_collection_active(SceneLayer *sl) +{ + int i = 0; + return collection_from_index(&sl->collections, sl->active_collection, &i); +} + +/* + * Recursively get the count of collections +*/ +static int collection_count(ListBase *lb) +{ + int i = 0; + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + i += collection_count(&lc->collections) + 1; + } + return i; +} + +/* + * Get the total number of collections + * (including all the nested collections) + */ +int BKE_layer_collection_count(SceneLayer *sl) +{ + return collection_count(&sl->collections); +} + +/* Recursively get the index for a given collection */ +static int index_from_collection(ListBase *lb, LayerCollection *lc, int *i) +{ + for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) { + if (lcol == lc) { + return *i; + } + + (*i)++; + + int i_nested = index_from_collection(&lcol->collections, lc, i); + if (i_nested != -1) { + return i_nested; + } + } + return -1; +} + +/* + * Return -1 if not found + */ +int BKE_layer_collection_findindex(SceneLayer *sl, LayerCollection *lc) +{ + int i = 0; + return index_from_collection(&sl->collections, lc, &i); +} + /* * Link a collection to a renderlayer * The collection needs to be created separately @@ -177,6 +252,7 @@ void BKE_collection_unlink(SceneLayer *sl, LayerCollection *lc) BLI_remlink(&sl->collections, lc); MEM_freeN(lc); + sl->active_collection = 0; } static void object_base_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects) |