From 23ebc45f700b7670616294b450337ff0a22f7a4b Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 11 Mar 2024 19:23:16 +0100 Subject: [PATCH] WM: Add dynamic callback version of operator "depends on cursor" flag For node tools, I would like to give the option of invoking the operator from the menu, but waiting for a mouse click for the future "Mouse Position" node. Not all node tools should do that though, and they all use the same operator type, so it needs to depend on an operator callback. That's implemented here. Pull Request: https://projects.blender.org/blender/blender/pulls/118983 --- source/blender/windowmanager/WM_api.hh | 3 +++ source/blender/windowmanager/WM_types.hh | 3 +++ .../blender/windowmanager/intern/wm_event_system.cc | 2 +- .../blender/windowmanager/intern/wm_operator_type.cc | 11 +++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index 8feb718bfba..0f90cee27d3 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -1190,6 +1190,9 @@ std::string WM_operatortype_description_or_name(bContext *C, wmOperatorType *ot, PointerRNA *properties); +/** Check the #OPTYPE_DEPENDS_ON_CURSOR flag and the callback. */ +bool WM_operator_depends_on_cursor(bContext &C, wmOperatorType &ot, PointerRNA *properties); + /* `wm_operator_utils.cc` */ /** diff --git a/source/blender/windowmanager/WM_types.hh b/source/blender/windowmanager/WM_types.hh index 7d32f572b38..3ee68207f9d 100644 --- a/source/blender/windowmanager/WM_types.hh +++ b/source/blender/windowmanager/WM_types.hh @@ -1060,6 +1060,9 @@ struct wmOperatorType { */ std::string (*get_description)(bContext *C, wmOperatorType *ot, PointerRNA *ptr); + /** A dynamic version of #OPTYPE_DEPENDS_ON_CURSOR which can depend on operator properties. */ + bool (*depends_on_cursor)(bContext &C, wmOperatorType &ot, PointerRNA *ptr); + /** RNA for properties. */ StructRNA *srna; diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 89da118247f..5e1b897956a 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -1978,7 +1978,7 @@ void WM_operator_name_call_ptr_with_depends_on_cursor(bContext *C, } } - if ((flag & OPTYPE_DEPENDS_ON_CURSOR) == 0) { + if (!WM_operator_depends_on_cursor(*C, *ot, properties)) { WM_operator_name_call_ptr(C, ot, opcontext, properties, event); return; } diff --git a/source/blender/windowmanager/intern/wm_operator_type.cc b/source/blender/windowmanager/intern/wm_operator_type.cc index 19e77a2570d..df8f41181bf 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.cc +++ b/source/blender/windowmanager/intern/wm_operator_type.cc @@ -615,4 +615,15 @@ std::string WM_operatortype_description_or_name(bContext *C, return text; } +bool WM_operator_depends_on_cursor(bContext &C, wmOperatorType &ot, PointerRNA *properties) +{ + if (ot.flag & OPTYPE_DEPENDS_ON_CURSOR) { + return true; + } + if (ot.depends_on_cursor) { + return ot.depends_on_cursor(C, ot, properties); + } + return false; +} + /** \} */