Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2019-10-04 16:19:30 +0300
committerJulian Eisel <eiseljulian@gmail.com>2019-10-04 17:46:32 +0300
commit5f51e781720649be7c1079353d068a51829b33b9 (patch)
treee1b88b64da244a008b1a3471f2255173c51a6957 /source/blender/editors/space_node/node_select.c
parentbe2cd4bb5325fa7950a412fdd14448d49b342b57 (diff)
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.
Diffstat (limited to 'source/blender/editors/space_node/node_select.c')
-rw-r--r--source/blender/editors/space_node/node_select.c76
1 files changed, 8 insertions, 68 deletions
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,