diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-02-25 03:18:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-02-25 03:18:21 +0400 |
commit | 4e1ea1f9fd84fa37513165689fdc3edbb11f0856 (patch) | |
tree | 497f78daa1c549273ec4715e40640ef9740e4c04 /source/blender/editors/object/object_add.c | |
parent | 83e53afb18b0bae4cfc21dcabc14a5720494af0e (diff) |
patch [#34411] Patch for image drag and drop to create Empty rather than BG image
from Kevin Mackay (yakca)
Diffstat (limited to 'source/blender/editors/object/object_add.c')
-rw-r--r-- | source/blender/editors/object/object_add.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index bc577f6ee29..02dcb559843 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -67,6 +67,7 @@ #include "BKE_displist.h" #include "BKE_effect.h" #include "BKE_group.h" +#include "BKE_image.h" #include "BKE_lamp.h" #include "BKE_lattice.h" #include "BKE_library.h" @@ -735,6 +736,79 @@ void OBJECT_OT_empty_add(wmOperatorType *ot) ED_object_add_generic_props(ot, FALSE); } +static int empty_drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + Base *base = NULL; + Image *ima = NULL; + Object *ob = NULL; + + /* check image input variables */ + if (RNA_struct_property_is_set(op->ptr, "filepath")) { + char path[FILE_MAX]; + + RNA_string_get(op->ptr, "filepath", path); + ima = BKE_image_load_exists(path); + } + else if (RNA_struct_property_is_set(op->ptr, "name")) { + char name[MAX_ID_NAME - 2]; + + RNA_string_get(op->ptr, "name", name); + ima = (Image *)BKE_libblock_find_name(ID_IM, name); + } + + if (ima == NULL) { + BKE_report(op->reports, RPT_ERROR, "Not an image"); + return OPERATOR_CANCELLED; + } + + base = ED_view3d_give_base_under_cursor(C, event->mval); + + /* if empty under cursor, then set object */ + if (base && base->object->type == OB_EMPTY) { + ob = base->object; + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, CTX_data_scene(C)); + } + else { + /* add new empty */ + unsigned int layer; + float loc[3], rot[3]; + + if (!ED_object_add_generic_get_opts(C, op, loc, rot, NULL, &layer, NULL)) + return OPERATOR_CANCELLED; + + ob = ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer); + ob->empty_drawtype = OB_EMPTY_IMAGE; + } + + ob->data = ima; + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_drop_named_image(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Add Empty Image/Drop Image To Empty"; + ot->description = "Add an empty image type to scene with data"; + ot->idname = "OBJECT_OT_drop_named_image"; + + /* api callbacks */ + ot->invoke = empty_drop_named_image_invoke; + ot->poll = ED_operator_objectmode; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + prop = RNA_def_string(ot->srna, "filepath", "", FILE_MAX, "Filepath", "Path to image file"); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + prop = RNA_def_string(ot->srna, "name", "", MAX_ID_NAME - 2, "Name", "Image name to assign"); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + ED_object_add_generic_props(ot, FALSE); +} + /********************* Add Lamp Operator ********************/ static const char *get_lamp_defname(int type) |