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