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