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