Merging r50162 through r50171 from trunk into soc-2011-tomato
[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 #define SAMPLE_FLT_ISNONE FLT_MAX
343 static float _sample_col[4] = {SAMPLE_FLT_ISNONE};  /* bad bad, 2.5 will do better?... no it won't... */
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)BLI_RCT_SIZE_X(butr), (short)BLI_RCT_SIZE_X(butr),
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_rctf_isect_pt(&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 = BLI_RCT_CENTER_Y(rect) + (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 = BLI_RCT_CENTER_Y(rect) + (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)(BLI_RCT_SIZE_X(&rect) - 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 = BLI_RCT_CENTER_X(rct) - (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 (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == FALSE) {
1001                 uiEndBlock(C, node->block);
1002                 node->block = NULL;
1003                 return;
1004         }
1005
1006         UI_GetThemeColor4ubv(TH_NODE_FRAME, color);
1007         alpha = (float)(color[3]) / 255.0f;
1008         
1009         /* shadow */
1010         node_draw_shadow(snode, node, BASIS_RAD, alpha);
1011         
1012         /* body */
1013         if (node->flag & NODE_CUSTOM_COLOR)
1014                 glColor4f(node->color[0], node->color[1], node->color[2], alpha);
1015         else
1016                 UI_ThemeColor4(TH_NODE_FRAME);
1017         glEnable(GL_BLEND);
1018         uiSetRoundBox(UI_CNR_ALL);
1019         uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
1020         glDisable(GL_BLEND);
1021
1022         /* outline active and selected emphasis */
1023         if (node->flag & SELECT) {
1024                 glEnable(GL_BLEND);
1025                 glEnable(GL_LINE_SMOOTH);
1026                 
1027                 if (node->flag & NODE_ACTIVE)
1028                         UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -40);
1029                 else
1030                         UI_ThemeColorShadeAlpha(TH_SELECT, 0, -40);
1031                 uiSetRoundBox(UI_CNR_ALL);
1032                 uiDrawBox(GL_LINE_LOOP,
1033                           rct->xmin, rct->ymin,
1034                           rct->xmax, rct->ymax, BASIS_RAD);
1035                 
1036                 glDisable(GL_LINE_SMOOTH);
1037                 glDisable(GL_BLEND);
1038         }
1039         
1040         /* label */
1041         node_draw_frame_label(node, snode->aspect);
1042         
1043         UI_ThemeClearColor(color_id);
1044                 
1045         uiEndBlock(C, node->block);
1046         uiDrawBlock(C, node->block);
1047         node->block = NULL;
1048 }
1049
1050 static int node_resize_area_frame(bNode *node, int x, int y)
1051 {
1052         const float size = 10.0f;
1053         NodeFrame *data = (NodeFrame *)node->storage;
1054         rctf totr = node->totr;
1055         int dir = 0;
1056         
1057         /* shrinking frame size is determined by child nodes */
1058         if (!(data->flag & NODE_FRAME_RESIZEABLE))
1059                 return 0;
1060         
1061         if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax)
1062                 dir |= NODE_RESIZE_RIGHT;
1063         if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax)
1064                 dir |= NODE_RESIZE_LEFT;
1065         if (x >= totr.xmin && x < totr.xmax && y >= totr.ymax - size && y < totr.ymax)
1066                 dir |= NODE_RESIZE_TOP;
1067         if (x >= totr.xmin && x < totr.xmax && y >= totr.ymin && y < totr.ymin + size)
1068                 dir |= NODE_RESIZE_BOTTOM;
1069         
1070         return dir;
1071 }
1072
1073 static void node_buts_frame_details(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1074 {
1075         uiItemR(layout, ptr, "label_size", 0, IFACE_("Label Size"), ICON_NONE);
1076         uiItemR(layout, ptr, "shrink", 0, IFACE_("Shrink"), ICON_NONE);
1077 }
1078
1079
1080 #define NODE_REROUTE_SIZE   8.0f
1081
1082 static void node_update_reroute(const bContext *UNUSED(C), bNodeTree *UNUSED(ntree), bNode *node)
1083 {
1084         bNodeSocket *nsock;
1085         float locx, locy;
1086         float size = NODE_REROUTE_SIZE;
1087         
1088         /* get "global" coords */
1089         nodeToView(node, 0.0f, 0.0f, &locx, &locy);
1090         
1091         /* reroute node has exactly one input and one output, both in the same place */
1092         nsock = node->outputs.first;
1093         nsock->locx = locx;
1094         nsock->locy = locy;
1095
1096         nsock = node->inputs.first;
1097         nsock->locx = locx;
1098         nsock->locy = locy;
1099
1100         node->width = size * 2;
1101         node->totr.xmin = locx - size;
1102         node->totr.xmax = locx + size;
1103         node->totr.ymax = locy + size;
1104         node->totr.ymin = locy - size;
1105 }
1106
1107 static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(snode),  bNodeTree *ntree, bNode *node)
1108 {
1109         bNodeSocket *sock;
1110 #if 0   /* UNUSED */
1111         rctf *rct = &node->totr;
1112         float size = NODE_REROUTE_SIZE;
1113 #endif
1114         float socket_size = NODE_SOCKSIZE;
1115
1116         /* skip if out of view */
1117         if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
1118             node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) {
1119
1120                 uiEndBlock(C, node->block);
1121                 node->block = NULL;
1122                 return;
1123         }
1124
1125         /* XXX only kept for debugging
1126          * selection state is indicated by socket outline below!
1127          */
1128 #if 0
1129         /* body */
1130         uiSetRoundBox(15);
1131         UI_ThemeColor4(TH_NODE);
1132         glEnable(GL_BLEND);
1133         uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, size);
1134         glDisable(GL_BLEND);
1135
1136         /* outline active and selected emphasis */
1137         if (node->flag & SELECT) {
1138                 glEnable(GL_BLEND);
1139                 glEnable(GL_LINE_SMOOTH);
1140                 /* using different shades of TH_TEXT_HI for the empasis, like triangle */
1141                 if (node->flag & NODE_ACTIVE)
1142                         UI_ThemeColorShadeAlpha(TH_TEXT_HI, 0, -40);
1143                 else
1144                         UI_ThemeColorShadeAlpha(TH_TEXT_HI, -20, -120);
1145                 uiDrawBox(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size);
1146
1147                 glDisable(GL_LINE_SMOOTH);
1148                 glDisable(GL_BLEND);
1149         }
1150 #endif
1151
1152         /* only draw input socket. as they all are placed on the same position.
1153          * highlight also if node itself is selected, since we don't display the node body separately!
1154          */
1155         for (sock = node->inputs.first; sock; sock = sock->next) {
1156                 node_socket_circle_draw(ntree, sock, socket_size, (sock->flag & SELECT) || (node->flag & SELECT));
1157         }
1158
1159         uiEndBlock(C, node->block);
1160         uiDrawBlock(C, node->block);
1161         node->block = NULL;
1162 }
1163
1164 /* Special tweak area for reroute node.
1165  * Since this node is quite small, we use a larger tweak area for grabbing than for selection.
1166  */
1167 static int node_tweak_area_reroute(bNode *node, int x, int y)
1168 {
1169         /* square of tweak radius */
1170         static const float tweak_radius_sq = 576;  /* 24 * 24 */
1171         
1172         bNodeSocket *sock = node->inputs.first;
1173         float dx = sock->locx - x;
1174         float dy = sock->locy - y;
1175         return (dx * dx + dy * dy <= tweak_radius_sq);
1176 }
1177
1178 static void node_common_set_butfunc(bNodeType *ntype)
1179 {
1180         switch (ntype->type) {
1181                 case NODE_GROUP:
1182                         ntype->uifunc = node_uifunc_group;
1183                         ntype->drawfunc = node_draw_group;
1184                         ntype->drawupdatefunc = node_update_group;
1185                         break;
1186                 case NODE_FORLOOP:
1187 //                      ntype->uifunc= node_common_buts_group;
1188                         ntype->drawfunc = node_draw_group;
1189                         ntype->drawupdatefunc = node_update_group;
1190                         break;
1191                 case NODE_WHILELOOP:
1192                         ntype->uifunc = node_common_buts_whileloop;
1193                         ntype->drawfunc = node_draw_group;
1194                         ntype->drawupdatefunc = node_update_group;
1195                         break;
1196                 case NODE_FRAME:
1197                         ntype->drawfunc = node_draw_frame;
1198                         ntype->drawupdatefunc = node_update_frame;
1199                         ntype->uifuncbut = node_buts_frame_details;
1200                         ntype->resize_area_func = node_resize_area_frame;
1201                         break;
1202                 case NODE_REROUTE:
1203                         ntype->drawfunc = node_draw_reroute;
1204                         ntype->drawupdatefunc = node_update_reroute;
1205                         ntype->tweak_area_func = node_tweak_area_reroute;
1206                         break;
1207         }
1208 }
1209
1210 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
1211
1212 static void node_buts_image_user(uiLayout *layout, bContext *C, PointerRNA *ptr,
1213                                  PointerRNA *imaptr, PointerRNA *iuserptr)
1214 {
1215         uiLayout *col;
1216         int source;
1217
1218         if (!imaptr->data)
1219                 return;
1220
1221         col = uiLayoutColumn(layout, FALSE);
1222         
1223         uiItemR(col, imaptr, "source", 0, "", ICON_NONE);
1224         
1225         source = RNA_enum_get(imaptr, "source");
1226
1227         if (source == IMA_SRC_SEQUENCE) {
1228                 /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
1229                 Scene *scene = CTX_data_scene(C);
1230                 ImageUser *iuser = iuserptr->data;
1231                 char numstr[32];
1232                 const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0, NULL);
1233                 BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr);
1234                 uiItemL(layout, numstr, ICON_NONE);
1235         }
1236
1237         if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
1238                 col = uiLayoutColumn(layout, TRUE);
1239                 uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
1240                 uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
1241                 uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
1242                 uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
1243                 uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
1244         }
1245
1246         col = uiLayoutColumn(layout, FALSE);
1247
1248         if (RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER)
1249                 uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
1250 }
1251
1252 static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
1253 {
1254         bNode *node = ptr->data;
1255         uiLayout *col;
1256         
1257         uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL);
1258         
1259         if (!node->id) return;
1260         
1261         col = uiLayoutColumn(layout, FALSE);
1262         uiItemR(col, ptr, "use_diffuse", 0, NULL, ICON_NONE);
1263         uiItemR(col, ptr, "use_specular", 0, NULL, ICON_NONE);
1264         uiItemR(col, ptr, "invert_normal", 0, NULL, ICON_NONE);
1265 }
1266
1267 static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1268 {
1269         uiLayout *row;
1270         
1271         uiItemL(layout, IFACE_("Location:"), ICON_NONE);
1272         row = uiLayoutRow(layout, TRUE);
1273         uiItemR(row, ptr, "translation", 0, "", ICON_NONE);
1274         
1275         uiItemL(layout, IFACE_("Rotation:"), ICON_NONE);
1276         row = uiLayoutRow(layout, TRUE);
1277         uiItemR(row, ptr, "rotation", 0, "", ICON_NONE);
1278         
1279         uiItemL(layout, IFACE_("Scale:"), ICON_NONE);
1280         row = uiLayoutRow(layout, TRUE);
1281         uiItemR(row, ptr, "scale", 0, "", ICON_NONE);
1282         
1283         row = uiLayoutRow(layout, TRUE);
1284         uiItemR(row, ptr, "use_min", 0, "Min", ICON_NONE);
1285         uiItemR(row, ptr, "min", 0, "", ICON_NONE);
1286         
1287         row = uiLayoutRow(layout, TRUE);
1288         uiItemR(row, ptr, "use_max", 0, "Max", ICON_NONE);
1289         uiItemR(row, ptr, "max", 0, "", ICON_NONE);
1290 }
1291
1292 static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1293
1294         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
1295 }
1296
1297 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
1298 {
1299         PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
1300         uiLayout *col;
1301
1302         col = uiLayoutColumn(layout, FALSE);
1303
1304         if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
1305                 PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
1306
1307                 uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
1308                 uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
1309         }
1310         else {
1311                 uiItemR(col, ptr, "uv_layer", 0, IFACE_("UV"), ICON_NONE);
1312                 uiItemR(col, ptr, "color_layer", 0, IFACE_("VCol"), ICON_NONE);
1313         }
1314 }
1315
1316 static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1317 {
1318         uiItemR(layout, ptr, "attribute_name", 0, IFACE_("Name"), ICON_NONE);
1319 }
1320
1321 static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1322 {
1323         PointerRNA imaptr = RNA_pointer_get(ptr, "image");
1324         PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
1325
1326         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1327         uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
1328         uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
1329
1330         if(RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX)
1331                 uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE);
1332
1333         /* note: image user properties used directly here, unlike compositor image node,
1334          * which redefines them in the node struct RNA to get proper updates.
1335          */
1336         node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr);
1337 }
1338
1339 static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, PointerRNA *ptr)
1340 {
1341         PointerRNA imaptr = RNA_pointer_get(ptr, "image");
1342         PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
1343
1344         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1345         uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
1346         uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
1347
1348         node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr);
1349 }
1350
1351 static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1352 {
1353         uiItemR(layout, ptr, "sun_direction", 0, "", ICON_NONE);
1354         uiItemR(layout, ptr, "turbidity", 0, NULL, ICON_NONE);
1355 }
1356
1357 static void node_shader_buts_tex_gradient(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1358 {
1359         uiItemR(layout, ptr, "gradient_type", 0, "", ICON_NONE);
1360 }
1361
1362 static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1363 {
1364         uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE);
1365 }
1366
1367 static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1368 {
1369         uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE);
1370 }
1371
1372 static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1373 {
1374         uiItemR(layout, ptr, "musgrave_type", 0, "", ICON_NONE);
1375 }
1376
1377 static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1378 {
1379         uiItemR(layout, ptr, "coloring", 0, "", ICON_NONE);
1380 }
1381
1382 static void node_shader_buts_glossy(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1383 {
1384         uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE);
1385 }
1386
1387 /* only once called */
1388 static void node_shader_set_butfunc(bNodeType *ntype)
1389 {
1390         switch (ntype->type) {
1391                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
1392
1393                 case SH_NODE_MATERIAL:
1394                 case SH_NODE_MATERIAL_EXT:
1395                         ntype->uifunc = node_shader_buts_material;
1396                         break;
1397                 case SH_NODE_TEXTURE:
1398                         ntype->uifunc = node_buts_texture;
1399                         break;
1400                 case SH_NODE_NORMAL:
1401                         ntype->uifunc = node_buts_normal;
1402                         break;
1403                 case SH_NODE_CURVE_VEC:
1404                         ntype->uifunc = node_buts_curvevec;
1405                         break;
1406                 case SH_NODE_CURVE_RGB:
1407                         ntype->uifunc = node_buts_curvecol;
1408                         break;
1409                 case SH_NODE_MAPPING:
1410                         ntype->uifunc = node_shader_buts_mapping;
1411                         break;
1412                 case SH_NODE_VALUE:
1413                         ntype->uifunc = node_buts_value;
1414                         break;
1415                 case SH_NODE_RGB:
1416                         ntype->uifunc = node_buts_rgb;
1417                         break;
1418                 case SH_NODE_MIX_RGB:
1419                         ntype->uifunc = node_buts_mix_rgb;
1420                         break;
1421                 case SH_NODE_VALTORGB:
1422                         ntype->uifunc = node_buts_colorramp;
1423                         break;
1424                 case SH_NODE_MATH: 
1425                         ntype->uifunc = node_buts_math;
1426                         break; 
1427                 case SH_NODE_VECT_MATH: 
1428                         ntype->uifunc = node_shader_buts_vect_math;
1429                         break; 
1430                 case SH_NODE_GEOMETRY:
1431                         ntype->uifunc = node_shader_buts_geometry;
1432                         break;
1433                 case SH_NODE_ATTRIBUTE:
1434                         ntype->uifunc = node_shader_buts_attribute;
1435                         break;
1436                 case SH_NODE_TEX_SKY:
1437                         ntype->uifunc = node_shader_buts_tex_sky;
1438                         break;
1439                 case SH_NODE_TEX_IMAGE:
1440                         ntype->uifunc = node_shader_buts_tex_image;
1441                         break;
1442                 case SH_NODE_TEX_ENVIRONMENT:
1443                         ntype->uifunc = node_shader_buts_tex_environment;
1444                         break;
1445                 case SH_NODE_TEX_GRADIENT:
1446                         ntype->uifunc = node_shader_buts_tex_gradient;
1447                         break;
1448                 case SH_NODE_TEX_MAGIC:
1449                         ntype->uifunc = node_shader_buts_tex_magic;
1450                         break;
1451                 case SH_NODE_TEX_WAVE:
1452                         ntype->uifunc = node_shader_buts_tex_wave;
1453                         break;
1454                 case SH_NODE_TEX_MUSGRAVE:
1455                         ntype->uifunc = node_shader_buts_tex_musgrave;
1456                         break;
1457                 case SH_NODE_TEX_VORONOI:
1458                         ntype->uifunc = node_shader_buts_tex_voronoi;
1459                         break;
1460                 case SH_NODE_BSDF_GLOSSY:
1461                 case SH_NODE_BSDF_GLASS:
1462                         ntype->uifunc = node_shader_buts_glossy;
1463                         break;
1464         }
1465 }
1466
1467 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
1468
1469 static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1470 {
1471         bNode *node = ptr->data;
1472         PointerRNA imaptr, iuserptr;
1473         
1474         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1475         
1476         if (!node->id) return;
1477         
1478         imaptr = RNA_pointer_get(ptr, "image");
1479         RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr);
1480         
1481         node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr);
1482 }
1483
1484 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
1485 {
1486         bNode *node = ptr->data;
1487         uiLayout *col, *row;
1488         PointerRNA op_ptr;
1489         PointerRNA scn_ptr;
1490         PropertyRNA *prop;
1491         const char *layer_name;
1492         char scene_name[MAX_ID_NAME - 2];
1493         wmOperatorType *ot = WM_operatortype_find("RENDER_OT_render", 1);
1494
1495         BLI_assert(ot != 0);
1496
1497         uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
1498         
1499         if (!node->id) return;
1500
1501         col = uiLayoutColumn(layout, FALSE);
1502         row = uiLayoutRow(col, FALSE);
1503         uiItemR(row, ptr, "layer", 0, "", ICON_NONE);
1504         
1505         prop = RNA_struct_find_property(ptr, "layer");
1506         if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)))
1507                 return;
1508         
1509         scn_ptr = RNA_pointer_get(ptr, "scene");
1510         RNA_string_get(&scn_ptr, "name", scene_name);
1511         
1512         WM_operator_properties_create_ptr(&op_ptr, ot);
1513         RNA_string_set(&op_ptr, "layer", layer_name);
1514         RNA_string_set(&op_ptr, "scene", scene_name);
1515         uiItemFullO_ptr(row, ot, "", ICON_RENDER_STILL, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
1516
1517 }
1518
1519
1520 static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1521 {
1522         uiLayout *col, *row;
1523         int reference;
1524         int filter;
1525         
1526         col = uiLayoutColumn(layout, FALSE);
1527         filter = RNA_enum_get(ptr, "filter_type");
1528         reference = RNA_boolean_get(ptr, "use_variable_size");
1529
1530         uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE);
1531         if (filter != R_FILTER_FAST_GAUSS) {
1532                 uiItemR(col, ptr, "use_variable_size", 0, NULL, ICON_NONE);
1533                 if (!reference) {
1534                         uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE);
1535                 }
1536                 uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
1537         }
1538         
1539         uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE);
1540         
1541         if (RNA_boolean_get(ptr, "use_relative")) {
1542                 uiItemL(col, IFACE_("Aspect Correction"), 0);
1543                 row = uiLayoutRow(layout, TRUE);
1544                 uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0);
1545                 
1546                 col = uiLayoutColumn(layout, TRUE);
1547                 uiItemR(col, ptr, "factor_x", 0, IFACE_("X"), ICON_NONE);
1548                 uiItemR(col, ptr, "factor_y", 0, IFACE_("Y"), ICON_NONE);
1549         }
1550         else {
1551                 col = uiLayoutColumn(layout, TRUE);
1552                 uiItemR(col, ptr, "size_x", 0, IFACE_("X"), ICON_NONE);
1553                 uiItemR(col, ptr, "size_y", 0, IFACE_("Y"), ICON_NONE);
1554         }
1555 }
1556
1557 static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1558 {
1559         uiLayout *col;
1560         
1561         uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
1562         uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE);
1563         
1564         col = uiLayoutColumn(layout, TRUE);
1565         uiItemL(col, IFACE_("Center:"), ICON_NONE);
1566         uiItemR(col, ptr, "center_x", 0, IFACE_("X"), ICON_NONE);
1567         uiItemR(col, ptr, "center_y", 0, IFACE_("Y"), ICON_NONE);
1568         
1569         uiItemS(layout);
1570         
1571         col = uiLayoutColumn(layout, TRUE);
1572         uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE);
1573         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
1574         
1575         uiItemS(layout);
1576         
1577         uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE);
1578         uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE);
1579 }
1580
1581 static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1582 {       
1583         uiLayout *col;
1584         
1585         col = uiLayoutColumn(layout, TRUE);
1586         uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
1587         uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE);
1588         uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
1589 }
1590
1591 static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1592 {
1593         uiLayout *sub, *col;
1594         
1595         col = uiLayoutColumn(layout, FALSE);
1596         uiItemL(col, IFACE_("Bokeh Type:"), ICON_NONE);
1597         uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE);
1598         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
1599
1600         uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
1601
1602         col = uiLayoutColumn(layout, FALSE);
1603         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer") == TRUE);
1604         uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE);
1605
1606         uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
1607         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
1608
1609         col = uiLayoutColumn(layout, FALSE);
1610         uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
1611         
1612         col = uiLayoutColumn(layout, FALSE);
1613         uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
1614         sub = uiLayoutColumn(col, FALSE);
1615         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer") == FALSE);
1616         uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE);
1617 }
1618
1619 /* qdn: glare node */
1620 static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1621 {       
1622         uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE);
1623         uiItemR(layout, ptr, "quality", 0, "", ICON_NONE);
1624
1625         if (RNA_enum_get(ptr, "glare_type") != 1) {
1626                 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
1627         
1628                 if (RNA_enum_get(ptr, "glare_type") != 0)
1629                         uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1630         }
1631         
1632         uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE);
1633         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
1634
1635         if (RNA_enum_get(ptr, "glare_type") == 2) {
1636                 uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE);
1637                 uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE);
1638         }
1639         if (RNA_enum_get(ptr, "glare_type") == 0 || RNA_enum_get(ptr, "glare_type") == 2) {
1640                 uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1641                 
1642                 if (RNA_enum_get(ptr, "glare_type") == 0)
1643                         uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE);
1644         }
1645         if (RNA_enum_get(ptr, "glare_type") == 1) {
1646                 uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE);
1647         }
1648 }
1649
1650 static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1651 {       
1652         uiLayout *col;
1653
1654         col = uiLayoutColumn(layout, FALSE);
1655         uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE);
1656         if (RNA_enum_get(ptr, "tonemap_type") == 0) {
1657                 uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1658                 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
1659                 uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE);
1660         }
1661         else {
1662                 uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE);
1663                 uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1664                 uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1665                 uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1666         }
1667 }
1668
1669 static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1670 {
1671         uiLayout *col;
1672
1673         col = uiLayoutColumn(layout, FALSE);
1674         uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE);
1675
1676         col = uiLayoutColumn(col, FALSE);
1677         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector") == FALSE);
1678         uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE);
1679         uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE);
1680 }
1681
1682 static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1683 {
1684         uiLayout *col;
1685         
1686         col = uiLayoutColumn(layout, FALSE);
1687         uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE);
1688         uiItemR(col, ptr, "factor", 0, IFACE_("Blur"), ICON_NONE);
1689         
1690         col = uiLayoutColumn(layout, TRUE);
1691         uiItemL(col, IFACE_("Speed:"), ICON_NONE);
1692         uiItemR(col, ptr, "speed_min", 0, IFACE_("Min"), ICON_NONE);
1693         uiItemR(col, ptr, "speed_max", 0, IFACE_("Max"), ICON_NONE);
1694
1695         uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE);
1696 }
1697
1698 static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1699 {
1700         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
1701 }
1702
1703 static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1704 {
1705         uiItemR(layout, ptr, "axis", 0, "", ICON_NONE);
1706 }
1707
1708 static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1709 {
1710         uiLayout *col;
1711
1712         uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE);
1713         uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE);
1714
1715         col = uiLayoutColumn(layout, TRUE);
1716         if (RNA_boolean_get(ptr, "relative")) {
1717                 uiItemR(col, ptr, "rel_min_x", 0, IFACE_("Left"), ICON_NONE);
1718                 uiItemR(col, ptr, "rel_max_x", 0, IFACE_("Right"), ICON_NONE);
1719                 uiItemR(col, ptr, "rel_min_y", 0, IFACE_("Up"), ICON_NONE);
1720                 uiItemR(col, ptr, "rel_max_y", 0, IFACE_("Down"), ICON_NONE);
1721         }
1722         else {
1723                 uiItemR(col, ptr, "min_x", 0, IFACE_("Left"), ICON_NONE);
1724                 uiItemR(col, ptr, "max_x", 0, IFACE_("Right"), ICON_NONE);
1725                 uiItemR(col, ptr, "min_y", 0, IFACE_("Up"), ICON_NONE);
1726                 uiItemR(col, ptr, "max_y", 0, IFACE_("Down"), ICON_NONE);
1727         }
1728 }
1729
1730 static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1731 {
1732         uiLayout *row, *col;
1733         
1734         col = uiLayoutColumn(layout, FALSE);
1735         row = uiLayoutRow(col, FALSE);
1736         uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1737         uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
1738 }
1739
1740 static void node_composit_buts_double_edge_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1741 {
1742         uiLayout *col;
1743
1744         col = uiLayoutColumn(layout, FALSE);
1745
1746         uiItemL(col, IFACE_("Inner Edge:"), ICON_NONE);
1747         uiItemR(col, ptr, "inner_mode", 0, "", ICON_NONE);
1748         uiItemL(col, IFACE_("Buffer Edge:"), ICON_NONE);
1749         uiItemR(col, ptr, "edge_mode", 0, "", ICON_NONE);
1750 }
1751
1752 static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1753 {
1754         uiLayout *sub, *col;
1755         
1756         col = uiLayoutColumn(layout, TRUE);
1757         uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
1758         uiItemR(col, ptr, "size", 0, NULL, ICON_NONE);
1759         
1760         col = uiLayoutColumn(layout, TRUE);
1761         uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE);
1762         sub = uiLayoutColumn(col, FALSE);
1763         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min"));
1764         uiItemR(sub, ptr, "min", 0, "", ICON_NONE);
1765         
1766         col = uiLayoutColumn(layout, TRUE);
1767         uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE);
1768         sub = uiLayoutColumn(col, FALSE);
1769         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max"));
1770         uiItemR(sub, ptr, "max", 0, "", ICON_NONE);
1771 }
1772
1773 static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1774 {       
1775         uiLayout *col;
1776         
1777         col = uiLayoutColumn(layout, TRUE);
1778         uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE);
1779         uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE);
1780 }
1781
1782 static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1783 {       
1784         uiLayout *col;
1785         
1786         col = uiLayoutColumn(layout, TRUE);
1787         uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE);
1788 }
1789
1790
1791 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1792 {
1793         uiLayout *col;
1794         
1795         col = uiLayoutColumn(layout, FALSE);
1796         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1797         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1798         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1799 }
1800
1801 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1802 {
1803         uiItemR(layout, ptr, "type", 0, NULL, ICON_NONE);
1804         uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
1805         switch (RNA_enum_get(ptr, "type")) {
1806                 case CMP_NODE_DILATEERODE_DISTANCE_THRESH:
1807                         uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE);
1808                         break;
1809                 case CMP_NODE_DILATEERODE_DISTANCE_FEATHER:
1810                         uiItemR(layout, ptr, "falloff", 0, NULL, ICON_NONE);
1811                         break;
1812         }
1813 }
1814
1815 static void node_composit_buts_inpaint(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1816 {
1817         uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
1818 }
1819
1820 static void node_composit_buts_despeckle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1821 {
1822         uiLayout *col;
1823
1824         col = uiLayoutColumn(layout, FALSE);
1825         uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
1826         uiItemR(col, ptr, "threshold_neighbour", 0, NULL, ICON_NONE);
1827 }
1828
1829 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1830 {
1831         uiLayout *col;
1832         
1833         col = uiLayoutColumn(layout, TRUE);
1834         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1835         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1836 }
1837
1838 static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1839 {
1840         uiLayout *col, *row;
1841         
1842         col = uiLayoutColumn(layout, TRUE);
1843    
1844         uiItemL(layout, IFACE_("Color Space:"), ICON_NONE);
1845         row = uiLayoutRow(layout, FALSE);
1846         uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1847
1848         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1849         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1850 }
1851
1852 static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1853 {
1854         uiLayout *row, *col;
1855         
1856         uiItemL(layout, IFACE_("Despill Channel:"), ICON_NONE);
1857         row = uiLayoutRow(layout, FALSE);
1858         uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1859
1860         col = uiLayoutColumn(layout, FALSE);
1861         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
1862
1863         if (RNA_enum_get(ptr, "limit_method") == 0) {
1864                 uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE);
1865                 row = uiLayoutRow(col, FALSE);
1866                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1867         }
1868
1869         uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1870         uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE);
1871         if (RNA_boolean_get(ptr, "use_unspill") == TRUE) {
1872                 uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1873                 uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1874                 uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1875         }
1876 }
1877
1878 static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1879 {
1880         uiLayout *col;
1881         
1882         col = uiLayoutColumn(layout, FALSE);
1883         uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE);
1884         uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
1885         
1886         col = uiLayoutColumn(layout, TRUE);
1887         /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now */
1888         uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1889         /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now*/
1890 }
1891
1892 static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1893 {
1894         uiLayout *col;
1895         
1896         col = uiLayoutColumn(layout, TRUE);
1897         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1898         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1899         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1900 }
1901
1902 static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1903 {       
1904         uiLayout *col, *row;
1905
1906         uiItemL(layout, IFACE_("Color Space:"), ICON_NONE);
1907         row = uiLayoutRow(layout, FALSE);
1908         uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1909
1910         col = uiLayoutColumn(layout, FALSE);
1911         uiItemL(col, IFACE_("Key Channel:"), ICON_NONE);
1912         row = uiLayoutRow(col, FALSE);
1913         uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1914
1915         col = uiLayoutColumn(layout, FALSE);
1916
1917         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
1918         if (RNA_enum_get(ptr, "limit_method") == 0) {
1919                 uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE);
1920                 row = uiLayoutRow(col, FALSE);
1921                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1922         }
1923
1924         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1925         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1926 }
1927
1928 static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1929 {
1930         uiLayout *col;
1931         
1932         col = uiLayoutColumn(layout, TRUE);
1933         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1934         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1935 }
1936
1937 static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1938 {
1939         uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE);
1940 }
1941
1942 static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1943 {
1944         uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE);
1945         uiItemR(layout, ptr, "use_antialiasing", 0, NULL, ICON_NONE);
1946 }
1947
1948 /* draw function for file output node sockets, displays only sub-path and format, no value button */
1949 static void node_draw_input_file_output(const bContext *C, uiBlock *block,
1950                                         bNodeTree *ntree, bNode *node, bNodeSocket *sock,
1951                                         const char *UNUSED(name), int x, int y, int width)
1952 {
1953         uiLayout *layout, *row;
1954         PointerRNA nodeptr, inputptr, imfptr;
1955         int imtype;
1956         int rx, ry;
1957         RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
1958         
1959         layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y + NODE_DY, width, 20, UI_GetStyle());
1960         row = uiLayoutRow(layout, FALSE);
1961         
1962         imfptr = RNA_pointer_get(&nodeptr, "format");
1963         imtype = RNA_enum_get(&imfptr, "file_format");
1964         if (imtype == R_IMF_IMTYPE_MULTILAYER) {
1965                 NodeImageMultiFileSocket *input = sock->storage;
1966                 RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotLayer, input, &inputptr);
1967                 
1968                 uiItemL(row, input->layer, 0);
1969         }
1970         else {
1971                 NodeImageMultiFileSocket *input = sock->storage;
1972                 PropertyRNA *imtype_prop;
1973                 const char *imtype_name;
1974                 RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotFile, input, &inputptr);
1975                 
1976                 uiItemL(row, input->path, 0);
1977                 
1978                 if (!RNA_boolean_get(&inputptr, "use_node_format"))
1979                         imfptr = RNA_pointer_get(&inputptr, "format");
1980                 
1981                 imtype_prop = RNA_struct_find_property(&imfptr, "file_format");
1982                 RNA_property_enum_name((bContext *)C, &imfptr, imtype_prop,
1983                                        RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name);
1984                 uiBlockSetEmboss(block, UI_EMBOSSP);
1985                 uiItemL(row, imtype_name, 0);
1986                 uiBlockSetEmboss(block, UI_EMBOSSN);
1987         }
1988         
1989         uiBlockLayoutResolve(block, &rx, &ry);
1990 }
1991 static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1992 {
1993         PointerRNA imfptr = RNA_pointer_get(ptr, "format");
1994         int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER);
1995         
1996         if (multilayer)
1997                 uiItemL(layout, IFACE_("Path:"), 0);
1998         else
1999                 uiItemL(layout, IFACE_("Base Path:"), 0);
2000         uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE);
2001 }
2002 static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C, PointerRNA *ptr)
2003 {
2004         PointerRNA imfptr = RNA_pointer_get(ptr, "format");
2005         PointerRNA active_input_ptr, op_ptr;
2006         uiLayout *row;
2007         int active_index;
2008         int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER);
2009         
2010         node_composit_buts_file_output(layout, C, ptr);
2011         uiTemplateImageSettings(layout, &imfptr, TRUE);
2012         
2013         uiItemS(layout);
2014         
2015         uiItemO(layout, IFACE_("Add Input"), ICON_ZOOMIN, "NODE_OT_output_file_add_socket");
2016         
2017         active_index = RNA_int_get(ptr, "active_input_index");
2018         /* using different collection properties if multilayer format is enabled */
2019         if (multilayer) {
2020                 uiTemplateList(layout, C, ptr, "layer_slots", ptr, "active_input_index", NULL, 0, 0, 0);
2021                 RNA_property_collection_lookup_int(ptr, RNA_struct_find_property(ptr, "layer_slots"),
2022                                                    active_index, &active_input_ptr);
2023         }
2024         else {
2025                 uiTemplateList(layout, C, ptr, "file_slots", ptr, "active_input_index", NULL, 0, 0, 0);
2026                 RNA_property_collection_lookup_int(ptr, RNA_struct_find_property(ptr, "file_slots"),
2027                                                    active_index, &active_input_ptr);
2028         }
2029         /* XXX collection lookup does not return the ID part of the pointer, setting this manually here */
2030         active_input_ptr.id.data = ptr->id.data;
2031         
2032         row = uiLayoutRow(layout, TRUE);
2033         op_ptr = uiItemFullO(row, "NODE_OT_output_file_move_active_socket", "",
2034                              ICON_TRIA_UP, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
2035         RNA_enum_set(&op_ptr, "direction", 1);
2036         op_ptr = uiItemFullO(row, "NODE_OT_output_file_move_active_socket", "",
2037                              ICON_TRIA_DOWN, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
2038         RNA_enum_set(&op_ptr, "direction", 2);
2039         
2040         if (active_input_ptr.data) {
2041                 if (multilayer) {
2042                         uiLayout *row, *col;
2043                         col = uiLayoutColumn(layout, TRUE);
2044                         
2045                         uiItemL(col, IFACE_("Layer:"), 0);
2046                         row = uiLayoutRow(col, FALSE);
2047                         uiItemR(row, &active_input_ptr, "name", 0, "", 0);
2048                         uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "",
2049                                     ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY);
2050                 }
2051                 else {
2052                         uiLayout *row, *col;
2053                         col = uiLayoutColumn(layout, TRUE);
2054                         
2055                         uiItemL(col, IFACE_("File Path:"), 0);
2056                         row = uiLayoutRow(col, FALSE);
2057                         uiItemR(row, &active_input_ptr, "path", 0, "", 0);
2058                         uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "",
2059                                     ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY);
2060                         
2061                         /* format details for individual files */
2062                         imfptr = RNA_pointer_get(&active_input_ptr, "format");
2063                         
2064                         col = uiLayoutColumn(layout, TRUE);
2065                         uiItemL(col, IFACE_("Format:"), 0);
2066                         uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, 0);
2067                         
2068                         col = uiLayoutColumn(layout, FALSE);
2069                         uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == FALSE);
2070                         uiTemplateImageSettings(col, &imfptr, TRUE);
2071                 }
2072         }
2073 }
2074
2075 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2076 {
2077         uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
2078
2079         if (RNA_enum_get(ptr, "space") == CMP_SCALE_RENDERPERCENT) {
2080                 uiLayout *row;
2081                 uiItemR(layout, ptr, "frame_method", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2082                 row = uiLayoutRow(layout, TRUE);
2083                 uiItemR(row, ptr, "offset_x", 0, "X", ICON_NONE);
2084                 uiItemR(row, ptr, "offset_y", 0, "Y", ICON_NONE);
2085         }
2086 }
2087
2088 static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2089 {
2090         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
2091 }
2092
2093 static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2094 {
2095         uiLayout *col;
2096         
2097         col = uiLayoutColumn(layout, FALSE);
2098         uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE);
2099         uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE);
2100 }
2101
2102 static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2103 {
2104         uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
2105 }
2106
2107 static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2108 {
2109         uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2110 }
2111
2112 static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2113 {
2114         uiLayout *split, *col, *row;
2115         
2116         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
2117         
2118         if (RNA_enum_get(ptr, "correction_method") == 0) {
2119         
2120                 split = uiLayoutSplit(layout, 0.0f, FALSE);
2121                 col = uiLayoutColumn(split, FALSE);
2122                 uiTemplateColorWheel(col, ptr, "lift", 1, 1, 0, 1);
2123                 row = uiLayoutRow(col, FALSE);
2124                 uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE);
2125                 
2126                 col = uiLayoutColumn(split, FALSE);
2127                 uiTemplateColorWheel(col, ptr, "gamma", 1, 1, 1, 1);
2128                 row = uiLayoutRow(col, FALSE);
2129                 uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE);
2130                 
2131                 col = uiLayoutColumn(split, FALSE);
2132                 uiTemplateColorWheel(col, ptr, "gain", 1, 1, 1, 1);
2133                 row = uiLayoutRow(col, FALSE);
2134                 uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE);
2135
2136         }
2137         else {
2138                 
2139                 split = uiLayoutSplit(layout, 0.0f, FALSE);
2140                 col = uiLayoutColumn(split, FALSE);
2141                 uiTemplateColorWheel(col, ptr, "offset", 1, 1, 0, 1);
2142                 row = uiLayoutRow(col, FALSE);
2143                 uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE);
2144                 
2145                 col = uiLayoutColumn(split, FALSE);
2146                 uiTemplateColorWheel(col, ptr, "power", 1, 1, 0, 1);
2147                 row = uiLayoutRow(col, FALSE);
2148                 uiItemR(row, ptr, "power", 0, NULL, ICON_NONE);
2149                 
2150                 col = uiLayoutColumn(split, FALSE);
2151                 uiTemplateColorWheel(col, ptr, "slope", 1, 1, 0, 1);
2152                 row = uiLayoutRow(col, FALSE);
2153                 uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE);
2154         }
2155
2156 }
2157 static void node_composit_buts_colorbalance_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2158 {
2159         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
2160
2161         if (RNA_enum_get(ptr, "correction_method") == 0) {
2162
2163                 uiTemplateColorWheel(layout, ptr, "lift", 1, 1, 0, 1);
2164                 uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE);
2165
2166                 uiTemplateColorWheel(layout, ptr, "gamma", 1, 1, 1, 1);
2167                 uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE);
2168
2169                 uiTemplateColorWheel(layout, ptr, "gain", 1, 1, 1, 1);
2170                 uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE);
2171         }
2172         else {
2173                 uiTemplateColorWheel(layout, ptr, "offset", 1, 1, 0, 1);
2174                 uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE);
2175
2176                 uiTemplateColorWheel(layout, ptr, "power", 1, 1, 0, 1);
2177                 uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE);
2178
2179                 uiTemplateColorWheel(layout, ptr, "slope", 1, 1, 0, 1);
2180                 uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE);
2181         }
2182 }
2183
2184
2185 static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2186 {
2187         bNode *node = ptr->data;
2188         CurveMapping *cumap = node->storage;
2189
2190         if (_sample_col[0] != SAMPLE_FLT_ISNONE) {
2191                 cumap->flag |= CUMA_DRAW_SAMPLE;
2192                 copy_v3_v3(cumap->sample, _sample_col);
2193         }
2194         else {
2195                 cumap->flag &= ~CUMA_DRAW_SAMPLE;
2196         }
2197
2198         uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0);
2199 }
2200
2201 static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2202
2203         uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
2204 }
2205
2206 static void node_composit_buts_movieclip(uiLayout *layout, bContext *C, PointerRNA *ptr)
2207 {
2208         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2209 }
2210
2211 static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, PointerRNA *ptr)
2212 {
2213         bNode *node = ptr->data;
2214
2215         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2216
2217         if (!node->id)
2218                 return;
2219
2220         uiItemR(layout, ptr, "filter_type", 0, "", 0);
2221 }
2222
2223 static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2224 {
2225         uiItemR(layout, ptr, "filter_type", 0, "", 0);
2226 }
2227
2228 static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr)
2229 {
2230         bNode *node = ptr->data;
2231
2232         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2233
2234         if (!node->id)
2235                 return;
2236
2237         uiItemR(layout, ptr, "distortion_type", 0, "", 0);
2238 }
2239
2240 static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2241 {
2242         uiLayout *row;
2243         
2244         row = uiLayoutRow(layout, FALSE);
2245         uiItemR(row, ptr, "red", 0, NULL, ICON_NONE);
2246         uiItemR(row, ptr, "green", 0, NULL, ICON_NONE);
2247         uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE);
2248
2249         row = uiLayoutRow(layout, FALSE);
2250         uiItemL(row, "", 0);
2251         uiItemL(row, IFACE_("Saturation"), 0);
2252         uiItemL(row, IFACE_("Contrast"), 0);
2253         uiItemL(row, IFACE_("Gamma"), 0);
2254         uiItemL(row, IFACE_("Gain"), 0);
2255         uiItemL(row, IFACE_("Lift"), 0);
2256
2257         row = uiLayoutRow(layout, FALSE);
2258         uiItemL(row, IFACE_("Master"), 0);
2259         uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2260         uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2261         uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2262         uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2263         uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2264
2265         row = uiLayoutRow(layout, FALSE);
2266         uiItemL(row, IFACE_("Highlights"), 0);
2267         uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2268         uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2269         uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2270         uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2271         uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2272
2273         row = uiLayoutRow(layout, FALSE);
2274         uiItemL(row, IFACE_("Midtones"), 0);
2275         uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2276         uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2277         uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2278         uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2279         uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2280
2281         row = uiLayoutRow(layout, FALSE);
2282         uiItemL(row, IFACE_("Shadows"), 0);
2283         uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2284         uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2285         uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2286         uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2287         uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2288
2289         row = uiLayoutRow(layout, FALSE);
2290         uiItemR(row, ptr, "midtones_start", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2291         uiItemR(row, ptr, "midtones_end", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2292 }
2293
2294 static void node_composit_buts_colorcorrection_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2295 {
2296         uiLayout *row;
2297         
2298         row = uiLayoutRow(layout, FALSE);
2299         uiItemR(row, ptr, "red", 0, NULL, ICON_NONE);
2300         uiItemR(row, ptr, "green", 0, NULL, ICON_NONE);
2301         uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE);
2302         row = layout;
2303         uiItemL(row, IFACE_("Saturation"), 0);
2304         uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2305         uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2306         uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2307         uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2308
2309         uiItemL(row, IFACE_("Contrast"), 0);
2310         uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2311         uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2312         uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2313         uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2314
2315         uiItemL(row, IFACE_("Gamma"), 0);
2316         uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2317         uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2318         uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2319         uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2320
2321         uiItemL(row, IFACE_("Gain"), 0);
2322         uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2323         uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2324         uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2325         uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2326         
2327         uiItemL(row, IFACE_("Lift"), 0);
2328         uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2329         uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2330         uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2331         uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2332
2333         row = uiLayoutRow(layout, FALSE);
2334         uiItemR(row, ptr, "midtones_start", 0, NULL, ICON_NONE);
2335         uiItemR(row, ptr, "midtones_end", 0, NULL, ICON_NONE);
2336 }
2337
2338 static void node_composit_buts_switch(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2339 {
2340         uiItemR(layout, ptr, "check", 0, NULL, ICON_NONE);
2341 }
2342
2343 static void node_composit_buts_boxmask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2344 {
2345         uiLayout *row;
2346         
2347         row = uiLayoutRow(layout, TRUE);
2348         uiItemR(row, ptr, "x", 0, NULL, ICON_NONE);
2349         uiItemR(row, ptr, "y", 0, NULL, ICON_NONE);
2350         
2351         row = uiLayoutRow(layout, TRUE);
2352         uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2353         uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2354
2355         uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
2356         uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
2357 }
2358
2359 static void node_composit_buts_bokehimage(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2360 {
2361         uiItemR(layout, ptr, "flaps", 0, NULL, ICON_NONE);
2362         uiItemR(layout, ptr, "angle", 0, NULL, ICON_NONE);
2363         uiItemR(layout, ptr, "rounding", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2364         uiItemR(layout, ptr, "catadioptric", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2365         uiItemR(layout, ptr, "shift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2366 }
2367
2368 static void node_composit_buts_bokehblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2369 {
2370         uiItemR(layout, ptr, "use_variable_size", 0, NULL, ICON_NONE);
2371         // uiItemR(layout, ptr, "f_stop", 0, NULL, ICON_NONE);  // UNUSED
2372         uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
2373 }
2374
2375 void node_composit_backdrop_viewer(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
2376 {
2377 //      node_composit_backdrop_canvas(snode, backdrop, node, x, y);
2378         if (node->custom1 == 0) {
2379                 const float backdropWidth = backdrop->x;
2380                 const float backdropHeight = backdrop->y;
2381                 const float cx  = x + snode->zoom * backdropWidth * node->custom3;
2382                 const float cy = y + snode->zoom * backdropHeight * node->custom4;
2383
2384                 glColor3f(1.0, 1.0, 1.0);
2385
2386                 glBegin(GL_LINES);
2387                 glVertex2f(cx - 25, cy - 25);
2388                 glVertex2f(cx + 25, cy + 25);
2389                 glVertex2f(cx + 25, cy - 25);
2390                 glVertex2f(cx - 25, cy + 25);
2391                 glEnd();
2392         }
2393 }
2394
2395 void node_composit_backdrop_boxmask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
2396 {
2397         NodeBoxMask *boxmask = node->storage;
2398         const float backdropWidth = backdrop->x;
2399         const float backdropHeight = backdrop->y;
2400         const float aspect = backdropWidth / backdropHeight;
2401         const float rad = DEG2RADF(-boxmask->rotation);
2402         const float cosine = cosf(rad);
2403         const float sine = sinf(rad);
2404         const float halveBoxWidth = backdropWidth * (boxmask->width / 2.0f);
2405         const float halveBoxHeight = backdropHeight * (boxmask->height / 2.0f) * aspect;
2406
2407         float cx, cy, x1, x2, x3, x4;
2408         float y1, y2, y3, y4;
2409
2410
2411         /* keep this, saves us from a version patch */
2412         if (snode->zoom == 0.0f) snode->zoom = 1.0f;
2413
2414         glColor3f(1.0, 1.0, 1.0);
2415
2416         cx  = x + snode->zoom * backdropWidth * boxmask->x;
2417         cy = y + snode->zoom * backdropHeight * boxmask->y;
2418
2419         x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2420         x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2421         x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2422         x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2423         y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2424         y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2425         y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2426         y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2427
2428         glBegin(GL_LINE_LOOP);
2429         glVertex2f(x1, y1);
2430         glVertex2f(x2, y2);
2431         glVertex2f(x3, y3);
2432         glVertex2f(x4, y4);
2433         glEnd();
2434 }
2435
2436 void node_composit_backdrop_ellipsemask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
2437 {
2438         NodeEllipseMask *ellipsemask = node->storage;
2439         const float backdropWidth = backdrop->x;
2440         const float backdropHeight = backdrop->y;
2441         const float aspect = backdropWidth / backdropHeight;
2442         const float rad = DEG2RADF(-ellipsemask->rotation);
2443         const float cosine = cosf(rad);
2444         const float sine = sinf(rad);
2445         const float halveBoxWidth = backdropWidth * (ellipsemask->width / 2.0f);
2446         const float halveBoxHeight = backdropHeight * (ellipsemask->height / 2.0f) * aspect;
2447
2448         float cx, cy, x1, x2, x3, x4;
2449         float y1, y2, y3, y4;
2450
2451
2452         /* keep this, saves us from a version patch */
2453         if (snode->zoom == 0.0f) snode->zoom = 1.0f;
2454
2455         glColor3f(1.0, 1.0, 1.0);
2456
2457         cx  = x + snode->zoom * backdropWidth * ellipsemask->x;
2458         cy = y + snode->zoom * backdropHeight * ellipsemask->y;
2459
2460         x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2461         x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2462         x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2463         x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2464         y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2465         y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2466         y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2467         y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2468
2469         glBegin(GL_LINE_LOOP);
2470
2471         glVertex2f(x1, y1);
2472         glVertex2f(x2, y2);
2473         glVertex2f(x3, y3);
2474         glVertex2f(x4, y4);
2475         glEnd();
2476 }
2477
2478 static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2479 {
2480         uiLayout *row;
2481         row = uiLayoutRow(layout, TRUE);
2482         uiItemR(row, ptr, "x", 0, NULL, ICON_NONE);
2483         uiItemR(row, ptr, "y", 0, NULL, ICON_NONE);
2484         row = uiLayoutRow(layout, TRUE);
2485         uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2486         uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2487
2488         uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
2489         uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
2490 }
2491
2492 static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2493 {
2494         uiLayout *col;
2495         
2496         uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE);
2497         if (RNA_enum_get(ptr, "tile_order") == 0) {
2498                 col = uiLayoutColumn(layout, TRUE);
2499                 uiItemR(col, ptr, "center_x", 0, NULL, ICON_NONE);
2500                 uiItemR(col, ptr, "center_y", 0, NULL, ICON_NONE);
2501         }
2502 }
2503
2504 static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *ptr)
2505 {
2506         bNode *node = ptr->data;
2507
2508         uiTemplateID(layout, C, ptr, "mask", NULL, NULL, NULL);
2509         uiItemR(layout, ptr, "use_antialiasing", 0, NULL, ICON_NONE);
2510         uiItemR(layout, ptr, "use_feather", 0, NULL, ICON_NONE);
2511
2512         uiItemR(layout, ptr, "size_source", 0, "", ICON_NONE);
2513
2514         if (node->custom1 & (CMP_NODEFLAG_MASK_FIXED | CMP_NODEFLAG_MASK_FIXED_SCENE)) {
2515                 uiItemR(layout, ptr, "size_x", 0, NULL, ICON_NONE);
2516                 uiItemR(layout, ptr, "size_y", 0, NULL, ICON_NONE);
2517         }
2518
2519         uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE);
2520         if (node->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) {
2521                 uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE);
2522                 uiItemR(layout, ptr, "motion_blur_shutter", 0, NULL, ICON_NONE);
2523         }
2524 }
2525
2526 static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, PointerRNA *ptr)
2527 {
2528         bNode *node = ptr->data;
2529
2530         uiTemplateID(layout, C, ptr, "clip", NULL, NULL, NULL);
2531
2532         if (node->id) {
2533                 MovieClip *clip = (MovieClip *) node->id;
2534                 uiLayout *col;
2535                 PointerRNA tracking_ptr;
2536
2537                 RNA_pointer_create(&clip->id, &RNA_MovieTracking, &clip->tracking, &tracking_ptr);
2538
2539                 col = uiLayoutColumn(layout, TRUE);
2540                 uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
2541         }
2542 }
2543
2544 static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2545 {
2546         /* bNode *node= ptr->data; */ /* UNUSED */
2547
2548         uiItemR(layout, ptr, "blur_pre", 0, NULL, ICON_NONE);
2549         uiItemR(layout, ptr, "screen_balance", 0, NULL, ICON_NONE);
2550         uiItemR(layout, ptr, "despill_factor", 0, NULL, ICON_NONE);
2551         uiItemR(layout, ptr, "despill_balance", 0, NULL, ICON_NONE);
2552         uiItemR(layout, ptr, "edge_kernel_radius", 0, NULL, ICON_NONE);
2553         uiItemR(layout, ptr, "edge_kernel_tolerance", 0, NULL, ICON_NONE);
2554         uiItemR(layout, ptr, "clip_black", 0, NULL, ICON_NONE);
2555         uiItemR(layout, ptr, "clip_white", 0, NULL, ICON_NONE);
2556         uiItemR(layout, ptr, "dilate_distance", 0, NULL, ICON_NONE);
2557         uiItemR(layout, ptr, "feather_falloff", 0, NULL, ICON_NONE);
2558         uiItemR(layout, ptr, "feather_distance", 0, NULL, ICON_NONE);
2559         uiItemR(layout, ptr, "blur_post", 0, NULL, ICON_NONE);
2560 }
2561
2562 static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRNA *ptr)
2563 {
2564         bNode *node = ptr->data;
2565
2566         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2567
2568         if (node->id) {
2569                 MovieClip *clip = (MovieClip *) node->id;
2570                 MovieTracking *tracking = &clip->tracking;
2571                 MovieTrackingObject *object;
2572                 uiLayout *col;
2573                 PointerRNA tracking_ptr;
2574                 NodeTrackPosData *data = node->storage;
2575
2576                 RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr);
2577
2578                 col = uiLayoutColumn(layout, 0);
2579                 uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
2580
2581                 object = BKE_tracking_object_get_named(tracking, data->tracking_object);
2582                 if (object) {
2583                         PointerRNA object_ptr;
2584
2585                         RNA_pointer_create(&clip->id, &RNA_MovieTrackingObject, object, &object_ptr);
2586
2587                         uiItemPointerR(col, ptr, "track_name", &object_ptr, "tracks", "", ICON_ANIM_DATA);
2588                 }
2589                 else {
2590                         uiItemR(layout, ptr, "track_name", 0, "", ICON_ANIM_DATA);
2591                 }
2592
2593                 uiItemR(layout, ptr, "position", 0, NULL, ICON_NONE);
2594
2595                 if (node->custom1 == 2) {
2596                         uiItemR(layout, ptr, "relative_frame", 0, NULL, ICON_NONE);
2597                 }
2598         }
2599 }
2600
2601 /* only once called */
2602 static void node_composit_set_butfunc(bNodeType *ntype)
2603 {
2604         switch (ntype->type) {
2605                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
2606
2607                 case CMP_NODE_IMAGE:
2608                         ntype->uifunc = node_composit_buts_image;
2609                         break;
2610                 case CMP_NODE_R_LAYERS:
2611                         ntype->uifunc = node_composit_buts_renderlayers;
2612                         break;
2613                 case CMP_NODE_NORMAL:
2614                         ntype->uifunc = node_buts_normal;
2615                         break;
2616                 case CMP_NODE_CURVE_VEC:
2617                         ntype->uifunc = node_buts_curvevec;
2618                         break;
2619                 case CMP_NODE_CURVE_RGB:
2620                         ntype->uifunc = node_buts_curvecol;
2621                         break;
2622                 case CMP_NODE_VALUE:
2623                         ntype->uifunc = node_buts_value;
2624                         break;
2625                 case CMP_NODE_RGB:
2626                         ntype->uifunc = node_buts_rgb;
2627                         break;
2628                 case CMP_NODE_FLIP:
2629                         ntype->uifunc = node_composit_buts_flip;
2630                         break;
2631                 case CMP_NODE_SPLITVIEWER:
2632                         ntype->uifunc = node_composit_buts_splitviewer;
2633                         break;
2634                 case CMP_NODE_MIX_RGB:
2635                         ntype->uifunc = node_buts_mix_rgb;
2636                         break;
2637                 case CMP_NODE_VALTORGB:
2638                         ntype->uifunc = node_buts_colorramp;
2639                         break;
2640                 case CMP_NODE_CROP:
2641                         ntype->uifunc = node_composit_buts_crop;
2642                         break;
2643                 case CMP_NODE_BLUR:
2644                         ntype->uifunc = node_composit_buts_blur;
2645                         break;
2646                 case CMP_NODE_DBLUR:
2647                         ntype->uifunc = node_composit_buts_dblur;
2648                         break;
2649                 case CMP_NODE_BILATERALBLUR:
2650                         ntype->uifunc = node_composit_buts_bilateralblur;
2651                         break;
2652                 case CMP_NODE_DEFOCUS:
2653                         ntype->uifunc = node_composit_buts_defocus;
2654                         break;
2655                 case CMP_NODE_GLARE:
2656                         ntype->uifunc = node_composit_buts_glare;
2657                         break;
2658                 case CMP_NODE_TONEMAP:
2659                         ntype->uifunc = node_composit_buts_tonemap;
2660                         break;
2661                 case CMP_NODE_LENSDIST:
2662                         ntype->uifunc = node_composit_buts_lensdist;
2663                         break;
2664                 case CMP_NODE_VECBLUR:
2665                         ntype->uifunc = node_composit_buts_vecblur;
2666                         break;
2667                 case CMP_NODE_FILTER:
2668                         ntype->uifunc = node_composit_buts_filter;
2669                         break;
2670                 case CMP_NODE_MAP_VALUE:
2671                         ntype->uifunc = node_composit_buts_map_value;
2672                         break;
2673                 case CMP_NODE_TIME:
2674                         ntype->uifunc = node_buts_time;
2675                         break;
2676                 case CMP_NODE_ALPHAOVER:
2677                         ntype->uifunc = node_composit_buts_alphaover;
2678                         break;
2679                 case CMP_NODE_HUE_SAT:
2680                         ntype->uifunc = node_composit_buts_hue_sat;
2681                         break;
2682                 case CMP_NODE_TEXTURE:
2683                         ntype->uifunc = node_buts_texture;
2684                         break;
2685                 case CMP_NODE_DILATEERODE:
2686                         ntype->uifunc = node_composit_buts_dilateerode;
2687                         break;
2688                 case CMP_NODE_INPAINT:
2689                         ntype->uifunc = node_composit_buts_inpaint;
2690                         break;
2691                 case CMP_NODE_DESPECKLE:
2692                         ntype->uifunc = node_composit_buts_despeckle;
2693                         break;
2694                 case CMP_NODE_OUTPUT_FILE:
2695                         ntype->uifunc = node_composit_buts_file_output;
2696                         ntype->uifuncbut = node_composit_buts_file_output_details;
2697                         ntype->drawinputfunc = node_draw_input_file_output;
2698                         break;
2699                 case CMP_NODE_DIFF_MATTE:
2700                         ntype->uifunc = node_composit_buts_diff_matte;
2701                         break;
2702                 case CMP_NODE_DIST_MATTE:
2703                         ntype->uifunc = node_composit_buts_distance_matte;
2704                         break;
2705                 case CMP_NODE_COLOR_SPILL:
2706                         ntype->uifunc = node_composit_buts_color_spill;
2707                         break;
2708                 case CMP_NODE_CHROMA_MATTE:
2709                         ntype->uifunc = node_composit_buts_chroma_matte;
2710                         break;
2711                 case CMP_NODE_COLOR_MATTE:
2712                         ntype->uifunc = node_composit_buts_color_matte;
2713                         break;
2714                 case CMP_NODE_SCALE:
2715                         ntype->uifunc = node_composit_buts_scale;
2716                         break;
2717                 case CMP_NODE_ROTATE:
2718                         ntype->uifunc = node_composit_buts_rotate;
2719                         break;
2720                 case CMP_NODE_CHANNEL_MATTE:
2721                         ntype->uifunc = node_composit_buts_channel_matte;
2722                         break;
2723                 case CMP_NODE_LUMA_MATTE:
2724                         ntype->uifunc = node_composit_buts_luma_matte;
2725                         break;
2726                 case CMP_NODE_MAP_UV:
2727                         ntype->uifunc = node_composit_buts_map_uv;
2728                         break;
2729                 case CMP_NODE_ID_MASK:
2730                         ntype->uifunc = node_composit_buts_id_mask;
2731                         break;
2732                 case CMP_NODE_DOUBLEEDGEMASK:
2733                         ntype->uifunc = node_composit_buts_double_edge_mask;
2734                         break;
2735                 case CMP_NODE_MATH:
2736                         ntype->uifunc = node_buts_math;
2737                         break;
2738                 case CMP_NODE_INVERT:
2739                         ntype->uifunc = node_composit_buts_invert;
2740                         break;
2741                 case CMP_NODE_PREMULKEY:
2742                         ntype->uifunc = node_composit_buts_premulkey;
2743                         break;
2744                 case CMP_NODE_VIEW_LEVELS:
2745                         ntype->uifunc = node_composit_buts_view_levels;
2746                         break;
2747                 case CMP_NODE_COLORBALANCE:
2748                         ntype->uifunc = node_composit_buts_colorbalance;
2749                         ntype->uifuncbut = node_composit_buts_colorbalance_but;
2750                         break;
2751                 case CMP_NODE_HUECORRECT:
2752                         ntype->uifunc = node_composit_buts_huecorrect;
2753                         break;
2754                 case CMP_NODE_ZCOMBINE:
2755                         ntype->uifunc = node_composit_buts_zcombine;
2756                         break;
2757                 case CMP_NODE_COMBYCCA:
2758                 case CMP_NODE_SEPYCCA:
2759                         ntype->uifunc = node_composit_buts_ycc;
2760                         break;
2761                 case CMP_NODE_MOVIECLIP:
2762                         ntype->uifunc = node_composit_buts_movieclip;
2763                         break;
2764                 case CMP_NODE_STABILIZE2D:
2765                         ntype->uifunc = node_composit_buts_stabilize2d;
2766                         break;
2767                 case CMP_NODE_TRANSFORM:
2768                         ntype->uifunc = node_composit_buts_transform;
2769                         break;
2770                 case CMP_NODE_MOVIEDISTORTION:
2771                         ntype->uifunc = node_composit_buts_moviedistortion;
2772                         break;
2773                 case CMP_NODE_COLORCORRECTION:
2774                         ntype->uifunc = node_composit_buts_colorcorrection;
2775                         ntype->uifuncbut = node_composit_buts_colorcorrection_but;
2776                         break;
2777                 case CMP_NODE_SWITCH:
2778                         ntype->uifunc = node_composit_buts_switch;
2779                         break;
2780                 case CMP_NODE_MASK_BOX:
2781                         ntype->uifunc = node_composit_buts_boxmask;
2782                         ntype->uibackdropfunc = node_composit_backdrop_boxmask;
2783                         break;
2784                 case CMP_NODE_MASK_ELLIPSE:
2785                         ntype->uifunc = node_composit_buts_ellipsemask;
2786                         ntype->uibackdropfunc = node_composit_backdrop_ellipsemask;
2787                         break;
2788                 case CMP_NODE_BOKEHIMAGE:
2789                         ntype->uifunc = node_composit_buts_bokehimage;
2790                         break;
2791                 case CMP_NODE_BOKEHBLUR:
2792                         ntype->uifunc = node_composit_buts_bokehblur;
2793                         break;
2794                 case CMP_NODE_VIEWER:
2795                         ntype->uifunc = NULL;
2796                         ntype->uifuncbut = node_composit_buts_viewer_but;
2797                         ntype->uibackdropfunc = node_composit_backdrop_viewer;
2798                         break;
2799                 case CMP_NODE_MASK:
2800                         ntype->uifunc = node_composit_buts_mask;
2801                         break;
2802                 case CMP_NODE_KEYINGSCREEN:
2803                         ntype->uifunc = node_composit_buts_keyingscreen;
2804                         break;
2805                 case CMP_NODE_KEYING:
2806                         ntype->uifunc = node_composit_buts_keying;
2807                         break;
2808                 case CMP_NODE_TRACKPOS:
2809                         ntype->uifunc = node_composit_buts_trackpos;
2810                         break;
2811                 default:
2812                         ntype->uifunc = NULL;
2813         }
2814 }
2815
2816 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
2817
2818 static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2819 {
2820         uiLayout *col;
2821         
2822         col = uiLayoutColumn(layout, TRUE);
2823         uiItemR(col, ptr, "offset", 0, IFACE_("Offset"), ICON_NONE);
2824         uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE);
2825         
2826         col = uiLayoutColumn(layout, TRUE);
2827         uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE);
2828         uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE);
2829 }
2830
2831 static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2832 {
2833         PointerRNA tex_ptr;
2834         bNode *node = ptr->data;
2835         ID *id = ptr->id.data;
2836         Tex *tex = (Tex *)node->storage;
2837         uiLayout *col, *row;
2838         
2839         RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr);
2840
2841         col = uiLayoutColumn(layout, FALSE);
2842
2843         switch (tex->type) {
2844                 case TEX_BLEND:
2845                         uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE);
2846                         row = uiLayoutRow(col, FALSE);
2847                         uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2848                         break;
2849
2850                 case TEX_MARBLE:
2851                         row = uiLayoutRow(col, FALSE);
2852                         uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2853                         row = uiLayoutRow(col, FALSE);
2854                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2855                         row = uiLayoutRow(col, FALSE);
2856                         uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2857                         row = uiLayoutRow(col, FALSE);
2858                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2859                         break;
2860
2861                 case TEX_MAGIC:
2862                         uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE);
2863                         break;
2864
2865                 case TEX_STUCCI:
2866                         row = uiLayoutRow(col, FALSE);
2867                         uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2868                         row = uiLayoutRow(col, FALSE);
2869                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2870                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2871                         break;
2872
2873                 case TEX_WOOD:
2874                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2875                         uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE);
2876                         row = uiLayoutRow(col, FALSE);
2877                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2878                         row = uiLayoutRow(col, FALSE);
2879                         uiLayoutSetActive(row, !(ELEM(tex->stype, TEX_BAND, TEX_RING)));
2880                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2881                         break;
2882                         
2883                 case TEX_CLOUDS:
2884                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2885                         row = uiLayoutRow(col, FALSE);
2886                         uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2887                         row = uiLayoutRow(col, FALSE);
2888                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2889                         uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, IFACE_("Depth"), ICON_NONE);
2890                         break;
2891                         
2892                 case TEX_DISTNOISE:
2893                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2894                         uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE);
2895                         break;
2896
2897                 case TEX_MUSGRAVE:
2898                         uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE);
2899                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2900                         break;
2901                 case TEX_VORONOI:
2902                         uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE);
2903                         if (tex->vn_distm == TEX_MINKOVSKY) {
2904                                 uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE);
2905                         }
2906                         uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE);
2907                         break;
2908         }
2909 }
2910
2911 static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
2912 {
2913         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
2914 }
2915
2916 static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2917 {
2918         uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
2919 }
2920
2921 /* only once called */
2922 static void node_texture_set_butfunc(bNodeType *ntype)
2923 {
2924         if (ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX) {
2925                 ntype->uifunc = node_texture_buts_proc;
2926         }
2927         else {
2928                 switch (ntype->type) {
2929
2930                         case TEX_NODE_MATH:
2931                                 ntype->uifunc = node_buts_math;
2932                                 break;
2933
2934                         case TEX_NODE_MIX_RGB:
2935                                 ntype->uifunc = node_buts_mix_rgb;
2936                                 break;
2937
2938                         case TEX_NODE_VALTORGB:
2939                                 ntype->uifunc = node_buts_colorramp;
2940                                 break;
2941
2942                         case TEX_NODE_CURVE_RGB:
2943                                 ntype->uifunc = node_buts_curvecol;
2944                                 break;
2945
2946                         case TEX_NODE_CURVE_TIME:
2947                                 ntype->uifunc = node_buts_time;
2948                                 break;
2949
2950                         case TEX_NODE_TEXTURE:
2951                                 ntype->uifunc = node_buts_texture;
2952                                 break;
2953
2954                         case TEX_NODE_BRICKS:
2955                                 ntype->uifunc = node_texture_buts_bricks;
2956                                 break;
2957
2958                         case TEX_NODE_IMAGE:
2959                                 ntype->uifunc = node_texture_buts_image;
2960                                 break;
2961
2962                         case TEX_NODE_OUTPUT:
2963                                 ntype->uifunc = node_texture_buts_output;
2964                                 break;
2965                 }
2966         }
2967 }
2968
2969 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
2970
2971 void ED_node_init_butfuncs(void)
2972 {
2973         bNodeTreeType *treetype;
2974         bNodeType *ntype;
2975         bNodeSocketType *stype;
2976         int i;
2977         
2978         /* node type ui functions */
2979         for (i = 0; i < NUM_NTREE_TYPES; ++i) {
2980                 treetype = ntreeGetType(i);
2981                 if (treetype) {
2982                         for (ntype = treetype->node_types.first; ntype; ntype = ntype->next) {
2983                                 /* default ui functions */
2984                                 ntype->drawfunc = node_draw_default;
2985                                 ntype->drawupdatefunc = node_update_default;
2986                                 ntype->select_area_func = node_select_area_default;
2987                                 ntype->tweak_area_func = node_tweak_area_default;
2988                                 ntype->uifunc = NULL;
2989                                 ntype->uifuncbut = NULL;
2990                                 ntype->drawinputfunc = node_draw_input_default;
2991                                 ntype->drawoutputfunc = node_draw_output_default;
2992                                 ntype->resize_area_func = node_resize_area_default;
2993                                 
2994                                 node_common_set_butfunc(ntype);
2995                                 
2996                                 switch (i) {
2997                                         case NTREE_COMPOSIT:
2998                                                 node_composit_set_butfunc(ntype);
2999                                                 break;
3000                                         case NTREE_SHADER:
3001                                                 node_shader_set_butfunc(ntype);
3002                                                 break;
3003                                         case NTREE_TEXTURE:
3004                                                 node_texture_set_butfunc(ntype);
3005                                                 break;
3006                                 }
3007                         }
3008                 }
3009         }
3010         
3011         /* socket type ui functions */
3012         for (i = 0; i < NUM_SOCKET_TYPES; ++i) {
3013                 stype = ntreeGetSocketType(i);
3014                 if (stype) {
3015                         switch (stype->type) {
3016                                 case SOCK_FLOAT:
3017                                 case SOCK_INT:
3018                                 case SOCK_BOOLEAN:
3019                                         stype->buttonfunc = node_socket_button_default;
3020                                         break;
3021                                 case SOCK_VECTOR:
3022                                         stype->buttonfunc = node_socket_button_components;
3023                                         break;
3024                                 case SOCK_RGBA:
3025                                         stype->buttonfunc = node_socket_button_color;
3026                                         break;
3027                                 case SOCK_SHADER:
3028                                         stype->buttonfunc = node_socket_button_label;
3029                                         break;
3030                                 default:
3031                                         stype->buttonfunc = NULL;
3032                         }
3033                 }
3034         }
3035 }
3036
3037 /* ************** Generic drawing ************** */
3038
3039 void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
3040 {
3041         
3042         if ((snode->flag & SNODE_BACKDRAW) && snode->treetype == NTREE_COMPOSIT) {
3043                 Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
3044                 void *lock;
3045                 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
3046                 if (ibuf) {
3047                         SpaceNode *snode = CTX_wm_space_node(C);
3048                         float x, y; 
3049                         unsigned char *display_buffer;
3050                         void *cache_handle;
3051                         
3052                         glMatrixMode(GL_PROJECTION);
3053                         glPushMatrix();
3054                         glMatrixMode(GL_MODELVIEW);
3055                         glPushMatrix();
3056
3057                         /* keep this, saves us from a version patch */
3058                         if (snode->zoom == 0.0f) snode->zoom = 1.0f;
3059                         
3060                         /* somehow the offset has to be calculated inverse */
3061                         
3062                         glaDefine2DArea(&ar->winrct);
3063                         /* ortho at pixel level curarea */
3064                         wmOrtho2(-GLA_PIXEL_OFS, ar->winx - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, ar->winy - GLA_PIXEL_OFS);
3065                         
3066                         x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
3067                         y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
3068                         
3069
3070                         display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
3071
3072                         if (display_buffer) {
3073                                 if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) {
3074                                         int ofs;
3075
3076 #ifdef __BIG_ENDIAN__
3077                                         if      (snode->flag & SNODE_SHOW_R) ofs = 2;
3078                                         else if (snode->flag & SNODE_SHOW_G) ofs = 1;
3079                                         else                                 ofs = 0;
3080 #else
3081                                         if      (snode->flag & SNODE_SHOW_R) ofs = 1;
3082                                         else if (snode->flag & SNODE_SHOW_G) ofs = 2;
3083                                         else                                 ofs = 3;
3084 #endif
3085
3086                                         glPixelZoom(snode->zoom, snode->zoom);
3087                                         /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
3088
3089                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT,
3090                                                           ((unsigned char *)ibuf->rect) + ofs);
3091
3092                                         glPixelZoom(1.0f, 1.0f);
3093                                 }
3094                                 else if (snode->flag & SNODE_SHOW_ALPHA) {
3095                                         glPixelZoom(snode->zoom, snode->zoom);
3096                                         /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
3097 #ifdef __BIG_ENDIAN__
3098                                         glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
3099 #endif
3100                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, display_buffer);
3101
3102 #ifdef __BIG_ENDIAN__
3103                                         glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
3104 #endif
3105                                         glPixelZoom(1.0f, 1.0f);
3106                                 }
3107                                 else if (snode->flag & SNODE_USE_ALPHA) {
3108                                         glEnable(GL_BLEND);
3109                                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3110                                         glPixelZoom(snode->zoom, snode->zoom);
3111                                         
3112                                         glaDrawPixelsS