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