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