[Bf-blender-cvs] [e5774282b94] blender-v3.0-release: Fix asset preview not showing up for current file data-blocks
Julian Eisel
noreply at git.blender.org
Thu Nov 18 11:47:27 CET 2021
Commit: e5774282b94772af8822f4e3ab8b24207a450fb8
Author: Julian Eisel
Date: Thu Nov 18 11:23:15 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rBe5774282b94772af8822f4e3ab8b24207a450fb8
Fix asset preview not showing up for current file data-blocks
For data-blocks from the current file, the image-buffer for dragging
wasn't set at all. This wasn't intentional, dragging things in the Asset
Browser should just always show the preview.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface.c
M source/blender/editors/space_file/file_draw.c
M source/blender/windowmanager/intern/wm_dragdrop.c
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 725c9921d13..065b0a2d057 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -773,6 +773,7 @@ void UI_block_translate(uiBlock *block, int x, int y);
int UI_but_return_value_get(uiBut *but);
void UI_but_drag_set_id(uiBut *but, struct ID *id);
+void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale);
void UI_but_drag_set_asset(uiBut *but,
const struct AssetHandle *asset,
const char *path,
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 9f9324505ad..6ad0ef9de18 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6238,6 +6238,16 @@ void UI_but_drag_set_id(uiBut *but, ID *id)
but->dragpoin = (void *)id;
}
+/**
+ * Set an image to display while dragging. This works for any drag type (`WM_DRAG_XXX`).
+ * Not to be confused with #UI_but_drag_set_image(), which sets up dragging of an image.
+ */
+void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale)
+{
+ but->imb = imb;
+ but->imb_scale = scale;
+}
+
/**
* \param asset: May be passed from a temporary variable, drag data only stores a copy of this.
*/
@@ -6266,8 +6276,7 @@ void UI_but_drag_set_asset(uiBut *but,
}
but->dragpoin = asset_drag;
but->dragflag |= UI_BUT_DRAGPOIN_FREE;
- but->imb = imb;
- but->imb_scale = scale;
+ UI_but_drag_attach_image(but, imb, scale);
}
void UI_but_drag_set_rna(uiBut *but, PointerRNA *ptr)
@@ -6322,8 +6331,7 @@ void UI_but_drag_set_image(
if (use_free) {
but->dragflag |= UI_BUT_DRAGPOIN_FREE;
}
- but->imb = imb;
- but->imb_scale = scale;
+ UI_but_drag_attach_image(but, imb, scale);
}
PointerRNA *UI_but_operator_ptr_get(uiBut *but)
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 66aabe39e44..e393cc41a86 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -178,6 +178,10 @@ static void file_draw_icon(const SpaceFile *sfile,
if ((id = filelist_file_get_id(file))) {
UI_but_drag_set_id(but, id);
+ ImBuf *preview_image = filelist_file_getimage(file);
+ if (preview_image) {
+ UI_but_drag_attach_image(but, preview_image, UI_DPI_FAC);
+ }
}
else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS &&
(file->typeflag & FILE_TYPE_ASSET) != 0) {
@@ -504,6 +508,7 @@ static void file_draw_preview(const SpaceFile *sfile,
if ((id = filelist_file_get_id(file))) {
UI_but_drag_set_id(but, id);
+ UI_but_drag_attach_image(but, imb, scale);
}
/* path is no more static, cannot give it directly to but... */
else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS &&
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 64aa55c058c..49b84abf9a2 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -767,6 +767,12 @@ static void wm_drag_draw_icon(bContext *UNUSED(C),
const int xy[2])
{
int x, y;
+
+ /* This could also get the preview image of an ID when dragging one. But the big preview icon may
+ * actually not always be wanted, for example when dragging objects in the Outliner it gets in
+ * the way). So make the drag user set an image buffer explicitly (e.g. through
+ * #UI_but_drag_attach_image()). */
+
if (drag->imb) {
x = xy[0] - drag->sx / 2;
y = xy[1] - drag->sy / 2;
More information about the Bf-blender-cvs
mailing list