[Bf-blender-cvs] [796c599194c] ui-asset-view-template: Add initial asset-view template, with dummy contents (palette colors)
Julian Eisel
noreply at git.blender.org
Tue Feb 23 18:52:46 CET 2021
Commit: 796c599194c4017b7f32970b582d249ca6413289
Author: Julian Eisel
Date: Tue Feb 23 18:30:00 2021 +0100
Branches: ui-asset-view-template
https://developer.blender.org/rB796c599194c4017b7f32970b582d249ca6413289
Add initial asset-view template, with dummy contents (palette colors)
Idea is to be able to display a list of assets in a layout, by giving it
some custom filtering settings (not done yet). This would be just a
uiList managed by Blender, displaying previews similar to the Asset
Browser.
I decided to use uiLists for this because it already deals with stuff
like writing its UI data to .blends (e.g. filtering and sort settings),
filtering and scrolling. But I think we'll have to do a number of
general improvements to them. Here I just added a new (C-only for now)
"flexible grid" list display type, which uses bigger previews and
behaves much better than the currend "grid" one.
There's a bit of hacking going on here and things will probably change.
For now I'm just interested in getting the basics done to see if the
direction is good.
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/CMakeLists.txt
A source/blender/editors/interface/interface_template_asset_view.cc
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/space_api/spacetypes.c
M source/blender/makesdna/DNA_screen_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_palette.c
M source/blender/makesrna/intern/rna_ui_api.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 4690abe5cec..3f4a082ed2e 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6983,6 +6983,18 @@ class VIEW3D_PT_context_properties(Panel):
rna_prop_ui.draw(self.layout, context, member, object, False)
+class VIEW3D_PT_asset_testing(Panel):
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'UI'
+ bl_label = "Asset Testing"
+ bl_category = "Assets"
+
+ def draw(self, context):
+ layout = self.layout
+
+ layout.template_asset_view()
+
+
# Grease Pencil Object - Multiframe falloff tools
class VIEW3D_PT_gpencil_multi_frame(Panel):
bl_space_type = 'VIEW_3D'
@@ -7696,6 +7708,7 @@ classes = (
VIEW3D_PT_transform_orientations,
VIEW3D_PT_overlay_gpencil_options,
VIEW3D_PT_context_properties,
+ VIEW3D_PT_asset_testing,
VIEW3D_PT_paint_vertex_context_menu,
VIEW3D_PT_paint_texture_context_menu,
VIEW3D_PT_paint_weight_context_menu,
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 81641239c6a..4bc7107323d 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2196,6 +2196,7 @@ int uiTemplateRecentFiles(struct uiLayout *layout, int rows);
void uiTemplateFileSelectPath(uiLayout *layout,
struct bContext *C,
struct FileSelectParams *params);
+void uiTemplateAssetView(struct uiLayout *layout, struct bContext *C);
/* items */
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname);
@@ -2449,6 +2450,7 @@ typedef struct uiDragColorHandle {
void ED_operatortypes_ui(void);
void ED_keymap_ui(struct wmKeyConfig *keyconf);
+void ED_uilisttypes_ui(void);
void UI_drop_color_copy(struct wmDrag *drag, struct wmDropBox *drop);
bool UI_drop_color_poll(struct bContext *C,
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 82bcd5d7eb4..4948c884be3 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -65,6 +65,7 @@ set(SRC
interface_region_tooltip.c
interface_regions.c
interface_style.c
+ interface_template_asset_view.cc
interface_template_search_menu.c
interface_template_search_operator.c
interface_templates.c
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
new file mode 100644
index 00000000000..2701103eef5
--- /dev/null
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -0,0 +1,111 @@
+/*
+ * 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 edinterface
+ */
+
+#include "DNA_userdef_types.h"
+
+#include "BLI_string.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "UI_interface.h"
+
+#include "WM_api.h"
+
+#include "interface_intern.h"
+
+/* TODO temporary includes for palettes. */
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_screen.h"
+#include "DNA_brush_types.h"
+#include "RNA_access.h"
+
+static void asset_view_draw_item(uiList *UNUSED(ui_list),
+ bContext *UNUSED(C),
+ uiLayout *layout,
+ PointerRNA *UNUSED(dataptr),
+ PointerRNA *itemptr,
+ int UNUSED(icon),
+ PointerRNA *UNUSED(active_dataptr),
+ const char *UNUSED(active_propname),
+ int index,
+ int UNUSED(flt_flag))
+{
+ uiBlock *block = uiLayoutGetBlock(layout);
+ uiButColor *color_but = (uiButColor *)uiDefButR(block,
+ UI_BTYPE_COLOR,
+ 0,
+ "",
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y,
+ itemptr,
+ "color",
+ -1,
+ 0.0,
+ 1.0,
+ 0.0,
+ 0.0,
+ "");
+ color_but->is_pallete_color = true;
+ color_but->palette_color_index = index;
+}
+
+static uiListType *UI_UL_asset_view(void)
+{
+ uiListType *list_type = (uiListType *)MEM_callocN(sizeof(*list_type), __func__);
+
+ BLI_strncpy(list_type->idname, "UI_UL_asset_view", sizeof(list_type->idname));
+ list_type->draw_item = asset_view_draw_item;
+
+ return list_type;
+}
+
+void ED_uilisttypes_ui()
+{
+ WM_uilisttype_add(UI_UL_asset_view());
+}
+
+void uiTemplateAssetView(uiLayout *layout, bContext *C)
+{
+ Palette *palette = (Palette *)CTX_data_main(C)->palettes.first;
+
+ PointerRNA id_ptr;
+ RNA_id_pointer_create(&palette->id, &id_ptr);
+
+ PointerRNA colors_poin;
+ RNA_pointer_create(&palette->id, &RNA_PaletteColors, palette, &colors_poin);
+ uiTemplateList(layout,
+ C,
+ "UI_UL_asset_view",
+ "asset_view",
+ &id_ptr,
+ "colors",
+ &colors_poin,
+ "active_index",
+ nullptr,
+ 0,
+ 0,
+ UILST_LAYOUT_FLEXIBLE_GRID,
+ 0,
+ false,
+ false);
+}
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 67446ca681f..710bdf74165 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -5916,6 +5916,62 @@ static char *uilist_item_tooltip_func(bContext *UNUSED(C), void *argN, const cha
return BLI_sprintfN("%s - %s", tip, dyn_tooltip);
}
+/**
+ * \brief ui_list_create
+ *
+ * \note Note that \a layout_type may be NULL.
+ */
+static uiList *ui_list_create(bContext *C,
+ uiListType *ui_list_type,
+ const char ui_list_id[UI_MAX_NAME_STR],
+ int layout_type,
+ int activei,
+ bool sort_reverse,
+ bool sort_lock)
+{
+ /* Allows to work in popups. */
+ ARegion *region = CTX_wm_menu(C);
+ if (region == NULL) {
+ region = CTX_wm_region(C);
+ }
+ uiList *ui_list = BLI_findstring(®ion->ui_lists, ui_list_id, offsetof(uiList, list_id));
+
+ if (!ui_list) {
+ ui_list = MEM_callocN(sizeof(uiList), "uiList");
+ BLI_strncpy(ui_list->list_id, ui_list_id, sizeof(ui_list->list_id));
+ BLI_addtail(®ion->ui_lists, ui_list);
+ ui_list->list_grip = -UI_LIST_AUTO_SIZE_THRESHOLD; /* Force auto size by default. */
+ if (sort_reverse) {
+ ui_list->filter_sort_flag |= UILST_FLT_SORT_REVERSE;
+ }
+ if (sort_lock) {
+ ui_list->filter_sort_flag |= UILST_FLT_SORT_LOCK;
+ }
+ }
+
+ if (!ui_list->dyn_data) {
+ ui_list->dyn_data = MEM_callocN(sizeof(uiListDyn), "uiList.dyn_data");
+ }
+ uiListDyn *dyn_data = ui_list->dyn_data;
+
+ /* Because we can't actually pass type across save&load... */
+ ui_list->type = ui_list_type;
+ ui_list->layout_type = layout_type;
+
+ /* Reset filtering data. */
+ MEM_SAFE_FREE(dyn_data->items_filter_flags);
+ MEM_SAFE_FREE(dyn_data->items_filter_neworder);
+ dyn_data->items_len = dyn_data->items_shown = -1;
+
+ /* When active item changed since last draw, scroll to it. */
+ if (activei != ui_list->list_last_activei) {
+ ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM;
+ ui_list->list_last_activei = activei;
+ }
+
+ return ui_list;
+}
+
void uiTemplateList(uiLayout *layout,
bContext *C,
const char *listtype_name,
@@ -6017,46 +6073,10 @@ void uiTemplateList(uiLayout *layout,
BLI_snprintf(
ui_list_id, sizeof(ui_list_id), "%s_%s", ui_list_type->idname, list_id ? list_id : "");
- /* Allows to work in popups. */
- ARegion *region = CTX_wm_menu(C);
- if (region == NULL) {
- region = CTX_wm_region(C);
- }
- uiList *ui_list = BLI_findstring(®ion->ui_lists, ui_list_id, offsetof(uiList, list_id));
-
- if (!ui_list) {
- ui_list = MEM_callocN(sizeof(uiList), "uiList");
- BLI_strncpy(ui_list->list_id, ui_list_id, sizeof(ui_list->list_id));
- BLI_addtail(®ion->ui_lists, ui_list);
- ui_list->list_grip = -UI_LIST_AUTO_SIZE_THRESHOLD; /* Force auto size by default. */
- if (sort_reverse) {
- ui_list->filter_sort_flag |= UILST_FLT_SORT_REVERSE;
- }
- if (sort_lock) {
- ui_list->filter_sort_flag |= UILST_FLT_SORT_LOCK;
- }
- }
-
- if (!ui_list->dyn_data) {
- ui_list->dyn_data = MEM_callocN(sizeof(uiListDyn), "uiList.dyn_data");
- }
+ uiList *ui_list = ui_list_create(
+ C, ui_list_type, ui_list_id, layout_type, activei, sort
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list