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