Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzeem Bande-Ali <azeemba>2022-03-04 02:28:48 +0300
committerHarley Acheson <harley.acheson@gmail.com>2022-03-04 02:28:48 +0300
commitfd2519e0b6948903892c3cfc373c903337979407 (patch)
tree4150c341b86662fc66c9dd6edf44cd98dc155225 /source/blender/editors/interface/interface_ops.c
parent471f27d66bd71e80db82c41db2a6fd58f854b46a (diff)
UI: Drag & Drop to Properties Materials Panel
Support drag/drop of materials to Properties Material Slots. See D13549 for more details. Differential Revision: https://developer.blender.org/D13549 Reviewed by Julian Eisel
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 498c22748ce..0722584c7d8 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -10,6 +10,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
+#include "DNA_material_types.h"
#include "DNA_modifier_types.h" /* for handling geometry nodes properties */
#include "DNA_object_types.h" /* for OB_DATA_SUPPORT_ID */
#include "DNA_screen_types.h"
@@ -27,6 +28,7 @@
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
+#include "BKE_material.h"
#include "BKE_node.h"
#include "BKE_report.h"
#include "BKE_screen.h"
@@ -2109,6 +2111,86 @@ static void UI_OT_tree_view_item_rename(wmOperatorType *ot)
ot->flag = OPTYPE_INTERNAL;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Material Drag/Drop Operator
+ *
+ * \{ */
+
+static bool ui_drop_material_poll(bContext *C)
+{
+ PointerRNA ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
+ Object *ob = ptr.data;
+ if (ob == NULL) {
+ return false;
+ }
+
+ PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
+ if (RNA_pointer_is_null(&mat_slot)) {
+ return false;
+ }
+
+ return true;
+}
+
+static int ui_drop_material_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+
+ if (!RNA_struct_property_is_set(op->ptr, "session_uuid")) {
+ return OPERATOR_CANCELLED;
+ }
+ const uint32_t session_uuid = (uint32_t)RNA_int_get(op->ptr, "session_uuid");
+ Material *ma = (Material *)BKE_libblock_find_session_uuid(bmain, ID_MA, session_uuid);
+ if (ma == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ PointerRNA ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
+ Object *ob = ptr.data;
+ BLI_assert(ob);
+
+ PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
+ BLI_assert(mat_slot.data);
+ const int target_slot = RNA_int_get(&mat_slot, "slot_index") + 1;
+
+ /* only drop grease pencil material on grease pencil objects */
+ if ((ma->gp_style != NULL) && (ob->type != OB_GPENCIL)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ BKE_object_material_assign(bmain, ob, ma, target_slot, BKE_MAT_ASSIGN_USERPREF);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, ma);
+ DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+
+ return OPERATOR_FINISHED;
+}
+
+static void UI_OT_drop_material(wmOperatorType *ot)
+{
+ ot->name = "Drop Material in Material slots";
+ ot->description = "Drag material to Material slots in Properties";
+ ot->idname = "UI_OT_drop_material";
+
+ ot->poll = ui_drop_material_poll;
+ ot->exec = ui_drop_material_exec;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+
+ PropertyRNA *prop = RNA_def_int(ot->srna,
+ "session_uuid",
+ 0,
+ INT32_MIN,
+ INT32_MAX,
+ "Session UUID",
+ "Session UUID of the data-block to assign",
+ INT32_MIN,
+ INT32_MAX);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
+}
/** \} */
@@ -2130,6 +2212,7 @@ void ED_operatortypes_ui(void)
WM_operatortype_append(UI_OT_jump_to_target_button);
WM_operatortype_append(UI_OT_drop_color);
WM_operatortype_append(UI_OT_drop_name);
+ WM_operatortype_append(UI_OT_drop_material);
#ifdef WITH_PYTHON
WM_operatortype_append(UI_OT_editsource);
WM_operatortype_append(UI_OT_edittranslation_init);