2.5 / Nodes / Border select
authorNathan Letwory <nathan@letworyinteractive.com>
Mon, 5 Jan 2009 23:53:04 +0000 (23:53 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Mon, 5 Jan 2009 23:53:04 +0000 (23:53 +0000)
* bring border select (BKey), works in editor, but draws
  badly only in header when initiated from menu, so that's
  commented out for now.

source/blender/editors/space_node/node_header.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 7191bb2214c7db82eda5c15879a5cbe48c8e5728..8858805c0acdd3dc4054ee05bb2c4a5033b4d9a8 100644 (file)
@@ -75,7 +75,8 @@ static void do_node_selectmenu(bContext *C, void *arg, int event)
        
        switch(event) {
                case 1: /* border select */
-                       // XXX node_border_select(snode);
+                       // NODE_FIX_ME border select draws in menu area only :S
+                       // WM_operator_name_call(C, "NODE_OT_border_select", WM_OP_INVOKE_REGION_WIN, NULL, NULL);
                        break;
                case 2: /* select/deselect all */
                        // XXX node_deselectall(snode, 1);
index a8857671f4bd2ef3ca10c9622d8eef6c694ea1e6..40fc72f97de57dab402fe8acfc817b10eacfe6d4 100644 (file)
@@ -39,6 +39,10 @@ struct wmWindowManager;
 
 #define NODE_SELECT_MOUSE              1
 
+/* border select defines XXX these seem to be hardcode values still in border select invoke, check */
+#define NODE_EXTEND                            1
+#define NODE_EXCLUSIVE                 3
+
 /* node_header.c */
 void node_header_buttons(const bContext *C, ARegion *ar);
 
@@ -54,6 +58,7 @@ void NODE_OT_select(struct wmOperatorType *ot);
 void NODE_OT_extend_select(struct wmOperatorType *ot);
 void NODE_OT_toggle_visibility(struct wmOperatorType *ot);
 void NODE_OT_fit_all(struct wmOperatorType *ot);
+void NODE_OT_border_select(struct wmOperatorType *ot);
 
 /* drawnode.c */
 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link);
index dc6f3c77cdfdfdf316f31f3f285cf5b48f7ace83..5be6f6a9777f9eb3ee9f7e84f86e2efdb1a0a4d8 100644 (file)
@@ -52,6 +52,7 @@ void node_operatortypes(void)
        WM_operatortype_append(NODE_OT_extend_select);
        WM_operatortype_append(NODE_OT_toggle_visibility);
        WM_operatortype_append(NODE_OT_fit_all);
+       WM_operatortype_append(NODE_OT_border_select);
 }
 
 void node_keymap(struct wmWindowManager *wm)
@@ -62,6 +63,7 @@ void node_keymap(struct wmWindowManager *wm)
        RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_extend_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select_type", NODE_SELECT_MOUSE);
        WM_keymap_add_item(keymap, "NODE_OT_toggle_visibility", ACTIONMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NODE_OT_fit_all", HOMEKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "NODE_OT_border_select", BKEY, KM_PRESS, 0, 0);
        
        transform_keymap_for_space(wm, keymap, SPACE_NODE);
 }
index 6623d1fb4f49a8a86184a91b46475aa39bd17ea1..bd3a3e405d07da4a988c9efefb5aa9486638b1ce 100644 (file)
@@ -190,3 +190,72 @@ void NODE_OT_select(wmOperatorType *ot)
        prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
        prop = RNA_def_property(ot->srna, "extend", PROP_INT, PROP_NONE);
 }
+
+/* ****** Border Select ****** */
+
+static EnumPropertyItem prop_select_types[] = {
+       {NODE_EXCLUSIVE, "EXCLUSIVE", "Exclusive", ""}, /* right mouse */
+       {NODE_EXTEND, "EXTEND", "Extend", ""}, /* left mouse */
+       {0, NULL, NULL, NULL}
+};
+
+static int node_borderselect_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
+       ARegion *ar= CTX_wm_region(C);
+       bNode *node;
+       rcti rect;
+       rctf rectf;
+       short val;
+       
+       val= RNA_int_get(op->ptr, "event_type");
+       
+       rect.xmin= RNA_int_get(op->ptr, "xmin");
+       rect.ymin= RNA_int_get(op->ptr, "ymin");
+       UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
+       
+       rect.xmax= RNA_int_get(op->ptr, "xmax");
+       rect.ymax= RNA_int_get(op->ptr, "ymax");
+       UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
+       
+       
+       printf("%d - %f %f %f %f\n", val, rectf.xmin, rectf.ymin, rectf.xmax, rectf.ymax);
+       
+       for(node= snode->edittree->nodes.first; node; node= node->next) {
+               printf("\t%f %f %f %f\n", node->totr.xmin, node->totr.ymin, node->totr.xmax, node->totr.ymax);
+               if(BLI_isect_rctf(&rectf, &node->totr, NULL)) {
+                       if(val==NODE_EXTEND)
+                               node->flag |= SELECT;
+                       else
+                               node->flag &= ~SELECT;
+               }
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_border_select(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       
+       /* identifiers */
+       ot->name= "Border Select";
+       ot->idname= "NODE_OT_border_select";
+       
+       /* api callbacks */
+       ot->invoke= WM_border_select_invoke;
+       ot->exec= node_borderselect_exec;
+       ot->modal= WM_border_select_modal;
+       
+       ot->poll= ED_operator_node_active;
+       
+       /* rna */
+       RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
+
+       prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_select_types);
+}
\ No newline at end of file