Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_relationships.c
| Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | if (link->tosock == socket) { | ||||
| vec[0][1], vec[1][1], vec[2][1], vec[3][1], data + 1, resolution, sizeof(float[2])); | vec[0][1], vec[1][1], vec[2][1], vec[3][1], data + 1, resolution, sizeof(float[2])); | ||||
| for (int i = 0; i < resolution * 2; i += 2) { | for (int i = 0; i < resolution * 2; i += 2) { | ||||
| float *l1 = &data[i]; | float *l1 = &data[i]; | ||||
| float *l2 = &data[i + 2]; | float *l2 = &data[i + 2]; | ||||
| float distance = dist_squared_to_line_segment_v2(cursor, l1, l2); | float distance = dist_squared_to_line_segment_v2(cursor, l1, l2); | ||||
| if (distance < cursor_link_touch_distance) { | if (distance < cursor_link_touch_distance) { | ||||
| link_to_pick = link; | link_to_pick = link; | ||||
| RNA_int_set(op->ptr, "last_picked_link_index", link->multi_input_socket_index); | nldrag->last_picked_multi_input_socket_link = link_to_pick; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* If no linked was picked in this call, try using the one picked in the previous call. | /* If no linked was picked in this call, try using the one picked in the previous call. | ||||
| * Not essential for the basic behavior, but can make interaction feel a bit better if | * Not essential for the basic behavior, but can make interaction feel a bit better if | ||||
| * the mouse moves to the right and loses the "selection." */ | * the mouse moves to the right and loses the "selection." */ | ||||
| if (!link_to_pick) { | if (!link_to_pick) { | ||||
| int last_picked_link_index = RNA_int_get(op->ptr, "last_picked_link_index"); | bNodeLink *last_picked_link = nldrag->last_picked_multi_input_socket_link; | ||||
| if (last_picked_link_index > -1) { | if (last_picked_link) { | ||||
| LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { | link_to_pick = last_picked_link; | ||||
| if (link->multi_input_socket_index == last_picked_link_index) { | |||||
| link_to_pick = link; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| if (link_to_pick) { | if (link_to_pick) { | ||||
| /* Highlight is set here and cleared in the next iteration or if the operation finishes. */ | /* Highlight is set here and cleared in the next iteration or if the operation finishes. */ | ||||
| link_to_pick->flag |= NODE_LINK_TEMP_HIGHLIGHT; | link_to_pick->flag |= NODE_LINK_TEMP_HIGHLIGHT; | ||||
| ED_area_tag_redraw(CTX_wm_area(C)); | ED_area_tag_redraw(CTX_wm_area(C)); | ||||
| ▲ Show 20 Lines • Show All 719 Lines • ▼ Show 20 Lines | static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| bool detach = RNA_boolean_get(op->ptr, "detach"); | bool detach = RNA_boolean_get(op->ptr, "detach"); | ||||
| float cursor[2]; | float cursor[2]; | ||||
| UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); | UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); | ||||
| RNA_float_set_array(op->ptr, "drag_start", cursor); | RNA_float_set_array(op->ptr, "drag_start", cursor); | ||||
| RNA_int_set(op->ptr, "last_picked_link_index", -1); | |||||
| RNA_boolean_set(op->ptr, "has_link_picked", false); | RNA_boolean_set(op->ptr, "has_link_picked", false); | ||||
| ED_preview_kill_jobs(CTX_wm_manager(C), bmain); | ED_preview_kill_jobs(CTX_wm_manager(C), bmain); | ||||
| bNodeLinkDrag *nldrag = node_link_init(bmain, snode, cursor, detach); | bNodeLinkDrag *nldrag = node_link_init(bmain, snode, cursor, detach); | ||||
| nldrag->last_picked_multi_input_socket_link = NULL; | |||||
| if (nldrag) { | if (nldrag) { | ||||
| op->customdata = nldrag; | op->customdata = nldrag; | ||||
| BLI_addtail(&snode->runtime->linkdrag, nldrag); | BLI_addtail(&snode->runtime->linkdrag, nldrag); | ||||
| /* add modal handler */ | /* add modal handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | RNA_def_float_array(ot->srna, | ||||
| 0, | 0, | ||||
| -UI_PRECISION_FLOAT_MAX, | -UI_PRECISION_FLOAT_MAX, | ||||
| UI_PRECISION_FLOAT_MAX, | UI_PRECISION_FLOAT_MAX, | ||||
| "Drag Start", | "Drag Start", | ||||
| "The position of the mouse cursor at the start of the operation", | "The position of the mouse cursor at the start of the operation", | ||||
| -UI_PRECISION_FLOAT_MAX, | -UI_PRECISION_FLOAT_MAX, | ||||
| UI_PRECISION_FLOAT_MAX); | UI_PRECISION_FLOAT_MAX); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN); | RNA_def_property_flag(prop, PROP_HIDDEN); | ||||
| RNA_def_int(ot->srna, | |||||
| "last_picked_link_index", | |||||
| -1, | |||||
| -1, | |||||
| 4095, | |||||
| "Last Picked Link Index", | |||||
| "The index of the last picked link on a multi-input socket", | |||||
| -1, | |||||
| 4095); | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN); | RNA_def_property_flag(prop, PROP_HIDDEN); | ||||
| } | } | ||||
| /* ********************** Make Link operator ***************** */ | /* ********************** Make Link operator ***************** */ | ||||
| /* makes a link between selected output and input sockets */ | /* makes a link between selected output and input sockets */ | ||||
| static int node_make_link_exec(bContext *C, wmOperator *op) | static int node_make_link_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 988 Lines • Show Last 20 Lines | |||||