Merging r38562 through r38614 from trunkinto soc-2011-tomato
[blender.git] / source / blender / editors / space_node / drawnode.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2005 Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Bob Holcomb, Thomas Dinges
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/editors/space_node/drawnode.c
31  *  \ingroup spnode
32  */
33
34
35 #include <math.h>
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "BLI_blenlib.h"
40 #include "BLI_math.h"
41 #include "BLI_utildefines.h"
42
43 #include "DNA_node_types.h"
44 #include "DNA_material_types.h"
45 #include "DNA_object_types.h"
46 #include "DNA_scene_types.h"
47 #include "DNA_space_types.h"
48 #include "DNA_screen_types.h"
49
50 #include "BKE_context.h"
51 #include "BKE_curve.h"
52 #include "BKE_global.h"
53 #include "BKE_image.h"
54 #include "BKE_library.h"
55 #include "BKE_main.h"
56
57 #include "CMP_node.h"
58 #include "SHD_node.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_glutil.h"
62
63 #include "BLF_api.h"
64
65 #include "MEM_guardedalloc.h"
66
67
68 #include "RNA_access.h"
69
70 #include "ED_node.h"
71
72 #include "WM_api.h"
73 #include "WM_types.h"
74
75 #include "UI_interface.h"
76 #include "UI_resources.h"
77
78 #include "IMB_imbuf.h"
79 #include "IMB_imbuf_types.h"
80
81 #include "node_intern.h"
82
83
84 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
85
86 static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
87 {
88         PointerRNA sockptr;
89         PropertyRNA *prop;
90         
91         /* first socket stores value */
92         prop = RNA_struct_find_property(ptr, "outputs");
93         RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
94         
95         uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE);
96 }
97
98 static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
99 {
100         uiLayout *col;
101         PointerRNA sockptr;
102         PropertyRNA *prop;
103         
104         /* first socket stores value */
105         prop = RNA_struct_find_property(ptr, "outputs");
106         RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
107         
108         col = uiLayoutColumn(layout, 0);
109         uiTemplateColorWheel(col, &sockptr, "default_value", 1, 0, 0, 0);
110         uiItemR(col, &sockptr, "default_value", 0, "", ICON_NONE);
111 }
112
113 static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
114 {       
115         uiLayout *row;
116
117         bNodeTree *ntree= (bNodeTree*)ptr->id.data;
118
119         row= uiLayoutRow(layout, 1);
120         uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE);
121         if(ntree->type == NTREE_COMPOSIT)
122                 uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA);
123 }
124
125 static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
126 {
127         uiLayout *row;
128 #if 0
129         /* XXX no context access here .. */
130         bNode *node= ptr->data;
131         CurveMapping *cumap= node->storage;
132         
133         if(cumap) {
134                 cumap->flag |= CUMA_DRAW_CFRA;
135                 if(node->custom1<node->custom2)
136                         cumap->sample[0]= (float)(CFRA - node->custom1)/(float)(node->custom2-node->custom1);
137         }
138 #endif
139
140         uiTemplateCurveMapping(layout, ptr, "curve", 's', 0, 0);
141
142         row= uiLayoutRow(layout, 1);
143         uiItemR(row, ptr, "frame_start", 0, "Sta", ICON_NONE);
144         uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
145 }
146
147 static void node_buts_colorramp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
148 {
149         uiTemplateColorRamp(layout, ptr, "color_ramp", 0);
150 }
151
152 static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
153 {
154         uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0);
155 }
156
157 static float *_sample_col= NULL;        // bad bad, 2.5 will do better?
158 #if 0
159 static void node_curvemap_sample(float *col)
160 {
161         _sample_col= col;
162 }
163 #endif
164
165 static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
166 {
167         bNode *node= ptr->data;
168         CurveMapping *cumap= node->storage;
169
170         if(_sample_col) {
171                 cumap->flag |= CUMA_DRAW_SAMPLE;
172                 VECCOPY(cumap->sample, _sample_col);
173         }
174         else 
175                 cumap->flag &= ~CUMA_DRAW_SAMPLE;
176
177         uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0);
178 }
179
180 static void node_normal_cb(bContext *C, void *ntree_v, void *node_v)
181 {
182         Main *bmain = CTX_data_main(C);
183
184         ED_node_generic_update(bmain, ntree_v, node_v);
185         WM_event_add_notifier(C, NC_NODE|NA_EDITED, ntree_v);
186 }
187
188 static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
189 {
190         uiBlock *block= uiLayoutAbsoluteBlock(layout);
191         bNodeTree *ntree= ptr->id.data;
192         bNode *node= ptr->data;
193         rctf *butr= &node->butr;
194         bNodeSocket *sock= node->outputs.first;         /* first socket stores normal */
195         uiBut *bt;
196         
197         bt= uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "", 
198                           (short)butr->xmin, (short)butr->xmin, butr->xmax-butr->xmin, butr->xmax-butr->xmin, 
199                           sock->ns.vec, 0.0f, 1.0f, 0, 0, "");
200         uiButSetFunc(bt, node_normal_cb, ntree, node);
201 }
202 #if 0 // not used in 2.5x yet
203 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
204 {
205         Main *bmain= CTX_data_main(C);
206         bNodeTree *ntree= ntree_v;
207         bNode *node= node_v;
208         Tex *tex;
209         
210         if(node->menunr<1) return;
211         
212         if(node->id) {
213                 node->id->us--;
214                 node->id= NULL;
215         }
216         tex= BLI_findlink(&bmain->tex, node->menunr-1);
217
218         node->id= &tex->id;
219         id_us_plus(node->id);
220         BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
221         
222         nodeSetActive(ntree, node);
223         
224         if( ntree->type == NTREE_TEXTURE )
225                 ntreeTexCheckCyclics( ntree );
226         
227         // allqueue(REDRAWBUTSSHADING, 0);
228         // allqueue(REDRAWNODE, 0);
229         NodeTagChanged(ntree, node); 
230         
231         node->menunr= 0;
232 }
233 #endif
234 static void node_dynamic_update_cb(bContext *C, void *UNUSED(ntree_v), void *node_v)
235 {
236         Main *bmain= CTX_data_main(C);
237         Material *ma;
238         bNode *node= (bNode *)node_v;
239         ID *id= node->id;
240         int error= 0;
241
242         if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) error= 1;
243
244         /* Users only have to press the "update" button in one pynode
245          * and we also update all others sharing the same script */
246         for (ma= bmain->mat.first; ma; ma= ma->id.next) {
247                 if (ma->nodetree) {
248                         bNode *nd;
249                         for (nd= ma->nodetree->nodes.first; nd; nd= nd->next) {
250                                 if ((nd->type == NODE_DYNAMIC) && (nd->id == id)) {
251                                         nd->custom1= 0;
252                                         nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_REPARSE);
253                                         nd->menunr= 0;
254                                         if (error)
255                                                 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_ERROR);
256                                 }
257                         }
258                 }
259         }
260
261         // allqueue(REDRAWBUTSSHADING, 0);
262         // allqueue(REDRAWNODE, 0);
263         // XXX BIF_preview_changed(ID_MA);
264 }
265
266 static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
267 {
268         bNode *node= ptr->data;
269
270         short multi = (
271                 node->id &&
272                 ((Tex*)node->id)->use_nodes &&
273                 (node->type != CMP_NODE_TEXTURE) &&
274                 (node->type != TEX_NODE_TEXTURE)
275         );
276         
277         uiItemR(layout, ptr, "texture", 0, "", ICON_NONE);
278         
279         if(multi) {
280                 /* Number Drawing not optimal here, better have a list*/
281                 uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE);
282         }
283 }
284
285 static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
286
287         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
288 }
289
290 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
291
292 static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v)
293 {
294         Main *bmain= CTX_data_main(C);
295         bNodeTree *ntree= ntree_v;
296         bNode *node= node_v;
297         ID *oldid;
298         
299         if(node->menunr<1) return;
300         
301         if(node->id) {
302                 node->id->us--;
303         }
304         oldid= node->id;
305         node->id= BLI_findlink(&bmain->text, node->menunr-1);
306         id_us_plus(node->id);
307         BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
308
309         node->custom1= BSET(node->custom1, NODE_DYNAMIC_NEW);
310         
311         nodeSetActive(ntree, node);
312
313         // allqueue(REDRAWBUTSSHADING, 0);
314         // allqueue(REDRAWNODE, 0);
315
316         node->menunr= 0;
317 }
318
319 static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
320 {
321         bNode *node= ptr->data;
322         uiLayout *col;
323         
324         uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL);
325         
326         if(!node->id) return;
327         
328         col= uiLayoutColumn(layout, 0);
329         uiItemR(col, ptr, "use_diffuse", 0, NULL, ICON_NONE);
330         uiItemR(col, ptr, "use_specular", 0, NULL, ICON_NONE);
331         uiItemR(col, ptr, "invert_normal", 0, NULL, ICON_NONE);
332 }
333
334 static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
335 {
336         uiLayout *row;
337         
338         uiItemL(layout, "Location:", ICON_NONE);
339         row= uiLayoutRow(layout, 1);
340         uiItemR(row, ptr, "location", 0, "", ICON_NONE);
341         
342         uiItemL(layout, "Rotation:", ICON_NONE);
343         row= uiLayoutRow(layout, 1);
344         uiItemR(row, ptr, "rotation", 0, "", ICON_NONE);
345         
346         uiItemL(layout, "Scale:", ICON_NONE);
347         row= uiLayoutRow(layout, 1);
348         uiItemR(row, ptr, "scale", 0, "", ICON_NONE);
349         
350         row= uiLayoutRow(layout, 1);
351         uiItemR(row, ptr, "use_min", 0, "Min", ICON_NONE);
352         uiItemR(row, ptr, "min", 0, "", ICON_NONE);
353         
354         row= uiLayoutRow(layout, 1);
355         uiItemR(row, ptr, "use_max", 0, "Max", ICON_NONE);
356         uiItemR(row, ptr, "max", 0, "", ICON_NONE);
357         
358 }
359
360 static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
361
362         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
363 }
364
365 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
366 {
367         PointerRNA obptr= CTX_data_pointer_get(C, "active_object");
368         uiLayout *col;
369
370         col= uiLayoutColumn(layout, 0);
371
372         if(obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
373                 PointerRNA dataptr= RNA_pointer_get(&obptr, "data");
374
375                 uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
376                 uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
377         }
378         else {
379                 uiItemR(col, ptr, "uv_layer", 0, "UV", ICON_NONE);
380                 uiItemR(col, ptr, "color_layer", 0, "VCol", ICON_NONE);
381         }
382 }
383
384 static void node_shader_buts_dynamic(uiLayout *layout, bContext *C, PointerRNA *ptr)
385
386         Main *bmain= CTX_data_main(C);
387         uiBlock *block= uiLayoutAbsoluteBlock(layout);
388         bNode *node= ptr->data;
389         bNodeTree *ntree= ptr->id.data;
390         rctf *butr= &node->butr;
391         uiBut *bt;
392         // XXX SpaceNode *snode= curarea->spacedata.first;
393         short dy= (short)butr->ymin;
394         int xoff=0;
395
396         /* B_NODE_EXEC is handled in butspace.c do_node_buts */
397         if(!node->id) {
398                         const char *strp;
399                         IDnames_to_pupstring(&strp, NULL, "", &(bmain->text), NULL, NULL);
400                         node->menunr= 0;
401                         bt= uiDefButS(block, MENU, B_NODE_EXEC/*+node->nr*/, strp, 
402                                                         butr->xmin, dy, 19, 19, 
403                                                         &node->menunr, 0, 0, 0, 0, "Browses existing choices");
404                         uiButSetFunc(bt, node_browse_text_cb, ntree, node);
405                         xoff=19;
406                         if(strp) MEM_freeN((void *)strp);
407         }
408         else {
409                 bt = uiDefBut(block, BUT, B_NOP, "Update",
410                                 butr->xmin+xoff, butr->ymin+20, 50, 19,
411                                 &node->menunr, 0.0, 19.0, 0, 0, "Refresh this node (and all others that use the same script)");
412                 uiButSetFunc(bt, node_dynamic_update_cb, ntree, node);
413
414                 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) {
415                         // UI_ThemeColor(TH_REDALERT);
416                         // XXX ui_rasterpos_safe(butr->xmin + xoff, butr->ymin + 5, snode->aspect);
417                         // XXX snode_drawstring(snode, "Error! Check console...", butr->xmax - butr->xmin);
418                         ;
419                 }
420         }
421 }
422
423 /* only once called */
424 static void node_shader_set_butfunc(bNodeType *ntype)
425 {
426         ntype->uifuncbut = NULL;
427         switch(ntype->type) {
428                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
429
430                 case SH_NODE_MATERIAL:
431                 case SH_NODE_MATERIAL_EXT:
432                         ntype->uifunc= node_shader_buts_material;
433                         break;
434                 case SH_NODE_TEXTURE:
435                         ntype->uifunc= node_buts_texture;
436                         break;
437                 case SH_NODE_NORMAL:
438                         ntype->uifunc= node_buts_normal;
439                         break;
440                 case SH_NODE_CURVE_VEC:
441                         ntype->uifunc= node_buts_curvevec;
442                         break;
443                 case SH_NODE_CURVE_RGB:
444                         ntype->uifunc= node_buts_curvecol;
445                         break;
446                 case SH_NODE_MAPPING:
447                         ntype->uifunc= node_shader_buts_mapping;
448                         break;
449                 case SH_NODE_VALUE:
450                         ntype->uifunc= node_buts_value;
451                         break;
452                 case SH_NODE_RGB:
453                         ntype->uifunc= node_buts_rgb;
454                         break;
455                 case SH_NODE_MIX_RGB:
456                         ntype->uifunc= node_buts_mix_rgb;
457                         break;
458                 case SH_NODE_VALTORGB:
459                         ntype->uifunc= node_buts_colorramp;
460                         break;
461                 case SH_NODE_MATH: 
462                         ntype->uifunc= node_buts_math;
463                         break; 
464                 case SH_NODE_VECT_MATH: 
465                         ntype->uifunc= node_shader_buts_vect_math;
466                         break; 
467                 case SH_NODE_GEOMETRY:
468                         ntype->uifunc= node_shader_buts_geometry;
469                         break;
470                 case NODE_DYNAMIC:
471                         ntype->uifunc= node_shader_buts_dynamic;
472                         break;
473                 default:
474                         ntype->uifunc= NULL;
475         }
476                 if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
477 }
478
479 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
480
481 static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
482 {
483         uiLayout *col;
484         bNode *node= ptr->data;
485         PointerRNA imaptr;
486         PropertyRNA *prop;
487         int source;
488         
489         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
490         
491         if(!node->id) return;
492         
493         prop = RNA_struct_find_property(ptr, "image");
494         if (!prop || RNA_property_type(prop) != PROP_POINTER) return;
495         imaptr= RNA_property_pointer_get(ptr, prop);
496         
497         col= uiLayoutColumn(layout, 0);
498         
499         uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE);
500         
501         source= RNA_enum_get(&imaptr, "source");
502
503         if(source == IMA_SRC_SEQUENCE) {
504                 /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
505                 Scene *scene= CTX_data_scene(C);
506                 ImageUser *iuser= node->storage;
507                 char tstr[32];
508                 const int framenr= BKE_image_user_get_frame(iuser, CFRA, 0);
509                 BLI_snprintf(tstr, sizeof(tstr), "Frame: %d", framenr);
510                 uiItemL(layout, tstr, ICON_NONE);
511         }
512
513         if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
514                 col= uiLayoutColumn(layout, 1);
515                 uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
516                 uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
517                 uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
518                 uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
519                 uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
520         }
521
522         col= uiLayoutColumn(layout, 0);
523         
524         if (RNA_enum_get(&imaptr, "type")== IMA_TYPE_MULTILAYER)
525                 uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
526 }
527
528 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
529 {
530         bNode *node= ptr->data;
531         uiLayout *col, *row;
532         PointerRNA op_ptr;
533         PointerRNA scn_ptr;
534         PropertyRNA *prop;
535         const char *layer_name;
536         char scene_name[MAX_ID_NAME-2];
537         
538         uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
539         
540         if(!node->id) return;
541
542         col= uiLayoutColumn(layout, 0);
543         row = uiLayoutRow(col, 0);
544         uiItemR(row, ptr, "layer", 0, "", ICON_NONE);
545         
546         prop = RNA_struct_find_property(ptr, "layer");
547         if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)))
548                 return;
549         
550         scn_ptr = RNA_pointer_get(ptr, "scene");
551         RNA_string_get(&scn_ptr, "name", scene_name);
552         
553         WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
554         RNA_string_set(&op_ptr, "layer", layer_name);
555         RNA_string_set(&op_ptr, "scene", scene_name);
556         uiItemFullO(row, "RENDER_OT_render", "", ICON_RENDER_STILL, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
557
558 }
559
560
561 static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
562 {
563         uiLayout *col, *row;
564         
565         col= uiLayoutColumn(layout, 0);
566         
567         uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE);
568         if (RNA_enum_get(ptr, "filter_type")!= R_FILTER_FAST_GAUSS) {
569                 uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE);
570                 uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
571         }
572         
573         uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE);
574         
575         if (RNA_boolean_get(ptr, "use_relative")) {
576                 uiItemL(col, "Aspect Correction", 0);
577                 row= uiLayoutRow(layout, 1);
578                 uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0);
579                 
580                 col= uiLayoutColumn(layout, 1);
581                 uiItemR(col, ptr, "factor_x", 0, "X", ICON_NONE);
582                 uiItemR(col, ptr, "factor_y", 0, "Y", ICON_NONE);
583         }
584         else {
585                 col= uiLayoutColumn(layout, 1);
586                 uiItemR(col, ptr, "size_x", 0, "X", ICON_NONE);
587                 uiItemR(col, ptr, "size_y", 0, "Y", ICON_NONE);
588         }
589 }
590
591 static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
592 {
593         uiLayout *col;
594         
595         uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
596         uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE);
597         
598         col= uiLayoutColumn(layout, 1);
599         uiItemL(col, "Center:", ICON_NONE);
600         uiItemR(col, ptr, "center_x", 0, "X", ICON_NONE);
601         uiItemR(col, ptr, "center_y", 0, "Y", ICON_NONE);
602         
603         uiItemS(layout);
604         
605         col= uiLayoutColumn(layout, 1);
606         uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE);
607         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
608         
609         uiItemS(layout);
610         
611         uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE);
612         uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE);
613 }
614
615 static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
616 {       
617         uiLayout *col;
618         
619         col= uiLayoutColumn(layout, 1);
620         uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
621         uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE);
622         uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
623 }
624
625 static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
626 {
627         uiLayout *sub, *col;
628         
629         col= uiLayoutColumn(layout, 0);
630         uiItemL(col, "Bokeh Type:", ICON_NONE);
631         uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE);
632         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
633
634         uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
635
636         col = uiLayoutColumn(layout, 0);
637         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer")==1);
638         uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE);
639
640         uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
641         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
642
643         col = uiLayoutColumn(layout, 0);
644         uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
645         sub = uiLayoutColumn(col, 0);
646         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_preview"));
647         uiItemR(sub, ptr, "samples", 0, NULL, ICON_NONE);
648         
649         col = uiLayoutColumn(layout, 0);
650         uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
651         sub = uiLayoutColumn(col, 0);
652         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer")==0);
653         uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE);
654 }
655
656 /* qdn: glare node */
657 static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
658 {       
659         uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE);
660         uiItemR(layout, ptr, "quality", 0, "", ICON_NONE);
661
662         if (RNA_enum_get(ptr, "glare_type")!= 1) {
663                 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
664         
665                 if (RNA_enum_get(ptr, "glare_type")!= 0) 
666                         uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
667         }
668         
669         uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE);
670         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
671
672         if (RNA_enum_get(ptr, "glare_type")== 2) {
673                 uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE);
674                 uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE);
675         }
676         if (RNA_enum_get(ptr, "glare_type")== 0 || RNA_enum_get(ptr, "glare_type")== 2) {
677                 uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
678                 
679                 if (RNA_enum_get(ptr, "glare_type")== 0) 
680                         uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE);
681         }
682         if (RNA_enum_get(ptr, "glare_type")== 1) {
683                 uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE);
684         }
685 }
686
687 static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
688 {       
689         uiLayout *col;
690
691         col = uiLayoutColumn(layout, 0);
692         uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE);
693         if (RNA_enum_get(ptr, "tonemap_type")== 0) {
694                 uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
695                 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
696                 uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE);
697         }
698         else {
699                 uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE);
700                 uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
701                 uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
702                 uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
703         }
704 }
705
706 static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
707 {
708         uiLayout *col;
709
710         col= uiLayoutColumn(layout, 0);
711         uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE);
712
713         col = uiLayoutColumn(col, 0);
714         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector")==0);
715         uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE);
716         uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE);
717 }
718
719 static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
720 {
721         uiLayout *col;
722         
723         col= uiLayoutColumn(layout, 0);
724         uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE);
725         uiItemR(col, ptr, "factor", 0, "Blur", ICON_NONE);
726         
727         col= uiLayoutColumn(layout, 1);
728         uiItemL(col, "Speed:", ICON_NONE);
729         uiItemR(col, ptr, "speed_min", 0, "Min", ICON_NONE);
730         uiItemR(col, ptr, "speed_max", 0, "Max", ICON_NONE);
731
732         uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE);
733 }
734
735 static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
736 {
737         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
738 }
739
740 static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
741 {
742         uiItemR(layout, ptr, "axis", 0, "", ICON_NONE);
743 }
744
745 static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
746 {
747         uiLayout *col;
748
749         uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE);
750         uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE);
751
752         col= uiLayoutColumn(layout, 1);
753         if (RNA_boolean_get(ptr, "relative")){
754                 uiItemR(col, ptr, "rel_min_x", 0, "Left", ICON_NONE);
755                 uiItemR(col, ptr, "rel_max_x", 0, "Right", ICON_NONE);
756                 uiItemR(col, ptr, "rel_min_y", 0, "Up", ICON_NONE);
757                 uiItemR(col, ptr, "rel_max_y", 0, "Down", ICON_NONE);
758         } else {
759                 uiItemR(col, ptr, "min_x", 0, "Left", ICON_NONE);
760                 uiItemR(col, ptr, "max_x", 0, "Right", ICON_NONE);
761                 uiItemR(col, ptr, "min_y", 0, "Up", ICON_NONE);
762                 uiItemR(col, ptr, "max_y", 0, "Down", ICON_NONE);
763         }
764 }
765
766 static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
767 {
768         uiLayout *row, *col;
769         
770         col= uiLayoutColumn(layout, 0);
771         row= uiLayoutRow(col, 0);
772         uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
773         uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
774 }
775
776 static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
777 {
778         uiLayout *sub, *col;
779         
780         col =uiLayoutColumn(layout, 1);
781         uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
782         uiItemR(col, ptr, "size", 0, NULL, ICON_NONE);
783         
784         col =uiLayoutColumn(layout, 1);
785         uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE);
786         sub =uiLayoutColumn(col, 0);
787         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min"));
788         uiItemR(sub, ptr, "min", 0, "", ICON_NONE);
789         
790         col =uiLayoutColumn(layout, 1);
791         uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE);
792         sub =uiLayoutColumn(col, 0);
793         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max"));
794         uiItemR(sub, ptr, "max", 0, "", ICON_NONE);
795 }
796
797 static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
798 {       
799         uiLayout *col;
800         
801         col =uiLayoutColumn(layout, 1);
802         uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE);
803         uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE);
804 }
805
806 static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
807 {       
808         uiLayout *col;
809         
810         col =uiLayoutColumn(layout, 1);
811         uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE);
812 }
813
814
815 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
816 {
817         uiLayout *col;
818         
819         col =uiLayoutColumn(layout, 0);
820         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
821         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
822         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
823 }
824
825 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
826 {
827         uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
828 }
829
830 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
831 {
832         uiLayout *col;
833         
834         col =uiLayoutColumn(layout, 1);
835         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
836         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
837 }
838
839 static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
840 {
841         uiLayout *col;
842         
843         col =uiLayoutColumn(layout, 1);
844         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
845         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
846 }
847
848 static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
849 {
850         uiLayout *row, *col;
851         
852         uiItemL(layout, "Despill Channel:", ICON_NONE);
853         row =uiLayoutRow(layout,0);
854         uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
855
856         col= uiLayoutColumn(layout, 0);
857         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
858
859         if(RNA_enum_get(ptr, "limit_method")==0) {
860                 uiItemL(col, "Limiting Channel:", ICON_NONE);
861                 row=uiLayoutRow(col,0);
862                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
863         }
864
865         uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
866         uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE);
867         if (RNA_boolean_get(ptr, "use_unspill")== 1) {
868                 uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
869                 uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
870                 uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
871         }
872 }
873
874 static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
875 {
876         uiLayout *col;
877         
878         col= uiLayoutColumn(layout, 0);
879         uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE);
880         uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
881         
882         col= uiLayoutColumn(layout, 1);
883         /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now */
884         uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
885         /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now*/
886 }
887
888 static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
889 {
890         uiLayout *col;
891         
892         col= uiLayoutColumn(layout, 1);
893         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
894         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
895         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
896 }
897
898 static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
899 {       
900         uiLayout *col, *row;
901
902         uiItemL(layout, "Color Space:", ICON_NONE);
903         row= uiLayoutRow(layout, 0);
904         uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
905
906         col=uiLayoutColumn(layout, 0);
907         uiItemL(col, "Key Channel:", ICON_NONE);
908         row= uiLayoutRow(col, 0);
909         uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
910
911         col =uiLayoutColumn(layout, 0);
912
913         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
914         if(RNA_enum_get(ptr, "limit_method")==0) {
915                 uiItemL(col, "Limiting Channel:", ICON_NONE);
916                 row=uiLayoutRow(col,0);
917                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
918         }
919
920         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
921         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
922 }
923
924 static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
925 {
926         uiLayout *col;
927         
928         col= uiLayoutColumn(layout, 1);
929         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
930         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
931 }
932
933 static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
934 {
935         uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE);
936 }
937
938 static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
939 {
940         uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE);
941 }
942
943 static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
944 {
945         uiLayout *col, *row;
946
947         col= uiLayoutColumn(layout, 0);
948         uiItemR(col, ptr, "filepath", 0, "", ICON_NONE);
949         uiItemR(col, ptr, "image_type", 0, "", ICON_NONE);
950         
951         row= uiLayoutRow(layout, 0);
952         if (RNA_enum_get(ptr, "image_type")== R_OPENEXR) {
953                 uiItemR(row, ptr, "use_exr_half", 0, NULL, ICON_NONE);
954                 uiItemR(row, ptr, "exr_codec", 0, "", ICON_NONE);
955         }
956         else if (RNA_enum_get(ptr, "image_type")== R_JPEG90) {
957                 uiItemR(row, ptr, "quality", UI_ITEM_R_SLIDER, "Quality", ICON_NONE);
958         }
959         else if (RNA_enum_get(ptr, "image_type")== R_PNG) {
960                 uiItemR(row, ptr, "quality", UI_ITEM_R_SLIDER, "Compression", ICON_NONE);
961         }
962         
963         row= uiLayoutRow(layout, 1);
964         uiItemR(row, ptr, "frame_start", 0, "Start", ICON_NONE);
965         uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
966 }
967
968 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
969 {
970         uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
971 }
972
973 static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
974 {
975         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
976 }
977
978 static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
979 {
980         uiLayout *col;
981         
982         col= uiLayoutColumn(layout, 0);
983         uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE);
984         uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE);
985 }
986
987 static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
988 {
989         uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
990 }
991
992 static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
993 {
994         uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
995 }
996
997 static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
998 {
999         uiLayout *split, *col, *row;
1000         
1001         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
1002         
1003         if (RNA_enum_get(ptr, "correction_method")== 0) {
1004         
1005                 split = uiLayoutSplit(layout, 0, 0);
1006                 col = uiLayoutColumn(split, 0);
1007                 uiTemplateColorWheel(col, ptr, "lift", 1, 1, 0, 1);
1008                 row = uiLayoutRow(col, 0);
1009                 uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE);
1010                 
1011                 col = uiLayoutColumn(split, 0);
1012                 uiTemplateColorWheel(col, ptr, "gamma", 1, 1, 1, 1);
1013                 row = uiLayoutRow(col, 0);
1014                 uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE);
1015                 
1016                 col = uiLayoutColumn(split, 0);
1017                 uiTemplateColorWheel(col, ptr, "gain", 1, 1, 1, 1);
1018                 row = uiLayoutRow(col, 0);
1019                 uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE);
1020
1021         } else {
1022                 
1023                 split = uiLayoutSplit(layout, 0, 0);
1024                 col = uiLayoutColumn(split, 0);
1025                 uiTemplateColorWheel(col, ptr, "offset", 1, 1, 0, 1);
1026                 row = uiLayoutRow(col, 0);
1027                 uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE);
1028                 
1029                 col = uiLayoutColumn(split, 0);
1030                 uiTemplateColorWheel(col, ptr, "power", 1, 1, 0, 1);
1031                 row = uiLayoutRow(col, 0);
1032                 uiItemR(row, ptr, "power", 0, NULL, ICON_NONE);
1033                 
1034                 col = uiLayoutColumn(split, 0);
1035                 uiTemplateColorWheel(col, ptr, "slope", 1, 1, 0, 1);
1036                 row = uiLayoutRow(col, 0);
1037                 uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE);
1038         }
1039
1040 }
1041 static void node_composit_buts_colorbalance_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1042 {
1043         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
1044
1045         if (RNA_enum_get(ptr, "correction_method")== 0) {
1046
1047         uiTemplateColorWheel(layout, ptr, "lift", 1, 1, 0, 1);
1048                 uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE);
1049
1050                 uiTemplateColorWheel(layout, ptr, "gamma", 1, 1, 1, 1);
1051                 uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE);
1052
1053                 uiTemplateColorWheel(layout, ptr, "gain", 1, 1, 1, 1);
1054                 uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE);
1055         } else {
1056                 uiTemplateColorWheel(layout, ptr, "offset", 1, 1, 0, 1);
1057                 uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE);
1058
1059                 uiTemplateColorWheel(layout, ptr, "power", 1, 1, 0, 1);
1060                 uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE);
1061
1062                 uiTemplateColorWheel(layout, ptr, "slope", 1, 1, 0, 1);
1063                 uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE);
1064         }
1065 }
1066
1067
1068 static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1069 {
1070         uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0);
1071 }
1072
1073 static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1074
1075         uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
1076 }
1077
1078 static void node_composit_buts_movieclip(uiLayout *layout, bContext *C, PointerRNA *ptr)
1079 {
1080         uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
1081 }
1082
1083 /* only once called */
1084 static void node_composit_set_butfunc(bNodeType *ntype)
1085 {
1086         ntype->uifuncbut = NULL;
1087         switch(ntype->type) {
1088                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
1089
1090                 case CMP_NODE_IMAGE:
1091                         ntype->uifunc= node_composit_buts_image;
1092                         break;
1093                 case CMP_NODE_R_LAYERS:
1094                         ntype->uifunc= node_composit_buts_renderlayers;
1095                         break;
1096                 case CMP_NODE_NORMAL:
1097                         ntype->uifunc= node_buts_normal;
1098                         break;
1099                 case CMP_NODE_CURVE_VEC:
1100                         ntype->uifunc= node_buts_curvevec;
1101                         break;
1102                 case CMP_NODE_CURVE_RGB:
1103                         ntype->uifunc= node_buts_curvecol;
1104                         break;
1105                 case CMP_NODE_VALUE:
1106                         ntype->uifunc= node_buts_value;
1107                         break;
1108                 case CMP_NODE_RGB:
1109                         ntype->uifunc= node_buts_rgb;
1110                         break;
1111                 case CMP_NODE_FLIP:
1112                         ntype->uifunc= node_composit_buts_flip;
1113                         break;
1114                 case CMP_NODE_SPLITVIEWER:
1115                         ntype->uifunc= node_composit_buts_splitviewer;
1116                         break;
1117                 case CMP_NODE_MIX_RGB:
1118                         ntype->uifunc= node_buts_mix_rgb;
1119                         break;
1120                 case CMP_NODE_VALTORGB:
1121                         ntype->uifunc= node_buts_colorramp;
1122                         break;
1123                 case CMP_NODE_CROP:
1124                         ntype->uifunc= node_composit_buts_crop;
1125                         break;
1126                 case CMP_NODE_BLUR:
1127                         ntype->uifunc= node_composit_buts_blur;
1128                         break;
1129                 case CMP_NODE_DBLUR:
1130                         ntype->uifunc= node_composit_buts_dblur;
1131                         break;
1132                 case CMP_NODE_BILATERALBLUR:
1133                         ntype->uifunc= node_composit_buts_bilateralblur;
1134                         break;
1135                 case CMP_NODE_DEFOCUS:
1136                         ntype->uifunc = node_composit_buts_defocus;
1137                         break;
1138                 case CMP_NODE_GLARE:
1139                         ntype->uifunc = node_composit_buts_glare;
1140                         break;
1141                 case CMP_NODE_TONEMAP:
1142                         ntype->uifunc = node_composit_buts_tonemap;
1143                         break;
1144                 case CMP_NODE_LENSDIST:
1145                         ntype->uifunc = node_composit_buts_lensdist;
1146                         break;
1147                 case CMP_NODE_VECBLUR:
1148                         ntype->uifunc= node_composit_buts_vecblur;
1149                         break;
1150                 case CMP_NODE_FILTER:
1151                         ntype->uifunc= node_composit_buts_filter;
1152                         break;
1153                 case CMP_NODE_MAP_VALUE:
1154                         ntype->uifunc= node_composit_buts_map_value;
1155                         break;
1156                 case CMP_NODE_TIME:
1157                         ntype->uifunc= node_buts_time;
1158                         break;
1159                 case CMP_NODE_ALPHAOVER:
1160                         ntype->uifunc= node_composit_buts_alphaover;
1161                         break;
1162                 case CMP_NODE_HUE_SAT:
1163                         ntype->uifunc= node_composit_buts_hue_sat;
1164                         break;
1165                 case CMP_NODE_TEXTURE:
1166                         ntype->uifunc= node_buts_texture;
1167                         break;
1168                 case CMP_NODE_DILATEERODE:
1169                         ntype->uifunc= node_composit_buts_dilateerode;
1170                         break;
1171                 case CMP_NODE_OUTPUT_FILE:
1172                         ntype->uifunc= node_composit_buts_file_output;
1173                         break;
1174                 case CMP_NODE_DIFF_MATTE:
1175                         ntype->uifunc=node_composit_buts_diff_matte;
1176                         break;
1177                 case CMP_NODE_DIST_MATTE:
1178                         ntype->uifunc=node_composit_buts_distance_matte;
1179                         break;
1180                 case CMP_NODE_COLOR_SPILL:
1181                         ntype->uifunc=node_composit_buts_color_spill;
1182                         break;
1183                 case CMP_NODE_CHROMA_MATTE:
1184                         ntype->uifunc=node_composit_buts_chroma_matte;
1185                         break;
1186                 case CMP_NODE_COLOR_MATTE:
1187                         ntype->uifunc=node_composit_buts_color_matte;
1188                         break;
1189                 case CMP_NODE_SCALE:
1190                         ntype->uifunc= node_composit_buts_scale;
1191                         break;
1192                 case CMP_NODE_ROTATE:
1193                         ntype->uifunc=node_composit_buts_rotate;
1194                         break;
1195                 case CMP_NODE_CHANNEL_MATTE:
1196                         ntype->uifunc= node_composit_buts_channel_matte;
1197                         break;
1198                 case CMP_NODE_LUMA_MATTE:
1199                         ntype->uifunc= node_composit_buts_luma_matte;
1200                         break;
1201                 case CMP_NODE_MAP_UV:
1202                         ntype->uifunc= node_composit_buts_map_uv;
1203                         break;
1204                 case CMP_NODE_ID_MASK:
1205                         ntype->uifunc= node_composit_buts_id_mask;
1206                         break;
1207                 case CMP_NODE_MATH:
1208                         ntype->uifunc= node_buts_math;
1209                         break;
1210                 case CMP_NODE_INVERT:
1211                         ntype->uifunc= node_composit_buts_invert;
1212                         break;
1213                 case CMP_NODE_PREMULKEY:
1214                         ntype->uifunc= node_composit_buts_premulkey;
1215                         break;
1216                 case CMP_NODE_VIEW_LEVELS:
1217                         ntype->uifunc=node_composit_buts_view_levels;
1218                         break;
1219                 case CMP_NODE_COLORBALANCE:
1220                         ntype->uifunc=node_composit_buts_colorbalance;
1221                         ntype->uifuncbut=node_composit_buts_colorbalance_but;
1222                         break;
1223                 case CMP_NODE_HUECORRECT:
1224                         ntype->uifunc=node_composit_buts_huecorrect;
1225                         break;
1226                 case CMP_NODE_ZCOMBINE:
1227                         ntype->uifunc=node_composit_buts_zcombine;
1228                         break;
1229                 case CMP_NODE_COMBYCCA:
1230                 case CMP_NODE_SEPYCCA:
1231                         ntype->uifunc=node_composit_buts_ycc;
1232                         break;
1233                 case CMP_NODE_MOVIECLIP:
1234                         ntype->uifunc= node_composit_buts_movieclip;
1235                         break;
1236                 default:
1237                         ntype->uifunc= NULL;
1238         }
1239         if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
1240
1241 }
1242
1243 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
1244
1245 static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1246 {
1247         uiLayout *col;
1248         
1249         col= uiLayoutColumn(layout, 1);
1250         uiItemR(col, ptr, "offset", 0, "Offset", ICON_NONE);
1251         uiItemR(col, ptr, "offset_frequency", 0, "Frequency", ICON_NONE);
1252         
1253         col= uiLayoutColumn(layout, 1);
1254         uiItemR(col, ptr, "squash", 0, "Squash", ICON_NONE);
1255         uiItemR(col, ptr, "squash_frequency", 0, "Frequency", ICON_NONE);
1256 }
1257
1258 static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1259 {
1260         PointerRNA tex_ptr;
1261         bNode *node= ptr->data;
1262         ID *id= ptr->id.data;
1263         Tex *tex = (Tex *)node->storage;
1264         uiLayout *col, *row;
1265         
1266         RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr);
1267
1268         col= uiLayoutColumn(layout, 0);
1269
1270         switch( tex->type ) {
1271                 case TEX_BLEND:
1272                         uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE);
1273                         row= uiLayoutRow(col, 0);
1274                         uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1275                         break;
1276
1277                 case TEX_MARBLE:
1278                         row= uiLayoutRow(col, 0);
1279                         uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1280                         row= uiLayoutRow(col, 0);
1281                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1282                         row= uiLayoutRow(col, 0);
1283                         uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1284                         row= uiLayoutRow(col, 0);
1285                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1286                         break;
1287
1288                 case TEX_MAGIC:
1289                         uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE);
1290                         break;
1291
1292                 case TEX_STUCCI:
1293                         row= uiLayoutRow(col, 0);
1294                         uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1295                         row= uiLayoutRow(col, 0);
1296                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1297                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1298                         break;
1299
1300                 case TEX_WOOD:
1301                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1302                         uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE);
1303                         row= uiLayoutRow(col, 0);
1304                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1305                         row= uiLayoutRow(col, 0);
1306                         uiLayoutSetActive(row, !(RNA_enum_get(&tex_ptr, "wood_type")==TEX_BAND || RNA_enum_get(&tex_ptr, "wood_type")==TEX_RING)); 
1307                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1308                         break;
1309                         
1310                 case TEX_CLOUDS:
1311                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1312                         row= uiLayoutRow(col, 0);
1313                         uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1314                         row= uiLayoutRow(col, 0);
1315                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1316                         uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, "Depth", ICON_NONE);
1317                         break;
1318                         
1319                 case TEX_DISTNOISE:
1320                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1321                         uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE);
1322                         break;
1323
1324                 case TEX_MUSGRAVE:
1325                         uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE);
1326                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1327                         break;
1328                 case TEX_VORONOI:
1329                         uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE);
1330                         if(tex->vn_distm == TEX_MINKOVSKY) {
1331                                 uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE);
1332                         }
1333                         uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE);
1334                         break;
1335         }
1336 }
1337
1338 static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1339 {
1340         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1341 }
1342
1343 static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1344 {
1345         uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
1346 }
1347
1348 /* only once called */
1349 static void node_texture_set_butfunc(bNodeType *ntype)
1350 {
1351     ntype->uifuncbut = NULL;
1352         if( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
1353                 ntype->uifunc = node_texture_buts_proc;
1354         }
1355         else switch(ntype->type) {
1356                 
1357                 case TEX_NODE_MATH:
1358                         ntype->uifunc = node_buts_math;
1359                         break;
1360                 
1361                 case TEX_NODE_MIX_RGB:
1362                         ntype->uifunc = node_buts_mix_rgb;
1363                         break;
1364                         
1365                 case TEX_NODE_VALTORGB:
1366                         ntype->uifunc = node_buts_colorramp;
1367                         break;
1368                         
1369                 case TEX_NODE_CURVE_RGB:
1370                         ntype->uifunc= node_buts_curvecol;
1371                         break;
1372                         
1373                 case TEX_NODE_CURVE_TIME:
1374                         ntype->uifunc = node_buts_time;
1375                         break;
1376                         
1377                 case TEX_NODE_TEXTURE:
1378                         ntype->uifunc = node_buts_texture;
1379                         break;
1380                         
1381                 case TEX_NODE_BRICKS:
1382                         ntype->uifunc = node_texture_buts_bricks;
1383                         break;
1384                         
1385                 case TEX_NODE_IMAGE:
1386                         ntype->uifunc = node_texture_buts_image;
1387                         break;
1388                         
1389                 case TEX_NODE_OUTPUT:
1390                         ntype->uifunc = node_texture_buts_output;
1391                         break;
1392                         
1393                 default:
1394                         ntype->uifunc= NULL;
1395         }
1396         if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
1397 }
1398
1399 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
1400
1401 void ED_init_node_butfuncs(void)
1402 {
1403         bNodeType *ntype;
1404         
1405         /* shader nodes */
1406         ntype= node_all_shaders.first;
1407         while(ntype) {
1408                 node_shader_set_butfunc(ntype);
1409                 ntype= ntype->next;
1410         }
1411         /* composit nodes */
1412         ntype= node_all_composit.first;
1413         while(ntype) {
1414                 node_composit_set_butfunc(ntype);
1415                 ntype= ntype->next;
1416         }
1417         ntype = node_all_textures.first;
1418         while(ntype) {
1419                 node_texture_set_butfunc(ntype);
1420                 ntype= ntype->next;
1421         }
1422 }
1423
1424 /* ************** Generic drawing ************** */
1425
1426 void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
1427 {
1428         
1429         if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
1430                 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
1431                 void *lock;
1432                 ImBuf *ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
1433                 if(ibuf) {
1434                         float x, y; 
1435                         
1436                         glMatrixMode(GL_PROJECTION);
1437                         glPushMatrix();
1438                         glMatrixMode(GL_MODELVIEW);
1439                         glPushMatrix();
1440
1441                         /* keep this, saves us from a version patch */
1442                         if(snode->zoom==0.0f) snode->zoom= 1.0f;
1443                         
1444                         /* somehow the offset has to be calculated inverse */
1445                         
1446                         glaDefine2DArea(&ar->winrct);
1447                         /* ortho at pixel level curarea */
1448                         wmOrtho2(-0.375, ar->winx-0.375, -0.375, ar->winy-0.375);
1449                         
1450                         x = (ar->winx-snode->zoom*ibuf->x)/2 + snode->xof;
1451                         y = (ar->winy-snode->zoom*ibuf->y)/2 + snode->yof;
1452                         
1453                         if(!ibuf->rect) {
1454                                 if(color_manage)
1455                                         ibuf->profile = IB_PROFILE_LINEAR_RGB;
1456                                 else
1457                                         ibuf->profile = IB_PROFILE_NONE;
1458                                 IMB_rect_from_float(ibuf);
1459                         }
1460
1461                         if(ibuf->rect) {
1462                                 if (snode->flag & SNODE_SHOW_ALPHA) {
1463                                         glPixelZoom(snode->zoom, snode->zoom);
1464                                         /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
1465                                         if(ENDIAN_ORDER == B_ENDIAN)
1466                                                 glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
1467                                         
1468                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
1469                                         
1470                                         glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
1471                                         glPixelZoom(1.0f, 1.0f);
1472                                 } else if (snode->flag & SNODE_USE_ALPHA) {
1473                                         glEnable(GL_BLEND);
1474                                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1475                                         glPixelZoom(snode->zoom, snode->zoom);
1476                                         
1477                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1478                                         
1479                                         glPixelZoom(1.0f, 1.0f);
1480                                         glDisable(GL_BLEND);
1481                                 } else {
1482                                         glPixelZoom(snode->zoom, snode->zoom);
1483                                         
1484                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1485                                         
1486                                         glPixelZoom(1.0f, 1.0f);
1487                                 }
1488                         }
1489                         
1490                         glMatrixMode(GL_PROJECTION);
1491                         glPopMatrix();
1492                         glMatrixMode(GL_MODELVIEW);
1493                         glPopMatrix();
1494                 }
1495
1496                 BKE_image_release_ibuf(ima, lock);
1497         }
1498 }
1499
1500 void draw_nodespace_color_info(ARegion *ar, int color_manage, int channels, int x, int y, char *cp, float *fp)
1501 {
1502         char str[256];
1503         float dx= 6;
1504         /* text colors */
1505         /* XXX colored text not allowed in Blender UI */
1506         #if 0
1507         unsigned char red[3] = {255, 50, 50};
1508         unsigned char green[3] = {0, 255, 0};
1509         unsigned char blue[3] = {100, 100, 255};
1510         #else
1511         unsigned char red[3] = {255, 255, 255};
1512         unsigned char green[3] = {255, 255, 255};
1513         unsigned char blue[3] = {255, 255, 255};
1514         #endif
1515         float hue=0, sat=0, val=0, lum=0, u=0, v=0;
1516         float col[4], finalcol[4];
1517
1518         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1519         glEnable(GL_BLEND);
1520
1521         /* noisy, high contrast make impossible to read if lower alpha is used. */
1522         glColor4ub(0, 0, 0, 190);
1523         glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
1524         glDisable(GL_BLEND);
1525
1526         BLF_size(blf_mono_font, 11, 72);
1527
1528         glColor3ub(255, 255, 255);
1529         sprintf(str, "X:%-4d  Y:%-4d |", x, y);
1530         // UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
1531         BLF_position(blf_mono_font, dx, 6, 0);
1532         BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1533         dx += BLF_width(blf_mono_font, str);
1534
1535         #if 0   /* XXX no Z value in compo backdrop atm */
1536         if(zp) {
1537                 glColor3ub(255, 255, 255);
1538                 sprintf(str, " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
1539                 BLF_position(blf_mono_font, dx, 6, 0);
1540                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1541                 dx += BLF_width(blf_mono_font, str);
1542         }
1543         if(zpf) {
1544                 glColor3ub(255, 255, 255);
1545                 sprintf(str, " Z:%-.3f |", *zpf);
1546                 BLF_position(blf_mono_font, dx, 6, 0);
1547                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1548                 dx += BLF_width(blf_mono_font, str);
1549         }
1550         #endif
1551
1552         if(channels >= 3) {
1553                 glColor3ubv(red);
1554                 if (fp)
1555                         sprintf(str, "  R:%-.4f", fp[0]);
1556                 else if (cp)
1557                         sprintf(str, "  R:%-3d", cp[0]);
1558                 else
1559                         sprintf(str, "  R:-");
1560                 BLF_position(blf_mono_font, dx, 6, 0);
1561                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1562                 dx += BLF_width(blf_mono_font, str);
1563                 
1564                 glColor3ubv(green);
1565                 if (fp)
1566                         sprintf(str, "  G:%-.4f", fp[1]);
1567                 else if (cp)
1568                         sprintf(str, "  G:%-3d", cp[1]);
1569                 else
1570                         sprintf(str, "  G:-");
1571                 BLF_position(blf_mono_font, dx, 6, 0);
1572                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1573                 dx += BLF_width(blf_mono_font, str);
1574                 
1575                 glColor3ubv(blue);
1576                 if (fp)
1577                         sprintf(str, "  B:%-.4f", fp[2]);
1578                 else if (cp)
1579                         sprintf(str, "  B:%-3d", cp[2]);
1580                 else
1581                         sprintf(str, "  B:-");
1582                 BLF_position(blf_mono_font, dx, 6, 0);
1583                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1584                 dx += BLF_width(blf_mono_font, str);
1585                 
1586                 if(channels == 4) {
1587                         glColor3ub(255, 255, 255);
1588                         if (fp)
1589                                 sprintf(str, "  A:%-.4f", fp[3]);
1590                         else if (cp)
1591                                 sprintf(str, "  A:%-3d", cp[3]);
1592                         else
1593                                 sprintf(str, "- ");
1594                         BLF_position(blf_mono_font, dx, 6, 0);
1595                         BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1596                         dx += BLF_width(blf_mono_font, str);
1597                 }
1598         }
1599         
1600         /* color rectangle */
1601         if (channels==1) {
1602                 if (fp)
1603                         col[0] = col[1] = col[2] = fp[0];
1604                 else if (cp)
1605                         col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
1606                 else
1607                         col[0] = col[1] = col[2] = 0.0f;
1608         }
1609         else if (channels==3) {
1610                 if (fp)
1611                         copy_v3_v3(col, fp);
1612                 else if (cp) {
1613                         col[0] = (float)cp[0]/255.0f;
1614                         col[1] = (float)cp[1]/255.0f;
1615                         col[2] = (float)cp[2]/255.0f;
1616                 }
1617                 else
1618                         zero_v3(col);
1619         }
1620         else if (channels==4) {
1621                 if (fp)
1622                         copy_v4_v4(col, fp);
1623                 else if (cp) {
1624                         col[0] = (float)cp[0]/255.0f;
1625                         col[1] = (float)cp[1]/255.0f;
1626                         col[2] = (float)cp[2]/255.0f;
1627                         col[3] = (float)cp[3]/255.0f;
1628                 }
1629                 else
1630                         zero_v4(col);
1631         }
1632         if (color_manage) {
1633                 linearrgb_to_srgb_v3_v3(finalcol, col);
1634                 finalcol[3] = col[3];
1635         }
1636         else {
1637                 copy_v4_v4(finalcol, col);
1638         }
1639         glDisable(GL_BLEND);
1640         glColor3fv(finalcol);
1641         dx += 5;
1642         glBegin(GL_QUADS);
1643         glVertex2f(dx, 3);
1644         glVertex2f(dx, 17);
1645         glVertex2f(dx+30, 17);
1646         glVertex2f(dx+30, 3);
1647         glEnd();
1648         dx += 35;
1649
1650         glColor3ub(255, 255, 255);
1651         if(channels == 1) {
1652                 if (fp) {
1653                         rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
1654                         rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v);
1655                 }
1656                 else if (cp) {
1657                         rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val);
1658                         rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v);
1659                 }
1660                 
1661                 sprintf(str, "V:%-.4f", val);
1662                 BLF_position(blf_mono_font, dx, 6, 0);
1663                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1664                 dx += BLF_width(blf_mono_font, str);
1665
1666                 sprintf(str, "   L:%-.4f", lum);
1667                 BLF_position(blf_mono_font, dx, 6, 0);
1668                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1669                 dx += BLF_width(blf_mono_font, str);
1670         }
1671         else if(channels >= 3) {
1672                 if (fp) {
1673                         rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val);
1674                         rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v);
1675                 }
1676                 else if (cp) {
1677                         rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val);
1678                         rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v);
1679                 }
1680
1681                 sprintf(str, "H:%-.4f", hue);
1682                 BLF_position(blf_mono_font, dx, 6, 0);
1683                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1684                 dx += BLF_width(blf_mono_font, str);
1685
1686                 sprintf(str, "  S:%-.4f", sat);
1687                 BLF_position(blf_mono_font, dx, 6, 0);
1688                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1689                 dx += BLF_width(blf_mono_font, str);
1690
1691                 sprintf(str, "  V:%-.4f", val);
1692                 BLF_position(blf_mono_font, dx, 6, 0);
1693                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1694                 dx += BLF_width(blf_mono_font, str);
1695
1696                 sprintf(str, "   L:%-.4f", lum);
1697                 BLF_position(blf_mono_font, dx, 6, 0);
1698                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1699                 dx += BLF_width(blf_mono_font, str);
1700         }
1701
1702         (void)dx;
1703 }
1704
1705 #if 0
1706 /* note: needs to be userpref or opengl profile option */
1707 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
1708 {
1709
1710         draw_nodespace_grid(snode);
1711         
1712         if(snode->flag & SNODE_BACKDRAW) {
1713                 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
1714                 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
1715                 if(ibuf) {
1716                         int x, y;
1717                         float zoom = 1.0;
1718
1719                         glMatrixMode(GL_PROJECTION);
1720                         glPushMatrix();
1721                         glMatrixMode(GL_MODELVIEW);
1722                         glPushMatrix();
1723                         
1724                         glaDefine2DArea(&sa->winrct);
1725
1726                         if(ibuf->x > sa->winx || ibuf->y > sa->winy) {
1727                                 float zoomx, zoomy;
1728                                 zoomx= (float)sa->winx/ibuf->x;
1729                                 zoomy= (float)sa->winy/ibuf->y;
1730                                 zoom = MIN2(zoomx, zoomy);
1731                         }
1732                         
1733                         x = (sa->winx-zoom*ibuf->x)/2 + snode->xof;
1734                         y = (sa->winy-zoom*ibuf->y)/2 + snode->yof;
1735
1736                         glPixelZoom(zoom, zoom);
1737
1738                         glColor4f(1.0, 1.0, 1.0, 1.0);
1739                         if(ibuf->rect)
1740                                 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
1741                         else if(ibuf->channels==4)
1742                                 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
1743
1744                         glPixelZoom(1.0, 1.0);
1745
1746                         glMatrixMode(GL_PROJECTION);
1747                         glPopMatrix();
1748                         glMatrixMode(GL_MODELVIEW);
1749                         glPopMatrix();
1750                 }
1751         }
1752 }
1753 #endif
1754
1755 /* if v2d not NULL, it clips and returns 0 if not visible */
1756 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
1757 {
1758         float dist, vec[4][2];
1759         
1760         /* in v0 and v3 we put begin/end points */
1761         if(link->fromsock) {
1762                 vec[0][0]= link->fromsock->locx;
1763                 vec[0][1]= link->fromsock->locy;
1764         }
1765         else {
1766                 if(snode==NULL) return 0;
1767                 vec[0][0]= snode->mx;
1768                 vec[0][1]= snode->my;
1769         }
1770         if(link->tosock) {
1771                 vec[3][0]= link->tosock->locx;
1772                 vec[3][1]= link->tosock->locy;
1773         }
1774         else {
1775                 if(snode==NULL) return 0;
1776                 vec[3][0]= snode->mx;
1777                 vec[3][1]= snode->my;
1778         }
1779         
1780         dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
1781         
1782         /* check direction later, for top sockets */
1783         vec[1][0]= vec[0][0]+dist;
1784         vec[1][1]= vec[0][1];
1785         
1786         vec[2][0]= vec[3][0]-dist;
1787         vec[2][1]= vec[3][1];
1788         
1789         if(v2d && MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax); /* clipped */      
1790         else if (v2d && MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin); /* clipped */
1791         else {
1792                 
1793                 /* always do all three, to prevent data hanging around */
1794                 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
1795                 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
1796                 
1797                 return 1;
1798         }
1799         return 0;
1800 }
1801
1802 #define LINK_RESOL      24
1803 void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 )
1804 {
1805         float coord_array[LINK_RESOL+1][2];
1806         
1807         if(node_link_bezier_points(v2d, snode, link, coord_array, LINK_RESOL)) {
1808                 float dist, spline_step = 0.0f;
1809                 int i;
1810                 
1811                 /* store current linewidth */
1812                 float linew;
1813                 glGetFloatv(GL_LINE_WIDTH, &linew);
1814                 
1815                 /* we can reuse the dist variable here to increment the GL curve eval amount*/
1816                 dist = 1.0f/(float)LINK_RESOL;
1817                 
1818                 glEnable(GL_LINE_SMOOTH);
1819                 
1820                 if(do_triple) {
1821                         UI_ThemeColorShadeAlpha(th_col3, -80, -120);
1822                         glLineWidth(4.0f);
1823                         
1824                         glBegin(GL_LINE_STRIP);
1825                         for(i=0; i<=LINK_RESOL; i++) {
1826                                 glVertex2fv(coord_array[i]);
1827                         }
1828                         glEnd();
1829                 }
1830                 
1831                 UI_ThemeColor(th_col1);
1832                 glLineWidth(1.5f);
1833                 
1834                 glBegin(GL_LINE_STRIP);
1835                 for(i=0; i<=LINK_RESOL; i++) {
1836                         if(do_shaded) {
1837                                 UI_ThemeColorBlend(th_col1, th_col2, spline_step);
1838                                 spline_step += dist;
1839                         }
1840                         glVertex2fv(coord_array[i]);
1841                 }
1842                 glEnd();
1843                 
1844                 glDisable(GL_LINE_SMOOTH);
1845                 
1846                 /* restore previuos linewidth */
1847                 glLineWidth(linew);
1848         }
1849 }
1850
1851 /* note; this is used for fake links in groups too */
1852 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
1853 {
1854         int do_shaded= 0, th_col1= TH_HEADER, th_col2= TH_HEADER;
1855         int do_triple= 0, th_col3= TH_WIRE;
1856         
1857         if(link->fromsock==NULL && link->tosock==NULL)
1858                 return;
1859         
1860         /* new connection */
1861         if(!link->fromsock || !link->tosock) {
1862                 th_col1 = TH_ACTIVE;
1863                 do_triple = 1;
1864         }
1865         else {
1866                 /* going to give issues once... */
1867                 if(link->tosock->flag & SOCK_UNAVAIL)
1868                         return;
1869                 if(link->fromsock->flag & SOCK_UNAVAIL)
1870                         return;
1871                 
1872                 /* a bit ugly... but thats how we detect the internal group links */
1873                 if(!link->fromnode || !link->tonode) {
1874                         UI_ThemeColorBlend(TH_BACK, TH_WIRE, 0.5f);
1875                         do_shaded= 0;
1876                 }
1877                 else {
1878                         /* check cyclic */
1879                         if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
1880                                 /* special indicated link, on drop-node */
1881                                 if(link->flag & NODE_LINKFLAG_HILITE) {
1882                                         th_col1= th_col2= TH_ACTIVE;
1883                                 }
1884                                 else {
1885                                         /* regular link */
1886                                         if(link->fromnode->flag & SELECT)
1887                                                 th_col1= TH_EDGE_SELECT;
1888                                         if(link->tonode->flag & SELECT)
1889                                                 th_col2= TH_EDGE_SELECT;
1890                                 }
1891                                 do_shaded= 1;
1892                                 do_triple= 1;
1893                         }                               
1894                         else {
1895                                 th_col1 = TH_REDALERT;
1896                         }
1897                 }
1898         }
1899         
1900         node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
1901 }
1902
1903