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 /* ************************** Node generic ************** */
58 /* allows to walk the list in order of visibility */
59 static bNode *next_node(bNodeTree *ntree)
61 static bNode *current=NULL, *last= NULL;
64 /* set current to the first selected node */
65 for(current= ntree->nodes.last; current; current= current->prev)
66 if(current->flag & NODE_SELECT)
69 /* set last to the first unselected node */
70 for(last= ntree->nodes.last; last; last= last->prev)
71 if((last->flag & NODE_SELECT)==0)
79 /* no nodes, or we are ready */
83 /* now we walk the list backwards, but we always return current */
84 if(current->flag & NODE_SELECT) {
87 /* find previous selected */
88 current= current->prev;
89 while(current && (current->flag & NODE_SELECT)==0)
90 current= current->prev;
92 /* find first unselected */
101 /* find previous unselected */
102 current= current->prev;
103 while(current && (current->flag & NODE_SELECT))
104 current= current->prev;
112 static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
114 rctf totr= node->totr;
116 totr.ymin= totr.ymax-20.0f;
118 totr.xmax= totr.xmin+15.0f;
119 if(BLI_in_rctf(&totr, mx, my)) {
120 node->flag |= NODE_HIDDEN;
121 // allqueue(REDRAWNODE, 0);
125 totr.xmax= node->totr.xmax;
126 totr.xmin= totr.xmax-18.0f;
127 if(node->typeinfo->flag & NODE_PREVIEW) {
128 if(BLI_in_rctf(&totr, mx, my)) {
129 node->flag ^= NODE_PREVIEW;
130 // allqueue(REDRAWNODE, 0);
135 if(node->type == NODE_GROUP) {
136 if(BLI_in_rctf(&totr, mx, my)) {
137 snode_make_group_editable(snode, node);
142 if(node->typeinfo->flag & NODE_OPTIONS) {
143 if(BLI_in_rctf(&totr, mx, my)) {
144 node->flag ^= NODE_OPTIONS;
145 // allqueue(REDRAWNODE, 0);
150 /* hide unused sockets */
151 if(BLI_in_rctf(&totr, mx, my)) {
152 // XXX node_hide_unhide_sockets(snode, node);
157 totr.xmin= totr.xmax-10.0f;
158 totr.ymax= totr.ymin+10.0f;
159 if(BLI_in_rctf(&totr, mx, my)) {
160 // XXX scale_node(snode, node);
166 static int do_header_hidden_node(SpaceNode *snode, bNode *node, float mx, float my)
168 rctf totr= node->totr;
170 totr.xmax= totr.xmin+15.0f;
171 if(BLI_in_rctf(&totr, mx, my)) {
172 node->flag &= ~NODE_HIDDEN;
173 // allqueue(REDRAWNODE, 0);
177 totr.xmax= node->totr.xmax;
178 totr.xmin= node->totr.xmax-15.0f;
179 if(BLI_in_rctf(&totr, mx, my)) {
180 scale_node(snode, node);
186 static void node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short modifier)
194 UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &mx, &my);
196 for(next_node(snode->edittree); (node=next_node(NULL));) {
198 /* first check for the headers or scaling widget */
199 /* XXX if(node->flag & NODE_HIDDEN) {
200 if(do_header_hidden_node(snode, node, mx, my))
204 if(do_header_node(snode, node, mx, my))
209 if(BLI_in_rctf(&node->totr, mx, my))
213 if((modifier & KM_SHIFT)==0)
214 node_deselectall(snode, 0);
216 if(modifier & KM_SHIFT) {
217 if(node->flag & SELECT)
218 node->flag &= ~SELECT;
220 node->flag |= SELECT;
223 node->flag |= SELECT;
225 node_set_active(snode, node);
228 if(modifier & KM_CTRL)
229 ;// node_link_viewer(snode, node);
231 //std_rmouse_transform(node_transform_ext); /* does undo push for select */
232 ED_region_tag_redraw(ar);
236 static int node_select_exec(bContext *C, wmOperator *op)
238 SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
239 ARegion *ar= CTX_wm_region(C);
244 select_type = RNA_enum_get(op->ptr, "select_type");
246 switch (select_type) {
247 case NODE_SELECT_MOUSE:
248 mval[0] = RNA_int_get(op->ptr, "mx");
249 mval[1] = RNA_int_get(op->ptr, "my");
250 modifier = RNA_int_get(op->ptr, "modifier");
251 node_mouse_select(snode, ar, mval, modifier);
254 return OPERATOR_FINISHED;
257 static int node_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
259 ARegion *ar= CTX_wm_region(C);
262 mval[0]= event->x - ar->winrct.xmin;
263 mval[1]= event->y - ar->winrct.ymin;
265 RNA_int_set(op->ptr, "mx", mval[0]);
266 RNA_int_set(op->ptr, "my", mval[1]);
268 return node_select_exec(C,op);
271 static int node_extend_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
273 RNA_int_set(op->ptr, "modifier", KM_SHIFT);
275 return node_select_invoke(C, op, event);
280 static EnumPropertyItem prop_select_items[] = {
281 {NODE_SELECT_MOUSE, "NORMAL", "Normal Select", "Select using the mouse"},
282 {0, NULL, NULL, NULL}};
284 void NODE_OT_extend_select(wmOperatorType *ot)
289 ot->name= "Activate/Select (Shift)";
290 ot->idname= "NODE_OT_extend_select";
293 ot->invoke= node_extend_select_invoke;
294 ot->poll= ED_operator_node_active;
296 prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
297 RNA_def_property_enum_items(prop, prop_select_items);
299 prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
300 prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
301 prop = RNA_def_property(ot->srna, "modifier", PROP_INT, PROP_NONE);
304 void NODE_OT_select(wmOperatorType *ot)
309 ot->name= "Activate/Select";
310 ot->idname= "NODE_OT_select";
313 ot->invoke= node_select_invoke;
314 ot->poll= ED_operator_node_active;
316 prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
317 RNA_def_property_enum_items(prop, prop_select_items);
319 prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
320 prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
321 prop = RNA_def_property(ot->srna, "modifier", PROP_INT, PROP_NONE);