Fix crash on edge slide when object has got multires modifier
[blender.git] / source / blender / editors / space_node / drawnode.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Bob Holcomb, Thomas Dinges
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/space_node/drawnode.c
29  *  \ingroup spnode
30  */
31
32
33 #include <math.h>
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "BLI_blenlib.h"
38 #include "BLI_math.h"
39 #include "BLI_utildefines.h"
40
41 #include "DNA_node_types.h"
42 #include "DNA_material_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_screen_types.h"
47
48 #include "BKE_context.h"
49 #include "BKE_curve.h"
50 #include "BKE_global.h"
51 #include "BKE_image.h"
52 #include "BKE_library.h"
53 #include "BKE_main.h"
54 #include "BKE_node.h"
55
56 #include "NOD_composite.h"
57 #include "NOD_shader.h"
58
59 #include "BIF_gl.h"
60 #include "BIF_glutil.h"
61
62 #include "BLF_api.h"
63
64 #include "MEM_guardedalloc.h"
65
66
67 #include "RNA_access.h"
68
69 #include "ED_node.h"
70
71 #include "WM_api.h"
72 #include "WM_types.h"
73
74 #include "UI_interface.h"
75 #include "UI_resources.h"
76
77 #include "IMB_imbuf.h"
78 #include "IMB_imbuf_types.h"
79
80 #include "node_intern.h"
81
82
83 // XXX interface.h
84 extern void ui_dropshadow(rctf *rct, float radius, float aspect, int select);
85
86 /* ****************** SOCKET BUTTON DRAW FUNCTIONS ***************** */
87
88 static void node_sync_cb(bContext *UNUSED(C), void *snode_v, void *node_v)
89 {
90         SpaceNode *snode= snode_v;
91         
92         if(snode->treetype==NTREE_SHADER) {
93                 nodeShaderSynchronizeID(node_v, 1);
94                 // allqueue(REDRAWBUTSSHADING, 0);
95         }
96 }
97
98 static void node_socket_button_label(const bContext *UNUSED(C), uiBlock *block,
99                                                           bNodeTree *UNUSED(ntree), bNode *UNUSED(node), bNodeSocket *sock,
100                                                           const char *UNUSED(name), int x, int y, int width)
101 {
102         uiDefBut(block, LABEL, 0, sock->name, x, y, width, NODE_DY, NULL, 0, 0, 0, 0, "");
103 }
104
105
106 static void node_socket_button_default(const bContext *C, uiBlock *block,
107                                                                 bNodeTree *ntree, bNode *node, bNodeSocket *sock,
108                                                                 const char *name, int x, int y, int width)
109 {
110         if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
111                 node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
112         else {
113                 PointerRNA ptr;
114                 uiBut *bt;
115                 
116                 RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
117                 
118                 bt = uiDefButR(block, NUM, B_NODE_EXEC, name,
119                                            x, y+1, width, NODE_DY-2, 
120                                            &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
121                 if (node)
122                         uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
123         }
124 }
125
126 typedef struct SocketComponentMenuArgs {
127         PointerRNA ptr;
128         int x, y, width;
129         uiButHandleFunc cb;
130         void *arg1, *arg2;
131 } SocketComponentMenuArgs;
132 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
133 static uiBlock *socket_component_menu(bContext *C, ARegion *ar, void *args_v)
134 {
135         SocketComponentMenuArgs *args= (SocketComponentMenuArgs*)args_v;
136         uiBlock *block;
137         uiLayout *layout;
138         
139         block= uiBeginBlock(C, ar, __func__, UI_EMBOSS);
140         uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN);
141         
142         layout= uiLayoutColumn(uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, args->x, args->y+2, args->width, NODE_DY, UI_GetStyle()), 0);
143         
144         uiItemR(layout, &args->ptr, "default_value", UI_ITEM_R_EXPAND, "", ICON_NONE);
145         
146         return block;
147 }
148 static void node_socket_button_components(const bContext *C, uiBlock *block,
149                                                                    bNodeTree *ntree, bNode *node, bNodeSocket *sock,
150                                                                    const char *name, int x, int y, int width)
151 {
152         if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
153                 node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
154         else {
155                 PointerRNA ptr;
156                 SocketComponentMenuArgs *args;
157                 
158                 RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
159                 
160                 args= MEM_callocN(sizeof(SocketComponentMenuArgs), "SocketComponentMenuArgs");
161                 
162                 args->ptr = ptr;
163                 args->x = x;
164                 args->y = y;
165                 args->width = width;
166                 args->cb = node_sync_cb;
167                 args->arg1 = CTX_wm_space_node(C);
168                 args->arg2 = node;
169                 
170                 uiDefBlockButN(block, socket_component_menu, args, name, x, y+1, width, NODE_DY-2, "");
171         }
172 }
173
174 static void node_socket_button_color(const bContext *C, uiBlock *block,
175                                                           bNodeTree *ntree, bNode *node, bNodeSocket *sock,
176                                                           const char *name, int x, int y, int width)
177 {
178         /* XXX would be nicer to have draw function based on sock->struct_type as well,
179          * but currently socket types are completely identified by data type only.
180          */
181         
182         switch (sock->struct_type) {
183         case SOCK_STRUCT_NONE: {
184                 if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
185                         node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
186                 else {
187                         PointerRNA ptr;
188                         uiBut *bt;
189                         int labelw= width - 40;
190                         RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
191                         
192                         bt=uiDefButR(block, COL, B_NODE_EXEC, "",
193                                                  x, y+2, (labelw>0 ? 40 : width), NODE_DY-2, 
194                                                  &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
195                         if (node)
196                                 uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
197                         
198                         if (name[0]!='\0' && labelw>0)
199                                 uiDefBut(block, LABEL, 0, name, x + 40, y+2, labelw, NODE_DY-2, NULL, 0, 0, 0, 0, "");
200                 }
201                 break;
202         }
203         case SOCK_STRUCT_OUTPUT_MULTI_FILE: {
204                 uiLayout *layout, *row;
205                 PointerRNA ptr, imfptr;
206                 PropertyRNA *imtype_prop;
207                 const char *imtype_name;
208                 int rx, ry;
209                 RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
210                 imfptr = RNA_pointer_get(&ptr, "format");
211                 
212                 layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y+NODE_DY, width, 20, UI_GetStyle());
213                 row = uiLayoutRow(layout, 0);           
214                 
215                 uiItemL(row, sock->name, 0);
216                 imtype_prop = RNA_struct_find_property(&imfptr, "file_format");
217                 RNA_property_enum_name((bContext*)C, &imfptr, imtype_prop, RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name);
218                 uiBlockSetEmboss(block, UI_EMBOSSP);
219                 uiItemL(row, imtype_name, 0);
220                 uiBlockSetEmboss(block, UI_EMBOSSN);
221                 
222                 uiBlockLayoutResolve(block, &rx, &ry);
223                 break;
224         }
225         }
226 }
227
228 /* ****************** BASE DRAW FUNCTIONS FOR NEW OPERATOR NODES ***************** */
229
230 #if 0 /* UNUSED */
231 static void node_draw_socket_new(bNodeSocket *sock, float size)
232 {
233         float x=sock->locx, y=sock->locy;
234         
235         /* 16 values of sin function */
236         static float si[16] = {
237                 0.00000000f, 0.39435585f,0.72479278f,0.93775213f,
238                 0.99871650f,0.89780453f,0.65137248f,0.29936312f,
239                 -0.10116832f,-0.48530196f,-0.79077573f,-0.96807711f,
240                 -0.98846832f,-0.84864425f,-0.57126821f,-0.20129852f
241         };
242         /* 16 values of cos function */
243         static float co[16] ={
244                 1.00000000f,0.91895781f,0.68896691f,0.34730525f,
245                 -0.05064916f,-0.44039415f,-0.75875812f,-0.95413925f,
246                 -0.99486932f,-0.87434661f,-0.61210598f,-0.25065253f,
247                 0.15142777f,0.52896401f,0.82076344f,0.97952994f,
248         };
249         int a;
250         
251         glColor3ub(180, 180, 180);
252         
253         glBegin(GL_POLYGON);
254         for(a=0; a<16; a++)
255                 glVertex2f(x+size*si[a], y+size*co[a]);
256         glEnd();
257         
258         glColor4ub(0, 0, 0, 150);
259         glEnable(GL_BLEND);
260         glEnable( GL_LINE_SMOOTH );
261         glBegin(GL_LINE_LOOP);
262         for(a=0; a<16; a++)
263                 glVertex2f(x+size*si[a], y+size*co[a]);
264         glEnd();
265         glDisable( GL_LINE_SMOOTH );
266         glDisable(GL_BLEND);
267 }
268 #endif
269
270 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
271
272 static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
273 {
274         PointerRNA sockptr;
275         PropertyRNA *prop;
276         
277         /* first socket stores value */
278         prop = RNA_struct_find_property(ptr, "outputs");
279         RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
280         
281         uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE);
282 }
283
284 static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
285 {
286         uiLayout *col;
287         PointerRNA sockptr;
288         PropertyRNA *prop;
289         
290         /* first socket stores value */
291         prop = RNA_struct_find_property(ptr, "outputs");
292         RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
293         
294         col = uiLayoutColumn(layout, 0);
295         uiTemplateColorWheel(col, &sockptr, "default_value", 1, 0, 0, 0);
296         uiItemR(col, &sockptr, "default_value", 0, "", ICON_NONE);
297 }
298
299 static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
300 {       
301         uiLayout *row;
302
303         bNodeTree *ntree= (bNodeTree*)ptr->id.data;
304
305         row= uiLayoutRow(layout, 1);
306         uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE);
307         if(ntree->type == NTREE_COMPOSIT)
308                 uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA);
309 }
310
311 static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
312 {
313         uiLayout *row;
314 #if 0
315         /* XXX no context access here .. */
316         bNode *node= ptr->data;
317         CurveMapping *cumap= node->storage;
318         
319         if(cumap) {
320                 cumap->flag |= CUMA_DRAW_CFRA;
321                 if(node->custom1<node->custom2)
322                         cumap->sample[0]= (float)(CFRA - node->custom1)/(float)(node->custom2-node->custom1);
323         }
324 #endif
325
326         uiTemplateCurveMapping(layout, ptr, "curve", 's', 0, 0);
327
328         row= uiLayoutRow(layout, 1);
329         uiItemR(row, ptr, "frame_start", 0, "Sta", ICON_NONE);
330         uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
331 }
332
333 static void node_buts_colorramp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
334 {
335         uiTemplateColorRamp(layout, ptr, "color_ramp", 0);
336 }
337
338 static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
339 {
340         uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0);
341 }
342
343 static float *_sample_col= NULL;        // bad bad, 2.5 will do better?
344 #if 0
345 static void node_curvemap_sample(float *col)
346 {
347         _sample_col= col;
348 }
349 #endif
350
351 static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
352 {
353         bNode *node= ptr->data;
354         CurveMapping *cumap= node->storage;
355
356         if(_sample_col) {
357                 cumap->flag |= CUMA_DRAW_SAMPLE;
358                 copy_v3_v3(cumap->sample, _sample_col);
359         }
360         else 
361                 cumap->flag &= ~CUMA_DRAW_SAMPLE;
362
363         uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0);
364 }
365
366 static void node_normal_cb(bContext *C, void *ntree_v, void *node_v)
367 {
368         Main *bmain = CTX_data_main(C);
369
370         ED_node_generic_update(bmain, ntree_v, node_v);
371         WM_event_add_notifier(C, NC_NODE|NA_EDITED, ntree_v);
372 }
373
374 static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
375 {
376         uiBlock *block= uiLayoutAbsoluteBlock(layout);
377         bNodeTree *ntree= ptr->id.data;
378         bNode *node= ptr->data;
379         rctf *butr= &node->butr;
380         bNodeSocket *sock= node->outputs.first;         /* first socket stores normal */
381         float *nor= ((bNodeSocketValueVector*)sock->default_value)->value;
382         uiBut *bt;
383         
384         bt= uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "", 
385                       (short)butr->xmin, (short)butr->xmin,
386                       butr->xmax-butr->xmin, butr->xmax-butr->xmin,
387                       nor, 0.0f, 1.0f, 0, 0, "");
388         uiButSetFunc(bt, node_normal_cb, ntree, node);
389 }
390 #if 0 // not used in 2.5x yet
391 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
392 {
393         Main *bmain= CTX_data_main(C);
394         bNodeTree *ntree= ntree_v;
395         bNode *node= node_v;
396         Tex *tex;
397         
398         if(node->menunr<1) return;
399         
400         if(node->id) {
401                 node->id->us--;
402                 node->id= NULL;
403         }
404         tex= BLI_findlink(&bmain->tex, node->menunr-1);
405
406         node->id= &tex->id;
407         id_us_plus(node->id);
408         BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
409         
410         nodeSetActive(ntree, node);
411         
412         if( ntree->type == NTREE_TEXTURE )
413                 ntreeTexCheckCyclics( ntree );
414         
415         // allqueue(REDRAWBUTSSHADING, 0);
416         // allqueue(REDRAWNODE, 0);
417         NodeTagChanged(ntree, node); 
418         
419         node->menunr= 0;
420 }
421 #endif
422 static void node_dynamic_update_cb(bContext *C, void *UNUSED(ntree_v), void *node_v)
423 {
424         Main *bmain= CTX_data_main(C);
425         Material *ma;
426         bNode *node= (bNode *)node_v;
427         ID *id= node->id;
428         int error= 0;
429
430         if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) error= 1;
431
432         /* Users only have to press the "update" button in one pynode
433          * and we also update all others sharing the same script */
434         for (ma= bmain->mat.first; ma; ma= ma->id.next) {
435                 if (ma->nodetree) {
436                         bNode *nd;
437                         for (nd= ma->nodetree->nodes.first; nd; nd= nd->next) {
438                                 if ((nd->type == NODE_DYNAMIC) && (nd->id == id)) {
439                                         nd->custom1= 0;
440                                         nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_REPARSE);
441                                         nd->menunr= 0;
442                                         if (error)
443                                                 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_ERROR);
444                                 }
445                         }
446                 }
447         }
448
449         // allqueue(REDRAWBUTSSHADING, 0);
450         // allqueue(REDRAWNODE, 0);
451         // XXX BIF_preview_changed(ID_MA);
452 }
453
454 static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
455 {
456         bNode *node= ptr->data;
457
458         short multi = (
459                 node->id &&
460                 ((Tex*)node->id)->use_nodes &&
461                 (node->type != CMP_NODE_TEXTURE) &&
462                 (node->type != TEX_NODE_TEXTURE)
463         );
464         
465         uiItemR(layout, ptr, "texture", 0, "", ICON_NONE);
466         
467         if(multi) {
468                 /* Number Drawing not optimal here, better have a list*/
469                 uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE);
470         }
471 }
472
473 static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
474
475         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
476 }
477
478 static int node_resize_area_default(bNode *node, int x, int y)
479 {
480         if (node->flag & NODE_HIDDEN) {
481                 rctf totr= node->totr;
482                 /* right part of node */
483                 totr.xmin= node->totr.xmax-20.0f;
484                 return BLI_in_rctf(&totr, x, y);
485         }
486         else {
487                 /* rect we're interested in is just the bottom right corner */
488                 rctf totr= node->totr;
489                 /* bottom right corner */
490                 totr.xmin= totr.xmax-10.0f;
491                 totr.ymax= totr.ymin+10.0f;
492                 return BLI_in_rctf(&totr, x, y);
493         }
494 }
495
496 /* ****************** BUTTON CALLBACKS FOR COMMON NODES ***************** */
497
498 /* width of socket columns in group display */
499 #define NODE_GROUP_FRAME                120
500
501 /* based on settings in node, sets drawing rect info. each redraw! */
502 /* note: this assumes only 1 group at a time is drawn (linked data) */
503 /* in node->totr the entire boundbox for the group is stored */
504 static void node_update_group(const bContext *C, bNodeTree *ntree, bNode *gnode)
505 {
506         if (!(gnode->flag & NODE_GROUP_EDIT)) {
507                 node_update_default(C, ntree, gnode);
508         }
509         else {
510                 bNodeTree *ngroup= (bNodeTree *)gnode->id;
511                 bNode *node;
512                 bNodeSocket *sock, *gsock;
513                 float locx, locy;
514                 rctf *rect= &gnode->totr;
515                 float node_group_frame= U.dpi*NODE_GROUP_FRAME/72;
516                 float group_header= 26*U.dpi/72;
517                 int counter;
518                 int dy;
519                 
520                 /* get "global" coords */
521                 nodeSpaceCoords(gnode, &locx, &locy);
522                 
523                 /* center them, is a bit of abuse of locx and locy though */
524                 node_update_nodetree(C, ngroup, locx, locy);
525                 
526                 rect->xmin = rect->xmax = locx;
527                 rect->ymin = rect->ymax = locy;
528                 
529                 counter= 1;
530                 for(node= ngroup->nodes.first; node; node= node->next) {
531                         if(counter) {
532                                 *rect= node->totr;
533                                 counter= 0;
534                         }
535                         else
536                                 BLI_union_rctf(rect, &node->totr);
537                 }
538                 
539                 /* add some room for links to group sockets */
540                 rect->xmin -= 4*NODE_DY;
541                 rect->xmax += 4*NODE_DY;
542                 rect->ymin-= NODE_DY;
543                 rect->ymax+= NODE_DY;
544                 
545                 /* input sockets */
546                 dy = 0.5f*(rect->ymin+rect->ymax) + NODE_DY*(BLI_countlist(&gnode->inputs)-1);
547                 gsock=ngroup->inputs.first;
548                 sock=gnode->inputs.first;
549                 while (gsock || sock) {
550                         while (sock && !sock->groupsock) {
551                                 sock->locx = rect->xmin - node_group_frame;
552                                 sock->locy = dy;
553
554                                 /* prevent long socket lists from growing out of the group box */
555                                 if (dy-3*NODE_DYS < rect->ymin)
556                                         rect->ymin = dy-3*NODE_DYS;
557                                 if (dy+3*NODE_DYS > rect->ymax)
558                                         rect->ymax = dy+3*NODE_DYS;
559                                 dy -= 2*NODE_DY;
560                                 
561                                 sock = sock->next;
562                         }
563                         while (gsock && (!sock || sock->groupsock!=gsock)) {
564                                 gsock->locx = rect->xmin;
565                                 gsock->locy = dy;
566                                 
567                                 /* prevent long socket lists from growing out of the group box */
568                                 if (dy-3*NODE_DYS < rect->ymin)
569                                         rect->ymin = dy-3*NODE_DYS;
570                                 if (dy+3*NODE_DYS > rect->ymax)
571                                         rect->ymax = dy+3*NODE_DYS;
572                                 dy -= 2*NODE_DY;
573                                 
574                                 gsock = gsock->next;
575                         }
576                         while (sock && gsock && sock->groupsock==gsock) {
577                                 gsock->locx = rect->xmin;
578                                 sock->locx = rect->xmin - node_group_frame;
579                                 sock->locy = gsock->locy = dy;
580                                 
581                                 /* prevent long socket lists from growing out of the group box */
582                                 if (dy-3*NODE_DYS < rect->ymin)
583                                         rect->ymin = dy-3*NODE_DYS;
584                                 if (dy+3*NODE_DYS > rect->ymax)
585                                         rect->ymax = dy+3*NODE_DYS;
586                                 dy -= 2*NODE_DY;
587                                 
588                                 sock = sock->next;
589                                 gsock = gsock->next;
590                         }
591                 }
592                 
593                 /* output sockets */
594                 dy = 0.5f*(rect->ymin+rect->ymax) + NODE_DY*(BLI_countlist(&gnode->outputs)-1);
595                 gsock=ngroup->outputs.first;
596                 sock=gnode->outputs.first;
597                 while (gsock || sock) {
598                         while (sock && !sock->groupsock) {
599                                 sock->locx = rect->xmax + node_group_frame;
600                                 sock->locy = dy - NODE_DYS;
601                                 
602                                 /* prevent long socket lists from growing out of the group box */
603                                 if (dy-3*NODE_DYS < rect->ymin)
604                                         rect->ymin = dy-3*NODE_DYS;
605                                 if (dy+3*NODE_DYS > rect->ymax)
606                                         rect->ymax = dy+3*NODE_DYS;
607                                 dy -= 2*NODE_DY;
608                                 
609                                 sock = sock->next;
610                         }
611                         while (gsock && (!sock || sock->groupsock!=gsock)) {
612                                 gsock->locx = rect->xmax;
613                                 gsock->locy = dy - NODE_DYS;
614                                 
615                                 /* prevent long socket lists from growing out of the group box */
616                                 if (dy-3*NODE_DYS < rect->ymin)
617                                         rect->ymin = dy-3*NODE_DYS;
618                                 if (dy+3*NODE_DYS > rect->ymax)
619                                         rect->ymax = dy+3*NODE_DYS;
620                                 dy -= 2*NODE_DY;
621                                 
622                                 gsock = gsock->next;
623                         }
624                         while (sock && gsock && sock->groupsock==gsock) {
625                                 gsock->locx = rect->xmax;
626                                 sock->locx = rect->xmax + node_group_frame;
627                                 sock->locy = gsock->locy = dy - NODE_DYS;
628                                 
629                                 /* prevent long socket lists from growing out of the group box */
630                                 if (dy-3*NODE_DYS < rect->ymin)
631                                         rect->ymin = dy-3*NODE_DYS;
632                                 if (dy+3*NODE_DYS > rect->ymax)
633                                         rect->ymax = dy+3*NODE_DYS;
634                                 dy -= 2*NODE_DY;
635                                 
636                                 sock = sock->next;
637                                 gsock = gsock->next;
638                         }
639                 }
640                 
641                 /* Set the block bounds to clip mouse events from underlying nodes.
642                  * Add margin for header and input/output columns.
643                  */
644                 uiExplicitBoundsBlock(gnode->block,
645                                                           rect->xmin - node_group_frame,
646                                                           rect->ymin,
647                                                           rect->xmax + node_group_frame,
648                                                           rect->ymax + group_header);
649         }
650 }
651
652 static void update_group_input_cb(bContext *UNUSED(C), void *UNUSED(snode_v), void *ngroup_v)
653 {
654         bNodeTree *ngroup= (bNodeTree*)ngroup_v;
655         
656         ngroup->update |= NTREE_UPDATE_GROUP_IN;
657         ntreeUpdateTree(ngroup);
658 }
659
660 static void update_group_output_cb(bContext *UNUSED(C), void *UNUSED(snode_v), void *ngroup_v)
661 {
662         bNodeTree *ngroup= (bNodeTree*)ngroup_v;
663         
664         ngroup->update |= NTREE_UPDATE_GROUP_OUT;
665         ntreeUpdateTree(ngroup);
666 }
667
668 static void draw_group_socket_name(SpaceNode *snode, bNode *gnode, bNodeSocket *sock, int in_out, float xoffset, float yoffset)
669 {
670         bNodeTree *ngroup= (bNodeTree*)gnode->id;
671         uiBut *bt;
672         
673         if (sock->flag & SOCK_DYNAMIC) {
674                 bt = uiDefBut(gnode->block, TEX, 0, "", 
675                                           sock->locx+xoffset, sock->locy+1+yoffset, 72, NODE_DY,
676                                           sock->name, 0, sizeof(sock->name), 0, 0, "");
677                 if (in_out==SOCK_IN)
678                         uiButSetFunc(bt, update_group_input_cb, snode, ngroup);
679                 else
680                         uiButSetFunc(bt, update_group_output_cb, snode, ngroup);
681         }
682         else {
683                 uiDefBut(gnode->block, LABEL, 0, sock->name,
684                          sock->locx+xoffset, sock->locy+1+yoffset, 72, NODE_DY,
685                          NULL, 0, sizeof(sock->name), 0, 0, "");
686         }
687 }
688
689 static void draw_group_socket(const bContext *C, SpaceNode *snode, bNodeTree *ntree, bNode *gnode, bNodeSocket *sock, bNodeSocket *gsock, int index, int in_out)
690 {
691         bNodeTree *ngroup= (bNodeTree*)gnode->id;
692         bNodeSocketType *stype= ntreeGetSocketType(gsock ? gsock->type : sock->type);
693         uiBut *bt;
694         float offset;
695         int draw_value;
696         float node_group_frame= U.dpi*NODE_GROUP_FRAME/72;
697         float socket_size= NODE_SOCKSIZE*U.dpi/72;
698         float arrowbutw= 0.8f*UI_UNIT_X;
699         /* layout stuff for buttons on group left frame */
700         float colw= 0.6f*node_group_frame;
701         float col1= 6 - node_group_frame;
702         float col2= col1 + colw+6;
703         float col3= - arrowbutw - 6;
704         /* layout stuff for buttons on group right frame */
705         float cor1= 6;
706         float cor2= cor1 + arrowbutw + 6;
707         float cor3= cor2 + arrowbutw + 6;
708         
709         /* node and group socket circles */
710         if (sock)
711                 node_socket_circle_draw(ntree, sock, socket_size);
712         if (gsock)
713                 node_socket_circle_draw(ngroup, gsock, socket_size);
714         
715         /* socket name */
716         offset = (in_out==SOCK_IN ? col1 : cor3);
717         if (!gsock)
718                 offset += (in_out==SOCK_IN ? node_group_frame : -node_group_frame);
719         
720         /* draw both name and value button if:
721          * 1) input: not internal
722          * 2) output: (node type uses const outputs) and (group output is unlinked)
723          */
724         draw_value = 0;
725         switch (in_out) {
726         case SOCK_IN:
727                 draw_value = !(gsock && (gsock->flag & SOCK_INTERNAL));
728                 break;
729         case SOCK_OUT:
730                 if (gnode->typeinfo->flag & NODE_CONST_OUTPUT)
731                         draw_value = !(gsock && gsock->link);
732                 break;
733         }
734         if (draw_value) {
735                 /* both name and value buttons */
736                 if (gsock) {
737                         draw_group_socket_name(snode, gnode, gsock, in_out, offset, 0);
738                         if (stype->buttonfunc)
739                                 stype->buttonfunc(C, gnode->block, ngroup, NULL, gsock, "", gsock->locx+offset, gsock->locy-NODE_DY, colw);
740                 }
741                 else {
742                         draw_group_socket_name(snode, gnode, sock, in_out, offset, 0);
743                         if (stype->buttonfunc)
744                                 stype->buttonfunc(C, gnode->block, ngroup, NULL, sock, "", sock->locx+offset, sock->locy-NODE_DY, colw);
745                 }
746         }
747         else {
748                 /* only name, no value button */
749                 if (gsock)
750                         draw_group_socket_name(snode, gnode, gsock, in_out, offset, -NODE_DYS);
751                 else
752                         draw_group_socket_name(snode, gnode, sock, in_out, offset, -NODE_DYS);
753         }
754         
755         if (gsock && (gsock->flag & SOCK_DYNAMIC)) {
756                 /* up/down buttons */
757                 offset = (in_out==SOCK_IN ? col2 : cor2);
758                 uiBlockSetDirection(gnode->block, UI_TOP);
759                 uiBlockBeginAlign(gnode->block);
760                 bt = uiDefIconButO(gnode->block, BUT, "NODE_OT_group_socket_move_up", 0, ICON_TRIA_UP,
761                                                    gsock->locx+offset, gsock->locy, arrowbutw, arrowbutw, "");
762                 if (!gsock->prev || !(gsock->prev->flag & SOCK_DYNAMIC))
763                         uiButSetFlag(bt, UI_BUT_DISABLED);
764                 RNA_int_set(uiButGetOperatorPtrRNA(bt), "index", index);
765                 RNA_enum_set(uiButGetOperatorPtrRNA(bt), "in_out", in_out);
766                 bt = uiDefIconButO(gnode->block, BUT, "NODE_OT_group_socket_move_down", 0, ICON_TRIA_DOWN,
767                                                    gsock->locx+offset, gsock->locy-arrowbutw, arrowbutw, arrowbutw, "");
768                 if (!gsock->next || !(gsock->next->flag & SOCK_DYNAMIC))
769                         uiButSetFlag(bt, UI_BUT_DISABLED);
770                 RNA_int_set(uiButGetOperatorPtrRNA(bt), "index", index);
771                 RNA_enum_set(uiButGetOperatorPtrRNA(bt), "in_out", in_out);
772                 uiBlockEndAlign(gnode->block);
773                 uiBlockSetDirection(gnode->block, 0);
774                 
775                 /* remove button */
776                 offset = (in_out==SOCK_IN ? col3 : cor1);
777                 uiBlockSetEmboss(gnode->block, UI_EMBOSSN);
778                 bt = uiDefIconButO(gnode->block, BUT, "NODE_OT_group_socket_remove", 0, ICON_X,
779                                                    gsock->locx+offset, gsock->locy-0.5f*arrowbutw, arrowbutw, arrowbutw, "");
780                 RNA_int_set(uiButGetOperatorPtrRNA(bt), "index", index);
781                 RNA_enum_set(uiButGetOperatorPtrRNA(bt), "in_out", in_out);
782                 uiBlockSetEmboss(gnode->block, UI_EMBOSS);
783         }
784 }
785
786 /* groups are, on creation, centered around 0,0 */
787 static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
788 {
789         if (!(gnode->flag & NODE_GROUP_EDIT)) {
790                 node_draw_default(C, ar, snode, ntree, gnode);
791         }
792         else {
793                 bNodeTree *ngroup= (bNodeTree *)gnode->id;
794                 bNodeSocket *sock, *gsock;
795                 uiLayout *layout;
796                 PointerRNA ptr;
797                 rctf rect= gnode->totr;
798                 float node_group_frame= U.dpi*NODE_GROUP_FRAME/72;
799                 float group_header= 26*U.dpi/72;
800                 
801                 int index;
802                 
803                 /* backdrop header */
804                 glEnable(GL_BLEND);
805                 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
806                 UI_ThemeColorShadeAlpha(TH_NODE_GROUP, 0, -70);
807                 uiDrawBox(GL_POLYGON, rect.xmin-node_group_frame, rect.ymax, rect.xmax+node_group_frame, rect.ymax+group_header, BASIS_RAD);
808                 
809                 /* backdrop body */
810                 UI_ThemeColorShadeAlpha(TH_BACK, -8, -70);
811                 uiSetRoundBox(UI_CNR_NONE);
812                 uiDrawBox(GL_POLYGON, rect.xmin, rect.ymin, rect.xmax, rect.ymax, BASIS_RAD);
813         
814                 /* input column */
815                 UI_ThemeColorShadeAlpha(TH_BACK, 10, -50);
816                 uiSetRoundBox(UI_CNR_BOTTOM_LEFT);
817                 uiDrawBox(GL_POLYGON, rect.xmin-node_group_frame, rect.ymin, rect.xmin, rect.ymax, BASIS_RAD);
818         
819                 /* output column */
820                 UI_ThemeColorShadeAlpha(TH_BACK, 10, -50);
821                 uiSetRoundBox(UI_CNR_BOTTOM_RIGHT);
822                 uiDrawBox(GL_POLYGON, rect.xmax, rect.ymin, rect.xmax+node_group_frame, rect.ymax, BASIS_RAD);
823         
824                 /* input column separator */
825                 glColor4ub(200, 200, 200, 140);
826                 glBegin(GL_LINES);
827                 glVertex2f(rect.xmin, rect.ymin);
828                 glVertex2f(rect.xmin, rect.ymax);
829                 glEnd();
830         
831                 /* output column separator */
832                 glColor4ub(200, 200, 200, 140);
833                 glBegin(GL_LINES);
834                 glVertex2f(rect.xmax, rect.ymin);
835                 glVertex2f(rect.xmax, rect.ymax);
836                 glEnd();
837         
838                 /* group node outline */
839                 uiSetRoundBox(UI_CNR_ALL);
840                 glColor4ub(200, 200, 200, 140);
841                 glEnable( GL_LINE_SMOOTH );
842                 uiDrawBox(GL_LINE_LOOP, rect.xmin-node_group_frame, rect.ymin, rect.xmax+node_group_frame, rect.ymax+group_header, BASIS_RAD);
843                 glDisable( GL_LINE_SMOOTH );
844                 glDisable(GL_BLEND);
845                 
846                 /* backdrop title */
847                 UI_ThemeColor(TH_TEXT_HI);
848         
849                 layout = uiBlockLayout(gnode->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, (short)(rect.xmin+15), (short)(rect.ymax+group_header),
850                                                            MIN2((int)(rect.xmax - rect.xmin-18.0f), node_group_frame+20), group_header, UI_GetStyle());
851                 RNA_pointer_create(&ntree->id, &RNA_Node, gnode, &ptr);
852                 uiTemplateIDBrowse(layout, (bContext*)C, &ptr, "node_tree", NULL, NULL, NULL);
853                 uiBlockLayoutResolve(gnode->block, NULL, NULL);
854         
855                 /* draw the internal tree nodes and links */
856                 node_draw_nodetree(C, ar, snode, ngroup);
857         
858                 /* group sockets */
859                 gsock=ngroup->inputs.first;
860                 sock=gnode->inputs.first;
861                 index = 0;
862                 while (gsock || sock) {
863                         while (sock && !sock->groupsock) {
864                                 draw_group_socket(C, snode, ntree, gnode, sock, NULL, index, SOCK_IN);
865                                 sock = sock->next;
866                         }
867                         while (gsock && (!sock || sock->groupsock!=gsock)) {
868                                 draw_group_socket(C, snode, ntree, gnode, NULL, gsock, index, SOCK_IN);
869                                 gsock = gsock->next;
870                                 ++index;
871                         }
872                         while (sock && gsock && sock->groupsock==gsock) {
873                                 draw_group_socket(C, snode, ntree, gnode, sock, gsock, index, SOCK_IN);
874                                 sock = sock->next;
875                                 gsock = gsock->next;
876                                 ++index;
877                         }
878                 }
879                 gsock=ngroup->outputs.first;
880                 sock=gnode->outputs.first;
881                 index = 0;
882                 while (gsock || sock) {
883                         while (sock && !sock->groupsock) {
884                                 draw_group_socket(C, snode, ntree, gnode, sock, NULL, index, SOCK_OUT);
885                                 sock = sock->next;
886                         }
887                         while (gsock && (!sock || sock->groupsock!=gsock)) {
888                                 draw_group_socket(C, snode, ntree, gnode, NULL, gsock, index, SOCK_OUT);
889                                 gsock = gsock->next;
890                                 ++index;
891                         }
892                         while (sock && gsock && sock->groupsock==gsock) {
893                                 draw_group_socket(C, snode, ntree, gnode, sock, gsock, index, SOCK_OUT);
894                                 sock = sock->next;
895                                 gsock = gsock->next;
896                                 ++index;
897                         }
898                 }
899                 
900                 uiEndBlock(C, gnode->block);
901                 uiDrawBlock(C, gnode->block);
902                 gnode->block= NULL;
903         }
904 }
905
906 void node_uifunc_group(uiLayout *layout, bContext *C, PointerRNA *ptr)
907 {
908         uiTemplateIDBrowse(layout, C, ptr, "node_tree", NULL, NULL, NULL);
909 }
910
911 static void node_common_buts_whileloop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
912 {
913         uiItemR(layout, ptr, "max_iterations", 0, NULL, 0);
914 }
915
916 static void node_update_frame(const bContext *UNUSED(C), bNodeTree *UNUSED(ntree), bNode *node)
917 {
918         float locx, locy;
919
920         /* get "global" coords */
921         nodeSpaceCoords(node, &locx, &locy);
922
923         node->prvr.xmin= locx + NODE_DYS;
924         node->prvr.xmax= locx + node->width- NODE_DYS;
925
926         node->totr.xmin= locx;
927         node->totr.xmax= locx + node->width;
928         node->totr.ymax= locy;
929         node->totr.ymin= locy - node->height;
930 }
931
932 static void node_common_set_butfunc(bNodeType *ntype)
933 {
934         switch(ntype->type) {
935                 case NODE_GROUP:
936                         ntype->uifunc= node_uifunc_group;
937                         ntype->drawfunc= node_draw_group;
938                         ntype->drawupdatefunc= node_update_group;
939                         break;
940                 case NODE_FORLOOP:
941 //                      ntype->uifunc= node_common_buts_group;
942                         ntype->drawfunc= node_draw_group;
943                         ntype->drawupdatefunc= node_update_group;
944                         break;
945                 case NODE_WHILELOOP:
946                         ntype->uifunc= node_common_buts_whileloop;
947                         ntype->drawfunc= node_draw_group;
948                         ntype->drawupdatefunc= node_update_group;
949                         break;
950                 case NODE_FRAME:
951                         ntype->drawupdatefunc= node_update_frame;
952                         break;
953         }
954 }
955
956 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
957
958 static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v)
959 {
960         Main *bmain= CTX_data_main(C);
961         bNodeTree *ntree= ntree_v;
962         bNode *node= node_v;
963         /* ID *oldid; */ /* UNUSED */
964         
965         if(node->menunr<1) return;
966         
967         if(node->id) {
968                 node->id->us--;
969         }
970         /* oldid= node->id; */ /* UNUSED */
971         node->id= BLI_findlink(&bmain->text, node->menunr-1);
972         id_us_plus(node->id);
973         BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
974
975         node->custom1= BSET(node->custom1, NODE_DYNAMIC_NEW);
976         
977         nodeSetActive(ntree, node);
978
979         // allqueue(REDRAWBUTSSHADING, 0);
980         // allqueue(REDRAWNODE, 0);
981
982         node->menunr= 0;
983 }
984
985 static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
986 {
987         bNode *node= ptr->data;
988         uiLayout *col;
989         
990         uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL);
991         
992         if(!node->id) return;
993         
994         col= uiLayoutColumn(layout, 0);
995         uiItemR(col, ptr, "use_diffuse", 0, NULL, ICON_NONE);
996         uiItemR(col, ptr, "use_specular", 0, NULL, ICON_NONE);
997         uiItemR(col, ptr, "invert_normal", 0, NULL, ICON_NONE);
998 }
999
1000 static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1001 {
1002         uiLayout *row;
1003         
1004         uiItemL(layout, "Location:", ICON_NONE);
1005         row= uiLayoutRow(layout, 1);
1006         uiItemR(row, ptr, "location", 0, "", ICON_NONE);
1007         
1008         uiItemL(layout, "Rotation:", ICON_NONE);
1009         row= uiLayoutRow(layout, 1);
1010         uiItemR(row, ptr, "rotation", 0, "", ICON_NONE);
1011         
1012         uiItemL(layout, "Scale:", ICON_NONE);
1013         row= uiLayoutRow(layout, 1);
1014         uiItemR(row, ptr, "scale", 0, "", ICON_NONE);
1015         
1016         row= uiLayoutRow(layout, 1);
1017         uiItemR(row, ptr, "use_min", 0, "Min", ICON_NONE);
1018         uiItemR(row, ptr, "min", 0, "", ICON_NONE);
1019         
1020         row= uiLayoutRow(layout, 1);
1021         uiItemR(row, ptr, "use_max", 0, "Max", ICON_NONE);
1022         uiItemR(row, ptr, "max", 0, "", ICON_NONE);
1023 }
1024
1025 static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1026
1027         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
1028 }
1029
1030 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
1031 {
1032         PointerRNA obptr= CTX_data_pointer_get(C, "active_object");
1033         uiLayout *col;
1034
1035         col= uiLayoutColumn(layout, 0);
1036
1037         if(obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
1038                 PointerRNA dataptr= RNA_pointer_get(&obptr, "data");
1039
1040                 uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
1041                 uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
1042         }
1043         else {
1044                 uiItemR(col, ptr, "uv_layer", 0, "UV", ICON_NONE);
1045                 uiItemR(col, ptr, "color_layer", 0, "VCol", ICON_NONE);
1046         }
1047 }
1048
1049 static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1050 {
1051         uiItemR(layout, ptr, "attribute_name", 0, "Name", ICON_NONE);
1052 }
1053
1054 static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1055 {
1056         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1057         uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
1058 }
1059
1060 static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1061 {
1062         uiItemR(layout, ptr, "sun_direction", 0, "", ICON_NONE);
1063         uiItemR(layout, ptr, "turbidity", 0, NULL, ICON_NONE);
1064 }
1065
1066 static void node_shader_buts_tex_gradient(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1067 {
1068         uiItemR(layout, ptr, "gradient_type", 0, "", ICON_NONE);
1069 }
1070
1071 static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1072 {
1073         uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE);
1074 }
1075
1076 static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1077 {
1078         uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE);
1079 }
1080
1081 static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1082 {
1083         uiItemR(layout, ptr, "musgrave_type", 0, "", ICON_NONE);
1084 }
1085
1086 static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1087 {
1088         uiItemR(layout, ptr, "coloring", 0, "", ICON_NONE);
1089 }
1090
1091 static void node_shader_buts_glossy(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1092 {
1093         uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE);
1094 }
1095
1096 static void node_shader_buts_dynamic(uiLayout *layout, bContext *C, PointerRNA *ptr)
1097
1098         Main *bmain= CTX_data_main(C);
1099         uiBlock *block= uiLayoutAbsoluteBlock(layout);
1100         bNode *node= ptr->data;
1101         bNodeTree *ntree= ptr->id.data;
1102         rctf *butr= &node->butr;
1103         uiBut *bt;
1104         // XXX SpaceNode *snode= curarea->spacedata.first;
1105         short dy= (short)butr->ymin;
1106         int xoff=0;
1107
1108         /* B_NODE_EXEC is handled in butspace.c do_node_buts */
1109         if(!node->id) {
1110                         const char *strp;
1111                         IDnames_to_pupstring(&strp, NULL, "", &(bmain->text), NULL, NULL);
1112                         node->menunr= 0;
1113                         bt= uiDefButS(block, MENU, B_NODE_EXEC/*+node->nr*/, strp, 
1114                                                         butr->xmin, dy, 19, 19, 
1115                                                         &node->menunr, 0, 0, 0, 0, "Browses existing choices");
1116                         uiButSetFunc(bt, node_browse_text_cb, ntree, node);
1117                         xoff=19;
1118                         if(strp) MEM_freeN((void *)strp);
1119         }
1120         else {
1121                 bt = uiDefBut(block, BUT, B_NOP, "Update",
1122                                 butr->xmin+xoff, butr->ymin+20, 50, 19,
1123                                 &node->menunr, 0.0, 19.0, 0, 0, "Refresh this node (and all others that use the same script)");
1124                 uiButSetFunc(bt, node_dynamic_update_cb, ntree, node);
1125
1126                 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) {
1127                         // UI_ThemeColor(TH_REDALERT);
1128                         // XXX ui_rasterpos_safe(butr->xmin + xoff, butr->ymin + 5, snode->aspect);
1129                         // XXX snode_drawstring(snode, "Error! Check console...", butr->xmax - butr->xmin);
1130                         ;
1131                 }
1132         }
1133 }
1134
1135 /* only once called */
1136 static void node_shader_set_butfunc(bNodeType *ntype)
1137 {
1138         ntype->uifuncbut = NULL;
1139         switch(ntype->type) {
1140                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
1141
1142                 case SH_NODE_MATERIAL:
1143                 case SH_NODE_MATERIAL_EXT:
1144                         ntype->uifunc= node_shader_buts_material;
1145                         break;
1146                 case SH_NODE_TEXTURE:
1147                         ntype->uifunc= node_buts_texture;
1148                         break;
1149                 case SH_NODE_NORMAL:
1150                         ntype->uifunc= node_buts_normal;
1151                         break;
1152                 case SH_NODE_CURVE_VEC:
1153                         ntype->uifunc= node_buts_curvevec;
1154                         break;
1155                 case SH_NODE_CURVE_RGB:
1156                         ntype->uifunc= node_buts_curvecol;
1157                         break;
1158                 case SH_NODE_MAPPING:
1159                         ntype->uifunc= node_shader_buts_mapping;
1160                         break;
1161                 case SH_NODE_VALUE:
1162                         ntype->uifunc= node_buts_value;
1163                         break;
1164                 case SH_NODE_RGB:
1165                         ntype->uifunc= node_buts_rgb;
1166                         break;
1167                 case SH_NODE_MIX_RGB:
1168                         ntype->uifunc= node_buts_mix_rgb;
1169                         break;
1170                 case SH_NODE_VALTORGB:
1171                         ntype->uifunc= node_buts_colorramp;
1172                         break;
1173                 case SH_NODE_MATH: 
1174                         ntype->uifunc= node_buts_math;
1175                         break; 
1176                 case SH_NODE_VECT_MATH: 
1177                         ntype->uifunc= node_shader_buts_vect_math;
1178                         break; 
1179                 case SH_NODE_GEOMETRY:
1180                         ntype->uifunc= node_shader_buts_geometry;
1181                         break;
1182                 case SH_NODE_ATTRIBUTE:
1183                         ntype->uifunc= node_shader_buts_attribute;
1184                         break;
1185                 case SH_NODE_TEX_SKY:
1186                         ntype->uifunc= node_shader_buts_tex_sky;
1187                         break;
1188                 case SH_NODE_TEX_IMAGE:
1189                         ntype->uifunc= node_shader_buts_tex_image;
1190                         break;
1191                 case SH_NODE_TEX_ENVIRONMENT:
1192                         ntype->uifunc= node_shader_buts_tex_image;
1193                         break;
1194                 case SH_NODE_TEX_GRADIENT:
1195                         ntype->uifunc= node_shader_buts_tex_gradient;
1196                         break;
1197                 case SH_NODE_TEX_MAGIC:
1198                         ntype->uifunc= node_shader_buts_tex_magic;
1199                         break;
1200                 case SH_NODE_TEX_WAVE:
1201                         ntype->uifunc= node_shader_buts_tex_wave;
1202                         break;
1203                 case SH_NODE_TEX_MUSGRAVE:
1204                         ntype->uifunc= node_shader_buts_tex_musgrave;
1205                         break;
1206                 case SH_NODE_TEX_VORONOI:
1207                         ntype->uifunc= node_shader_buts_tex_voronoi;
1208                         break;
1209                 case SH_NODE_BSDF_GLOSSY:
1210                 case SH_NODE_BSDF_GLASS:
1211                         ntype->uifunc= node_shader_buts_glossy;
1212                         break;
1213                 case NODE_DYNAMIC:
1214                         ntype->uifunc= node_shader_buts_dynamic;
1215                         break;
1216         }
1217                 if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
1218 }
1219
1220 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
1221
1222 static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1223 {
1224         uiLayout *col;
1225         bNode *node= ptr->data;
1226         PointerRNA imaptr;
1227         PropertyRNA *prop;
1228         int source;
1229         
1230         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1231         
1232         if(!node->id) return;
1233         
1234         prop = RNA_struct_find_property(ptr, "image");
1235         if (!prop || RNA_property_type(prop) != PROP_POINTER) return;
1236         imaptr= RNA_property_pointer_get(ptr, prop);
1237         
1238         col= uiLayoutColumn(layout, 0);
1239         
1240         uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE);
1241         
1242         source= RNA_enum_get(&imaptr, "source");
1243
1244         if(source == IMA_SRC_SEQUENCE) {
1245                 /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
1246                 Scene *scene= CTX_data_scene(C);
1247                 ImageUser *iuser= node->storage;
1248                 char numstr[32];
1249                 const int framenr= BKE_image_user_get_frame(iuser, CFRA, 0);
1250                 BLI_snprintf(numstr, sizeof(numstr), "Frame: %d", framenr);
1251                 uiItemL(layout, numstr, ICON_NONE);
1252         }
1253
1254         if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
1255                 col= uiLayoutColumn(layout, 1);
1256                 uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
1257                 uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
1258                 uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
1259                 uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
1260                 uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
1261         }
1262
1263         col= uiLayoutColumn(layout, 0);
1264         
1265         if (RNA_enum_get(&imaptr, "type")== IMA_TYPE_MULTILAYER)
1266                 uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
1267 }
1268
1269 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
1270 {
1271         bNode *node= ptr->data;
1272         uiLayout *col, *row;
1273         PointerRNA op_ptr;
1274         PointerRNA scn_ptr;
1275         PropertyRNA *prop;
1276         const char *layer_name;
1277         char scene_name[MAX_ID_NAME-2];
1278         wmOperatorType *ot = WM_operatortype_find("RENDER_OT_render", 1);
1279
1280         BLI_assert(ot != 0);
1281
1282         uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
1283         
1284         if(!node->id) return;
1285
1286         col= uiLayoutColumn(layout, 0);
1287         row = uiLayoutRow(col, 0);
1288         uiItemR(row, ptr, "layer", 0, "", ICON_NONE);
1289         
1290         prop = RNA_struct_find_property(ptr, "layer");
1291         if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)))
1292                 return;
1293         
1294         scn_ptr = RNA_pointer_get(ptr, "scene");
1295         RNA_string_get(&scn_ptr, "name", scene_name);
1296         
1297         WM_operator_properties_create_ptr(&op_ptr, ot);
1298         RNA_string_set(&op_ptr, "layer", layer_name);
1299         RNA_string_set(&op_ptr, "scene", scene_name);
1300         uiItemFullO_ptr(row, ot, "", ICON_RENDER_STILL, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
1301
1302 }
1303
1304
1305 static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1306 {
1307         uiLayout *col, *row;
1308         
1309         col= uiLayoutColumn(layout, 0);
1310         
1311         uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE);
1312         if (RNA_enum_get(ptr, "filter_type")!= R_FILTER_FAST_GAUSS) {
1313                 uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE);
1314                 uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
1315         }
1316         
1317         uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE);
1318         
1319         if (RNA_boolean_get(ptr, "use_relative")) {
1320                 uiItemL(col, "Aspect Correction", 0);
1321                 row= uiLayoutRow(layout, 1);
1322                 uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0);
1323                 
1324                 col= uiLayoutColumn(layout, 1);
1325                 uiItemR(col, ptr, "factor_x", 0, "X", ICON_NONE);
1326                 uiItemR(col, ptr, "factor_y", 0, "Y", ICON_NONE);
1327         }
1328         else {
1329                 col= uiLayoutColumn(layout, 1);
1330                 uiItemR(col, ptr, "size_x", 0, "X", ICON_NONE);
1331                 uiItemR(col, ptr, "size_y", 0, "Y", ICON_NONE);
1332         }
1333 }
1334
1335 static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1336 {
1337         uiLayout *col;
1338         
1339         uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
1340         uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE);
1341         
1342         col= uiLayoutColumn(layout, 1);
1343         uiItemL(col, "Center:", ICON_NONE);
1344         uiItemR(col, ptr, "center_x", 0, "X", ICON_NONE);
1345         uiItemR(col, ptr, "center_y", 0, "Y", ICON_NONE);
1346         
1347         uiItemS(layout);
1348         
1349         col= uiLayoutColumn(layout, 1);
1350         uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE);
1351         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
1352         
1353         uiItemS(layout);
1354         
1355         uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE);
1356         uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE);
1357 }
1358
1359 static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1360 {       
1361         uiLayout *col;
1362         
1363         col= uiLayoutColumn(layout, 1);
1364         uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
1365         uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE);
1366         uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
1367 }
1368
1369 static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1370 {
1371         uiLayout *sub, *col;
1372         
1373         col= uiLayoutColumn(layout, 0);
1374         uiItemL(col, "Bokeh Type:", ICON_NONE);
1375         uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE);
1376         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
1377
1378         uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
1379
1380         col = uiLayoutColumn(layout, 0);
1381         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer")==1);
1382         uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE);
1383
1384         uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
1385         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
1386
1387         col = uiLayoutColumn(layout, 0);
1388         uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
1389         sub = uiLayoutColumn(col, 0);
1390         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_preview"));
1391         uiItemR(sub, ptr, "samples", 0, NULL, ICON_NONE);
1392         
1393         col = uiLayoutColumn(layout, 0);
1394         uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
1395         sub = uiLayoutColumn(col, 0);
1396         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer")==0);
1397         uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE);
1398 }
1399
1400 /* qdn: glare node */
1401 static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1402 {       
1403         uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE);
1404         uiItemR(layout, ptr, "quality", 0, "", ICON_NONE);
1405
1406         if (RNA_enum_get(ptr, "glare_type")!= 1) {
1407                 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
1408         
1409                 if (RNA_enum_get(ptr, "glare_type")!= 0) 
1410                         uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1411         }
1412         
1413         uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE);
1414         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
1415
1416         if (RNA_enum_get(ptr, "glare_type")== 2) {
1417                 uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE);
1418                 uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE);
1419         }
1420         if (RNA_enum_get(ptr, "glare_type")== 0 || RNA_enum_get(ptr, "glare_type")== 2) {
1421                 uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1422                 
1423                 if (RNA_enum_get(ptr, "glare_type")== 0) 
1424                         uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE);
1425         }
1426         if (RNA_enum_get(ptr, "glare_type")== 1) {
1427                 uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE);
1428         }
1429 }
1430
1431 static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1432 {       
1433         uiLayout *col;
1434
1435         col = uiLayoutColumn(layout, 0);
1436         uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE);
1437         if (RNA_enum_get(ptr, "tonemap_type")== 0) {
1438                 uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1439                 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
1440                 uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE);
1441         }
1442         else {
1443                 uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE);
1444                 uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1445                 uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1446                 uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1447         }
1448 }
1449
1450 static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1451 {
1452         uiLayout *col;
1453
1454         col= uiLayoutColumn(layout, 0);
1455         uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE);
1456
1457         col = uiLayoutColumn(col, 0);
1458         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector")==0);
1459         uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE);
1460         uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE);
1461 }
1462
1463 static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1464 {
1465         uiLayout *col;
1466         
1467         col= uiLayoutColumn(layout, 0);
1468         uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE);
1469         uiItemR(col, ptr, "factor", 0, "Blur", ICON_NONE);
1470         
1471         col= uiLayoutColumn(layout, 1);
1472         uiItemL(col, "Speed:", ICON_NONE);
1473         uiItemR(col, ptr, "speed_min", 0, "Min", ICON_NONE);
1474         uiItemR(col, ptr, "speed_max", 0, "Max", ICON_NONE);
1475
1476         uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE);
1477 }
1478
1479 static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1480 {
1481         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
1482 }
1483
1484 static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1485 {
1486         uiItemR(layout, ptr, "axis", 0, "", ICON_NONE);
1487 }
1488
1489 static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1490 {
1491         uiLayout *col;
1492
1493         uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE);
1494         uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE);
1495
1496         col= uiLayoutColumn(layout, 1);
1497         if (RNA_boolean_get(ptr, "relative")){
1498                 uiItemR(col, ptr, "rel_min_x", 0, "Left", ICON_NONE);
1499                 uiItemR(col, ptr, "rel_max_x", 0, "Right", ICON_NONE);
1500                 uiItemR(col, ptr, "rel_min_y", 0, "Up", ICON_NONE);
1501                 uiItemR(col, ptr, "rel_max_y", 0, "Down", ICON_NONE);
1502         } else {
1503                 uiItemR(col, ptr, "min_x", 0, "Left", ICON_NONE);
1504                 uiItemR(col, ptr, "max_x", 0, "Right", ICON_NONE);
1505                 uiItemR(col, ptr, "min_y", 0, "Up", ICON_NONE);
1506                 uiItemR(col, ptr, "max_y", 0, "Down", ICON_NONE);
1507         }
1508 }
1509
1510 static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1511 {
1512         uiLayout *row, *col;
1513         
1514         col= uiLayoutColumn(layout, 0);
1515         row= uiLayoutRow(col, 0);
1516         uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1517         uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
1518 }
1519
1520 static void node_composit_buts_double_edge_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1521 {
1522         uiLayout *col;
1523
1524         col= uiLayoutColumn(layout, 0);
1525
1526         uiItemL(col, "Inner Edge:", ICON_NONE);
1527         uiItemR(col, ptr, "inner_mode", 0, "", ICON_NONE);
1528         uiItemL(col, "Buffer Edge:", ICON_NONE);
1529         uiItemR(col, ptr, "edge_mode", 0, "", ICON_NONE);
1530 }
1531
1532 static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1533 {
1534         uiLayout *sub, *col;
1535         
1536         col = uiLayoutColumn(layout, 1);
1537         uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
1538         uiItemR(col, ptr, "size", 0, NULL, ICON_NONE);
1539         
1540         col = uiLayoutColumn(layout, 1);
1541         uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE);
1542         sub = uiLayoutColumn(col, 0);
1543         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min"));
1544         uiItemR(sub, ptr, "min", 0, "", ICON_NONE);
1545         
1546         col = uiLayoutColumn(layout, 1);
1547         uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE);
1548         sub = uiLayoutColumn(col, 0);
1549         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max"));
1550         uiItemR(sub, ptr, "max", 0, "", ICON_NONE);
1551 }
1552
1553 static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1554 {       
1555         uiLayout *col;
1556         
1557         col = uiLayoutColumn(layout, 1);
1558         uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE);
1559         uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE);
1560 }
1561
1562 static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1563 {       
1564         uiLayout *col;
1565         
1566         col = uiLayoutColumn(layout, 1);
1567         uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE);
1568 }
1569
1570
1571 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1572 {
1573         uiLayout *col;
1574         
1575         col = uiLayoutColumn(layout, 0);
1576         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1577         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1578         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1579 }
1580
1581 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1582 {
1583         uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
1584 }
1585
1586 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1587 {
1588         uiLayout *col;
1589         
1590         col = uiLayoutColumn(layout, 1);
1591         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1592         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1593 }
1594
1595 static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1596 {
1597         uiLayout *col;
1598         
1599         col = uiLayoutColumn(layout, 1);
1600         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1601         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1602 }
1603
1604 static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1605 {
1606         uiLayout *row, *col;
1607         
1608         uiItemL(layout, "Despill Channel:", ICON_NONE);
1609         row = uiLayoutRow(layout,0);
1610         uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1611
1612         col= uiLayoutColumn(layout, 0);
1613         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
1614
1615         if(RNA_enum_get(ptr, "limit_method")==0) {
1616                 uiItemL(col, "Limiting Channel:", ICON_NONE);
1617                 row=uiLayoutRow(col,0);
1618                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1619         }
1620
1621         uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1622         uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE);
1623         if (RNA_boolean_get(ptr, "use_unspill")== 1) {
1624                 uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1625                 uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1626                 uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1627         }
1628 }
1629
1630 static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1631 {
1632         uiLayout *col;
1633         
1634         col= uiLayoutColumn(layout, 0);
1635         uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE);
1636         uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
1637         
1638         col= uiLayoutColumn(layout, 1);
1639         /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now */
1640         uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1641         /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now*/
1642 }
1643
1644 static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1645 {
1646         uiLayout *col;
1647         
1648         col= uiLayoutColumn(layout, 1);
1649         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1650         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1651         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1652 }
1653
1654 static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1655 {       
1656         uiLayout *col, *row;
1657
1658         uiItemL(layout, "Color Space:", ICON_NONE);
1659         row= uiLayoutRow(layout, 0);
1660         uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1661
1662         col=uiLayoutColumn(layout, 0);
1663         uiItemL(col, "Key Channel:", ICON_NONE);
1664         row= uiLayoutRow(col, 0);
1665         uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1666
1667         col = uiLayoutColumn(layout, 0);
1668
1669         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
1670         if(RNA_enum_get(ptr, "limit_method")==0) {
1671                 uiItemL(col, "Limiting Channel:", ICON_NONE);
1672                 row=uiLayoutRow(col,0);
1673                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1674         }
1675
1676         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1677         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1678 }
1679
1680 static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1681 {
1682         uiLayout *col;
1683         
1684         col= uiLayoutColumn(layout, 1);
1685         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1686         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1687 }
1688
1689 static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1690 {
1691         uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE);
1692 }
1693
1694 static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1695 {
1696         uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE);
1697         uiItemR(layout, ptr, "use_smooth_mask", 0, NULL, ICON_NONE);
1698 }
1699
1700 static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1701 {
1702         bNode *node= ptr->data;
1703         NodeImageFile *nif= node->storage;
1704         PointerRNA imfptr;
1705
1706         uiLayout *row;
1707
1708         uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
1709
1710         RNA_pointer_create(NULL, &RNA_ImageFormatSettings, &nif->im_format, &imfptr);
1711         uiTemplateImageSettings(layout, &imfptr);
1712
1713         row= uiLayoutRow(layout, 1);
1714         uiItemR(row, ptr, "frame_start", 0, "Start", ICON_NONE);
1715         uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
1716 }
1717
1718 static void node_composit_buts_multi_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1719 {
1720         uiItemL(layout, "Base Path:", 0);
1721         uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE);
1722 }
1723 static void node_composit_buts_multi_file_output_details(uiLayout *layout, bContext *C, PointerRNA *ptr)
1724 {
1725         PointerRNA active_input_ptr = RNA_pointer_get(ptr, "active_input");
1726         
1727         node_composit_buts_multi_file_output(layout, C, ptr);
1728         
1729         uiItemO(layout, "Add Input", ICON_ZOOMIN, "NODE_OT_output_multi_file_add_socket");
1730         
1731         uiTemplateList(layout, C, ptr, "inputs", ptr, "active_input_index", NULL, 0, 0, 0);
1732         
1733         if (active_input_ptr.data) {
1734                 PointerRNA imfptr = RNA_pointer_get(&active_input_ptr, "format");
1735                 uiLayout *row, *col;
1736                 
1737                 col = uiLayoutColumn(layout, 1);
1738                 uiItemL(col, "File Path:", 0);
1739                 row = uiLayoutRow(col, 0);
1740                 uiItemR(row, &active_input_ptr, "name", 0, "", 0);
1741                 uiItemFullO(row, "NODE_OT_output_multi_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY);
1742                 
1743                 uiItemS(layout);
1744                 
1745                 col = uiLayoutColumn(layout, 1);
1746                 uiItemL(col, "Format:", 0);
1747                 uiItemR(col, &active_input_ptr, "use_render_format", 0, NULL, 0);
1748                 
1749                 col= uiLayoutColumn(layout, 0);
1750                 uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_render_format")==0);
1751                 uiTemplateImageSettings(col, &imfptr);
1752         }
1753 }
1754
1755 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1756 {
1757         uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
1758 }
1759
1760 static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1761 {
1762         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
1763 }
1764
1765 static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1766 {
1767         uiLayout *col;
1768         
1769         col= uiLayoutColumn(layout, 0);
1770         uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE);
1771         uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE);
1772 }
1773
1774 static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1775 {
1776         uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
1777 }
1778
1779 static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1780 {
1781         uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1782 }
1783
1784 static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1785 {
1786         uiLayout *split, *col, *row;
1787         
1788         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
1789         
1790         if (RNA_enum_get(ptr, "correction_method")== 0) {
1791         
1792                 split = uiLayoutSplit(layout, 0, 0);
1793                 col = uiLayoutColumn(split, 0);
1794                 uiTemplateColorWheel(col, ptr, "lift", 1, 1, 0, 1);
1795                 row = uiLayoutRow(col, 0);
1796                 uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE);
1797                 
1798                 col = uiLayoutColumn(split, 0);
1799                 uiTemplateColorWheel(col, ptr, "gamma", 1, 1, 1, 1);
1800                 row = uiLayoutRow(col, 0);
1801                 uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE);
1802                 
1803                 col = uiLayoutColumn(split, 0);
1804                 uiTemplateColorWheel(col, ptr, "gain", 1, 1, 1, 1);
1805                 row = uiLayoutRow(col, 0);
1806                 uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE);
1807
1808         } else {
1809                 
1810                 split = uiLayoutSplit(layout, 0, 0);
1811                 col = uiLayoutColumn(split, 0);
1812                 uiTemplateColorWheel(col, ptr, "offset", 1, 1, 0, 1);
1813                 row = uiLayoutRow(col, 0);
1814                 uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE);
1815                 
1816                 col = uiLayoutColumn(split, 0);
1817                 uiTemplateColorWheel(col, ptr, "power", 1, 1, 0, 1);
1818                 row = uiLayoutRow(col, 0);
1819                 uiItemR(row, ptr, "power", 0, NULL, ICON_NONE);
1820                 
1821                 col = uiLayoutColumn(split, 0);
1822                 uiTemplateColorWheel(col, ptr, "slope", 1, 1, 0, 1);
1823                 row = uiLayoutRow(col, 0);
1824                 uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE);
1825         }
1826
1827 }
1828 static void node_composit_buts_colorbalance_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1829 {
1830         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
1831
1832         if (RNA_enum_get(ptr, "correction_method")== 0) {
1833
1834         uiTemplateColorWheel(layout, ptr, "lift", 1, 1, 0, 1);
1835                 uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE);
1836
1837                 uiTemplateColorWheel(layout, ptr, "gamma", 1, 1, 1, 1);
1838                 uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE);
1839
1840                 uiTemplateColorWheel(layout, ptr, "gain", 1, 1, 1, 1);
1841                 uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE);
1842         } else {
1843                 uiTemplateColorWheel(layout, ptr, "offset", 1, 1, 0, 1);
1844                 uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE);
1845
1846                 uiTemplateColorWheel(layout, ptr, "power", 1, 1, 0, 1);
1847                 uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE);
1848
1849                 uiTemplateColorWheel(layout, ptr, "slope", 1, 1, 0, 1);
1850                 uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE);
1851         }
1852 }
1853
1854
1855 static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1856 {
1857         uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0);
1858 }
1859
1860 static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1861
1862         uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
1863 }
1864
1865 static void node_composit_buts_movieclip(uiLayout *layout, bContext *C, PointerRNA *ptr)
1866 {
1867         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
1868 }
1869
1870 static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, PointerRNA *ptr)
1871 {
1872         bNode *node= ptr->data;
1873
1874         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
1875
1876         if(!node->id)
1877                 return;
1878
1879         uiItemR(layout, ptr, "filter_type", 0, "", 0);
1880 }
1881
1882 static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1883 {
1884         uiItemR(layout, ptr, "filter_type", 0, "", 0);
1885 }
1886
1887 static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr)
1888 {
1889         bNode *node= ptr->data;
1890
1891         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
1892
1893         if(!node->id)
1894                 return;
1895
1896         uiItemR(layout, ptr, "distortion_type", 0, "", 0);
1897 }
1898
1899 /* only once called */
1900 static void node_composit_set_butfunc(bNodeType *ntype)
1901 {
1902         ntype->uifuncbut = NULL;
1903         switch(ntype->type) {
1904                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
1905
1906                 case CMP_NODE_IMAGE:
1907                         ntype->uifunc= node_composit_buts_image;
1908                         break;
1909                 case CMP_NODE_R_LAYERS:
1910                         ntype->uifunc= node_composit_buts_renderlayers;
1911                         break;
1912                 case CMP_NODE_NORMAL:
1913                         ntype->uifunc= node_buts_normal;
1914                         break;
1915                 case CMP_NODE_CURVE_VEC:
1916                         ntype->uifunc= node_buts_curvevec;
1917                         break;
1918                 case CMP_NODE_CURVE_RGB:
1919                         ntype->uifunc= node_buts_curvecol;
1920                         break;
1921                 case CMP_NODE_VALUE:
1922                         ntype->uifunc= node_buts_value;
1923                         break;
1924                 case CMP_NODE_RGB:
1925                         ntype->uifunc= node_buts_rgb;
1926                         break;
1927                 case CMP_NODE_FLIP:
1928                         ntype->uifunc= node_composit_buts_flip;
1929                         break;
1930                 case CMP_NODE_SPLITVIEWER:
1931                         ntype->uifunc= node_composit_buts_splitviewer;
1932                         break;
1933                 case CMP_NODE_MIX_RGB:
1934                         ntype->uifunc= node_buts_mix_rgb;
1935                         break;
1936                 case CMP_NODE_VALTORGB:
1937                         ntype->uifunc= node_buts_colorramp;
1938                         break;
1939                 case CMP_NODE_CROP:
1940                         ntype->uifunc= node_composit_buts_crop;
1941                         break;
1942                 case CMP_NODE_BLUR:
1943                         ntype->uifunc= node_composit_buts_blur;
1944                         break;
1945                 case CMP_NODE_DBLUR:
1946                         ntype->uifunc= node_composit_buts_dblur;
1947                         break;
1948                 case CMP_NODE_BILATERALBLUR:
1949                         ntype->uifunc= node_composit_buts_bilateralblur;
1950                         break;
1951                 case CMP_NODE_DEFOCUS:
1952                         ntype->uifunc = node_composit_buts_defocus;
1953                         break;
1954                 case CMP_NODE_GLARE:
1955                         ntype->uifunc = node_composit_buts_glare;
1956                         break;
1957                 case CMP_NODE_TONEMAP:
1958                         ntype->uifunc = node_composit_buts_tonemap;
1959                         break;
1960                 case CMP_NODE_LENSDIST:
1961                         ntype->uifunc = node_composit_buts_lensdist;
1962                         break;
1963                 case CMP_NODE_VECBLUR:
1964                         ntype->uifunc= node_composit_buts_vecblur;
1965                         break;
1966                 case CMP_NODE_FILTER:
1967                         ntype->uifunc= node_composit_buts_filter;
1968                         break;
1969                 case CMP_NODE_MAP_VALUE:
1970                         ntype->uifunc= node_composit_buts_map_value;
1971                         break;
1972                 case CMP_NODE_TIME:
1973                         ntype->uifunc= node_buts_time;
1974                         break;
1975                 case CMP_NODE_ALPHAOVER:
1976                         ntype->uifunc= node_composit_buts_alphaover;
1977                         break;
1978                 case CMP_NODE_HUE_SAT:
1979                         ntype->uifunc= node_composit_buts_hue_sat;
1980                         break;
1981                 case CMP_NODE_TEXTURE:
1982                         ntype->uifunc= node_buts_texture;
1983                         break;
1984                 case CMP_NODE_DILATEERODE:
1985                         ntype->uifunc= node_composit_buts_dilateerode;
1986                         break;
1987                 case CMP_NODE_OUTPUT_FILE:
1988                         ntype->uifunc= node_composit_buts_file_output;
1989                         break;
1990                 case CMP_NODE_OUTPUT_MULTI_FILE:
1991                         ntype->uifunc= node_composit_buts_multi_file_output;
1992                         ntype->uifuncbut= node_composit_buts_multi_file_output_details;
1993                         break;
1994                 case CMP_NODE_DIFF_MATTE:
1995                         ntype->uifunc=node_composit_buts_diff_matte;
1996                         break;
1997                 case CMP_NODE_DIST_MATTE:
1998                         ntype->uifunc=node_composit_buts_distance_matte;
1999                         break;
2000                 case CMP_NODE_COLOR_SPILL:
2001                         ntype->uifunc=node_composit_buts_color_spill;
2002                         break;
2003                 case CMP_NODE_CHROMA_MATTE:
2004                         ntype->uifunc=node_composit_buts_chroma_matte;
2005                         break;
2006                 case CMP_NODE_COLOR_MATTE:
2007                         ntype->uifunc=node_composit_buts_color_matte;
2008                         break;
2009                 case CMP_NODE_SCALE:
2010                         ntype->uifunc= node_composit_buts_scale;
2011                         break;
2012                 case CMP_NODE_ROTATE:
2013                         ntype->uifunc=node_composit_buts_rotate;
2014                         break;
2015                 case CMP_NODE_CHANNEL_MATTE:
2016                         ntype->uifunc= node_composit_buts_channel_matte;
2017                         break;
2018                 case CMP_NODE_LUMA_MATTE:
2019                         ntype->uifunc= node_composit_buts_luma_matte;
2020                         break;
2021                 case CMP_NODE_MAP_UV:
2022                         ntype->uifunc= node_composit_buts_map_uv;
2023                         break;
2024                 case CMP_NODE_ID_MASK:
2025                         ntype->uifunc= node_composit_buts_id_mask;
2026                         break;
2027                 case CMP_NODE_DOUBLEEDGEMASK:
2028                         ntype->uifunc= node_composit_buts_double_edge_mask;
2029                         break;
2030                 case CMP_NODE_MATH:
2031                         ntype->uifunc= node_buts_math;
2032                         break;
2033                 case CMP_NODE_INVERT:
2034                         ntype->uifunc= node_composit_buts_invert;
2035                         break;
2036                 case CMP_NODE_PREMULKEY:
2037                         ntype->uifunc= node_composit_buts_premulkey;
2038                         break;
2039                 case CMP_NODE_VIEW_LEVELS:
2040                         ntype->uifunc=node_composit_buts_view_levels;
2041                         break;
2042                 case CMP_NODE_COLORBALANCE:
2043                         ntype->uifunc=node_composit_buts_colorbalance;
2044                         ntype->uifuncbut=node_composit_buts_colorbalance_but;
2045                         break;
2046                 case CMP_NODE_HUECORRECT:
2047                         ntype->uifunc=node_composit_buts_huecorrect;
2048                         break;
2049                 case CMP_NODE_ZCOMBINE:
2050                         ntype->uifunc=node_composit_buts_zcombine;
2051                         break;
2052                 case CMP_NODE_COMBYCCA:
2053                 case CMP_NODE_SEPYCCA:
2054                         ntype->uifunc=node_composit_buts_ycc;
2055                         break;
2056                 case CMP_NODE_MOVIECLIP:
2057                         ntype->uifunc= node_composit_buts_movieclip;
2058                         break;
2059                 case CMP_NODE_STABILIZE2D:
2060                         ntype->uifunc= node_composit_buts_stabilize2d;
2061                         break;
2062                 case CMP_NODE_TRANSFORM:
2063                         ntype->uifunc= node_composit_buts_transform;
2064                         break;
2065                 case CMP_NODE_MOVIEDISTORTION:
2066                         ntype->uifunc= node_composit_buts_moviedistortion;
2067                         break;
2068                 default:
2069                         ntype->uifunc= NULL;
2070         }
2071         if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
2072
2073 }
2074
2075 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
2076
2077 static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2078 {
2079         uiLayout *col;
2080         
2081         col= uiLayoutColumn(layout, 1);
2082         uiItemR(col, ptr, "offset", 0, "Offset", ICON_NONE);
2083         uiItemR(col, ptr, "offset_frequency", 0, "Frequency", ICON_NONE);
2084         
2085         col= uiLayoutColumn(layout, 1);
2086         uiItemR(col, ptr, "squash", 0, "Squash", ICON_NONE);
2087         uiItemR(col, ptr, "squash_frequency", 0, "Frequency", ICON_NONE);
2088 }
2089
2090 static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2091 {
2092         PointerRNA tex_ptr;
2093         bNode *node= ptr->data;
2094         ID *id= ptr->id.data;
2095         Tex *tex = (Tex *)node->storage;
2096         uiLayout *col, *row;
2097         
2098         RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr);
2099
2100         col= uiLayoutColumn(layout, 0);
2101
2102         switch( tex->type ) {
2103                 case TEX_BLEND:
2104                         uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE);
2105                         row= uiLayoutRow(col, 0);
2106                         uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2107                         break;
2108
2109                 case TEX_MARBLE:
2110                         row= uiLayoutRow(col, 0);
2111                         uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2112                         row= uiLayoutRow(col, 0);
2113                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2114                         row= uiLayoutRow(col, 0);
2115                         uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2116                         row= uiLayoutRow(col, 0);
2117                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2118                         break;
2119
2120                 case TEX_MAGIC:
2121                         uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE);
2122                         break;
2123
2124                 case TEX_STUCCI:
2125                         row= uiLayoutRow(col, 0);
2126                         uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2127                         row= uiLayoutRow(col, 0);
2128                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2129                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2130                         break;
2131
2132                 case TEX_WOOD:
2133                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2134                         uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE);
2135                         row= uiLayoutRow(col, 0);
2136                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2137                         row= uiLayoutRow(col, 0);
2138                         uiLayoutSetActive(row, !(RNA_enum_get(&tex_ptr, "wood_type")==TEX_BAND || RNA_enum_get(&tex_ptr, "wood_type")==TEX_RING)); 
2139                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2140                         break;
2141                         
2142                 case TEX_CLOUDS:
2143                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2144                         row= uiLayoutRow(col, 0);
2145                         uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2146                         row= uiLayoutRow(col, 0);
2147                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2148                         uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, "Depth", ICON_NONE);
2149                         break;
2150                         
2151                 case TEX_DISTNOISE:
2152                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2153                         uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE);
2154                         break;
2155
2156                 case TEX_MUSGRAVE:
2157                         uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE);
2158                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2159                         break;
2160                 case TEX_VORONOI:
2161                         uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE);
2162                         if(tex->vn_distm == TEX_MINKOVSKY) {
2163                                 uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE);
2164                         }
2165                         uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE);
2166                         break;
2167         }
2168 }
2169
2170 static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
2171 {
2172         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
2173 }
2174
2175 static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2176 {
2177         uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
2178 }
2179
2180 /* only once called */
2181 static void node_texture_set_butfunc(bNodeType *ntype)
2182 {
2183         ntype->uifuncbut = NULL;
2184         if( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
2185                 ntype->uifunc = node_texture_buts_proc;
2186         }
2187         else switch(ntype->type) {
2188                 
2189                 case TEX_NODE_MATH:
2190                         ntype->uifunc = node_buts_math;
2191                         break;
2192                 
2193                 case TEX_NODE_MIX_RGB:
2194                         ntype->uifunc = node_buts_mix_rgb;
2195                         break;
2196                         
2197                 case TEX_NODE_VALTORGB:
2198                         ntype->uifunc = node_buts_colorramp;
2199                         break;
2200                         
2201                 case TEX_NODE_CURVE_RGB:
2202                         ntype->uifunc= node_buts_curvecol;
2203                         break;
2204                         
2205                 case TEX_NODE_CURVE_TIME:
2206                         ntype->uifunc = node_buts_time;
2207                         break;
2208                         
2209                 case TEX_NODE_TEXTURE:
2210                         ntype->uifunc = node_buts_texture;
2211                         break;
2212                         
2213                 case TEX_NODE_BRICKS:
2214                         ntype->uifunc = node_texture_buts_bricks;
2215                         break;
2216                         
2217                 case TEX_NODE_IMAGE:
2218                         ntype->uifunc = node_texture_buts_image;
2219                         break;
2220                         
2221                 case TEX_NODE_OUTPUT:
2222                         ntype->uifunc = node_texture_buts_output;
2223                         break;
2224         }
2225         if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
2226 }
2227
2228 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
2229
2230 void ED_init_node_butfuncs(void)
2231 {
2232         bNodeTreeType *treetype;
2233         bNodeType *ntype;
2234         bNodeSocketType *stype;
2235         int i;
2236         
2237         /* node type ui functions */
2238         for (i=0; i < NUM_NTREE_TYPES; ++i) {
2239                 treetype = ntreeGetType(i);
2240                 if (treetype) {
2241                         for (ntype= treetype->node_types.first; ntype; ntype= ntype->next) {
2242                                 /* default ui functions */
2243                                 ntype->drawfunc = node_draw_default;
2244                                 ntype->drawupdatefunc = node_update_default;
2245                                 ntype->uifunc = NULL;
2246                                 ntype->uifuncbut = NULL;
2247                                 ntype->resize_area_func = node_resize_area_default;
2248                                 
2249                                 node_common_set_butfunc(ntype);
2250                                 
2251                                 switch (i) {
2252                                 case NTREE_COMPOSIT:
2253                                         node_composit_set_butfunc(ntype);
2254                                         break;
2255                                 case NTREE_SHADER:
2256                                         node_shader_set_butfunc(ntype);
2257                                         break;
2258                                 case NTREE_TEXTURE:
2259                                         node_texture_set_butfunc(ntype);
2260                                         break;
2261                                 }
2262                         }
2263                 }
2264         }
2265         
2266         /* socket type ui functions */
2267         for (i=0; i < NUM_SOCKET_TYPES; ++i) {
2268                 stype = ntreeGetSocketType(i);
2269                 if (stype) {
2270                         switch(stype->type) {
2271                         case SOCK_FLOAT:
2272                         case SOCK_INT:
2273                         case SOCK_BOOLEAN:
2274                                 stype->buttonfunc = node_socket_button_default;
2275                                 break;
2276                         case SOCK_VECTOR:
2277                                 stype->buttonfunc = node_socket_button_components;
2278                                 break;
2279                         case SOCK_RGBA:
2280                                 stype->buttonfunc = node_socket_button_color;
2281                                 break;
2282                         case SOCK_SHADER:
2283                                 stype->buttonfunc = node_socket_button_label;
2284                                 break;
2285                         default:
2286                                 stype->buttonfunc = NULL;
2287                         }
2288                 }
2289         }
2290 }
2291
2292 /* ************** Generic drawing ************** */
2293
2294 void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
2295 {
2296         
2297         if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
2298                 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2299                 void *lock;
2300                 ImBuf *ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
2301                 if(ibuf) {
2302                         float x, y; 
2303                         
2304                         glMatrixMode(GL_PROJECTION);
2305                         glPushMatrix();
2306                         glMatrixMode(GL_MODELVIEW);
2307                         glPushMatrix();
2308
2309                         /* keep this, saves us from a version patch */
2310                         if(snode->zoom==0.0f) snode->zoom= 1.0f;
2311                         
2312                         /* somehow the offset has to be calculated inverse */
2313                         
2314                         glaDefine2DArea(&ar->winrct);
2315                         /* ortho at pixel level curarea */
2316                         wmOrtho2(-0.375, ar->winx-0.375, -0.375, ar->winy-0.375);
2317                         
2318                         x = (ar->winx-snode->zoom*ibuf->x)/2 + snode->xof;
2319                         y = (ar->winy-snode->zoom*ibuf->y)/2 + snode->yof;
2320                         
2321                         if(!ibuf->rect) {
2322                                 if(color_manage)
2323                                         ibuf->profile = IB_PROFILE_LINEAR_RGB;
2324                                 else
2325                                         ibuf->profile = IB_PROFILE_NONE;
2326                                 IMB_rect_from_float(ibuf);
2327                         }
2328
2329                         if(ibuf->rect) {
2330                                 if (snode->flag & SNODE_SHOW_ALPHA) {
2331                                         glPixelZoom(snode->zoom, snode->zoom);
2332                                         /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
2333                                         if(ENDIAN_ORDER == B_ENDIAN)
2334                                                 glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
2335                                         
2336                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
2337                                         
2338                                         glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
2339                                         glPixelZoom(1.0f, 1.0f);
2340                                 } else if (snode->flag & SNODE_USE_ALPHA) {
2341                                         glEnable(GL_BLEND);
2342                                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2343                                         glPixelZoom(snode->zoom, snode->zoom);
2344                                         
2345                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2346                                         
2347                                         glPixelZoom(1.0f, 1.0f);
2348                                         glDisable(GL_BLEND);
2349                                 } else {
2350                                         glPixelZoom(snode->zoom, snode->zoom);
2351                                         
2352                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2353                                         
2354                                         glPixelZoom(1.0f, 1.0f);
2355                                 }
2356                         }
2357                         
2358                         glMatrixMode(GL_PROJECTION);
2359                         glPopMatrix();
2360                         glMatrixMode(GL_MODELVIEW);
2361                         glPopMatrix();
2362                 }
2363
2364                 BKE_image_release_ibuf(ima, lock);
2365         }
2366 }
2367
2368 #if 0
2369 /* note: needs to be userpref or opengl profile option */
2370 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
2371 {
2372
2373         draw_nodespace_grid(snode);
2374         
2375         if(snode->flag & SNODE_BACKDRAW) {
2376                 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2377                 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
2378                 if(ibuf) {
2379                         int x, y;
2380                         float zoom = 1.0;
2381
2382                         glMatrixMode(GL_PROJECTION);
2383                         glPushMatrix();
2384                         glMatrixMode(GL_MODELVIEW);
2385                         glPushMatrix();
2386                         
2387                         glaDefine2DArea(&sa->winrct);
2388
2389                         if(ibuf->x > sa->winx || ibuf->y > sa->winy) {
2390                                 float zoomx, zoomy;
2391                                 zoomx= (float)sa->winx/ibuf->x;
2392                                 zoomy= (float)sa->winy/ibuf->y;
2393                                 zoom = MIN2(zoomx, zoomy);
2394                         }
2395                         
2396                         x = (sa->winx-zoom*ibuf->x)/2 + snode->xof;
2397                         y = (sa->winy-zoom*ibuf->y)/2 + snode->yof;
2398
2399                         glPixelZoom(zoom, zoom);
2400
2401                         glColor4f(1.0, 1.0, 1.0, 1.0);
2402                         if(ibuf->rect)
2403                                 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
2404                         else if(ibuf->channels==4)
2405                                 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
2406
2407                         glPixelZoom(1.0, 1.0);
2408
2409                         glMatrixMode(GL_PROJECTION);
2410                         glPopMatrix();
2411                         glMatrixMode(GL_MODELVIEW);
2412                         glPopMatrix();
2413                 }
2414         }
2415 }
2416 #endif
2417
2418 /* if v2d not NULL, it clips and returns 0 if not visible */
2419 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
2420 {
2421         float dist, vec[4][2];
2422         
2423         /* in v0 and v3 we put begin/end points */
2424         if(link->fromsock) {
2425                 vec[0][0]= link->fromsock->locx;
2426                 vec[0][1]= link->fromsock->locy;
2427         }
2428         else {
2429                 if(snode==NULL) return 0;
2430                 vec[0][0]= snode->mx;
2431                 vec[0][1]= snode->my;
2432         }
2433         if(link->tosock) {
2434                 vec[3][0]= link->tosock->locx;
2435                 vec[3][1]= link->tosock->locy;
2436         }
2437         else {
2438                 if(snode==NULL) return 0;
2439                 vec[3][0]= snode->mx;
2440                 vec[3][1]= snode->my;
2441         }
2442
2443         dist= UI_GetThemeValue(TH_NODE_CURVING)*0.10f*ABS(vec[0][0] - vec[3][0]);
2444         
2445         /* check direction later, for top sockets */
2446         vec[1][0]= vec[0][0]+dist;
2447         vec[1][1]= vec[0][1];
2448         
2449         vec[2][0]= vec[3][0]-dist;
2450         vec[2][1]= vec[3][1];
2451         
2452         if(v2d && MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax); /* clipped */      
2453         else if (v2d && MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin); /* clipped */
2454         else {
2455                 
2456                 /* always do all three, to prevent data hanging around */
2457                 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
2458                 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
2459                 
2460                 return 1;
2461         }
2462         return 0;
2463 }
2464
2465 #define LINK_RESOL      24
2466 void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 )
2467 {
2468         float coord_array[LINK_RESOL+1][2];
2469         
2470         if(node_link_bezier_points(v2d, snode, link, coord_array, LINK_RESOL)) {
2471                 float dist, spline_step = 0.0f;
2472                 int i;
2473                 
2474                 /* store current linewidth */
2475                 float linew;
2476                 glGetFloatv(GL_LINE_WIDTH, &linew);
2477                 
2478                 /* we can reuse the dist variable here to increment the GL curve eval amount*/
2479                 dist = 1.0f/(float)LINK_RESOL;
2480                 
2481                 glEnable(GL_LINE_SMOOTH);
2482                 
2483                 if(do_triple) {
2484                         UI_ThemeColorShadeAlpha(th_col3, -80, -120);
2485                         glLineWidth(4.0f);
2486                         
2487                         glBegin(GL_LINE_STRIP);
2488                         for(i=0; i<=LINK_RESOL; i++) {
2489                                 glVertex2fv(coord_array[i]);
2490                         }
2491                         glEnd();
2492                 }
2493                 
2494                 /* XXX using GL_LINES for shaded node lines is a workaround
2495                  * for Intel hardware, this breaks with GL_LINE_STRIP and
2496                  * changing color in begin/end blocks.
2497                  */
2498                 glLineWidth(1.5f);
2499                 if(do_shaded) {
2500                         glBegin(GL_LINES);
2501                         for(i=0; i<LINK_RESOL; i++) {
2502                                 UI_ThemeColorBlend(th_col1, th_col2, spline_step);
2503                                 glVertex2fv(coord_array[i]);
2504                                 
2505                                 UI_ThemeColorBlend(th_col1, th_col2, spline_step+dist);
2506                                 glVertex2fv(coord_array[i+1]);
2507                                 
2508                                 spline_step += dist;
2509                         }
2510                         glEnd();
2511                 }
2512                 else {
2513                         UI_ThemeColor(th_col1);
2514                         glBegin(GL_LINE_STRIP);
2515                         for(i=0; i<=LINK_RESOL; i++) {
2516                                 glVertex2fv(coord_array[i]);
2517                         }
2518                         glEnd();
2519                 }
2520                 
2521                 glDisable(GL_LINE_SMOOTH);
2522                 
2523                 /* restore previuos linewidth */
2524                 glLineWidth(linew);
2525         }
2526 }
2527
2528 static void node_link_straight_points(View2D *UNUSED(v2d), SpaceNode *snode, bNodeLink *link, float coord_array[][2])
2529 {
2530         if(link->fromsock) {
2531                 coord_array[0][0]= link->fromsock->locx;
2532                 coord_array[0][1]= link->fromsock->locy;
2533         }
2534         else {
2535                 if(snode==NULL) return;
2536                 coord_array[0][0]= snode->mx;
2537                 coord_array[0][1]= snode->my;
2538         }
2539         if(link->tosock) {
2540                 coord_array[1][0]= link->tosock->locx;
2541                 coord_array[1][1]= link->tosock->locy;
2542         }
2543         else {
2544                 if(snode==NULL) return;
2545                 coord_array[1][0]= snode->mx;
2546                 coord_array[1][1]= snode->my;
2547         }
2548 }
2549
2550 void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 )
2551 {
2552         float coord_array[2][2];
2553         float linew;
2554         int i;
2555         
2556         node_link_straight_points(v2d, snode, link, coord_array);
2557         
2558         /* store current linewidth */
2559         glGetFloatv(GL_LINE_WIDTH, &linew);
2560         
2561         glEnable(GL_LINE_SMOOTH);
2562         
2563         if(do_triple) {
2564                 UI_ThemeColorShadeAlpha(th_col3, -80, -120);
2565                 glLineWidth(4.0f);
2566                 
2567                 glBegin(GL_LINES);
2568                 glVertex2fv(coord_array[0]);
2569                 glVertex2fv(coord_array[1]);
2570                 glEnd();
2571         }
2572         
2573         UI_ThemeColor(th_col1);
2574         glLineWidth(1.5f);
2575         
2576         /* XXX using GL_LINES for shaded node lines is a workaround
2577          * for Intel hardware, this breaks with GL_LINE_STRIP and
2578          * changing color in begin/end blocks.
2579          */
2580         if(do_shaded) {
2581                 glBegin(GL_LINES);
2582                 for (i=0; i < LINK_RESOL-1; ++i) {
2583                         float t= (float)i/(float)(LINK_RESOL-1);
2584                         UI_ThemeColorBlend(th_col1, th_col2, t);
2585                         glVertex2f((1.0f-t)*coord_array[0][0]+t*coord_array[1][0], (1.0f-t)*coord_array[0][1]+t*coord_array[1][1]);
2586                         
2587                         t= (float)(i+1)/(float)(LINK_RESOL-1);
2588                         UI_ThemeColorBlend(th_col1, th_col2, t);
2589                         glVertex2f((1.0f-t)*coord_array[0][0]+t*coord_array[1][0], (1.0f-t)*coord_array[0][1]+t*coord_array[1][1]);
2590                 }
2591                 glEnd();
2592         }
2593         else {
2594                 glBegin(GL_LINE_STRIP);
2595                 for (i=0; i < LINK_RESOL; ++i) {
2596                         float t= (float)i/(float)(LINK_RESOL-1);
2597                         glVertex2f((1.0f-t)*coord_array[0][0]+t*coord_array[1][0], (1.0f-t)*coord_array[0][1]+t*coord_array[1][1]);
2598                 }
2599                 glEnd();
2600         }
2601         
2602         glDisable(GL_LINE_SMOOTH);
2603         
2604         /* restore previuos linewidth */
2605         glLineWidth(linew);
2606 }
2607
2608 /* note; this is used for fake links in groups too */
2609 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
2610 {
2611         int do_shaded= 0, th_col1= TH_HEADER, th_col2= TH_HEADER;
2612         int do_triple= 0, th_col3= TH_WIRE;
2613         
2614         if(link->fromsock==NULL && link->tosock==NULL)
2615                 return;
2616         
2617         /* new connection */
2618         if(!link->fromsock || !link->tosock) {
2619                 th_col1 = TH_ACTIVE;
2620                 do_triple = 1;
2621         }
2622         else {
2623                 /* going to give issues once... */
2624                 if(link->tosock->flag & SOCK_UNAVAIL)
2625                         return;
2626                 if(link->fromsock->flag & SOCK_UNAVAIL)
2627                         return;
2628                 
2629                 /* a bit ugly... but thats how we detect the internal group links */
2630                 if(!link->fromnode || !link->tonode) {
2631                         UI_ThemeColorBlend(TH_BACK, TH_WIRE, 0.5f);
2632                         do_shaded= 0;
2633                 }
2634                 else {
2635                         /* check cyclic */
2636                         if((link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) && (link->flag & NODE_LINK_VALID)) {
2637                                 /* special indicated link, on drop-node */
2638                                 if(link->flag & NODE_LINKFLAG_HILITE) {
2639                                         th_col1= th_col2= TH_ACTIVE;
2640                                 }
2641                                 else {
2642                                         /* regular link */
2643                                         if(link->fromnode->flag & SELECT)
2644                                                 th_col1= TH_EDGE_SELECT;
2645                                         if(link->tonode->flag & SELECT)
2646                                                 th_col2= TH_EDGE_SELECT;
2647                                 }
2648                                 do_shaded= 1;
2649                                 do_triple= 1;
2650                         }                               
2651                         else {
2652                                 th_col1 = TH_REDALERT;
2653                         }
2654                 }
2655         }
2656         
2657         node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
2658 //      node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
2659 }