4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation, Nathan Letwory
26 * ***** END GPL LICENSE BLOCK *****
31 #include "DNA_node_types.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_screen_types.h"
34 #include "DNA_space_types.h"
36 #include "BKE_context.h"
38 #include "BKE_global.h"
42 #include "ED_space_api.h"
43 #include "ED_screen.h"
46 #include "RNA_access.h"
47 #include "RNA_define.h"
52 #include "UI_view2d.h"
54 #include "node_intern.h"
56 static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short extend)
64 UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &mx, &my);
66 for(next_node(snode->edittree); (node=next_node(NULL));) {
68 /* first check for the headers or scaling widget */
69 /* XXX if(node->flag & NODE_HIDDEN) {
70 if(do_header_hidden_node(snode, node, mx, my))
74 if(do_header_node(snode, node, mx, my))
79 if(BLI_in_rctf(&node->totr, mx, my))
83 if((extend & KM_SHIFT)==0)
84 node_deselectall(snode, 0);
86 if(extend & KM_SHIFT) {
87 if(node->flag & SELECT)
88 node->flag &= ~SELECT;
95 node_set_active(snode, node);
99 ;// node_link_viewer(snode, node);
101 //std_rmouse_transform(node_transform_ext); /* does undo push for select */
102 ED_region_tag_redraw(ar);
106 static int node_select_exec(bContext *C, wmOperator *op)
108 SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
109 ARegion *ar= CTX_wm_region(C);
114 select_type = RNA_enum_get(op->ptr, "select_type");
116 switch (select_type) {
117 case NODE_SELECT_MOUSE:
118 mval[0] = RNA_int_get(op->ptr, "mx");
119 mval[1] = RNA_int_get(op->ptr, "my");
120 extend = RNA_int_get(op->ptr, "extend");
121 node_mouse_select(snode, ar, mval, extend);
124 return OPERATOR_FINISHED;
127 static int node_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
129 ARegion *ar= CTX_wm_region(C);
132 mval[0]= event->x - ar->winrct.xmin;
133 mval[1]= event->y - ar->winrct.ymin;
135 RNA_int_set(op->ptr, "mx", mval[0]);
136 RNA_int_set(op->ptr, "my", mval[1]);
138 return node_select_exec(C,op);
141 static int node_extend_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
143 RNA_int_set(op->ptr, "extend", KM_SHIFT);
145 return node_select_invoke(C, op, event);
150 static EnumPropertyItem prop_select_items[] = {
151 {NODE_SELECT_MOUSE, "NORMAL", "Normal Select", "Select using the mouse"},
152 {0, NULL, NULL, NULL}};
154 void NODE_OT_extend_select(wmOperatorType *ot)
159 ot->name= "Activate/Select (Shift)";
160 ot->idname= "NODE_OT_extend_select";
163 ot->invoke= node_extend_select_invoke;
164 ot->poll= ED_operator_node_active;
166 prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
167 RNA_def_property_enum_items(prop, prop_select_items);
169 prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
170 prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
171 prop = RNA_def_property(ot->srna, "extend", PROP_INT, PROP_NONE);
174 void NODE_OT_select(wmOperatorType *ot)
179 ot->name= "Activate/Select";
180 ot->idname= "NODE_OT_select";
183 ot->invoke= node_select_invoke;
184 ot->poll= ED_operator_node_active;
186 prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
187 RNA_def_property_enum_items(prop, prop_select_items);
189 prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
190 prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
191 prop = RNA_def_property(ot->srna, "extend", PROP_INT, PROP_NONE);