[Bf-blender-cvs] [b8b7b0af703] asset-browser-grid-view: Add basic asset library loading, general cleanups
Julian Eisel
noreply at git.blender.org
Mon Jan 31 23:40:52 CET 2022
Commit: b8b7b0af703e27af0599c81580162f26a21c6912
Author: Julian Eisel
Date: Mon Jan 31 23:39:29 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rBb8b7b0af703e27af0599c81580162f26a21c6912
Add basic asset library loading, general cleanups
Adds an asset library selector and prints the list of assets when drawing the
Asset Browser main window.
===================================================================
M release/scripts/startup/bl_ui/space_assets.py
M source/blender/blenkernel/BKE_context.h
M source/blender/blenkernel/intern/context.c
M source/blender/editors/asset/ED_asset_list.h
M source/blender/editors/asset/ED_asset_list.hh
M source/blender/editors/asset/intern/asset_list.cc
M source/blender/editors/space_assets/CMakeLists.txt
A source/blender/editors/space_assets/asset_browser_draw.cc
M source/blender/editors/space_assets/asset_browser_intern.hh
A source/blender/editors/space_assets/asset_view.cc
A source/blender/editors/space_assets/asset_view.hh
M source/blender/editors/space_assets/space_assets.cc
M source/blender/makesdna/DNA_space_types.h
M source/blender/makesrna/intern/rna_space.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_assets.py b/release/scripts/startup/bl_ui/space_assets.py
index 5c14599267c..707c7b3e78d 100644
--- a/release/scripts/startup/bl_ui/space_assets.py
+++ b/release/scripts/startup/bl_ui/space_assets.py
@@ -25,10 +25,12 @@ class ASSETBROWSER_HT_header(Header):
def draw(self, context):
layout = self.layout
- # space = context.space_data
+ space = context.space_data
layout.template_header()
+ layout.prop(space, "asset_library_ref", text="")
+
classes = (
ASSETBROWSER_HT_header,
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 18c1848b737..9b26ecb709a 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -201,6 +201,7 @@ struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C);
struct SpaceClip *CTX_wm_space_clip(const bContext *C);
struct SpaceTopBar *CTX_wm_space_topbar(const bContext *C);
struct SpaceSpreadsheet *CTX_wm_space_spreadsheet(const bContext *C);
+struct SpaceAssets *CTX_wm_space_assets(const bContext *C);
void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
void CTX_wm_window_set(bContext *C, struct wmWindow *win);
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index ceaed5d2bba..e2d6b62e841 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -945,6 +945,15 @@ struct SpaceSpreadsheet *CTX_wm_space_spreadsheet(const bContext *C)
return NULL;
}
+struct SpaceAssets *CTX_wm_space_assets(const bContext *C)
+{
+ ScrArea *area = CTX_wm_area(C);
+ if (area && area->spacetype == SPACE_ASSETS) {
+ return area->spacedata.first;
+ }
+ return NULL;
+}
+
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
{
C->wm.manager = wm;
diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h
index 669bb6dbe36..eb094a6f1c0 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -38,7 +38,7 @@ struct wmNotifier;
void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_reference,
const struct bContext *C);
void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference,
- struct bContext *C);
+ const struct bContext *C);
void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C);
bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference);
/**
diff --git a/source/blender/editors/asset/ED_asset_list.hh b/source/blender/editors/asset/ED_asset_list.hh
index 24def2fb4ab..e31e5cab341 100644
--- a/source/blender/editors/asset/ED_asset_list.hh
+++ b/source/blender/editors/asset/ED_asset_list.hh
@@ -35,4 +35,9 @@ std::string ED_assetlist_asset_filepath_get(const bContext *C,
/* Can return false to stop iterating. */
using AssetListIterFn = blender::FunctionRef<bool(AssetHandle)>;
+/**
+ * Iterate the currently loaded assets for the referenced asset library, calling \a fn for each
+ * asset. This may be executed while the asset list is loading asynchronously. Assets will then be
+ * included as they get done loading.
+ */
void ED_assetlist_iterate(const AssetLibraryReference &library_reference, AssetListIterFn fn);
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index c075ae390d9..6b5f4993042 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -123,7 +123,7 @@ class AssetList : NonCopyable {
void setup();
void fetch(const bContext &C);
- void ensurePreviewsJob(bContext *C);
+ void ensurePreviewsJob(const bContext *C);
void clear(bContext *C);
bool needsRefetch() const;
@@ -224,7 +224,7 @@ void AssetList::iterate(AssetListIterFn fn) const
}
}
-void AssetList::ensurePreviewsJob(bContext *C)
+void AssetList::ensurePreviewsJob(const bContext *C)
{
FileList *files = filelist_;
int numfiles = filelist_files_ensure(files);
@@ -434,7 +434,8 @@ void ED_assetlist_storage_fetch(const AssetLibraryReference *library_reference,
AssetListStorage::fetch_library(*library_reference, *C);
}
-void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_reference, bContext *C)
+void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_reference,
+ const bContext *C)
{
AssetList *list = AssetListStorage::lookup_list(*library_reference);
diff --git a/source/blender/editors/space_assets/CMakeLists.txt b/source/blender/editors/space_assets/CMakeLists.txt
index 8e4419734da..dd36ea03895 100644
--- a/source/blender/editors/space_assets/CMakeLists.txt
+++ b/source/blender/editors/space_assets/CMakeLists.txt
@@ -30,8 +30,13 @@ set(INC
)
set(SRC
+ asset_browser_draw.cc
asset_browser_ops.cc
+ asset_view.cc
space_assets.cc
+
+ asset_browser_intern.hh
+ asset_view.hh
)
set(LIB
diff --git a/source/blender/editors/space_assets/asset_browser_draw.cc b/source/blender/editors/space_assets/asset_browser_draw.cc
new file mode 100644
index 00000000000..7a8c9023f3f
--- /dev/null
+++ b/source/blender/editors/space_assets/asset_browser_draw.cc
@@ -0,0 +1,60 @@
+/*
+ * 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 spassets
+ */
+
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_context.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "asset_browser_intern.hh"
+#include "asset_view.hh"
+
+namespace blender::ed::asset_browser {
+
+} // namespace blender::ed::asset_browser
+
+using namespace blender::ed::asset_browser;
+
+void asset_browser_main_region_draw(const bContext *C, ARegion *region)
+{
+ const SpaceAssets *asset_space = CTX_wm_space_assets(C);
+
+ UI_ThemeClearColor(TH_BACK);
+
+ const uiStyle *style = UI_style_get_dpi();
+ uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
+ uiLayout *layout = UI_block_layout(block,
+ UI_LAYOUT_VERTICAL,
+ UI_LAYOUT_PANEL,
+ style->panelspace,
+ 0,
+ region->sizex,
+ 1,
+ 0,
+ style);
+
+ asset_view_create_in_layout(*C, asset_space->asset_library_ref, *layout);
+
+ UI_block_end(C, block);
+ UI_block_draw(C, block);
+}
diff --git a/source/blender/editors/space_assets/asset_browser_intern.hh b/source/blender/editors/space_assets/asset_browser_intern.hh
index 18a0e438c7a..46248b83cea 100644
--- a/source/blender/editors/space_assets/asset_browser_intern.hh
+++ b/source/blender/editors/space_assets/asset_browser_intern.hh
@@ -22,6 +22,7 @@
void asset_browser_operatortypes();
-namespace blender::ed::asset_browser {
+struct ARegion;
+struct bContext;
-}
+void asset_browser_main_region_draw(const bContext *C, ARegion *region);
diff --git a/source/blender/editors/space_assets/asset_view.cc b/source/blender/editors/space_assets/asset_view.cc
new file mode 100644
index 00000000000..261b302b5af
--- /dev/null
+++ b/source/blender/editors/space_assets/asset_view.cc
@@ -0,0 +1,62 @@
+/*
+ * 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 spassets
+ */
+
+#include <iostream>
+
+#include "DNA_asset_types.h"
+
+#include "ED_asset.h"
+
+#include "UI_interface.h"
+
+#include "asset_view.hh"
+
+namespace blender::ed::asset_browser {
+
+AssetGridView::AssetGridView(const AssetLibraryReference &asset_library_ref)
+ : asset_library_ref_(asset_library_ref)
+{
+}
+
+void AssetGridView::build()
+{
+ ED_assetlist_iterate(asset_library_ref_, [](AssetHandle asset) {
+ std::cout << ED_asset_handle_get_name(&asset) << std::endl;
+ return true;
+ });
+ std::cout << std::endl;
+}
+
+void asset_view_create_in_layout(const bContext &C,
+ const AssetLibraryReference &asset_library_ref,
+ uiLayout &layout)
+{
+ uiBlock *block = uiLayoutGetBlock(&layout);
+
+ ED_assetlist_storage_fetch(&asset_library_ref, &C);
+ ED_assetlist_ensure_previews_job(&asset_library_ref, &C);
+
+ UI_block_layout_set_current(block, &layout);
+
+ AssetGridView grid_view{asset_library_ref};
+ grid_view.build();
+}
+
+} // namespace blender::ed::asset_browser
diff --git a/source/blender/editors/space_assets/asset_browser_intern.hh b/source/blend
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list