lasso select works in the node editor again, Ctrl+Alt+LMB, Ctrl+Alt+Shif+LMB to deselect
authorCampbell Barton <ideasman42@gmail.com>
Wed, 22 Aug 2012 13:34:06 +0000 (13:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 22 Aug 2012 13:34:06 +0000 (13:34 +0000)
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/node_select.c

index cbf050261521c7d28fc2c5bfe941fb6710c99e9e..97f7d7bf132e61e5b3e8e3e720d37bd332e04d2c 100644 (file)
@@ -42,7 +42,6 @@
 #include "BLI_math.h"
 #include "BLI_listbase.h"
 #include "BLI_rect.h"
-#include "BLI_lasso.h"
 #include "BLI_blenlib.h"
 
 #include "BKE_main.h"
index 048e09efab55e6c6305e37b569f70684c9a29a68..2bb550d1a636b2619936932dc4d06e1ce9daec04 100644 (file)
@@ -107,6 +107,7 @@ void NODE_OT_select_all(wmOperatorType *ot);
 void NODE_OT_select_linked_to(wmOperatorType *ot);
 void NODE_OT_select_linked_from(wmOperatorType *ot);
 void NODE_OT_select_border(struct wmOperatorType *ot);
+void NODE_OT_select_lasso(struct wmOperatorType *ot);
 void NODE_OT_select_same_type(struct wmOperatorType *ot);
 void NODE_OT_select_same_type_next(wmOperatorType *ot);
 void NODE_OT_select_same_type_prev(wmOperatorType *ot);
index 195dd60b72a14be893732fe565e041300166fdcb..a5032fb646593566aaa77c3ab1f3c623dd0bc0ac 100644 (file)
@@ -55,6 +55,7 @@ void node_operatortypes(void)
        WM_operatortype_append(NODE_OT_select_linked_to);
        WM_operatortype_append(NODE_OT_select_linked_from);
        WM_operatortype_append(NODE_OT_select_border);
+       WM_operatortype_append(NODE_OT_select_lasso);
        WM_operatortype_append(NODE_OT_select_same_type);
        WM_operatortype_append(NODE_OT_select_same_type_next);
        WM_operatortype_append(NODE_OT_select_same_type_prev);
@@ -217,6 +218,11 @@ void node_keymap(struct wmKeyConfig *keyconf)
        kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0);
        RNA_boolean_set(kmi->ptr, "tweak", TRUE);
        
+       kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
+       RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+       kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT | KM_ALT, 0);
+       RNA_boolean_set(kmi->ptr, "deselect", TRUE);
+
        /* each of these falls through if not handled... */
        WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
        kmi = WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
index 2f4e7648a5f730315c13becd6161f9aeb23bbf4a..f41f203aefe32eb0c07ecbe3fdd2bd86a9ba4fda 100644 (file)
@@ -35,6 +35,7 @@
 #include "BKE_node.h"
 
 #include "BLI_rect.h"
+#include "BLI_lasso.h"
 #include "BLI_utildefines.h"
 
 #include "ED_node.h"  /* own include */
@@ -48,7 +49,9 @@
 #include "WM_types.h"
 
 #include "UI_view2d.h"
+
+#include "MEM_guardedalloc.h"
+
 #include "node_intern.h"  /* own include */
 
 /* ****** helpers ****** */
@@ -534,6 +537,92 @@ void NODE_OT_select_border(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "tweak", 0, "Tweak", "Only activate when mouse is not over a node - useful for tweak gesture");
 }
 
+/* ****** Lasso Select ****** */
+
+static int do_lasso_select_node(bContext *C, int mcords[][2], short moves, short select)
+{
+       SpaceNode *snode = CTX_wm_space_node(C);
+       bNode *node;
+
+       ARegion *ar = CTX_wm_region(C);
+
+       rcti rect;
+       int change = FALSE;
+
+       /* get rectangle from operator */
+       BLI_lasso_boundbox(&rect, mcords, moves);
+
+       /* do actual selection */
+       for (node = snode->edittree->nodes.first; node; node = node->next) {
+               int screen_co[2];
+               const float cent[2] = {BLI_RCT_CENTER_X(&node->totr),
+                                      BLI_RCT_CENTER_Y(&node->totr)};
+
+               /* marker in screen coords */
+               UI_view2d_view_to_region(&ar->v2d,
+                                        cent[0], cent[1],
+                                        &screen_co[0], &screen_co[1]);
+
+               if (BLI_in_rcti(&rect, screen_co[0], screen_co[1]) &&
+                       BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX))
+               {
+                       if (select)
+                               node_select(node);
+                       else
+                               node_deselect(node);
+
+                       change = TRUE;
+               }
+       }
+
+       if (change) {
+               WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
+       }
+
+       return change;
+}
+
+static int node_lasso_select_exec(bContext *C, wmOperator *op)
+{
+       int mcords_tot;
+       int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot);
+
+       if (mcords) {
+               short select;
+
+               select = !RNA_boolean_get(op->ptr, "deselect");
+               do_lasso_select_node(C, mcords, mcords_tot, select);
+
+               MEM_freeN(mcords);
+
+               return OPERATOR_FINISHED;
+       }
+       return OPERATOR_PASS_THROUGH;
+}
+
+void NODE_OT_select_lasso(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Lasso Select";
+       ot->description = "Select nodes using lasso selection";
+       ot->idname = "NODE_OT_select_lasso";
+
+       /* api callbacks */
+       ot->invoke = WM_gesture_lasso_invoke;
+       ot->modal = WM_gesture_lasso_modal;
+       ot->exec = node_lasso_select_exec;
+       ot->poll = ED_operator_node_active;
+       ot->cancel = WM_gesture_lasso_cancel;
+
+       /* flags */
+       ot->flag = OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
+       RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect rather than select items");
+       RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first");
+}
+
 /* ****** Select/Deselect All ****** */
 
 static int node_select_all_exec(bContext *C, wmOperator *op)