[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28691] trunk/blender/source/blender/ editors: ***Drag and drop fun!***

William Reynish william at reynish.com
Sun May 9 20:07:17 CEST 2010


Revision: 28691
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28691
Author:   billrey
Date:     2010-05-09 20:07:17 +0200 (Sun, 09 May 2010)

Log Message:
-----------
***Drag and drop fun!***

Added ability to drag images and movies directly onto objects to assign them as textures.

You can drag them from the file browser, directly from the OS or even from other apps. Here's a video to demonstrate:

http://www.youtube.com/watch?v=fGe2U8F_JvE

Ton wanted to show me how to add it, but he ended up doing almost all of the coding himself ;)

Ton/Matt: Dropping a text file in the Text Editor fails for some reason. It aught to work - probably a keymap conflict of some sorts?

Modified Paths:
--------------
    trunk/blender/source/blender/editors/mesh/mesh_data.c
    trunk/blender/source/blender/editors/space_outliner/outliner_ops.c
    trunk/blender/source/blender/editors/space_sequencer/space_sequencer.c
    trunk/blender/source/blender/editors/space_text/space_text.c
    trunk/blender/source/blender/editors/space_view3d/space_view3d.c

Modified: trunk/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_data.c	2010-05-09 18:05:33 UTC (rev 28690)
+++ trunk/blender/source/blender/editors/mesh/mesh_data.c	2010-05-09 18:07:17 UTC (rev 28691)
@@ -43,6 +43,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
@@ -319,12 +320,26 @@
 	char name[32];
 	
 	/* check input variables */
-	RNA_string_get(op->ptr, "name", name);
-	ima= (Image *)find_id("IM", name);
-	if(base==NULL || base->object->type!=OB_MESH || ima==NULL) {
-		BKE_report(op->reports, RPT_ERROR, "Not a Mesh or no Image.");
-		return OPERATOR_CANCELLED;
+	if(RNA_property_is_set(op->ptr, "path")) {
+		char path[FILE_MAX];
+		
+		RNA_string_get(op->ptr, "path", path);
+		ima= BKE_add_image_file(path, 
+								scene ? scene->r.cfra : 1);
+		
+		if(!ima) {
+			BKE_report(op->reports, RPT_ERROR, "Not an Image.");
+			return OPERATOR_CANCELLED;
+		}
 	}
+	else {
+		RNA_string_get(op->ptr, "name", name);
+		ima= (Image *)find_id("IM", name);
+		if(base==NULL || base->object->type!=OB_MESH || ima==NULL) {
+			BKE_report(op->reports, RPT_ERROR, "Not a Mesh or no Image.");
+			return OPERATOR_CANCELLED;
+		}
+	}
 	
 	/* turn mesh in editmode */
 	/* BKE_mesh_get/end_editmesh: ED_uvedit_assign_image also calls this */
@@ -368,6 +383,7 @@
 	
 	/* properties */
 	RNA_def_string(ot->srna, "name", "Image", 24, "Name", "Image name to assign.");
+	RNA_def_string(ot->srna, "path", "Path", FILE_MAX, "Filepath", "Path to image file");
 }
 
 static int uv_texture_remove_exec(bContext *C, wmOperator *op)

Modified: trunk/blender/source/blender/editors/space_outliner/outliner_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_outliner/outliner_ops.c	2010-05-09 18:05:33 UTC (rev 28690)
+++ trunk/blender/source/blender/editors/space_outliner/outliner_ops.c	2010-05-09 18:07:17 UTC (rev 28691)
@@ -75,6 +75,8 @@
 {
 	wmKeyMap *keymap= WM_keymap_find(keyconf, "Outliner", SPACE_OUTLINER, 0);
 	
+	WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
+	
 	RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_PRESS, 0, 0)->ptr, "extend", 0);
 	RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
 	

Modified: trunk/blender/source/blender/editors/space_sequencer/space_sequencer.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/space_sequencer.c	2010-05-09 18:05:33 UTC (rev 28690)
+++ trunk/blender/source/blender/editors/space_sequencer/space_sequencer.c	2010-05-09 18:07:17 UTC (rev 28691)
@@ -306,7 +306,7 @@
 static int movie_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
 {
 	if(drag->type==WM_DRAG_PATH)
-		if(ELEM(drag->icon, ICON_FILE_MOVIE, ICON_FILE_BLANK))	/* rule might not work? */
+		if(ELEM3(drag->icon, 0, ICON_FILE_MOVIE, ICON_FILE_BLANK))	/* rule might not work? */
 			return 1;
 	return 0;
 }

Modified: trunk/blender/source/blender/editors/space_text/space_text.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/space_text.c	2010-05-09 18:05:33 UTC (rev 28690)
+++ trunk/blender/source/blender/editors/space_text/space_text.c	2010-05-09 18:07:17 UTC (rev 28691)
@@ -368,6 +368,36 @@
 	WM_cursor_set(win, BC_TEXTEDITCURSOR);
 }
 
+
+
+/* ************* dropboxes ************* */
+
+static int text_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+{
+	if(drag->type==WM_DRAG_PATH)
+		if(ELEM(drag->icon, 0, ICON_FILE_BLANK))	/* rule might not work? */
+			return 1;
+	return 0;
+}
+
+static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+	/* copy drag path to properties */
+	RNA_string_set(drop->ptr, "path", drag->path);
+}
+
+/* this region dropbox definition */
+static void text_dropboxes(void)
+{
+	ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
+	
+	WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy);
+
+}
+
+/* ************* end drop *********** */
+
+
 /****************** header region ******************/
 
 /* add handlers, stuff you only do once or on area/region changes */
@@ -413,6 +443,7 @@
 	st->keymap= text_keymap;
 	st->listener= text_listener;
 	st->context= text_context;
+	st->dropboxes = text_dropboxes;
 	
 	/* regions: main window */
 	art= MEM_callocN(sizeof(ARegionType), "spacetype text region");

Modified: trunk/blender/source/blender/editors/space_view3d/space_view3d.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/space_view3d.c	2010-05-09 18:05:33 UTC (rev 28690)
+++ trunk/blender/source/blender/editors/space_view3d/space_view3d.c	2010-05-09 18:07:17 UTC (rev 28691)
@@ -57,6 +57,8 @@
 
 #include "RNA_access.h"
 
+#include "UI_resources.h"
+
 #include "view3d_intern.h"	// own include
 
 /* ******************** manage regions ********************* */
@@ -416,6 +418,10 @@
 		if( GS(id->name)==ID_IM )
 			return 1;
 	}
+	else if(drag->type==WM_DRAG_PATH){
+		if(ELEM(drag->icon, 0, ICON_FILE_IMAGE))	/* rule might not work? */
+			return 1;
+	}
 	return 0;
 }
 
@@ -435,11 +441,21 @@
 static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
 	ID *id= (ID *)drag->poin;
-
+	
 	RNA_string_set(drop->ptr, "name", id->name+2);
 }
 
+static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+	ID *id= (ID *)drag->poin;
+	
+	if(id)
+		RNA_string_set(drop->ptr, "name", id->name+2);
+	if(drag->path) 
+		RNA_string_set(drop->ptr, "path", drag->path);
+}
 
+
 /* region dropbox definition */
 static void view3d_dropboxes(void)
 {
@@ -447,7 +463,7 @@
 	
 	WM_dropbox_add(lb, "OBJECT_OT_add_named_cursor", 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_drop_poll, view3d_id_drop_copy);
+	WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_drop_poll, view3d_id_path_drop_copy);
 }
 
 





More information about the Bf-blender-cvs mailing list