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_dropboxes.cc
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_dropboxes.cc')
-rw-r--r--source/blender/editors/interface/interface_dropboxes.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_dropboxes.cc b/source/blender/editors/interface/interface_dropboxes.cc
index a24554ef68d..40d1a0ca6f5 100644
--- a/source/blender/editors/interface/interface_dropboxes.cc
+++ b/source/blender/editors/interface/interface_dropboxes.cc
@@ -6,7 +6,11 @@
#include "BKE_context.h"
+#include "BLI_string.h"
+#include "BLT_translation.h"
+
#include "DNA_space_types.h"
+#include "DNA_material_types.h"
#include "MEM_guardedalloc.h"
@@ -61,6 +65,60 @@ static void ui_drop_name_copy(wmDrag *drag, wmDropBox *drop)
}
/* ---------------------------------------------------------------------- */
+/* Material Drag/Drop Operators */
+
+static bool ui_drop_material_poll(bContext *C, wmDrag *drag, const wmEvent *UNUSED(event))
+{
+ PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
+ return WM_drag_is_ID_type(drag, ID_MA) && !RNA_pointer_is_null(&mat_slot);
+}
+
+static void ui_drop_material_copy(wmDrag *drag, wmDropBox *drop)
+{
+ const ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_MA);
+ RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid);
+}
+
+static char *ui_drop_material_tooltip(bContext *C,
+ wmDrag *drag,
+ const int UNUSED(xy[2]),
+ struct wmDropBox *UNUSED(drop))
+{
+ PointerRNA rna_ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
+ Object *ob = (Object *)rna_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;
+
+ PointerRNA rna_prev_material = RNA_pointer_get(&mat_slot, "material");
+ Material *prev_mat_in_slot = (Material *)rna_prev_material.data;
+ const char *dragged_material_name = WM_drag_get_item_name(drag);
+
+ char *result;
+ if (prev_mat_in_slot) {
+ const char *tooltip = TIP_("Drop %s on slot %d (replacing %s) of %s");
+ result = BLI_sprintfN(tooltip,
+ dragged_material_name,
+ target_slot,
+ prev_mat_in_slot->id.name + 2,
+ ob->id.name + 2);
+ }
+ else if (target_slot == ob->actcol) {
+ const char *tooltip = TIP_("Drop %s on slot %d (active slot) of %s");
+ result = BLI_sprintfN(tooltip, dragged_material_name, target_slot, ob->id.name + 2);
+ }
+ else {
+ const char *tooltip = TIP_("Drop %s on slot %d of %s");
+ result = BLI_sprintfN(tooltip, dragged_material_name, target_slot, ob->id.name + 2);
+ }
+
+ return result;
+}
+
+/* -------------------------------------------------------------------- */
void ED_dropboxes_ui()
{
@@ -78,4 +136,10 @@ void ED_dropboxes_ui()
ui_drop_name_copy,
WM_drag_free_imported_drag_ID,
nullptr);
+ WM_dropbox_add(lb,
+ "UI_OT_drop_material",
+ ui_drop_material_poll,
+ ui_drop_material_copy,
+ WM_drag_free_imported_drag_ID,
+ ui_drop_material_tooltip);
}