diff options
Diffstat (limited to 'source/blender/editors/asset')
-rw-r--r-- | source/blender/editors/asset/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/editors/asset/ED_asset_filter.h | 35 | ||||
-rw-r--r-- | source/blender/editors/asset/ED_asset_list.h | 1 | ||||
-rw-r--r-- | source/blender/editors/asset/intern/asset_filter.cc | 64 | ||||
-rw-r--r-- | source/blender/editors/asset/intern/asset_list.cc | 27 |
5 files changed, 110 insertions, 19 deletions
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 2e25be51781..7e578b78809 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -31,6 +31,7 @@ set(INC_SYS ) set(SRC + intern/asset_filter.cc intern/asset_handle.cc intern/asset_library_reference.cc intern/asset_library_reference_enum.cc @@ -39,6 +40,7 @@ set(SRC intern/asset_ops.cc intern/asset_temp_id_consumer.cc + ED_asset_filter.h ED_asset_handle.h ED_asset_library.h ED_asset_list.h diff --git a/source/blender/editors/asset/ED_asset_filter.h b/source/blender/editors/asset/ED_asset_filter.h new file mode 100644 index 00000000000..fb2d3bfb273 --- /dev/null +++ b/source/blender/editors/asset/ED_asset_filter.h @@ -0,0 +1,35 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup edasset + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +struct AssetHandle; +struct AssetFilterSettings; + +bool ED_asset_filter_matches_asset(const struct AssetFilterSettings *filter, + const struct AssetHandle *asset); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h index 1e7f0f0de55..55a0ac0b500 100644 --- a/source/blender/editors/asset/ED_asset_list.h +++ b/source/blender/editors/asset/ED_asset_list.h @@ -32,7 +32,6 @@ struct ID; struct wmNotifier; void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_reference, - const struct AssetFilterSettings *filter_settings, const struct bContext *C); void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference, struct bContext *C); diff --git a/source/blender/editors/asset/intern/asset_filter.cc b/source/blender/editors/asset/intern/asset_filter.cc new file mode 100644 index 00000000000..397df33d596 --- /dev/null +++ b/source/blender/editors/asset/intern/asset_filter.cc @@ -0,0 +1,64 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup edasset + */ + +#include "BKE_idtype.h" + +#include "BLI_listbase.h" + +#include "DNA_ID.h" +#include "DNA_asset_types.h" + +#include "ED_asset_filter.h" +#include "ED_asset_handle.h" + +/** + * Compare \a asset against the settings of \a filter. + * + * Individual filter parameters are ORed with the asset properties. That means: + * * The asset type must be one of the ID types filtered by, and + * * The asset must contain at least one of the tags filtered by. + * However for an asset to be matching it must have one match in each of the parameters. I.e. one + * matching type __and__ at least one matching tag. + * + * \returns True if the asset should be visible with these filter settings (parameters match). + * Otherwise returns false (mismatch). + */ +bool ED_asset_filter_matches_asset(const AssetFilterSettings *filter, const AssetHandle *asset) +{ + ID_Type asset_type = ED_asset_handle_get_id_type(asset); + uint64_t asset_id_filter = BKE_idtype_idcode_to_idfilter(asset_type); + + if ((filter->id_types & asset_id_filter) == 0) { + return false; + } + /* Not very efficient (O(n^2)), could be improved quite a bit. */ + LISTBASE_FOREACH (const AssetTag *, filter_tag, &filter->tags) { + AssetMetaData *asset_data = ED_asset_handle_get_metadata(asset); + + AssetTag *matched_tag = (AssetTag *)BLI_findstring( + &asset_data->tags, filter_tag->name, offsetof(AssetTag, name)); + if (matched_tag == nullptr) { + return false; + } + } + + /* Succesfully passed through all filters. */ + return true; +} diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc index d94a2bbf438..57c25e1614b 100644 --- a/source/blender/editors/asset/intern/asset_list.cc +++ b/source/blender/editors/asset/intern/asset_list.cc @@ -122,7 +122,7 @@ class AssetList : NonCopyable { AssetList(AssetList &&other) = default; ~AssetList() = default; - void setup(const AssetFilterSettings *filter_settings = nullptr); + void setup(); void fetch(const bContext &C); void ensurePreviewsJob(bContext *C); void clear(bContext *C); @@ -141,7 +141,7 @@ AssetList::AssetList(eFileSelectType filesel_type, const AssetLibraryReference & { } -void AssetList::setup(const AssetFilterSettings *filter_settings) +void AssetList::setup() { FileList *files = filelist_; @@ -160,17 +160,13 @@ void AssetList::setup(const AssetFilterSettings *filter_settings) filelist_setrecursion(files, 1); filelist_setsorting(files, FILE_SORT_ALPHA, false); filelist_setlibrary(files, &library_ref_); - /* TODO different filtering settings require the list to be reread. That's a no-go for when we - * want to allow showing the same asset library with different filter settings (as in, - * different ID types). The filelist needs to be made smarter somehow, maybe goes together with - * the plan to separate the view (preview caching, filtering, etc. ) from the data. */ filelist_setfilter_options( files, - filter_settings != nullptr, + false, true, true, /* Just always hide parent, prefer to not add an extra user option for this. */ FILE_TYPE_BLENDERLIB, - filter_settings ? filter_settings->id_types : FILTER_ID_ALL, + FILTER_ID_ALL, true, "", ""); @@ -333,9 +329,7 @@ class AssetListStorage { /* Purely static class, can't instantiate this. */ AssetListStorage() = delete; - static void fetch_library(const AssetLibraryReference &library_reference, - const bContext &C, - const AssetFilterSettings *filter_settings = nullptr); + static void fetch_library(const AssetLibraryReference &library_reference, const bContext &C); static void destruct(); static AssetList *lookup_list(const AssetLibraryReference &library_ref); static void tagMainDataDirty(); @@ -353,8 +347,7 @@ class AssetListStorage { }; void AssetListStorage::fetch_library(const AssetLibraryReference &library_reference, - const bContext &C, - const AssetFilterSettings *filter_settings) + const bContext &C) { std::optional filesel_type = asset_library_reference_to_fileselect_type(library_reference); if (!filesel_type) { @@ -363,7 +356,7 @@ void AssetListStorage::fetch_library(const AssetLibraryReference &library_refere auto [list, is_new] = ensure_list_storage(library_reference, *filesel_type); if (is_new || list.needsRefetch()) { - list.setup(filter_settings); + list.setup(); list.fetch(C); } } @@ -440,11 +433,9 @@ using namespace blender::ed::asset; * Invoke asset list reading, potentially in a parallel job. Won't wait until the job is done, * and may return earlier. */ -void ED_assetlist_storage_fetch(const AssetLibraryReference *library_reference, - const AssetFilterSettings *filter_settings, - const bContext *C) +void ED_assetlist_storage_fetch(const AssetLibraryReference *library_reference, const bContext *C) { - AssetListStorage::fetch_library(*library_reference, *C, filter_settings); + AssetListStorage::fetch_library(*library_reference, *C); } void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_reference, bContext *C) |