2.5 MSVC9 projectfiles
[blender-staging.git] / source / blender / editors / space_node / node_select.c
index e6eb8596d089a9dbe60dc0333aae691abe508b1e..cc8e03e0b44b91744e6ddfea2a5cbbe75613443f 100644 (file)
  
 #include "node_intern.h"
  
-/* ************************** Node generic ************** */
-
-/* allows to walk the list in order of visibility */
-static bNode *next_node(bNodeTree *ntree)
-{
-       static bNode *current=NULL, *last= NULL;
-       
-       if(ntree) {
-               /* set current to the first selected node */
-               for(current= ntree->nodes.last; current; current= current->prev)
-                       if(current->flag & NODE_SELECT)
-                               break;
-               
-               /* set last to the first unselected node */
-               for(last= ntree->nodes.last; last; last= last->prev)
-                       if((last->flag & NODE_SELECT)==0)
-                               break;
-               
-               if(current==NULL)
-                       current= last;
-               
-               return NULL;
-       }
-       /* no nodes, or we are ready */
-       if(current==NULL)
-               return NULL;
-       
-       /* now we walk the list backwards, but we always return current */
-       if(current->flag & NODE_SELECT) {
-               bNode *node= current;
-               
-               /* find previous selected */
-               current= current->prev;
-               while(current && (current->flag & NODE_SELECT)==0)
-                       current= current->prev;
-               
-               /* find first unselected */
-               if(current==NULL)
-                       current= last;
-               
-               return node;
-       }
-       else {
-               bNode *node= current;
-               
-               /* find previous unselected */
-               current= current->prev;
-               while(current && (current->flag & NODE_SELECT))
-                       current= current->prev;
-               
-               return node;
-       }
-       
-       return NULL;
-}
-
-static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
-{
-       rctf totr= node->totr;
-       
-       totr.ymin= totr.ymax-20.0f;
-       
-       totr.xmax= totr.xmin+15.0f;
-       if(BLI_in_rctf(&totr, mx, my)) {
-               node->flag |= NODE_HIDDEN;
-               // allqueue(REDRAWNODE, 0);
-               return 1;
-       }       
-       
-       totr.xmax= node->totr.xmax;
-       totr.xmin= totr.xmax-18.0f;
-       if(node->typeinfo->flag & NODE_PREVIEW) {
-               if(BLI_in_rctf(&totr, mx, my)) {
-                       node->flag ^= NODE_PREVIEW;
-                       // allqueue(REDRAWNODE, 0);
-                       return 1;
-               }
-               totr.xmin-=18.0f;
-       }
-       if(node->type == NODE_GROUP) {
-               if(BLI_in_rctf(&totr, mx, my)) {
-                       snode_make_group_editable(snode, node);
-                       return 1;
-               }
-               totr.xmin-=18.0f;
-       }
-       if(node->typeinfo->flag & NODE_OPTIONS) {
-               if(BLI_in_rctf(&totr, mx, my)) {
-                       node->flag ^= NODE_OPTIONS;
-                       // allqueue(REDRAWNODE, 0);
-                       return 1;
-               }
-               totr.xmin-=18.0f;
-       }
-       /* hide unused sockets */
-       if(BLI_in_rctf(&totr, mx, my)) {
-               // XXX node_hide_unhide_sockets(snode, node);
-       }
-       
-       
-       totr= node->totr;
-       totr.xmin= totr.xmax-10.0f;
-       totr.ymax= totr.ymin+10.0f;
-       if(BLI_in_rctf(&totr, mx, my)) {
-               // XXX scale_node(snode, node);
-               return 1;
-       }
-       return 0;
-}
-
-static int do_header_hidden_node(SpaceNode *snode, bNode *node, float mx, float my)
-{
-       rctf totr= node->totr;
-       
-       totr.xmax= totr.xmin+15.0f;
-       if(BLI_in_rctf(&totr, mx, my)) {
-               node->flag &= ~NODE_HIDDEN;
-               // allqueue(REDRAWNODE, 0);
-               return 1;
-       }       
-       
-       totr.xmax= node->totr.xmax;
-       totr.xmin= node->totr.xmax-15.0f;
-       if(BLI_in_rctf(&totr, mx, my)) {
-               scale_node(snode, node);
-               return 1;
-       }
-       return 0;
-}
-
-static node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval)
+static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short extend)
 {
        bNode *node;
        float mx, my;
@@ -210,43 +80,36 @@ static node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval)
                        break;
        }
        if(node) {
-               // XXX if((G.qual & LR_SHIFTKEY)==0)
-               //      node_deselectall(snode, 0);
+               if((extend & KM_SHIFT)==0)
+                       node_deselectall(snode, 0);
                
-               // XXX
-               /*
-               if(G.qual & LR_SHIFTKEY) {
+               if(extend & KM_SHIFT) {
                        if(node->flag & SELECT)
                                node->flag &= ~SELECT;
                        else
                                node->flag |= SELECT;
                }
-               else */
+               else
                        node->flag |= SELECT;
                
                node_set_active(snode, node);
                
                /* viewer linking */
-               //if(G.qual & LR_CTRLKEY)
-               //      node_link_viewer(snode, node);
-               
-               /* not so nice (no event), but function below delays redraw otherwise */
-               //force_draw(0);
+               if(extend & KM_CTRL)
+                       ;//     node_link_viewer(snode, node);
                
                //std_rmouse_transform(node_transform_ext);     /* does undo push for select */
-               
-               return 1;
+               ED_region_tag_redraw(ar);
        }
-       return 0;
 }
 
 static int node_select_exec(bContext *C, wmOperator *op)
 {
        SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
        int select_type;
        short mval[2];
+       short extend;
 
        select_type = RNA_enum_get(op->ptr, "select_type");
        
@@ -254,7 +117,8 @@ static int node_select_exec(bContext *C, wmOperator *op)
                case NODE_SELECT_MOUSE:
                        mval[0] = RNA_int_get(op->ptr, "mx");
                        mval[1] = RNA_int_get(op->ptr, "my");
-                       node_mouse_select(snode, ar, mval);
+                       extend = RNA_int_get(op->ptr, "extend");
+                       node_mouse_select(snode, ar, mval, extend);
                        break;
        }
        return OPERATOR_FINISHED;
@@ -262,7 +126,6 @@ static int node_select_exec(bContext *C, wmOperator *op)
 
 static int node_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
        short mval[2];  
        
@@ -275,12 +138,39 @@ static int node_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return node_select_exec(C,op);
 }
 
+static int node_extend_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       RNA_int_set(op->ptr, "extend", KM_SHIFT);
+
+       return node_select_invoke(C, op, event);
+}
+
 /* operators */
 
 static EnumPropertyItem prop_select_items[] = {
        {NODE_SELECT_MOUSE, "NORMAL", "Normal Select", "Select using the mouse"},
        {0, NULL, NULL, NULL}};
 
+void NODE_OT_extend_select(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       
+       /* identifiers */
+       ot->name= "Activate/Select (Shift)";
+       ot->idname= "NODE_OT_extend_select";
+       
+       /* api callbacks */
+       ot->invoke= node_extend_select_invoke;
+       ot->poll= ED_operator_node_active;
+       
+       prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_select_items);
+       
+       prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
+       prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
+       prop = RNA_def_property(ot->srna, "extend", PROP_INT, PROP_NONE);
+}
+
 void NODE_OT_select(wmOperatorType *ot)
 {
        PropertyRNA *prop;
@@ -298,4 +188,70 @@ void NODE_OT_select(wmOperatorType *ot)
        
        prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
        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);
+       
+       for(node= snode->edittree->nodes.first; node; node= node->next) {
+               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