[Bf-blender-cvs] [e8027ec2a0c] master: UI Drag Drop: allow customizable drawing

Germano Cavalcante noreply at git.blender.org
Mon Oct 25 16:57:45 CEST 2021


Commit: e8027ec2a0cac4b0e92d51a64ccc40fd3f190a20
Author: Germano Cavalcante
Date:   Mon Oct 25 10:07:00 2021 -0300
Branches: master
https://developer.blender.org/rBe8027ec2a0cac4b0e92d51a64ccc40fd3f190a20

UI Drag Drop: allow customizable drawing

No functional changes.

This commit adds 3 callbacks for `wmDropBox` which allow custom drawing
without affecting the internal dropbox API.

Differential Revision: https://developer.blender.org/D12948

===================================================================

M	source/blender/editors/include/ED_object.h
M	source/blender/editors/interface/interface_dropboxes.cc
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/space_outliner/outliner_dragdrop.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_dragdrop.c
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/wm_event_system.h

===================================================================

diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index 083d167c573..458ce57ab86 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -202,7 +202,7 @@ void ED_object_parent(struct Object *ob,
                       const char *substr);
 char *ED_object_ot_drop_named_material_tooltip(struct bContext *C,
                                                struct PointerRNA *properties,
-                                               const struct wmEvent *event);
+                                               const int mval[2]);
 
 /* bitflags for enter/exit editmode */
 enum {
diff --git a/source/blender/editors/interface/interface_dropboxes.cc b/source/blender/editors/interface/interface_dropboxes.cc
index ae626080a9a..1cc06db3a8c 100644
--- a/source/blender/editors/interface/interface_dropboxes.cc
+++ b/source/blender/editors/interface/interface_dropboxes.cc
@@ -40,12 +40,11 @@ static bool ui_tree_view_drop_poll(bContext *C, wmDrag *drag, const wmEvent *eve
 
 static char *ui_tree_view_drop_tooltip(bContext *C,
                                        wmDrag *drag,
-                                       const wmEvent *event,
+                                       const int xy[2],
                                        wmDropBox *UNUSED(drop))
 {
   const ARegion *region = CTX_wm_region(C);
-  const uiTreeViewItemHandle *hovered_tree_item = UI_block_tree_view_find_item_at(region,
-                                                                                  event->xy);
+  const uiTreeViewItemHandle *hovered_tree_item = UI_block_tree_view_find_item_at(region, xy);
   if (!hovered_tree_item) {
     return nullptr;
   }
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index d81143d6081..a64510662d9 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -2589,10 +2589,10 @@ void OBJECT_OT_make_single_user(wmOperatorType *ot)
 
 char *ED_object_ot_drop_named_material_tooltip(bContext *C,
                                                PointerRNA *properties,
-                                               const wmEvent *event)
+                                               const int mval[2])
 {
   int mat_slot = 0;
-  Object *ob = ED_view3d_give_material_slot_under_cursor(C, event->mval, &mat_slot);
+  Object *ob = ED_view3d_give_material_slot_under_cursor(C, mval, &mat_slot);
   if (ob == NULL) {
     return BLI_strdup("");
   }
diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index a82f516b125..a391d032d7e 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -868,7 +868,7 @@ static bool datastack_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
 
 static char *datastack_drop_tooltip(bContext *UNUSED(C),
                                     wmDrag *drag,
-                                    const wmEvent *UNUSED(event),
+                                    const int UNUSED(xy[2]),
                                     struct wmDropBox *UNUSED(drop))
 {
   StackDropData *drop_data = drag->poin;
@@ -1201,11 +1201,13 @@ static bool collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event
 
 static char *collection_drop_tooltip(bContext *C,
                                      wmDrag *drag,
-                                     const wmEvent *event,
+                                     const int UNUSED(xy[2]),
                                      wmDropBox *UNUSED(drop))
 {
+  wmWindowManager *wm = CTX_wm_manager(C);
+  const wmEvent *event = wm->winactive ? wm->winactive->eventstate : NULL;
   CollectionDrop data;
-  if (!event->shift && collection_drop_init(C, drag, event, &data)) {
+  if (event && !event->shift && collection_drop_init(C, drag, event, &data)) {
     TreeElement *te = data.te;
     if (!data.from || event->ctrl) {
       return BLI_strdup(TIP_("Link inside Collection"));
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 7999018a6b6..eb30d0987ab 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -532,12 +532,17 @@ static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event
 
 static char *view3d_mat_drop_tooltip(bContext *C,
                                      wmDrag *drag,
-                                     const wmEvent *event,
+                                     const int xy[2],
                                      struct wmDropBox *drop)
 {
   const char *name = WM_drag_get_item_name(drag);
+  ARegion *region = CTX_wm_region(C);
   RNA_string_set(drop->ptr, "name", name);
-  return ED_object_ot_drop_named_material_tooltip(C, drop->ptr, event);
+  int mval[2] = {
+      xy[0] - region->winrct.xmin,
+      xy[1] - region->winrct.ymin,
+  };
+  return ED_object_ot_drop_named_material_tooltip(C, drop->ptr, mval);
 }
 
 static bool view3d_world_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
@@ -556,7 +561,7 @@ static bool view3d_object_data_drop_poll(bContext *C, wmDrag *drag, const wmEven
 
 static char *view3d_object_data_drop_tooltip(bContext *UNUSED(C),
                                              wmDrag *UNUSED(drag),
-                                             const wmEvent *UNUSED(event),
+                                             const int UNUSED(xy[2]),
                                              wmDropBox *UNUSED(drop))
 {
   return BLI_strdup(TIP_("Create object instance from object-data"));
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index eaf32c06aba..b4fe2f85b72 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -740,6 +740,10 @@ struct wmDropBox *WM_dropbox_add(
     void (*copy)(struct wmDrag *, struct wmDropBox *),
     void (*cancel)(struct Main *, struct wmDrag *, struct wmDropBox *),
     WMDropboxTooltipFunc tooltip);
+void WM_drag_draw_default_fn(struct bContext *C,
+                             struct wmWindow *win,
+                             struct wmDrag *drag,
+                             const int xy[2]);
 ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
 
 /* ID drag and drop */
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index f4595869baf..bbfc9d53e44 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -1020,7 +1020,7 @@ typedef struct wmDragAssetListItem {
 
 typedef char *(*WMDropboxTooltipFunc)(struct bContext *,
                                       struct wmDrag *,
-                                      const struct wmEvent *event,
+                                      const int xy[2],
                                       struct wmDropBox *drop);
 
 typedef struct wmDrag {
@@ -1038,8 +1038,11 @@ typedef struct wmDrag {
   float scale;
   int sx, sy;
 
-  /** If filled, draws operator tooltip/operator name. */
-  char tooltip[200];
+  /** Informs which dropbox is activated with the drag item.
+   * When this value changes, the #draw_activate and #draw_deactivate dropbox callbacks are
+   * triggered.
+   */
+  struct wmDropBox *active_dropbox;
   unsigned int flags;
 
   /** List of wmDragIDs, all are guaranteed to have the same ID type. */
@@ -1067,6 +1070,18 @@ typedef struct wmDropBox {
    */
   void (*cancel)(struct Main *, struct wmDrag *, struct wmDropBox *);
 
+  /** Override the default drawing function. */
+  void (*draw)(struct bContext *, struct wmWindow *, struct wmDrag *, const int *);
+
+  /** Called when pool returns true the first time. */
+  void (*draw_activate)(struct wmDropBox *, struct wmDrag *drag);
+
+  /** Called when pool returns false the first time or when the drag event ends. */
+  void (*draw_deactivate)(struct wmDropBox *, struct wmDrag *drag);
+
+  /** Custom data for drawing. */
+  void *draw_data;
+
   /** Custom tooltip shown during dragging. */
   WMDropboxTooltipFunc tooltip;
 
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 9af90355a79..8495fa2a082 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -43,6 +43,9 @@
 #include "BKE_idtype.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
+#include "BKE_screen.h"
+
+#include "GHOST_C-api.h"
 
 #include "BLO_readfile.h"
 
@@ -63,6 +66,7 @@
 #include "WM_api.h"
 #include "WM_types.h"
 #include "wm_event_system.h"
+#include "wm_window.h"
 
 /* ****************************************************** */
 
@@ -229,6 +233,9 @@ void WM_drag_data_free(int dragtype, void *poin)
 
 void WM_drag_free(wmDrag *drag)
 {
+  if (drag->active_dropbox && drag->active_dropbox->draw_deactivate) {
+    drag->active_dropbox->draw_deactivate(drag->active_dropbox, drag);
+  }
   if (drag->flags & WM_DRAG_FREE_DATA) {
     WM_drag_data_free(drag->type, drag->poin);
   }
@@ -250,11 +257,11 @@ void WM_drag_free_list(struct ListBase *lb)
   }
 }
 
-static char *dropbox_tooltip(bContext *C, wmDrag *drag, const wmEvent *event, wmDropBox *drop)
+static char *dropbox_tooltip(bContext *C, wmDrag *drag, const int xy[2], wmDropBox *drop)
 {
   char *tooltip = NULL;
   if (drop->tooltip) {
-    tooltip = drop->tooltip(C, drag, event, drop);
+    tooltip = drop->tooltip(C, drag, xy, drop);
   }
   if (!tooltip) {
     tooltip = BLI_strdup(WM_operatortype_name(drop->ot, drop->ptr));
@@ -286,7 +293,7 @@ static wmDropBox *dropbox_active(bContext *C,
 }
 
 /* return active operator tooltip/name when mouse is in box */
-static char *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event)
+static wmDropBox *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event)
 {
   wmWindow *win = CTX_wm_window(C);
   wmDropBox *drop = dropbox_active(C, &win->handlers, drag, ev

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list