[Bf-blender-cvs] [504287b9877] asset-engine: Add initial, very basic/proof-of-concept drag and drop linking.

Bastien Montagne noreply at git.blender.org
Mon Oct 9 20:13:51 CEST 2017


Commit: 504287b9877a85be40dc80fe700f5d80319d06ec
Author: Bastien Montagne
Date:   Mon Oct 9 20:12:45 2017 +0200
Branches: asset-engine
https://developer.blender.org/rB504287b9877a85be40dc80fe700f5d80319d06ec

Add initial, very basic/proof-of-concept drag and drop linking.

Essentially works, will still need (as usual :P) lots of extension and
fixes and enhancements...

===================================================================

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/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_types.h
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 527791653d9..efaf40fcb11 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -493,11 +493,11 @@ int     UI_but_return_value_get(uiBut *but);
 
 void    UI_but_drag_set_id(uiBut *but, struct ID *id);
 void    UI_but_drag_set_rna(uiBut *but, struct PointerRNA *ptr);
-void    UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free);
+void    UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free, const bool is_libpath);
 void    UI_but_drag_set_name(uiBut *but, const char *name);
 void    UI_but_drag_set_value(uiBut *but);
 void    UI_but_drag_set_image(
-                uiBut *but, const char *path, int icon, struct ImBuf *ima, float scale, const bool use_free);
+        uiBut *but, const char *path, int icon, struct ImBuf *ima, float scale, const bool use_free, const bool is_libpath);
 
 bool    UI_but_active_drop_name(struct bContext *C);
 bool    UI_but_active_drop_color(struct bContext *C);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 8b8122618bb..6f292e62880 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -4101,9 +4101,9 @@ void UI_but_drag_set_rna(uiBut *but, PointerRNA *ptr)
 	but->dragpoin = (void *)ptr;
 }
 
-void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free)
+void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free, const bool is_libpath)
 {
-	but->dragtype = WM_DRAG_PATH;
+	but->dragtype = is_libpath ? WM_DRAG_LIBPATH : WM_DRAG_PATH;
 	if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
 		MEM_SAFE_FREE(but->dragpoin);
 		but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
@@ -4130,9 +4130,9 @@ void UI_but_drag_set_value(uiBut *but)
 	but->dragtype = WM_DRAG_VALUE;
 }
 
-void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free)
+void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free, const bool is_libpath)
 {
-	but->dragtype = WM_DRAG_PATH;
+	but->dragtype = is_libpath ? WM_DRAG_LIBPATH : WM_DRAG_PATH;
 	ui_def_but_icon(but, icon, 0);  /* no flag UI_HAS_ICON, so icon doesnt draw in button */
 	if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
 		MEM_SAFE_FREE(but->dragpoin);
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 1c313659f2c..66689ca9134 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -264,7 +264,8 @@ static void draw_tile(int sx, int sy, int width, int height, int colorid, int sh
 }
 
 
-static void file_draw_icon(uiBlock *block, const char *path, int sx, int sy, int icon, int width, int height, bool drag)
+static void file_draw_icon(
+        uiBlock *block, const char *path, int sx, int sy, int icon, int width, int height, bool drag, const bool is_libpath)
 {
 	uiBut *but;
 	int x, y;
@@ -280,7 +281,7 @@ static void file_draw_icon(uiBlock *block, const char *path, int sx, int sy, int
 
 	if (drag) {
 		/* path is no more static, cannot give it directly to but... */
-		UI_but_drag_set_path(but, BLI_strdup(path), true);
+		UI_but_drag_set_path(but, BLI_strdup(path), true, is_libpath);
 	}
 }
 
@@ -324,7 +325,8 @@ void file_calc_previews(const bContext *C, ARegion *ar)
 
 static void file_draw_preview(
         uiBlock *block, const char *path, int sx, int sy, const float icon_aspect,
-        ImBuf *imb, const int icon, FileLayout *layout, const bool is_icon, const int typeflags, const bool drag)
+        ImBuf *imb, const int icon, FileLayout *layout, const bool is_icon, const int typeflags,
+        const bool drag, const bool is_libpath)
 {
 	uiBut *but;
 	float fx, fy;
@@ -404,7 +406,7 @@ static void file_draw_preview(
 	/* dragregion */
 	if (drag) {
 		/* path is no more static, cannot give it directly to but... */
-		UI_but_drag_set_image(but, BLI_strdup(path), icon, imb, scale, true);
+		UI_but_drag_set_image(but, BLI_strdup(path), icon, imb, scale, true, is_libpath);
 	}
 
 	glDisable(GL_BLEND);
@@ -521,6 +523,8 @@ void file_draw_list(const bContext *C, ARegion *ar)
 	const bool update_stat_strings = small_size != SMALL_SIZE_CHECK(layout->curr_size);
 	const float thumb_icon_aspect = sqrtf(64.0f / (float)(params->thumbnail_size));
 
+	const bool is_libpath = (sfile->params->type == FILE_LOADLIB);
+
 	numfiles = filelist_files_ensure(files, params);
 	
 	if (params->display != FILE_IMGDISPLAY) {
@@ -617,11 +621,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
 			}
 
 			file_draw_preview(block, path, sx, sy, thumb_icon_aspect,
-			                  imb, icon, layout, is_icon, file->typeflag, do_drag);
+			                  imb, icon, layout, is_icon, file->typeflag, do_drag, is_libpath);
 		}
 		else {
 			file_draw_icon(block, path, sx, sy - (UI_UNIT_Y / 6), filelist_geticon(files, i, true),
-			               ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE, do_drag);
+			               ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE, do_drag, is_libpath);
 			sx += ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X;
 		}
 
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 996506a9cf7..f12691e29d8 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -45,12 +45,15 @@
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_icons.h"
+#include "BKE_idcode.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 
+#include "../blenloader/BLO_readfile.h"
+
 #include "ED_space_api.h"
 #include "ED_screen.h"
 
@@ -584,6 +587,24 @@ static void view3d_main_region_exit(wmWindowManager *wm, ARegion *ar)
 	}
 }
 
+static int view3d_path_link_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *event)
+{
+	if (event->shift == false) {
+		if (drag->type == WM_DRAG_LIBPATH) {
+			char libname[FILE_MAX];
+			char *group, *name;
+			if (!BLO_library_path_explode(drag->path, libname, &group, &name) /* later... && (!aet || !path_to_idcode(path))*/ ) {
+				return 0;
+			}
+			switch (BKE_idcode_from_name(group)) {
+				case ID_OB:
+					return 1;
+			}
+		}
+	}
+	return 0;
+}
+
 static int view3d_ob_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
 {
 	if (drag->type == WM_DRAG_ID) {
@@ -662,6 +683,13 @@ static int view3d_ima_mesh_drop_poll(bContext *C, wmDrag *drag, const wmEvent *e
 	return 0;
 }
 
+static void view3d_path_link_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+	RNA_string_set(drop->ptr, "asset_engine", drag->ae_idname);
+	RNA_string_set(drop->ptr, "directory", "");
+	RNA_string_set(drop->ptr, "filename", drag->path);
+}
+
 static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
 	ID *id = drag->poin;
@@ -702,8 +730,11 @@ static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
 /* region dropbox definition */
 static void view3d_dropboxes(void)
 {
+	wmDropBox *drop;
 	ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
 	
+	drop = WM_dropbox_add(lb, "WM_OT_link", view3d_path_link_drop_poll, view3d_path_link_drop_copy);
+	drop->opcontext = WM_OP_EXEC_DEFAULT;
 	WM_dropbox_add(lb, "OBJECT_OT_add_named", view3d_ob_drop_poll, view3d_ob_drop_copy);
 	WM_dropbox_add(lb, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy);
 	WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_mesh_drop_poll, view3d_id_path_drop_copy);
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index f6049f10378..f3df1d5a796 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -638,6 +638,7 @@ typedef struct wmReport {
 #define WM_DRAG_NAME	3
 #define WM_DRAG_VALUE	4
 #define WM_DRAG_COLOR	5
+#define WM_DRAG_LIBPATH	6
 
 typedef enum wmDragFlags {
 	WM_DRAG_NOP         = 0,
@@ -651,8 +652,10 @@ typedef struct wmDrag {
 	
 	int icon, type;					/* type, see WM_DRAG defines above */
 	void *poin;
-	char path[1024]; /* FILE_MAX */
+	char path[1090]; /* FILE_MAX + MAX_ID_NAME */
 	double value;
+
+	char ae_idname[64];  /* BKE_ST_MAXNAME */
 	
 	struct ImBuf *imb;						/* if no icon but imbuf should be drawn around cursor */
 	float scale;
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 3a53906a8e8..9a43611db57 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -34,6 +34,7 @@
 
 #include "DNA_windowmanager_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_space_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -45,6 +46,7 @@
 #include "BIF_glutil.h"
 
 #include "BKE_context.h"
+#include "BKE_screen.h"
 
 #include "IMB_imbuf_types.h"
 
@@ -151,10 +153,18 @@ wmDrag *WM_event_start_drag(struct bContext *C, int icon, int type, void *poin,
 	drag->flags = flags;
 	drag->icon = icon;
 	drag->type = type;
-	if (type == WM_DRAG_PATH)
+	if (ELEM(type, WM_DRAG_PATH, WM_DRAG_LIBPATH)) {
 		BLI_strncpy(drag->path, poin, FILE_MAX);
-	else
+		if (type == WM_DRAG_LIBPATH) {
+			SpaceFile *sfile = CTX_wm_space_file(C);
+			if (sfile) {
+				BLI_strncpy(drag->ae_idname, sfile->asset_engine, BKE_ST_MAXNAME);
+			}
+		}
+	}
+	else {
 		drag->poin = poin;
+	}
 	drag->value = value;
 	
 	return drag;



More information about the Bf-blender-cvs mailing list