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