diff options
author | William Reynish <william@reynish.com> | 2010-05-09 22:07:17 +0400 |
---|---|---|
committer | William Reynish <william@reynish.com> | 2010-05-09 22:07:17 +0400 |
commit | 95bb364bda806a3d28ae45e2fddfc87842e9234c (patch) | |
tree | 03fc0981c65ad9423748f29784a04ae4982049ff /source/blender | |
parent | 6d8cb93f71b5fb3b0d1638378e0cd56696337cbe (diff) |
***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?
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 26 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/space_sequencer.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 31 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 20 |
5 files changed, 73 insertions, 8 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 70352e9399f..4eae2540fcc 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -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) diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c index fcd6e272390..d23e950a033 100644 --- a/source/blender/editors/space_outliner/outliner_ops.c +++ b/source/blender/editors/space_outliner/outliner_ops.c @@ -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); diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 073743976e8..b19e8652f7f 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -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; } diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 2e78a502461..8b46617d55e 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -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"); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index a37ecda99ac..326409f310f 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -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); } |