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