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