[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49330] branches/asset-browser: == assetbrowser ==
Andrea Weikert
elubie at gmx.net
Sat Jul 28 18:55:27 CEST 2012
Revision: 49330
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49330
Author: elubie
Date: 2012-07-28 16:55:26 +0000 (Sat, 28 Jul 2012)
Log Message:
-----------
== assetbrowser ==
Committing current state of work:
* implemented ItemList interface area (like Panels), drawable from Python
* implemented adding an asset file and showing the contents.
TODO:
* fix the layout, still need to figure out how to layout several colums with overflow into next column and proper scrolling if that is not enough
* actually get selection working for the individual items
Modified Paths:
--------------
branches/asset-browser/release/scripts/startup/bl_ui/space_asset.py
branches/asset-browser/source/blender/blenkernel/BKE_assets.h
branches/asset-browser/source/blender/blenkernel/BKE_screen.h
branches/asset-browser/source/blender/blenkernel/intern/assets.c
branches/asset-browser/source/blender/blenloader/BLO_readfile.h
branches/asset-browser/source/blender/blenloader/intern/readblenentry.c
branches/asset-browser/source/blender/editors/include/UI_interface.h
branches/asset-browser/source/blender/editors/interface/CMakeLists.txt
branches/asset-browser/source/blender/editors/interface/interface_intern.h
branches/asset-browser/source/blender/editors/screen/area.c
branches/asset-browser/source/blender/editors/space_asset/CMakeLists.txt
branches/asset-browser/source/blender/editors/space_asset/space_asset.c
branches/asset-browser/source/blender/makesdna/DNA_asset_types.h
branches/asset-browser/source/blender/makesrna/RNA_access.h
branches/asset-browser/source/blender/makesrna/intern/rna_asset.c
branches/asset-browser/source/blender/makesrna/intern/rna_ui.c
branches/asset-browser/source/blender/windowmanager/WM_types.h
Added Paths:
-----------
branches/asset-browser/source/blender/editors/interface/interface_itemlist.c
branches/asset-browser/source/blender/editors/space_asset/asset_ops.c
branches/asset-browser/source/blender/editors/space_asset/asset_ops.h
branches/asset-browser/source/blender/editors/space_asset/assetlist.c
branches/asset-browser/source/blender/editors/space_asset/assetlist.h
Modified: branches/asset-browser/release/scripts/startup/bl_ui/space_asset.py
===================================================================
--- branches/asset-browser/release/scripts/startup/bl_ui/space_asset.py 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/release/scripts/startup/bl_ui/space_asset.py 2012-07-28 16:55:26 UTC (rev 49330)
@@ -57,13 +57,41 @@
def draw(self, context):
pass
+
+ def icon_for_group(self, group):
+ icon = 'NONE'
+ if group == 'Action': icon = 'ACTION'
+ if group == 'Armature': icon = 'ARMATURE_DATA'
+ if group == 'Brush': icon = 'BRUSH_DATA'
+ if group == 'Camera': icon = 'CAMERA_DATA'
+ if group == 'Curve': icon = 'CURVE_DATA'
+ if group == 'GPencil': icon = 'GREASEPENCIL'
+ if group == 'Group': icon = 'GROUP'
+ if group == 'Image': icon = 'IMAGE_DATA'
+ if group == 'Lamp': icon = 'LAMP'
+ if group == 'Lattice': icon = 'LATTICE_DATA'
+ if group == 'Material': icon = 'MATERIAL_DATA'
+ if group == 'Metaball': icon = 'META_DATA'
+ if group == 'Mesh': icon = 'MESH_DATA'
+ if group == 'NodeTree': icon = 'NODETREE'
+ if group == 'Object': icon = 'OBJECT_DATA'
+ if group == 'Scene': icon = 'SCENE_DATA'
+ if group == 'Speaker': icon = 'SPEAKER'
+ if group == 'Sound': icon = 'SOUND'
+ if group == 'Texture': icon = 'TEXTURE_DATA'
+ if group == 'Text': icon = 'TEXT'
+ if group == 'VFont': icon = 'FONT_DATA'
+ if group == 'World': icon = 'WORLD_DATA'
+ if group == 'MovieClip': icon = 'CLIP'
+ if group == 'AssetCollection': icon = 'ASSET_MANAGER'
+ return icon
- def draw_item(self, context, column, row):
+ def draw_item(self, context, entry, group):
+ print(entry)
layout = self.layout
sasset = context.space_data
- labeltext = 'Label(' + str(column) + ',' + str(row) + ')'
col = layout.column(align=True)
- col.label(text=labeltext)
+ col.label(text=entry, icon=self.icon_for_group(group))
class AssetCollectionsPanel(bpy.types.Panel):
bl_space_type = "ASSET_BROWSER"
Modified: branches/asset-browser/source/blender/blenkernel/BKE_assets.h
===================================================================
--- branches/asset-browser/source/blender/blenkernel/BKE_assets.h 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/source/blender/blenkernel/BKE_assets.h 2012-07-28 16:55:26 UTC (rev 49330)
@@ -39,6 +39,8 @@
void *asset_collection_add(const char *name);
struct bAssetCollection *asset_collection_copy(struct bAssetCollection *collection);
+void asset_collection_update(struct Main *bmain, struct bAssetCollection *collection);
+void asset_file_update(struct Main *bmain, struct bAssetFile *af);
void asset_collection_make_local(struct Main *bmain, struct bAssetCollection *collection);
void asset_collection_free(struct bAssetCollection *collection);
Modified: branches/asset-browser/source/blender/blenkernel/BKE_screen.h
===================================================================
--- branches/asset-browser/source/blender/blenkernel/BKE_screen.h 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/source/blender/blenkernel/BKE_screen.h 2012-07-28 16:55:26 UTC (rev 49330)
@@ -228,14 +228,14 @@
struct uiLayout *layout; /* runtime for drawing */
} Menu;
-/* menu types */
+/* ui item list types */
typedef struct ItemListType {
struct ItemListType *next, *prev;
char idname[BKE_ST_MAXNAME]; /* unique name */
char label[BKE_ST_MAXNAME]; /* for button text */
- char *description;
+ char *description;
int space_type;
int region_type;
@@ -245,7 +245,7 @@
/* draw entirely, view changes should be handled here */
void (*draw)(const struct bContext *, struct ItemList *);
/* draw entirely, view changes should be handled here */
- void (*draw_item)(const struct bContext *, int column, int row, struct ItemList *);
+ void (*draw_item)(const struct bContext *, const char *entry, const char *group, struct ItemList *);
/* RNA integration */
ExtensionRNA ext;
} ItemListType;
@@ -253,6 +253,7 @@
typedef struct ItemList {
struct ItemListType *type; /* runtime */
struct uiLayout *layout; /* runtime for drawing */
+ int width, height;
} ItemList;
/* spacetypes */
Modified: branches/asset-browser/source/blender/blenkernel/intern/assets.c
===================================================================
--- branches/asset-browser/source/blender/blenkernel/intern/assets.c 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/source/blender/blenkernel/intern/assets.c 2012-07-28 16:55:26 UTC (rev 49330)
@@ -33,13 +33,17 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_bpath.h"
+#include "BLI_linklist.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
+#include "BLO_readfile.h"
+
+#include "BKE_assets.h"
#include "BKE_global.h"
+#include "BKE_idcode.h"
#include "BKE_library.h"
#include "BKE_main.h"
-#include "BKE_assets.h"
#include "BKE_utildefines.h"
#include "MEM_guardedalloc.h"
@@ -68,6 +72,78 @@
return acn;
}
+static int is_blend_file(char *asset_file)
+{
+ return BLO_has_bfile_extension(asset_file);
+}
+
+/* Append the linkable groups from the .blend file given by filename to the asset list */
+void assets_append_from_library(ListBase *assets, Main *bmain, char *filename)
+{
+ LinkNode *l, *names;
+ bAsset* asset;
+ struct BlendHandle *libfiledata= NULL;
+ int nnames;
+ char current_filename[1024];
+
+ /* name test */
+ if (!is_blend_file(filename)) {
+ return;
+ }
+
+ if (!assets ) {
+ return;
+ }
+
+ BLI_strncpy(current_filename, bmain->name, sizeof(current_filename));
+
+ /* there we go */
+ /* for the time being only read filedata when libfiledata==0 */
+ libfiledata= BLO_blendhandle_from_file(filename, NULL);
+ if (libfiledata == NULL) return;
+
+
+ names= BLO_blendhandle_get_linkable_assets(libfiledata);
+ nnames= BLI_linklist_length(names);
+
+ for (l= names; l; l= l->next) {
+ char *blockname= l->link;
+ const char *group= BKE_idcode_to_name(GS(blockname));
+ if (group) {
+ asset = MEM_callocN(sizeof(bAsset), "asset item");
+ BLI_strncpy(asset->group, group, sizeof(asset->group));
+ BLI_strncpy(asset->name, blockname+2, sizeof(asset->name));
+ BLI_strncpy(asset->lib, filename, sizeof(asset->lib));
+ BLI_addtail(assets, asset);
+ }
+ }
+
+ BLI_linklist_free(names, free);
+ BLO_blendhandle_close(libfiledata);
+
+ BLI_strncpy(bmain->name, current_filename, sizeof(bmain->name)); // prevent bmain->name to change
+
+}
+
+void asset_collection_update(Main *bmain, bAssetCollection *collection)
+{
+ bAssetFile *af;
+ for (af = collection->asset_files.first; af; af= af->next) {
+ if (af->changed) {
+ BLI_freelistN(&af->assets);
+ assets_append_from_library(&af->assets, bmain, af->filepath);
+ af->changed = 0;
+ }
+ }
+}
+
+void asset_file_update(struct Main *bmain, struct bAssetFile *af)
+{
+ BLI_freelistN(&af->assets);
+ assets_append_from_library(&af->assets, bmain, af->filepath);
+ af->changed = 0;
+}
+
void asset_collection_make_local(Main *bmain, bAssetCollection *ac)
{
/* already local, do nothing */
@@ -82,7 +158,17 @@
void asset_collection_free(bAssetCollection *collection)
{
+ bAssetFile *af;
+ bAssetDir *ad;
+
+ for (af = collection->asset_files.first; af; af = af->next) {
+ BLI_freelistN(&af->assets);
+ }
BLI_freelistN(&collection->asset_files);
+ for (ad = collection->asset_dirs.first; ad; ad = ad->next) {
+ BLI_freelistN(&ad->assets);
+ }
+ BLI_freelistN(&collection->asset_dirs);
}
struct bAssetFile* BKE_asset_file_add(bAssetCollection *collection)
Modified: branches/asset-browser/source/blender/blenloader/BLO_readfile.h
===================================================================
--- branches/asset-browser/source/blender/blenloader/BLO_readfile.h 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/source/blender/blenloader/BLO_readfile.h 2012-07-28 16:55:26 UTC (rev 49330)
@@ -154,6 +154,16 @@
int *tot_names);
/**
+ * Gets the names of all the datablocks in a file
+ * that can be linked
+ *
+ * \param bh The blendhandle to access.
+ * \return A BLI_linklist of strings. The string links
+ * should be freed with free (they were allocated with malloc).
+ */
+struct LinkNode *BLO_blendhandle_get_linkable_assets(struct BlendHandle *bh);
+
+/**
* Gets the previews of all the datablocks in a file
* of a certain type (ie. All the scene names in
* a file).
Modified: branches/asset-browser/source/blender/blenloader/intern/readblenentry.c
===================================================================
--- branches/asset-browser/source/blender/blenloader/intern/readblenentry.c 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/source/blender/blenloader/intern/readblenentry.c 2012-07-28 16:55:26 UTC (rev 49330)
@@ -218,6 +218,25 @@
return previews;
}
+LinkNode *BLO_blendhandle_get_linkable_assets(BlendHandle *bh)
+{
+ FileData *fd= (FileData*) bh;
+ LinkNode *names= NULL;
+ BHead *bhead;
+
+ for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
+ if (bhead->code==ENDB) {
+ break;
+ }
+ else if (BKE_idcode_is_linkable(bhead->code)) {
+ char *idname= bhead_id_name(fd, bhead);
+ BLI_linklist_prepend(&names, strdup(idname));
+ }
+ }
+
+ return names;
+}
+
LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
{
FileData *fd = (FileData *) bh;
Modified: branches/asset-browser/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/asset-browser/source/blender/editors/include/UI_interface.h 2012-07-28 13:48:29 UTC (rev 49329)
+++ branches/asset-browser/source/blender/editors/include/UI_interface.h 2012-07-28 16:55:26 UTC (rev 49330)
@@ -653,6 +653,14 @@
struct Panel *uiBeginPanel(struct ScrArea *sa, struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open);
void uiEndPanel(uiBlock *block, int width, int height);
+/* ItemList
+ *
+ * Only absolutely necessary parts for creating the item list
+ * interface will likely be reviewed
+ */
+struct ItemList *uiBeginItemList(struct ScrArea *sa, struct ARegion *ar, uiBlock *block, struct ItemListType *ilt, int *open);
+void uiEndItemList(uiBlock *block, int width, int height);
+
/* Handlers
*
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list