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