***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?
This commit is contained in:
William Reynish 2010-05-09 18:07:17 +00:00
parent 6d8cb93f71
commit 95bb364bda
5 changed files with 73 additions and 8 deletions

View File

@ -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,11 +320,25 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
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 */
@ -368,6 +383,7 @@ void MESH_OT_drop_named_image(wmOperatorType *ot)
/* 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)

View File

@ -75,6 +75,8 @@ void outliner_keymap(wmKeyConfig *keyconf)
{
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);

View File

@ -306,7 +306,7 @@ static int image_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
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;
}

View File

@ -368,6 +368,36 @@ static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
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 @@ void ED_spacetype_text(void)
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");

View File

@ -57,6 +57,8 @@
#include "RNA_access.h"
#include "UI_resources.h"
#include "view3d_intern.h" // own include
/* ******************** manage regions ********************* */
@ -416,6 +418,10 @@ static int view3d_ima_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
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,10 +441,20 @@ static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
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 @@ static void view3d_dropboxes(void)
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);
}