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