From 7898089de3f20b08a08516bd2fd2be7dd1c565fe Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 8 Jul 2021 22:16:50 +0200 Subject: Assets: Add an active asset library per workspace, for the UI to use This per-workspace active asset library will be used by the asset views later. Note that Asset Browsers have their own active asset library, overriding the one from the workspace. As part of this the `FileSelectAssetLibraryUID` type gets replaced by `AssetLibraryReference` which is on the asset level now, not the File/Asset Browser level. But some more work is needed to complete that, which is better done in a separate commit. This also moves the asset library from/to enum-value logic from RNA to the editor asset level, which will later be used by the asset view. --- source/blender/makesrna/intern/rna_space.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 1d00c379b06..bcc6e54f4fd 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2561,6 +2561,8 @@ static PointerRNA rna_FileSelectParams_filter_id_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_FileSelectIDFilter, ptr->data); } +/* TODO use rna_def_asset_library_reference_common() */ + static int rna_FileAssetSelectParams_asset_library_get(PointerRNA *ptr) { FileAssetSelectParams *params = ptr->data; @@ -2568,7 +2570,7 @@ static int rna_FileAssetSelectParams_asset_library_get(PointerRNA *ptr) BLI_assert(ptr->type == &RNA_FileAssetSelectParams); /* Simple case: Predefined repo, just set the value. */ - if (params->asset_library.type < FILE_ASSET_LIBRARY_CUSTOM) { + if (params->asset_library.type < ASSET_LIBRARY_CUSTOM) { return params->asset_library.type; } @@ -2577,11 +2579,11 @@ static int rna_FileAssetSelectParams_asset_library_get(PointerRNA *ptr) const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index( &U, params->asset_library.custom_library_index); if (user_library) { - return FILE_ASSET_LIBRARY_CUSTOM + params->asset_library.custom_library_index; + return ASSET_LIBRARY_CUSTOM + params->asset_library.custom_library_index; } BLI_assert(0); - return FILE_ASSET_LIBRARY_LOCAL; + return ASSET_LIBRARY_LOCAL; } static void rna_FileAssetSelectParams_asset_library_set(PointerRNA *ptr, int value) @@ -2589,26 +2591,26 @@ static void rna_FileAssetSelectParams_asset_library_set(PointerRNA *ptr, int val FileAssetSelectParams *params = ptr->data; /* Simple case: Predefined repo, just set the value. */ - if (value < FILE_ASSET_LIBRARY_CUSTOM) { + if (value < ASSET_LIBRARY_CUSTOM) { params->asset_library.type = value; params->asset_library.custom_library_index = -1; - BLI_assert(ELEM(value, FILE_ASSET_LIBRARY_LOCAL)); + BLI_assert(ELEM(value, ASSET_LIBRARY_LOCAL)); return; } const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index( - &U, value - FILE_ASSET_LIBRARY_CUSTOM); + &U, value - ASSET_LIBRARY_CUSTOM); /* Note that the path isn't checked for validity here. If an invalid library path is used, the * Asset Browser can give a nice hint on what's wrong. */ const bool is_valid = (user_library->name[0] && user_library->path[0]); if (!user_library) { - params->asset_library.type = FILE_ASSET_LIBRARY_LOCAL; + params->asset_library.type = ASSET_LIBRARY_LOCAL; params->asset_library.custom_library_index = -1; } else if (user_library && is_valid) { - params->asset_library.custom_library_index = value - FILE_ASSET_LIBRARY_CUSTOM; - params->asset_library.type = FILE_ASSET_LIBRARY_CUSTOM; + params->asset_library.custom_library_index = value - ASSET_LIBRARY_CUSTOM; + params->asset_library.type = ASSET_LIBRARY_CUSTOM; } } @@ -2617,8 +2619,8 @@ static const EnumPropertyItem *rna_FileAssetSelectParams_asset_library_itemf( { const EnumPropertyItem predefined_items[] = { /* For the future. */ - // {FILE_ASSET_REPO_BUNDLED, "BUNDLED", 0, "Bundled", "Show the default user assets"}, - {FILE_ASSET_LIBRARY_LOCAL, + // {ASSET_REPO_BUNDLED, "BUNDLED", 0, "Bundled", "Show the default user assets"}, + {ASSET_LIBRARY_LOCAL, "LOCAL", ICON_BLENDER, "Current File", @@ -2646,7 +2648,7 @@ static const EnumPropertyItem *rna_FileAssetSelectParams_asset_library_itemf( } /* Use library path as description, it's a nice hint for users. */ - EnumPropertyItem tmp = {FILE_ASSET_LIBRARY_CUSTOM + i, + EnumPropertyItem tmp = {ASSET_LIBRARY_CUSTOM + i, user_library->name, ICON_NONE, user_library->name, -- cgit v1.2.3 From a26a059244f247a85c48a28dedeb4a551110c793 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 9 Jul 2021 12:56:26 +0200 Subject: Assets: Initial Asset List as part of the Asset System design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements a basic, WIP version of the asset list. This is needed to give the asset view UI template asset reading and displaying functionality. See: * Asset System: Data Storage, Reading & UI Access - https://developer.blender.org/T88184 Especially the asset list internals should change. It uses the File/Asset Browser's `FileList` API, which isn't really meant for access from outside the File Browser. But as explained in T88184, it does a lot of the stuff we currently need, so we (Sybren Stüvel and I) decided to go this route for now. Work on a file-list rewrite which integrates well with the asset system started in the `asset-system-filelist` branch. Further includes: * Operator to reload the asset list. * New `bpy.types.AssetHandle.get_full_library_path()` function, which gets the full path of the asset via the asset-list. * Changes to preview loading to prevent the preview loading job to run eternally for asset views. File Browsers have this issue too, but should be fixed separately. --- source/blender/makesrna/intern/rna_space.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index bcc6e54f4fd..966e3e34b24 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -509,6 +509,7 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = { #ifdef RNA_RUNTIME # include "DNA_anim_types.h" +# include "DNA_asset_types.h" # include "DNA_scene_types.h" # include "DNA_screen_types.h" # include "DNA_userdef_types.h" -- cgit v1.2.3 From 55d48defc50fac7756ccf5b5afbba8f35cf31835 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 9 Jul 2021 15:50:21 +0200 Subject: File/Asset Browser: Extend file-entry and asset handle Python API Adds the following to `bpy.types.FileSelectEntry`: * `id_type`: The data-block type the file represenets, if any. * `local_id`: The local data-block it represents, if any (assets only). And the following to `bpy.types.AssetHandle`: * `local_id`: The local data-block the asset represents, if any. This kind of information and the references are important for asset related operators and UIs. They will be used by upcoming Pose Library features. --- source/blender/makesrna/intern/rna_space.c | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 966e3e34b24..f934b1400ee 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2694,6 +2694,32 @@ static int rna_FileBrowser_FileSelectEntry_name_length(PointerRNA *ptr) return (int)strlen(entry->name); } +static const EnumPropertyItem *rna_FileBrowser_FileSelectEntry_id_type_itemf( + bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *UNUSED(r_free)) +{ + const FileDirEntry *entry = ptr->data; + if (entry->blentype == 0) { + const static EnumPropertyItem none_items[] = { + {0, "NONE", 0, "None", ""}, + }; + return none_items; + } + + return rna_enum_id_type_items; +} + +static int rna_FileBrowser_FileSelectEntry_id_type_get(PointerRNA *ptr) +{ + const FileDirEntry *entry = ptr->data; + return entry->blentype; +} + +static PointerRNA rna_FileBrowser_FileSelectEntry_local_id_get(PointerRNA *ptr) +{ + const FileDirEntry *entry = ptr->data; + return rna_pointer_inherit_refine(ptr, &RNA_ID, entry->id); +} + static int rna_FileBrowser_FileSelectEntry_preview_icon_id_get(PointerRNA *ptr) { const FileDirEntry *entry = ptr->data; @@ -6306,6 +6332,28 @@ static void rna_def_fileselect_entry(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_struct_name_property(srna, prop); + prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_id_type_items); + RNA_def_property_enum_funcs(prop, + "rna_FileBrowser_FileSelectEntry_id_type_get", + NULL, + "rna_FileBrowser_FileSelectEntry_id_type_itemf"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text( + prop, + "Data-block Type", + "The type of the data-block, if the file represents one ('NONE' otherwise)"); + + prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "ID"); + RNA_def_property_pointer_funcs( + prop, "rna_FileBrowser_FileSelectEntry_local_id_get", NULL, NULL, NULL); + RNA_def_property_ui_text(prop, + "", + "The local data-block this file represents; only valid if that is a " + "data-block in this file"); + RNA_def_property_flag(prop, PROP_HIDDEN); + prop = RNA_def_int( srna, "preview_icon_id", -- cgit v1.2.3 From 8925d3b7bf989e1db364d989fbd0c6cdb9a2acdb Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 13 Jul 2021 18:07:57 +0200 Subject: UI/Assets: Initial Asset View UI template The asset view UI template is a mini-version of the Asset Browser that can be placed in regular layouts, regions or popups. At this point it's made specifically for placement in vertical layouts, it can be made more flexible in the future. Generally the way this is implemented will likely change a lot still as the asset system evolves. The Pose Library add-on will use the asset view to display pose libraries in the 3D View sidebar. References: * https://developer.blender.org/T86139 * https://code.blender.org/2021/06/asset-browser-project-update/#what-are-we-building * https://code.blender.org/2021/05/pose-library-v2-0/#use-from-3d-viewport Notes: * Important limitation: Due to the early & WIP implementation of the asset list, all asset views showing the same library will show the same assets. That is despite the ID type filter option the template provides. The first asset view created will determine what's visible. Of course this should be made to work eventually. * The template supports passing an activate and a drag operator name. The former is called when an asset is clicked on (e.g. to apply the asset) the latter when dragging (e.g. to .blend a pose asset). If no drag operator is set, regular asset drag & drop will be executed. * The template returns the properties for both operators (see example below). * The argument list for using the template is quite long, but we can't avoid that currently. The UI list design requires that we pass a number of RNA or custom properties to work with, that for the Pose Libraries should be registered at the Pose Library add-on level, not in core Blender. * Idea is that Python scripts or add-ons that want to use the asset view can register custom properties, to hold data like the list of assets, and the active asset index. Maybe that will change in future and we can manage these internally. As an example, the pose library add-on uses it like this: ``` activate_op_props, drag_op_props = layout.template_asset_view( "pose_assets", workspace, "active_asset_library", wm, "pose_assets", workspace, "active_pose_asset_index", filter_id_types={"filter_action"}, activate_operator="poselib.apply_pose_asset", drag_operator="poselib.blend_pose_asset", ) drag_op_props.release_confirm = True drag_op_props.flipped = wm.poselib_flipped activate_op_props.flipped = wm.poselib_flipped ``` --- source/blender/makesrna/intern/rna_space.c | 200 ++++++++--------------------- 1 file changed, 57 insertions(+), 143 deletions(-) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index f934b1400ee..0019f315bbe 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -3217,6 +3217,45 @@ static const EnumPropertyItem dt_uv_items[] = { {0, NULL, 0, NULL, NULL}, }; +static struct IDFilterEnumPropertyItem rna_enum_space_file_id_filter_categories[] = { + /* Categories */ + {FILTER_ID_SCE, "category_scene", ICON_SCENE_DATA, "Scenes", "Show scenes"}, + {FILTER_ID_AC, "category_animation", ICON_ANIM_DATA, "Animations", "Show animation data"}, + {FILTER_ID_OB | FILTER_ID_GR, + "category_object", + ICON_OUTLINER_COLLECTION, + "Objects & Collections", + "Show objects and collections"}, + {FILTER_ID_AR | FILTER_ID_CU | FILTER_ID_LT | FILTER_ID_MB | FILTER_ID_ME | FILTER_ID_HA | + FILTER_ID_PT | FILTER_ID_VO, + "category_geometry", + ICON_NODETREE, + "Geometry", + "Show meshes, curves, lattice, armatures and metaballs data"}, + {FILTER_ID_LS | FILTER_ID_MA | FILTER_ID_NT | FILTER_ID_TE, + "category_shading", + ICON_MATERIAL_DATA, + "Shading", + "Show materials, nodetrees, textures and Freestyle's linestyles"}, + {FILTER_ID_IM | FILTER_ID_MC | FILTER_ID_MSK | FILTER_ID_SO, + "category_image", + ICON_IMAGE_DATA, + "Images & Sounds", + "Show images, movie clips, sounds and masks"}, + {FILTER_ID_CA | FILTER_ID_LA | FILTER_ID_LP | FILTER_ID_SPK | FILTER_ID_WO, + "category_environment", + ICON_WORLD_DATA, + "Environment", + "Show worlds, lights, cameras and speakers"}, + {FILTER_ID_BR | FILTER_ID_GD | FILTER_ID_PA | FILTER_ID_PAL | FILTER_ID_PC | FILTER_ID_TXT | + FILTER_ID_VF | FILTER_ID_CF | FILTER_ID_WS, + "category_misc", + ICON_GREASEPENCIL, + "Miscellaneous", + "Show other data types"}, + {0, NULL, 0, NULL, NULL}, +}; + static void rna_def_space_generic_show_region_toggles(StructRNA *srna, int region_type_mask) { PropertyRNA *prop; @@ -6164,142 +6203,6 @@ static void rna_def_space_console(BlenderRNA *brna) /* Filter for datablock types in link/append. */ static void rna_def_fileselect_idfilter(BlenderRNA *brna) { - struct IDFilterBoolean { - /* 64 bit, so we can't use bitflag enum. */ - const uint64_t flag; - const char *identifier; - const int icon; - const char *name; - const char *description; - }; - - static const struct IDFilterBoolean booleans[] = { - /* Datablocks */ - {FILTER_ID_AC, "filter_action", ICON_ANIM_DATA, "Actions", "Show Action data-blocks"}, - {FILTER_ID_AR, - "filter_armature", - ICON_ARMATURE_DATA, - "Armatures", - "Show Armature data-blocks"}, - {FILTER_ID_BR, "filter_brush", ICON_BRUSH_DATA, "Brushes", "Show Brushes data-blocks"}, - {FILTER_ID_CA, "filter_camera", ICON_CAMERA_DATA, "Cameras", "Show Camera data-blocks"}, - {FILTER_ID_CF, "filter_cachefile", ICON_FILE, "Cache Files", "Show Cache File data-blocks"}, - {FILTER_ID_CU, "filter_curve", ICON_CURVE_DATA, "Curves", "Show Curve data-blocks"}, - {FILTER_ID_GD, - "filter_grease_pencil", - ICON_GREASEPENCIL, - "Grease Pencil", - "Show Grease pencil data-blocks"}, - {FILTER_ID_GR, - "filter_group", - ICON_OUTLINER_COLLECTION, - "Collections", - "Show Collection data-blocks"}, - {FILTER_ID_HA, "filter_hair", ICON_HAIR_DATA, "Hairs", "Show/hide Hair data-blocks"}, - {FILTER_ID_IM, "filter_image", ICON_IMAGE_DATA, "Images", "Show Image data-blocks"}, - {FILTER_ID_LA, "filter_light", ICON_LIGHT_DATA, "Lights", "Show Light data-blocks"}, - {FILTER_ID_LP, - "filter_light_probe", - ICON_OUTLINER_DATA_LIGHTPROBE, - "Light Probes", - "Show Light Probe data-blocks"}, - {FILTER_ID_LS, - "filter_linestyle", - ICON_LINE_DATA, - "Freestyle Linestyles", - "Show Freestyle's Line Style data-blocks"}, - {FILTER_ID_LT, "filter_lattice", ICON_LATTICE_DATA, "Lattices", "Show Lattice data-blocks"}, - {FILTER_ID_MA, - "filter_material", - ICON_MATERIAL_DATA, - "Materials", - "Show Material data-blocks"}, - {FILTER_ID_MB, "filter_metaball", ICON_META_DATA, "Metaballs", "Show Metaball data-blocks"}, - {FILTER_ID_MC, - "filter_movie_clip", - ICON_TRACKER_DATA, - "Movie Clips", - "Show Movie Clip data-blocks"}, - {FILTER_ID_ME, "filter_mesh", ICON_MESH_DATA, "Meshes", "Show Mesh data-blocks"}, - {FILTER_ID_MSK, "filter_mask", ICON_MOD_MASK, "Masks", "Show Mask data-blocks"}, - {FILTER_ID_NT, - "filter_node_tree", - ICON_NODETREE, - "Node Trees", - "Show Node Tree data-blocks"}, - {FILTER_ID_OB, "filter_object", ICON_OBJECT_DATA, "Objects", "Show Object data-blocks"}, - {FILTER_ID_PA, - "filter_particle_settings", - ICON_PARTICLE_DATA, - "Particles Settings", - "Show Particle Settings data-blocks"}, - {FILTER_ID_PAL, "filter_palette", ICON_COLOR, "Palettes", "Show Palette data-blocks"}, - {FILTER_ID_PC, - "filter_paint_curve", - ICON_CURVE_BEZCURVE, - "Paint Curves", - "Show Paint Curve data-blocks"}, - {FILTER_ID_PT, - "filter_pointcloud", - ICON_POINTCLOUD_DATA, - "Point Clouds", - "Show/hide Point Cloud data-blocks"}, - {FILTER_ID_SCE, "filter_scene", ICON_SCENE_DATA, "Scenes", "Show Scene data-blocks"}, - {FILTER_ID_SIM, - "filter_simulation", - ICON_PHYSICS, - "Simulations", - "Show Simulation data-blocks"}, /* TODO: Use correct icon. */ - {FILTER_ID_SPK, "filter_speaker", ICON_SPEAKER, "Speakers", "Show Speaker data-blocks"}, - {FILTER_ID_SO, "filter_sound", ICON_SOUND, "Sounds", "Show Sound data-blocks"}, - {FILTER_ID_TE, "filter_texture", ICON_TEXTURE_DATA, "Textures", "Show Texture data-blocks"}, - {FILTER_ID_TXT, "filter_text", ICON_TEXT, "Texts", "Show Text data-blocks"}, - {FILTER_ID_VF, "filter_font", ICON_FONT_DATA, "Fonts", "Show Font data-blocks"}, - {FILTER_ID_VO, "filter_volume", ICON_VOLUME_DATA, "Volumes", "Show/hide Volume data-blocks"}, - {FILTER_ID_WO, "filter_world", ICON_WORLD_DATA, "Worlds", "Show World data-blocks"}, - {FILTER_ID_WS, - "filter_work_space", - ICON_WORKSPACE, - "Workspaces", - "Show workspace data-blocks"}, - - /* Categories */ - {FILTER_ID_SCE, "category_scene", ICON_SCENE_DATA, "Scenes", "Show scenes"}, - {FILTER_ID_AC, "category_animation", ICON_ANIM_DATA, "Animations", "Show animation data"}, - {FILTER_ID_OB | FILTER_ID_GR, - "category_object", - ICON_OUTLINER_COLLECTION, - "Objects & Collections", - "Show objects and collections"}, - {FILTER_ID_AR | FILTER_ID_CU | FILTER_ID_LT | FILTER_ID_MB | FILTER_ID_ME | FILTER_ID_HA | - FILTER_ID_PT | FILTER_ID_VO, - "category_geometry", - ICON_NODETREE, - "Geometry", - "Show meshes, curves, lattice, armatures and metaballs data"}, - {FILTER_ID_LS | FILTER_ID_MA | FILTER_ID_NT | FILTER_ID_TE, - "category_shading", - ICON_MATERIAL_DATA, - "Shading", - "Show materials, nodetrees, textures and Freestyle's linestyles"}, - {FILTER_ID_IM | FILTER_ID_MC | FILTER_ID_MSK | FILTER_ID_SO, - "category_image", - ICON_IMAGE_DATA, - "Images & Sounds", - "Show images, movie clips, sounds and masks"}, - {FILTER_ID_CA | FILTER_ID_LA | FILTER_ID_LP | FILTER_ID_SPK | FILTER_ID_WO, - "category_environment", - ICON_WORLD_DATA, - "Environment", - "Show worlds, lights, cameras and speakers"}, - {FILTER_ID_BR | FILTER_ID_GD | FILTER_ID_PA | FILTER_ID_PAL | FILTER_ID_PC | FILTER_ID_TXT | - FILTER_ID_VF | FILTER_ID_CF | FILTER_ID_WS, - "category_misc", - ICON_GREASEPENCIL, - "Miscellaneous", - "Show other data types"}, - - {0, NULL, 0, NULL, NULL}}; StructRNA *srna = RNA_def_struct(brna, "FileSelectIDFilter", NULL); RNA_def_struct_sdna(srna, "FileSelectParams"); @@ -6307,12 +6210,23 @@ static void rna_def_fileselect_idfilter(BlenderRNA *brna) RNA_def_struct_ui_text( srna, "File Select ID Filter", "Which ID types to show/hide, when browsing a library"); - for (int i = 0; booleans[i].identifier; i++) { - PropertyRNA *prop = RNA_def_property(srna, booleans[i].identifier, PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "filter_id", booleans[i].flag); - RNA_def_property_ui_text(prop, booleans[i].name, booleans[i].description); - RNA_def_property_ui_icon(prop, booleans[i].icon, 0); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); + const struct IDFilterEnumPropertyItem *individual_ids_and_categories[] = { + rna_enum_id_type_filter_items, + rna_enum_space_file_id_filter_categories, + NULL, + }; + for (uint i = 0; individual_ids_and_categories[i]; i++) { + for (int j = 0; individual_ids_and_categories[i][j].identifier; j++) { + PropertyRNA *prop = RNA_def_property( + srna, individual_ids_and_categories[i][j].identifier, PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, NULL, "filter_id", individual_ids_and_categories[i][j].flag); + RNA_def_property_ui_text(prop, + individual_ids_and_categories[i][j].name, + individual_ids_and_categories[i][j].description); + RNA_def_property_ui_icon(prop, individual_ids_and_categories[i][j].icon, 0); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); + } } } @@ -6590,7 +6504,7 @@ static void rna_def_fileselect_asset_params(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - /* XXX copied from rna_def_fileselect_idfilter. */ + /* XXX copied from rna_enum_id_type_filter_items. */ static const EnumPropertyItem asset_category_items[] = { {FILTER_ID_SCE, "SCENES", ICON_SCENE_DATA, "Scenes", "Show scenes"}, {FILTER_ID_AC, "ANIMATIONS", ICON_ANIM_DATA, "Animations", "Show animation data"}, -- cgit v1.2.3 From d3c454d66c0a730eafa7edecec158ca3b9edb2d7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 16 Jul 2021 11:45:03 +1000 Subject: Cleanup: compiler warnings --- source/blender/makesrna/intern/rna_space.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 0019f315bbe..f2d2b190d87 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2699,7 +2699,7 @@ static const EnumPropertyItem *rna_FileBrowser_FileSelectEntry_id_type_itemf( { const FileDirEntry *entry = ptr->data; if (entry->blentype == 0) { - const static EnumPropertyItem none_items[] = { + static const EnumPropertyItem none_items[] = { {0, "NONE", 0, "None", ""}, }; return none_items; -- cgit v1.2.3 From e850c2b06d18e4292110d3fe9cdf5ebc7c281daa Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 21 Jul 2021 19:30:31 +0200 Subject: Cleanup: Centralize/unify asset library reference from/to enum code This was an open TODO, I wanted to have code for translating asset library references from and to enum values in a central place, and access that in the same way from both the Asset Browser and the Workspace RNA code. * Adds own file for the related functions. * Adds doxygen comments. * Updates RNA callbacks to properly use these functions. * Let these functions call each other, avoid duplicating logic. --- source/blender/makesrna/intern/rna_space.c | 107 ++--------------------------- 1 file changed, 6 insertions(+), 101 deletions(-) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index f2d2b190d87..4aee7e9d852 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -536,6 +536,7 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = { # include "DEG_depsgraph_build.h" # include "ED_anim_api.h" +# include "ED_asset.h" # include "ED_buttons.h" # include "ED_clip.h" # include "ED_fileselect.h" @@ -2562,112 +2563,19 @@ static PointerRNA rna_FileSelectParams_filter_id_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_FileSelectIDFilter, ptr->data); } -/* TODO use rna_def_asset_library_reference_common() */ - static int rna_FileAssetSelectParams_asset_library_get(PointerRNA *ptr) { FileAssetSelectParams *params = ptr->data; /* Just an extra sanity check to ensure this isn't somehow called for RNA_FileSelectParams. */ BLI_assert(ptr->type == &RNA_FileAssetSelectParams); - /* Simple case: Predefined repo, just set the value. */ - if (params->asset_library.type < ASSET_LIBRARY_CUSTOM) { - return params->asset_library.type; - } - - /* Note that the path isn't checked for validity here. If an invalid library path is used, the - * Asset Browser can give a nice hint on what's wrong. */ - const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index( - &U, params->asset_library.custom_library_index); - if (user_library) { - return ASSET_LIBRARY_CUSTOM + params->asset_library.custom_library_index; - } - - BLI_assert(0); - return ASSET_LIBRARY_LOCAL; + return ED_asset_library_reference_to_enum_value(¶ms->asset_library); } static void rna_FileAssetSelectParams_asset_library_set(PointerRNA *ptr, int value) { FileAssetSelectParams *params = ptr->data; - - /* Simple case: Predefined repo, just set the value. */ - if (value < ASSET_LIBRARY_CUSTOM) { - params->asset_library.type = value; - params->asset_library.custom_library_index = -1; - BLI_assert(ELEM(value, ASSET_LIBRARY_LOCAL)); - return; - } - - const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index( - &U, value - ASSET_LIBRARY_CUSTOM); - - /* Note that the path isn't checked for validity here. If an invalid library path is used, the - * Asset Browser can give a nice hint on what's wrong. */ - const bool is_valid = (user_library->name[0] && user_library->path[0]); - if (!user_library) { - params->asset_library.type = ASSET_LIBRARY_LOCAL; - params->asset_library.custom_library_index = -1; - } - else if (user_library && is_valid) { - params->asset_library.custom_library_index = value - ASSET_LIBRARY_CUSTOM; - params->asset_library.type = ASSET_LIBRARY_CUSTOM; - } -} - -static const EnumPropertyItem *rna_FileAssetSelectParams_asset_library_itemf( - bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) -{ - const EnumPropertyItem predefined_items[] = { - /* For the future. */ - // {ASSET_REPO_BUNDLED, "BUNDLED", 0, "Bundled", "Show the default user assets"}, - {ASSET_LIBRARY_LOCAL, - "LOCAL", - ICON_BLENDER, - "Current File", - "Show the assets currently available in this Blender session"}, - {0, NULL, 0, NULL, NULL}, - }; - - EnumPropertyItem *item = NULL; - int totitem = 0; - - /* Add separator if needed. */ - if (!BLI_listbase_is_empty(&U.asset_libraries)) { - const EnumPropertyItem sepr = {0, "", 0, "Custom", NULL}; - RNA_enum_item_add(&item, &totitem, &sepr); - } - - int i = 0; - for (bUserAssetLibrary *user_library = U.asset_libraries.first; user_library; - user_library = user_library->next, i++) { - /* Note that the path itself isn't checked for validity here. If an invalid library path is - * used, the Asset Browser can give a nice hint on what's wrong. */ - const bool is_valid = (user_library->name[0] && user_library->path[0]); - if (!is_valid) { - continue; - } - - /* Use library path as description, it's a nice hint for users. */ - EnumPropertyItem tmp = {ASSET_LIBRARY_CUSTOM + i, - user_library->name, - ICON_NONE, - user_library->name, - user_library->path}; - RNA_enum_item_add(&item, &totitem, &tmp); - } - - if (totitem) { - const EnumPropertyItem sepr = {0, "", 0, "Built-in", NULL}; - RNA_enum_item_add(&item, &totitem, &sepr); - } - - /* Add predefined items. */ - RNA_enum_items_add(&item, &totitem, predefined_items); - - RNA_enum_item_end(&item, &totitem); - *r_free = true; - return item; + params->asset_library = ED_asset_library_reference_from_enum_value(value); } static void rna_FileAssetSelectParams_asset_category_set(PointerRNA *ptr, uint64_t value) @@ -6559,12 +6467,9 @@ static void rna_def_fileselect_asset_params(BlenderRNA *brna) RNA_def_struct_ui_text( srna, "Asset Select Parameters", "Settings for the file selection in Asset Browser mode"); - prop = RNA_def_property(srna, "asset_library", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_items(prop, DummyRNA_NULL_items); - RNA_def_property_enum_funcs(prop, - "rna_FileAssetSelectParams_asset_library_get", - "rna_FileAssetSelectParams_asset_library_set", - "rna_FileAssetSelectParams_asset_library_itemf"); + prop = rna_def_asset_library_reference_common(srna, + "rna_FileAssetSelectParams_asset_library_get", + "rna_FileAssetSelectParams_asset_library_set"); RNA_def_property_ui_text(prop, "Asset Library", ""); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); -- cgit v1.2.3 From f23b14091f60ccb23659075885d29bd24cd97f9d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 23 Jul 2021 17:04:21 +1000 Subject: Cleanup: double spaces in strings --- source/blender/makesrna/intern/rna_space.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 4aee7e9d852..a213b418e0e 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -359,7 +359,7 @@ static const EnumPropertyItem display_channels_items[] = { "Color and Alpha", "Display image with RGB colors and alpha transparency"}, {0, "COLOR", ICON_IMAGE_RGB, "Color", "Display image with RGB colors"}, - {SI_SHOW_ALPHA, "ALPHA", ICON_IMAGE_ALPHA, "Alpha", "Display alpha transparency channel"}, + {SI_SHOW_ALPHA, "ALPHA", ICON_IMAGE_ALPHA, "Alpha", "Display alpha transparency channel"}, {SI_SHOW_ZBUF, "Z_BUFFER", ICON_IMAGE_ZDEPTH, -- cgit v1.2.3 From 0491052a9697a706b4cd14a1f478180ad6fb8c75 Mon Sep 17 00:00:00 2001 From: Richard Antalik Date: Thu, 29 Jul 2021 11:35:48 +0200 Subject: VSE: Change grid line drawing Add overlay option to disable grid drawing. Reuse drawing code from other editors (timeline editor) Add argument `display_minor_lines` to function `UI_view2d_draw_lines_x__discrete_frames_or_seconds` This way minor line drawing can be disabled and so it doesn't cause too much visual noise. Also spacing seems to be too fine, so VSE uses 3x what is defined in preferences. Reviewed By: fsiddi, Severin Differential Revision: https://developer.blender.org/D11790 --- source/blender/makesrna/intern/rna_space.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/blender/makesrna/intern/rna_space.c') diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index a213b418e0e..1d4318602c2 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -5519,6 +5519,11 @@ static void rna_def_space_sequencer(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "draw_flag", SEQ_DRAW_TRANSFORM_PREVIEW); RNA_def_property_ui_text(prop, "Transform Preview", "Show preview of the transformed frames"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SEQUENCER, NULL); + + prop = RNA_def_property(srna, "show_grid", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_SHOW_GRID); + RNA_def_property_ui_text(prop, "Show Grid", "Show vertical grid lines"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SEQUENCER, NULL); } static void rna_def_space_text(BlenderRNA *brna) -- cgit v1.2.3