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)
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 // XXX if((G.qual & LR_SHIFTKEY)==0)
214 // node_deselectall(snode, 0);
218 if(G.qual & LR_SHIFTKEY) {
219 if(node->flag & SELECT)
220 node->flag &= ~SELECT;
222 node->flag |= SELECT;
225 node->flag |= SELECT;
227 node_set_active(snode, node);
230 //if(G.qual & LR_CTRLKEY)
231 // node_link_viewer(snode, node);
233 /* not so nice (no event), but function below delays redraw otherwise */
236 //std_rmouse_transform(node_transform_ext); /* does undo push for select */
237 ED_region_tag_redraw(ar);
241 static int node_select_exec(bContext *C, wmOperator *op)
243 SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
244 ARegion *ar= CTX_wm_region(C);
248 select_type = RNA_enum_get(op->ptr, "select_type");
250 switch (select_type) {
251 case NODE_SELECT_MOUSE:
252 mval[0] = RNA_int_get(op->ptr, "mx");
253 mval[1] = RNA_int_get(op->ptr, "my");
254 node_mouse_select(snode, ar, mval);
257 return OPERATOR_FINISHED;
260 static int node_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
262 ARegion *ar= CTX_wm_region(C);
265 mval[0]= event->x - ar->winrct.xmin;
266 mval[1]= event->y - ar->winrct.ymin;
268 RNA_int_set(op->ptr, "mx", mval[0]);
269 RNA_int_set(op->ptr, "my", mval[1]);
271 return node_select_exec(C,op);
276 static EnumPropertyItem prop_select_items[] = {
277 {NODE_SELECT_MOUSE, "NORMAL", "Normal Select", "Select using the mouse"},
278 {0, NULL, NULL, NULL}};
280 void NODE_OT_select(wmOperatorType *ot)
285 ot->name= "Activate/Select";
286 ot->idname= "NODE_OT_select";
289 ot->invoke= node_select_invoke;
290 ot->poll= ED_operator_node_active;
292 prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
293 RNA_def_property_enum_items(prop, prop_select_items);
295 prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
296 prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);