[Bf-blender-cvs] [3f4ba64ae36] master: Cleanup: use depends-on-cursor for "Object Transfer Mode" operator
Campbell Barton
noreply at git.blender.org
Mon Oct 18 08:30:59 CEST 2021
Commit: 3f4ba64ae3645c82792fcb35af0e2d94a8f0a6b3
Author: Campbell Barton
Date: Mon Oct 18 17:07:24 2021 +1100
Branches: master
https://developer.blender.org/rB3f4ba64ae3645c82792fcb35af0e2d94a8f0a6b3
Cleanup: use depends-on-cursor for "Object Transfer Mode" operator
Replace modal operator with the OPTYPE_DEPENDS_ON_CURSOR flag.
This has the advantage of showing the shortcut in the menu.
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/object/object_modes.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 59991eac92a..64652dc8ff8 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3049,8 +3049,7 @@ class VIEW3D_MT_sculpt(Menu):
layout.separator()
- props = layout.operator("object.transfer_mode", text="Transfer Sculpt Mode")
- props.use_eyedropper = True
+ layout.operator("object.transfer_mode", text="Transfer Sculpt Mode")
class VIEW3D_MT_mask(Menu):
diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c
index 2c58ef02486..0c1b394a916 100644
--- a/source/blender/editors/object/object_modes.c
+++ b/source/blender/editors/object/object_modes.c
@@ -497,51 +497,8 @@ static bool object_transfer_mode_to_base(bContext *C, wmOperator *op, Base *base
return mode_transfered;
}
-static int object_transfer_mode_modal(bContext *C, wmOperator *op, const wmEvent *event)
-{
- switch (event->type) {
- case LEFTMOUSE:
- if (event->val == KM_PRESS) {
- WM_cursor_modal_restore(CTX_wm_window(C));
- ED_workspace_status_text(C, NULL);
-
- /* This ensures that the click was done in an viewport region. */
- bScreen *screen = CTX_wm_screen(C);
- ARegion *region = BKE_screen_find_main_region_at_xy(
- screen, SPACE_VIEW3D, event->x, event->y);
- if (!region) {
- return OPERATOR_CANCELLED;
- }
-
- const int mval[2] = {event->x - region->winrct.xmin, event->y - region->winrct.ymin};
- Base *base_dst = ED_view3d_give_base_under_cursor(C, mval);
- const bool mode_transfered = object_transfer_mode_to_base(C, op, base_dst);
- if (!mode_transfered) {
- return OPERATOR_CANCELLED;
- }
-
- return OPERATOR_FINISHED;
- }
- break;
- case RIGHTMOUSE: {
- WM_cursor_modal_restore(CTX_wm_window(C));
- ED_workspace_status_text(C, NULL);
- return OPERATOR_CANCELLED;
- }
- }
- return OPERATOR_RUNNING_MODAL;
-}
-
static int object_transfer_mode_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- const bool use_eyedropper = RNA_boolean_get(op->ptr, "use_eyedropper");
- if (use_eyedropper) {
- ED_workspace_status_text(C, TIP_("Click in the viewport to select an object"));
- WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER);
- WM_event_add_modal_handler(C, op);
- return OPERATOR_RUNNING_MODAL;
- }
-
Object *ob_src = CTX_data_active_object(C);
const eObjectMode src_mode = (eObjectMode)ob_src->mode;
@@ -569,17 +526,12 @@ void OBJECT_OT_transfer_mode(wmOperatorType *ot)
/* api callbacks */
ot->invoke = object_transfer_mode_invoke;
- ot->modal = object_transfer_mode_modal;
ot->poll = object_transfer_mode_poll;
/* Undo push is handled by the operator. */
- ot->flag = OPTYPE_REGISTER;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_DEPENDS_ON_CURSOR;
- RNA_def_boolean(ot->srna,
- "use_eyedropper",
- false,
- "Use Eyedropper",
- "Pick the object to switch to using an eyedropper");
+ ot->cursor_pending = WM_CURSOR_EYEDROPPER;
RNA_def_boolean(ot->srna,
"use_flash_on_transfer",
More information about the Bf-blender-cvs
mailing list