Index: source/blender/editors/space_node/node_select.c |
=================================================================== |
--- source/blender/editors/space_node/node_select.c (revision 43995) |
+++ source/blender/editors/space_node/node_select.c (working copy) |
@@ -38,6 +38,7 @@ |
#include "BKE_context.h" |
#include "BKE_main.h" |
+#include "BKE_node.h" |
#include "BLI_rect.h" |
#include "BLI_utildefines.h" |
@@ -650,3 +651,96 @@ |
/* flags */ |
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; |
} |
+ |
+/* ****** Select node tree proxy item ****** */ |
+ |
+static bNodeProxyItem *proxy_item_under_mouse(bNodeTree *ntree, int mx, int my) |
+{ |
+ bNodeProxyItem *item; |
+ |
+ for (item=ntree->proxy_inputs.first; item; item=item->next) { |
+ if (BLI_in_rctf(&item->totr, mx, my)) |
+ return item; |
+ } |
+ for (item=ntree->proxy_outputs.first; item; item=item->next) { |
+ if (BLI_in_rctf(&item->totr, mx, my)) |
+ return item; |
+ } |
+ return NULL; |
+} |
+ |
+ |
+static bNodeProxyItem *proxy_item_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const int mval[2]) |
+{ |
+ bNodeProxyItem *item; |
+ float mx, my; |
+ |
+ /* get mouse coordinates in view2d space */ |
+ mx= (float)mval[0]; |
+ my= (float)mval[1]; |
+ |
+ UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &mx, &my); |
+ |
+ /* find the closest visible node */ |
+ item = proxy_item_under_mouse(snode->edittree, mx, my); |
+ |
+ if (item) { |
+ node_deselect_all(snode); |
+ item->node->flag |= SELECT; |
+ |
+ ED_node_set_active(bmain, snode->edittree, item->node); |
+ |
+ node_sort(snode->edittree); |
+ } |
+ |
+ return item; |
+} |
+ |
+static int proxy_item_select_exec(bContext *C, wmOperator *op) |
+{ |
+ Main *bmain= CTX_data_main(C); |
+ SpaceNode *snode= CTX_wm_space_node(C); |
+ ARegion *ar= CTX_wm_region(C); |
+ int mval[2]; |
+ |
+ /* get settings from RNA properties for operator */ |
+ mval[0] = RNA_int_get(op->ptr, "mouse_x"); |
+ mval[1] = RNA_int_get(op->ptr, "mouse_y"); |
+ |
+ /* perform the select */ |
+ proxy_item_mouse_select(bmain, snode, ar, mval); |
+ |
+ /* send notifiers */ |
+ WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); |
+ |
+ /* allow tweak event to work too */ |
+ return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH; |
+} |
+ |
+static int proxy_item_select_invoke(bContext *C, wmOperator *op, wmEvent *event) |
+{ |
+ RNA_int_set(op->ptr, "mouse_x", event->mval[0]); |
+ RNA_int_set(op->ptr, "mouse_y", event->mval[1]); |
+ |
+ return proxy_item_select_exec(C,op); |
+} |
+ |
+ |
+void NODE_OT_select_proxy_item(wmOperatorType *ot) |
+{ |
+ /* identifiers */ |
+ ot->name= "Select Proxy Item"; |
+ ot->idname= "NODE_OT_select_proxy_item"; |
+ ot->description= "Select the node tree interface item under the cursor"; |
+ |
+ /* api callbacks */ |
+ ot->invoke= proxy_item_select_invoke; |
+ ot->poll= ED_operator_node_active; |
+ |
+ /* flags */ |
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; |
+ |
+ /* properties */ |
+ 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); |
+} |