[Bf-blender-cvs] [f04206cbc71] master: Cleanup: Add/use helper to check if dragging a certain ID type or asset ID type

Julian Eisel noreply at git.blender.org
Sun Jan 24 21:29:40 CET 2021


Commit: f04206cbc7129603a7c437b79b1d1c99bd191783
Author: Julian Eisel
Date:   Sun Jan 24 20:39:09 2021 +0100
Branches: master
https://developer.blender.org/rBf04206cbc7129603a7c437b79b1d1c99bd191783

Cleanup: Add/use helper to check if dragging a certain ID type or asset ID type

This check is a common pattern, avoid duplication by using a helper function.

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

M	source/blender/editors/space_node/space_node.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_dragdrop.c

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

diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c
index 66a029c2087..94915022ce9 100644
--- a/source/blender/editors/space_node/space_node.c
+++ b/source/blender/editors/space_node/space_node.c
@@ -664,7 +664,7 @@ static bool node_ima_drop_poll(bContext *UNUSED(C),
     /* rule might not work? */
     return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE));
   }
-  return WM_drag_get_local_ID(drag, ID_IM) || WM_drag_get_asset_data(drag, ID_IM);
+  return WM_drag_is_ID_type(drag, ID_IM);
 }
 
 static bool node_mask_drop_poll(bContext *UNUSED(C),
@@ -672,7 +672,7 @@ static bool node_mask_drop_poll(bContext *UNUSED(C),
                                 const wmEvent *UNUSED(event),
                                 const char **UNUSED(r_tooltip))
 {
-  return WM_drag_get_local_ID(drag, ID_MSK) || WM_drag_get_asset_data(drag, ID_MSK);
+  return WM_drag_is_ID_type(drag, ID_MSK);
 }
 
 static void node_id_drop_copy(wmDrag *drag, wmDropBox *drop)
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index b5b7f0b22cd..9f7cf48da0c 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -489,7 +489,7 @@ static bool view3d_drop_id_in_main_region_poll(bContext *C,
     return false;
   }
 
-  return WM_drag_get_local_ID(drag, id_type) || WM_drag_get_asset_data(drag, id_type);
+  return WM_drag_is_ID_type(drag, id_type);
 }
 
 static bool view3d_ob_drop_poll(bContext *C,
@@ -544,7 +544,7 @@ static bool view3d_ima_drop_poll(bContext *C,
     return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE));
   }
 
-  return WM_drag_get_local_ID(drag, ID_IM) || WM_drag_get_asset_data(drag, ID_IM);
+  return WM_drag_is_ID_type(drag, ID_IM);
 }
 
 static bool view3d_ima_bg_is_camera_view(bContext *C)
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 1f205a71338..fd4535ff94f 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -685,6 +685,7 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
 void WM_drag_add_local_ID(struct wmDrag *drag, struct ID *id, struct ID *from_parent);
 struct ID *WM_drag_get_local_ID(const struct wmDrag *drag, short idcode);
 struct ID *WM_drag_get_local_ID_from_event(const struct wmEvent *event, short idcode);
+bool WM_drag_is_ID_type(const struct wmDrag *drag, int idcode);
 
 struct wmDragAsset *WM_drag_get_asset_data(const struct wmDrag *drag, int idcode);
 struct ID *WM_drag_get_local_ID_or_import_from_asset(const struct wmDrag *drag, int idcode);
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 08f60fef0d2..289a18a771a 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -353,6 +353,14 @@ ID *WM_drag_get_local_ID_from_event(const wmEvent *event, short idcode)
   return WM_drag_get_local_ID(lb->first, idcode);
 }
 
+/**
+ * Check if the drag data is either a local ID or an external ID asset of type \a idcode.
+ */
+bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
+{
+  return WM_drag_get_local_ID(drag, idcode) || WM_drag_get_asset_data(drag, idcode);
+}
+
 wmDragAsset *WM_drag_get_asset_data(const wmDrag *drag, int idcode)
 {
   if (drag->type != WM_DRAG_ASSET) {



More information about the Bf-blender-cvs mailing list