Toggle links tool for Node Editor
[blender.git] / source / blender / src / header_node.c
1 /**
2  *
3  * $Id:
4  *
5  * ***** BEGIN GPL LICENSE BLOCK *****
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version. 
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
20  *
21  * The Original Code is Copyright (C) 2005 Blender Foundation.
22  * All rights reserved.
23  *
24  * The Original Code is: all of this file.
25  *
26  * Contributor(s): none yet.
27  *
28  * ***** END GPL LICENSE BLOCK *****
29  */
30
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_ID.h"
36 #include "DNA_material_types.h"
37 #include "DNA_node_types.h"
38 #include "DNA_object_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_view2d_types.h"
43 #include "DNA_userdef_types.h"
44
45 #include "BIF_gl.h"
46 #include "BIF_interface.h"
47 #include "BIF_previewrender.h"
48 #include "BIF_resources.h"
49 #include "BIF_screen.h"
50 #include "BIF_space.h"
51 #include "BIF_toolbox.h"
52 #include "BIF_butspace.h"
53
54 #include "BKE_global.h"
55 #include "BKE_main.h"
56 #include "BKE_material.h"
57 #include "BKE_node.h"
58
59 #include "BSE_drawipo.h"
60 #include "BSE_headerbuttons.h"
61 #include "BSE_node.h"
62
63 #include "blendef.h"
64 #include "butspace.h"
65 #include "mydevice.h"
66
67 void do_node_buttons(ScrArea *sa, unsigned short event)
68 {
69         SpaceNode *snode= sa->spacedata.first;
70         Material *ma;
71         
72         switch(event) {
73                 case B_NODE_USEMAT:
74                         ma= (Material *)snode->id;
75                         if(ma) {
76                                 if(ma->use_nodes && ma->nodetree==NULL) {
77                                         node_shader_default(ma);
78                                         snode_set_context(snode);
79                                 }
80                                 BIF_preview_changed(ID_MA);
81                                 allqueue(REDRAWNODE, 0);
82                                 allqueue(REDRAWBUTSSHADING, 0);
83                                 allqueue(REDRAWIPO, 0);
84                         }               
85                         break;
86                         
87                 case B_NODE_USESCENE:
88                         if(G.scene->use_nodes) {
89                                 if(G.scene->nodetree==NULL)
90                                         node_composit_default(G.scene);
91                                 addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
92                         }
93                         snode_set_context(snode);
94                         allqueue(REDRAWNODE, 0);
95                         break;
96         }
97 }
98
99 static void do_node_viewmenu(void *arg, int event)
100 {
101         SpaceNode *snode= curarea->spacedata.first; 
102         
103         switch(event) {
104                 case 1: /* Zoom in */
105                         snode_zoom_in(curarea);
106                         break;
107                 case 2: /* View all */
108                         snode_zoom_out(curarea);
109                         break;
110                 case 3: /* View all */
111                         snode_home(curarea, snode);
112                         break;
113         }
114         allqueue(REDRAWNODE, 0);
115 }
116
117 static uiBlock *node_viewmenu(void *arg_unused)
118 {
119         uiBlock *block;
120         short yco= 0, menuwidth=120;
121         
122         block= uiNewBlock(&curarea->uiblocks, "node_viewmenu", 
123                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
124         uiBlockSetButmFunc(block, do_node_viewmenu, NULL);
125
126         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom In|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
127         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Out|NumPad -", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
128         
129         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
130         
131         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
132         
133         if (!curarea->full) 
134                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
135         else 
136                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
137         
138         if(curarea->headertype==HEADERTOP) {
139                 uiBlockSetDirection(block, UI_DOWN);
140         }
141         else {
142                 uiBlockSetDirection(block, UI_TOP);
143                 uiBlockFlipOrder(block);
144         }
145         
146         uiTextBoundsBlock(block, 50);
147         
148         return block;
149 }
150
151 static void do_node_selectmenu(void *arg, int event)
152 {
153         SpaceNode *snode= curarea->spacedata.first; 
154         
155         /* functions in editnode.c assume there's a tree */
156         if(snode->nodetree==NULL)
157                 return;
158         
159         switch(event) {
160                 case 1: /* border select */
161                         node_border_select(snode);
162                         break;
163                 case 2: /* select/deselect all */
164                         node_deselectall(snode, 1);
165                         break;
166                 case 3: /* select linked in */
167                         node_select_linked(snode, 0);
168                         break;
169                 case 4: /* select linked out */
170                         node_select_linked(snode, 1);
171                         break;
172         }
173         allqueue(REDRAWNODE, 0);
174 }
175
176 static uiBlock *node_selectmenu(void *arg_unused)
177 {
178         uiBlock *block;
179         short yco= 0, menuwidth=120;
180         
181         block= uiNewBlock(&curarea->uiblocks, "node_selectmenu", 
182                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
183         uiBlockSetButmFunc(block, do_node_selectmenu, NULL);
184         
185         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
186         
187         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
188         
189         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
190         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Linked From|L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
191         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Linked To|Shift L", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
192         
193         if(curarea->headertype==HEADERTOP) {
194                 uiBlockSetDirection(block, UI_DOWN);
195         }
196         else {
197                 uiBlockSetDirection(block, UI_TOP);
198                 uiBlockFlipOrder(block);
199         }
200         
201         uiTextBoundsBlock(block, 50);
202         
203         return block;
204 }
205
206 void do_node_addmenu(void *arg, int event)
207 {
208         SpaceNode *snode= curarea->spacedata.first;
209         bNode *node;
210         float locx, locy;
211         short mval[2];
212         
213         /* store selection in temp test flag */
214         for(node= snode->edittree->nodes.first; node; node= node->next) {
215                 if(node->flag & NODE_SELECT) node->flag |= NODE_TEST;
216                 else node->flag &= ~NODE_TEST;
217         }
218         
219         getmouseco_areawin(mval);
220         areamouseco_to_ipoco(G.v2d, mval, &locx, &locy);
221         node= node_add_node(snode, event, locx, locy);
222         
223         /* uses test flag */
224         snode_autoconnect(snode, node, NODE_TEST);
225                 
226         addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
227         
228         BIF_undo_push("Add Node");
229         
230 }
231
232 static void node_make_addmenu(SpaceNode *snode, int nodeclass, uiBlock *block)
233 {
234         bNodeTree *ntree;
235         int tot= 0, a;
236         short yco= 0, menuwidth=120;
237         
238         ntree = snode->nodetree;
239         if(ntree) {
240                 /* mostly taken from toolbox.c, node_add_sublevel() */
241                 if(ntree) {
242                         if(nodeclass==NODE_CLASS_GROUP) {
243                                 bNodeTree *ngroup= G.main->nodetree.first;
244                                 for(; ngroup; ngroup= ngroup->id.next)
245                                         if(ngroup->type==ntree->type)
246                                                 tot++;
247                         }
248                         else {
249                                 bNodeType *type = ntree->alltypes.first;
250                                 while(type) {
251                                         if(type->nclass == nodeclass)
252                                                 tot++;
253                                         type= type->next;
254                                 }
255                         }
256                 }       
257                 
258                 if(tot==0) {
259                         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
260                         return;
261                 }
262                 
263                 if(nodeclass==NODE_CLASS_GROUP) {
264                         bNodeTree *ngroup= G.main->nodetree.first;
265                         for(tot=0, a=0; ngroup; ngroup= ngroup->id.next, tot++) {
266                                 if(ngroup->type==ntree->type) {
267                                         
268                                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, (ngroup->id.name+2), 0, 
269                                                 yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, NODE_GROUP_MENU+tot, "");
270                                         a++;
271                                 }
272                         }
273                 }
274                 else {
275                         bNodeType *type;
276                         for(a=0, type= ntree->alltypes.first; type; type=type->next) {
277                                 if( type->nclass == nodeclass ) {
278                                         printf("node %s\n", type->name);
279                                         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, type->name, 0, 
280                                                 yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, type->type, "");
281                                         a++;
282                                 }
283                         }
284                 }
285         } else {
286                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
287                 return;
288         }
289 }
290
291 static uiBlock *node_add_inputmenu(void *arg_unused)
292 {
293         SpaceNode *snode= curarea->spacedata.first;
294         uiBlock *block;
295
296         block= uiNewBlock(&curarea->uiblocks, "node_add_inputmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
297         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
298         
299         node_make_addmenu(snode, NODE_CLASS_INPUT, block);
300         
301         uiBlockSetDirection(block, UI_RIGHT);
302         uiTextBoundsBlock(block, 60);
303         
304         return block;
305 }
306 static uiBlock *node_add_outputmenu(void *arg_unused)
307 {
308         SpaceNode *snode= curarea->spacedata.first;
309         uiBlock *block;
310         
311         block= uiNewBlock(&curarea->uiblocks, "node_add_outputmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
312         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
313         
314         node_make_addmenu(snode, NODE_CLASS_OUTPUT, block);
315         
316         uiBlockSetDirection(block, UI_RIGHT);
317         uiTextBoundsBlock(block, 60);
318         
319         return block;
320 }
321 static uiBlock *node_add_colormenu(void *arg_unused)
322 {
323         SpaceNode *snode= curarea->spacedata.first;
324         uiBlock *block;
325         
326         block= uiNewBlock(&curarea->uiblocks, "node_add_colormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
327         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
328         
329         node_make_addmenu(snode, NODE_CLASS_OP_COLOR, block);
330         
331         uiBlockSetDirection(block, UI_RIGHT);
332         uiTextBoundsBlock(block, 60);
333         
334         return block;
335 }
336 static uiBlock *node_add_vectormenu(void *arg_unused)
337 {
338         SpaceNode *snode= curarea->spacedata.first;
339         uiBlock *block;
340         
341         block= uiNewBlock(&curarea->uiblocks, "node_add_vectormenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
342         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
343         
344         node_make_addmenu(snode, NODE_CLASS_OP_VECTOR, block);
345         
346         uiBlockSetDirection(block, UI_RIGHT);
347         uiTextBoundsBlock(block, 60);
348         
349         return block;
350 }
351 static uiBlock *node_add_filtermenu(void *arg_unused)
352 {
353         SpaceNode *snode= curarea->spacedata.first;
354         uiBlock *block;
355         
356         block= uiNewBlock(&curarea->uiblocks, "node_add_filtermenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
357         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
358         
359         node_make_addmenu(snode, NODE_CLASS_OP_FILTER, block);
360         
361         uiBlockSetDirection(block, UI_RIGHT);
362         uiTextBoundsBlock(block, 60);
363         
364         return block;
365 }
366 static uiBlock *node_add_convertermenu(void *arg_unused)
367 {
368         SpaceNode *snode= curarea->spacedata.first;
369         uiBlock *block;
370         
371         block= uiNewBlock(&curarea->uiblocks, "node_add_convertermenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
372         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
373         
374         node_make_addmenu(snode, NODE_CLASS_CONVERTOR, block);
375         
376         uiBlockSetDirection(block, UI_RIGHT);
377         uiTextBoundsBlock(block, 60);
378         
379         return block;
380 }
381 static uiBlock *node_add_mattemenu(void *arg_unused)
382 {
383         SpaceNode *snode= curarea->spacedata.first;
384         uiBlock *block;
385         
386         block= uiNewBlock(&curarea->uiblocks, "node_add_mattemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
387         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
388         
389         node_make_addmenu(snode, NODE_CLASS_MATTE, block);
390         
391         uiBlockSetDirection(block, UI_RIGHT);
392         uiTextBoundsBlock(block, 60);
393         
394         return block;
395 }
396 static uiBlock *node_add_distortmenu(void *arg_unused)
397 {
398         SpaceNode *snode= curarea->spacedata.first;
399         uiBlock *block;
400         
401         block= uiNewBlock(&curarea->uiblocks, "node_add_distortmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
402         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
403         
404         node_make_addmenu(snode, NODE_CLASS_DISTORT, block);
405         
406         uiBlockSetDirection(block, UI_RIGHT);
407         uiTextBoundsBlock(block, 60);
408         
409         return block;
410 }
411 static uiBlock *node_add_groupmenu(void *arg_unused)
412 {
413         SpaceNode *snode= curarea->spacedata.first;
414         uiBlock *block;
415         
416         block= uiNewBlock(&curarea->uiblocks, "node_add_groupmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
417         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
418         
419         node_make_addmenu(snode, NODE_CLASS_GROUP, block);
420         
421         uiBlockSetDirection(block, UI_RIGHT);
422         uiTextBoundsBlock(block, 60);
423         
424         return block;
425 }
426
427 static uiBlock *node_addmenu(void *arg_unused)
428 {
429         SpaceNode *snode= curarea->spacedata.first;
430         uiBlock *block;
431         short yco= 0, menuwidth=120;
432         
433         block= uiNewBlock(&curarea->uiblocks, "node_addmenu", 
434                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
435         uiBlockSetButmFunc(block, do_node_addmenu, NULL);
436         
437         if(snode->treetype==NTREE_SHADER) {
438                 uiDefIconTextBlockBut(block, node_add_inputmenu, NULL, ICON_RIGHTARROW_THIN, "Input", 0, yco-=20, 120, 19, "");
439                 uiDefIconTextBlockBut(block, node_add_outputmenu, NULL, ICON_RIGHTARROW_THIN, "Output", 0, yco-=20, 120, 19, "");
440                 uiDefIconTextBlockBut(block, node_add_colormenu, NULL, ICON_RIGHTARROW_THIN, "Color", 0, yco-=20, 120, 19, "");
441                 uiDefIconTextBlockBut(block, node_add_vectormenu, NULL, ICON_RIGHTARROW_THIN, "Vector", 0, yco-=20, 120, 19, "");
442                 uiDefIconTextBlockBut(block, node_add_convertermenu, NULL, ICON_RIGHTARROW_THIN, "Convertor", 0, yco-=20, 120, 19, "");
443                 uiDefIconTextBlockBut(block, node_add_groupmenu, NULL, ICON_RIGHTARROW_THIN, "Group", 0, yco-=20, 120, 19, "");
444         }
445         else if(snode->treetype==NTREE_COMPOSIT) {
446                 uiDefIconTextBlockBut(block, node_add_inputmenu, NULL, ICON_RIGHTARROW_THIN, "Input", 0, yco-=20, 120, 19, "");
447                 uiDefIconTextBlockBut(block, node_add_outputmenu, NULL, ICON_RIGHTARROW_THIN, "Output", 0, yco-=20, 120, 19, "");
448                 uiDefIconTextBlockBut(block, node_add_colormenu, NULL, ICON_RIGHTARROW_THIN, "Color", 0, yco-=20, 120, 19, "");
449                 uiDefIconTextBlockBut(block, node_add_vectormenu, NULL, ICON_RIGHTARROW_THIN, "Vector", 0, yco-=20, 120, 19, "");
450                 uiDefIconTextBlockBut(block, node_add_filtermenu, NULL, ICON_RIGHTARROW_THIN, "Filter", 0, yco-=20, 120, 19, "");
451                 uiDefIconTextBlockBut(block, node_add_convertermenu, NULL, ICON_RIGHTARROW_THIN, "Convertor", 0, yco-=20, 120, 19, "");
452                 uiDefIconTextBlockBut(block, node_add_mattemenu, NULL, ICON_RIGHTARROW_THIN, "Matte", 0, yco-=20, 120, 19, "");
453                 uiDefIconTextBlockBut(block, node_add_distortmenu, NULL, ICON_RIGHTARROW_THIN, "Distort", 0, yco-=20, 120, 19, "");
454                 uiDefIconTextBlockBut(block, node_add_groupmenu, NULL, ICON_RIGHTARROW_THIN, "Group", 0, yco-=20, 120, 19, "");
455
456         } else
457                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); 
458         
459         if(curarea->headertype==HEADERTOP) {
460                 uiBlockSetDirection(block, UI_DOWN);
461         }
462         else {
463                 uiBlockSetDirection(block, UI_TOP);
464                 uiBlockFlipOrder(block);
465         }
466         
467         uiTextBoundsBlock(block, 50);
468         
469         return block;
470 }
471
472 static void do_node_nodemenu(void *arg, int event)
473 {
474         SpaceNode *snode= curarea->spacedata.first; 
475         int fromlib=0;
476         
477         /* functions in editnode.c assume there's a tree */
478         if(snode->nodetree==NULL)
479                 return;
480         fromlib= (snode->id && snode->id->lib);
481         
482         switch(event) {
483                 case 1: /* grab/move */
484                         node_transform_ext(0,0);
485                         break;
486                 case 2: /* duplicate */
487                         if(fromlib) fromlib= -1;
488                         else node_adduplicate(snode);
489                         break;
490                 case 3: /* delete */
491                         if(fromlib) fromlib= -1;
492                         else node_delete(snode);
493                         break;
494                 case 4: /* make group */
495                         node_make_group(snode);
496                         break;
497                 case 5: /* ungroup */
498                         node_ungroup(snode);
499                         break;
500                 case 6: /* edit group */
501                         if(fromlib) fromlib= -1;
502                         else snode_make_group_editable(snode, NULL);
503                         break;
504                 case 7: /* hide/unhide */
505                         node_hide(snode);
506                         break;
507                 case 8: /* read saved render layers */
508                         node_read_renderlayers(snode);
509                         break;
510                 case 9: /* show cyclic */
511                         ntreeSolveOrder(snode->edittree);
512                         break;
513                 case 10: /* execute */
514                         addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
515                         break;
516                 case 11: /* toggle link */
517                         node_toggle_link(snode);
518                         break;
519         }
520         
521         if(fromlib==-1) error_libdata();
522         allqueue(REDRAWNODE, 0);
523 }
524
525 static uiBlock *node_nodemenu(void *arg_unused)
526 {
527         SpaceNode *snode= curarea->spacedata.first; 
528         uiBlock *block;
529         short yco= 0, menuwidth=120;
530         
531         block= uiNewBlock(&curarea->uiblocks, "node_nodemenu", 
532                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
533         uiBlockSetButmFunc(block, do_node_nodemenu, NULL);
534         
535         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
536         
537         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
538         
539         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate|Shift D", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
540         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete|X", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
541         
542         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
543
544         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Toggle Link|F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
545
546         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
547         
548         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make Group|Ctrl G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
549         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Ungroup|Alt G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
550         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Edit Group|Tab", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
551         
552         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
553         
554         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide/Unhide|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
555         
556         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
557         
558         if(snode->treetype==NTREE_COMPOSIT) {
559                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Execute Composite|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
560                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Read Saved Render Results|R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
561         }
562         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Cyclic Dependencies|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
563         
564         if(curarea->headertype==HEADERTOP) {
565                 uiBlockSetDirection(block, UI_DOWN);
566         }
567         else {
568                 uiBlockSetDirection(block, UI_TOP);
569                 uiBlockFlipOrder(block);
570         }
571         
572         uiTextBoundsBlock(block, 50);
573         
574         return block;
575 }
576
577 void node_buttons(ScrArea *sa)
578 {
579         SpaceNode *snode= sa->spacedata.first;
580         uiBlock *block;
581         short xco, xmax;
582         char name[256];
583         
584         sprintf(name, "header %d", sa->headwin);
585         block= uiNewBlock(&sa->uiblocks, name, UI_EMBOSS, UI_HELV, sa->headwin);
586
587         if(area_is_active_area(sa)) uiBlockSetCol(block, TH_HEADER);
588         else uiBlockSetCol(block, TH_HEADERDESEL);
589         
590         sa->butspacetype= SPACE_NODE;
591
592         xco = 8;
593         
594         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, 
595                                           windowtype_pup(), xco, 0, XIC+10, YIC, 
596                                           &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
597                                           "Displays Current Window Type");
598
599         xco += XIC + 14;
600
601         uiBlockSetEmboss(block, UI_EMBOSSN);
602         if (sa->flag & HEADER_NO_PULLDOWN) {
603                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, 
604                                           ICON_DISCLOSURE_TRI_RIGHT, xco,2,XIC,YIC-2,
605                                           &(sa->flag), 0, 0, 0, 0,  "Show pulldown menus");
606         }
607         else {
608                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, 
609                                           ICON_DISCLOSURE_TRI_DOWN,  xco,2,XIC,YIC-2,
610                                           &(sa->flag), 0, 0, 0, 0,  "Hide pulldown menus");
611         }
612         xco+=XIC;
613
614         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
615                 /* pull down menus */
616                 uiBlockSetEmboss(block, UI_EMBOSSP);
617         
618                 xmax= GetButStringLength("View");
619                 uiDefPulldownBut(block, node_viewmenu, NULL, 
620                                           "View", xco, -2, xmax-3, 24, "");
621                 xco+= xmax;
622                 
623                 xmax= GetButStringLength("Select");
624                 uiDefPulldownBut(block, node_selectmenu, NULL, 
625                                                  "Select", xco, -2, xmax-3, 24, "");
626                 xco+= xmax;
627                 
628                 xmax= GetButStringLength("Add");
629                 uiDefPulldownBut(block, node_addmenu, NULL, 
630                                                  "Add", xco, -2, xmax-3, 24, "");
631                 xco+= xmax;
632                 
633                 xmax= GetButStringLength("Node");
634                 uiDefPulldownBut(block, node_nodemenu, NULL, 
635                                                  "Node", xco, -2, xmax-3, 24, "");
636                 xco+= xmax;
637         }
638         
639         uiBlockSetEmboss(block, UI_EMBOSS);
640         
641         /* main type choosing */
642         uiBlockBeginAlign(block);
643         uiDefIconButI(block, ROW, B_REDR, ICON_MATERIAL_DEHLT, xco,2,XIC,YIC-2,
644                                   &(snode->treetype), 2, 0, 0, 0, "Material Nodes");
645         xco+= XIC;
646         uiDefIconButI(block, ROW, B_REDR, ICON_IMAGE_DEHLT, xco,2,XIC,YIC-2,
647                                   &(snode->treetype), 2, 1, 0, 0, "Composite Nodes");
648         xco+= 2*XIC;
649         uiBlockEndAlign(block);
650         
651         /* find and set the context */
652         snode_set_context(snode);
653         
654         if(snode->treetype==NTREE_SHADER) {
655                 if(snode->from) {
656                                                                                 /* 0, NULL -> pin */
657                         xco= std_libbuttons(block, xco, 0, 0, NULL, B_MATBROWSE, ID_MA, 1, snode->id, snode->from, &(snode->menunr), 
658                                            B_MATALONE, B_MATLOCAL, B_MATDELETE, B_AUTOMATNAME, B_KEEPDATA);
659                         
660                         if(snode->id) {
661                                 Material *ma= (Material *)snode->id;
662                                 uiDefButC(block, TOG, B_NODE_USEMAT, "Use Nodes", xco+5,0,70,19, &ma->use_nodes, 0.0f, 0.0f, 0, 0, "");
663                                 xco+=80;
664                         }
665                 }
666         }
667         else if(snode->treetype==NTREE_COMPOSIT) {
668                 uiDefButS(block, TOG, B_NODE_USESCENE, "Use Nodes", xco+5,0,70,19, &G.scene->use_nodes, 0.0f, 0.0f, 0, 0, "Indicate this Scene will use Nodes and execute them while editing");
669                 xco+= 80;
670                 uiDefButBitS(block, TOG, R_COMP_FREE, B_NOP, "Free Unused", xco+5,0,80,19, &G.scene->r.scemode, 0.0f, 0.0f, 0, 0, "Free Nodes that are not used while composite");
671                 xco+= 80;
672                 uiDefButBitS(block, TOG, SNODE_BACKDRAW, REDRAWNODE, "Backdrop", xco+5,0,80,19, &snode->flag, 0.0f, 0.0f, 0, 0, "Use active Viewer Node output as backdrop");
673                 xco+= 80;
674         }
675         
676         /* always as last  */
677         sa->headbutlen= xco+2*XIC;
678
679         uiDrawBlock(block);
680 }