patch [#34411] Patch for image drag and drop to create Empty rather than BG image
from Kevin Mackay (yakca)
This commit is contained in:
@@ -67,6 +67,7 @@
|
|||||||
#include "BKE_displist.h"
|
#include "BKE_displist.h"
|
||||||
#include "BKE_effect.h"
|
#include "BKE_effect.h"
|
||||||
#include "BKE_group.h"
|
#include "BKE_group.h"
|
||||||
|
#include "BKE_image.h"
|
||||||
#include "BKE_lamp.h"
|
#include "BKE_lamp.h"
|
||||||
#include "BKE_lattice.h"
|
#include "BKE_lattice.h"
|
||||||
#include "BKE_library.h"
|
#include "BKE_library.h"
|
||||||
@@ -735,6 +736,79 @@ void OBJECT_OT_empty_add(wmOperatorType *ot)
|
|||||||
ED_object_add_generic_props(ot, FALSE);
|
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 ********************/
|
/********************* Add Lamp Operator ********************/
|
||||||
|
|
||||||
static const char *get_lamp_defname(int type)
|
static const char *get_lamp_defname(int type)
|
||||||
|
@@ -113,6 +113,7 @@ void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
|
|||||||
void OBJECT_OT_text_add(struct wmOperatorType *ot);
|
void OBJECT_OT_text_add(struct wmOperatorType *ot);
|
||||||
void OBJECT_OT_armature_add(struct wmOperatorType *ot);
|
void OBJECT_OT_armature_add(struct wmOperatorType *ot);
|
||||||
void OBJECT_OT_empty_add(struct wmOperatorType *ot);
|
void OBJECT_OT_empty_add(struct wmOperatorType *ot);
|
||||||
|
void OBJECT_OT_drop_named_image(struct wmOperatorType *ot);
|
||||||
void OBJECT_OT_lamp_add(struct wmOperatorType *ot);
|
void OBJECT_OT_lamp_add(struct wmOperatorType *ot);
|
||||||
void OBJECT_OT_effector_add(struct wmOperatorType *ot);
|
void OBJECT_OT_effector_add(struct wmOperatorType *ot);
|
||||||
void OBJECT_OT_camera_add(struct wmOperatorType *ot);
|
void OBJECT_OT_camera_add(struct wmOperatorType *ot);
|
||||||
|
@@ -114,6 +114,7 @@ void ED_operatortypes_object(void)
|
|||||||
WM_operatortype_append(OBJECT_OT_text_add);
|
WM_operatortype_append(OBJECT_OT_text_add);
|
||||||
WM_operatortype_append(OBJECT_OT_armature_add);
|
WM_operatortype_append(OBJECT_OT_armature_add);
|
||||||
WM_operatortype_append(OBJECT_OT_empty_add);
|
WM_operatortype_append(OBJECT_OT_empty_add);
|
||||||
|
WM_operatortype_append(OBJECT_OT_drop_named_image);
|
||||||
WM_operatortype_append(OBJECT_OT_lamp_add);
|
WM_operatortype_append(OBJECT_OT_lamp_add);
|
||||||
WM_operatortype_append(OBJECT_OT_camera_add);
|
WM_operatortype_append(OBJECT_OT_camera_add);
|
||||||
WM_operatortype_append(OBJECT_OT_speaker_add);
|
WM_operatortype_append(OBJECT_OT_speaker_add);
|
||||||
|
@@ -619,16 +619,17 @@ static void draw_empty_image(Object *ob, const short dflag, const unsigned char
|
|||||||
|
|
||||||
if ((dflag & DRAW_CONSTCOLOR) == 0) {
|
if ((dflag & DRAW_CONSTCOLOR) == 0) {
|
||||||
glColor3ubv(ob_wire_col);
|
glColor3ubv(ob_wire_col);
|
||||||
|
|
||||||
/* Calculate the outline vertex positions */
|
|
||||||
glBegin(GL_LINE_LOOP);
|
|
||||||
glVertex2f(ofs_x, ofs_y);
|
|
||||||
glVertex2f(ofs_x + ima_x, ofs_y);
|
|
||||||
glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
|
|
||||||
glVertex2f(ofs_x, ofs_y + ima_y);
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calculate the outline vertex positions */
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
glVertex2f(ofs_x, ofs_y);
|
||||||
|
glVertex2f(ofs_x + ima_x, ofs_y);
|
||||||
|
glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
|
||||||
|
glVertex2f(ofs_x, ofs_y + ima_y);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
|
||||||
/* Reset GL settings */
|
/* Reset GL settings */
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
@@ -514,20 +514,22 @@ static int view3d_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int view3d_ima_bg_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
|
static int view3d_ima_empty_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
|
||||||
{
|
{
|
||||||
if (ED_view3d_give_base_under_cursor(C, event->mval) ) {
|
Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
|
||||||
return 0;
|
|
||||||
}
|
if (!base || (base && base->object->type == OB_EMPTY))
|
||||||
return view3d_ima_drop_poll(C, drag, event);
|
return view3d_ima_drop_poll(C, drag, event);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int view3d_ima_ob_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
|
static int view3d_ima_mesh_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
|
||||||
{
|
{
|
||||||
if (ED_view3d_give_base_under_cursor(C, event->mval) ) {
|
Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
|
||||||
return view3d_ima_drop_poll(C, drag, event);
|
|
||||||
}
|
if (base && base->object->type == OB_MESH)
|
||||||
return 0;
|
return view3d_ima_drop_poll(C, drag, event);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
|
static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
|
||||||
@@ -570,8 +572,8 @@ static void view3d_dropboxes(void)
|
|||||||
|
|
||||||
WM_dropbox_add(lb, "OBJECT_OT_add_named", view3d_ob_drop_poll, view3d_ob_drop_copy);
|
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, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy);
|
||||||
WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_ob_drop_poll, view3d_id_path_drop_copy);
|
WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_mesh_drop_poll, view3d_id_path_drop_copy);
|
||||||
WM_dropbox_add(lb, "VIEW3D_OT_background_image_add", view3d_ima_bg_drop_poll, view3d_id_path_drop_copy);
|
WM_dropbox_add(lb, "OBJECT_OT_drop_named_image", view3d_ima_empty_drop_poll, view3d_id_path_drop_copy);
|
||||||
WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy);
|
WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user