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