From 5f51e781720649be7c1079353d068a51829b33b9 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 4 Oct 2019 15:19:30 +0200 Subject: Node Editor: Use new operator utilities for node selection and dragging Previous commit moved most of this code into more general/generic utility functions, so we can use that in the Node Editor now. --- source/blender/editors/space_node/node_select.c | 76 +++---------------------- 1 file changed, 8 insertions(+), 68 deletions(-) (limited to 'source/blender/editors/space_node/node_select.c') diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index b66cd0d3069..e22ef389516 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -557,100 +557,40 @@ static int node_mouse_select(bContext *C, static int node_select_exec(bContext *C, wmOperator *op) { + const bool wait_to_deselect_others = RNA_boolean_get(op->ptr, "wait_to_deselect_others"); + /* get settings from RNA properties for operator */ int mval[2]; mval[0] = RNA_int_get(op->ptr, "mouse_x"); mval[1] = RNA_int_get(op->ptr, "mouse_y"); /* perform the select */ - const int ret_value = node_mouse_select(C, op, mval, false); + const int ret_value = node_mouse_select(C, op, mval, wait_to_deselect_others); /* allow tweak event to work too */ return ret_value | OPERATOR_PASS_THROUGH; } -static int node_select_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - const short init_event_type = (short)POINTER_AS_INT(op->customdata); - - /* get settings from RNA properties for operator */ - int mval[2]; - mval[0] = RNA_int_get(op->ptr, "mouse_x"); - mval[1] = RNA_int_get(op->ptr, "mouse_y"); - - if (init_event_type == 0) { - if (event->val == KM_PRESS) { - const int ret_value = node_mouse_select(C, op, mval, true); - - op->customdata = POINTER_FROM_INT((int)event->type); - if (ret_value & OPERATOR_RUNNING_MODAL) { - WM_event_add_modal_handler(C, op); - } - return ret_value | OPERATOR_PASS_THROUGH; - } - else { - /* If we are in init phase, and cannot validate init of modal operations, - * just fall back to basic exec. - */ - const int ret_value = node_mouse_select(C, op, mval, false); - return ret_value | OPERATOR_PASS_THROUGH; - } - } - else if (event->type == init_event_type && event->val == KM_RELEASE) { - const int ret_value = node_mouse_select(C, op, mval, false); - return ret_value | OPERATOR_PASS_THROUGH; - } - else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { - const int drag_delta[2] = { - mval[0] - event->mval[0], - mval[1] - event->mval[1], - }; - /* If user moves mouse more than defined threshold, we consider select operator as - * finished. Otherwise, it is still running until we get an 'release' event. In any - * case, we pass through event, but select op is not finished yet. */ - if (WM_event_drag_test_with_delta(event, drag_delta)) { - return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; - } - else { - /* Important not to return anything other than PASS_THROUGH here, - * otherwise it prevents underlying tweak detection code to work properly. */ - return OPERATOR_PASS_THROUGH; - } - } - - return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; -} - -static int node_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - RNA_int_set(op->ptr, "mouse_x", event->mval[0]); - RNA_int_set(op->ptr, "mouse_y", event->mval[1]); - - op->customdata = POINTER_FROM_INT(0); - - return node_select_modal(C, op, event); -} - void NODE_OT_select(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Select"; ot->idname = "NODE_OT_select"; ot->description = "Select the node under the cursor"; /* api callbacks */ - ot->invoke = node_select_invoke; ot->exec = node_select_exec; - ot->modal = node_select_modal; + ot->invoke = WM_generic_select_invoke; + ot->modal = WM_generic_select_modal; ot->poll = ED_operator_node_active; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - PropertyRNA *prop; - RNA_def_int(ot->srna, "mouse_x", 0, INT_MIN, INT_MAX, "Mouse X", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "mouse_y", 0, INT_MIN, INT_MAX, "Mouse Y", "", INT_MIN, INT_MAX); + WM_operator_properties_generic_select(ot); RNA_def_boolean(ot->srna, "extend", false, "Extend", ""); RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", ""); prop = RNA_def_boolean(ot->srna, -- cgit v1.2.3