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