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