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