Blender  V2.59
drawnode.c
Go to the documentation of this file.
00001 /*
00002  * $Id: drawnode.c 39015 2011-08-04 10:05:14Z jbakker $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2005 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Bob Holcomb, Thomas Dinges
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include <math.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 
00039 #include "BLI_blenlib.h"
00040 #include "BLI_math.h"
00041 #include "BLI_utildefines.h"
00042 
00043 #include "DNA_node_types.h"
00044 #include "DNA_material_types.h"
00045 #include "DNA_object_types.h"
00046 #include "DNA_scene_types.h"
00047 #include "DNA_space_types.h"
00048 #include "DNA_screen_types.h"
00049 
00050 #include "BKE_context.h"
00051 #include "BKE_curve.h"
00052 #include "BKE_global.h"
00053 #include "BKE_image.h"
00054 #include "BKE_library.h"
00055 #include "BKE_main.h"
00056 
00057 #include "CMP_node.h"
00058 #include "SHD_node.h"
00059 
00060 #include "BIF_gl.h"
00061 #include "BIF_glutil.h"
00062 
00063 #include "BLF_api.h"
00064 
00065 #include "MEM_guardedalloc.h"
00066 
00067 
00068 #include "RNA_access.h"
00069 
00070 #include "ED_node.h"
00071 
00072 #include "WM_api.h"
00073 #include "WM_types.h"
00074 
00075 #include "UI_interface.h"
00076 #include "UI_resources.h"
00077 
00078 #include "IMB_imbuf.h"
00079 #include "IMB_imbuf_types.h"
00080 
00081 #include "node_intern.h"
00082 
00083 
00084 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
00085 
00086 static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00087 {
00088         PointerRNA sockptr;
00089         PropertyRNA *prop;
00090         
00091         /* first socket stores value */
00092         prop = RNA_struct_find_property(ptr, "outputs");
00093         RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
00094         
00095         uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE);
00096 }
00097 
00098 static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00099 {
00100         uiLayout *col;
00101         PointerRNA sockptr;
00102         PropertyRNA *prop;
00103         
00104         /* first socket stores value */
00105         prop = RNA_struct_find_property(ptr, "outputs");
00106         RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
00107         
00108         col = uiLayoutColumn(layout, 0);
00109         uiTemplateColorWheel(col, &sockptr, "default_value", 1, 0, 0, 0);
00110         uiItemR(col, &sockptr, "default_value", 0, "", ICON_NONE);
00111 }
00112 
00113 static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00114 {       
00115         uiLayout *row;
00116 
00117         bNodeTree *ntree= (bNodeTree*)ptr->id.data;
00118 
00119         row= uiLayoutRow(layout, 1);
00120         uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE);
00121         if(ntree->type == NTREE_COMPOSIT)
00122                 uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA);
00123 }
00124 
00125 static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00126 {
00127         uiLayout *row;
00128 #if 0
00129         /* XXX no context access here .. */
00130         bNode *node= ptr->data;
00131         CurveMapping *cumap= node->storage;
00132         
00133         if(cumap) {
00134                 cumap->flag |= CUMA_DRAW_CFRA;
00135                 if(node->custom1<node->custom2)
00136                         cumap->sample[0]= (float)(CFRA - node->custom1)/(float)(node->custom2-node->custom1);
00137         }
00138 #endif
00139 
00140         uiTemplateCurveMapping(layout, ptr, "curve", 's', 0, 0);
00141 
00142         row= uiLayoutRow(layout, 1);
00143         uiItemR(row, ptr, "frame_start", 0, "Sta", ICON_NONE);
00144         uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
00145 }
00146 
00147 static void node_buts_colorramp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00148 {
00149         uiTemplateColorRamp(layout, ptr, "color_ramp", 0);
00150 }
00151 
00152 static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00153 {
00154         uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0);
00155 }
00156 
00157 static float *_sample_col= NULL;        // bad bad, 2.5 will do better?
00158 #if 0
00159 static void node_curvemap_sample(float *col)
00160 {
00161         _sample_col= col;
00162 }
00163 #endif
00164 
00165 static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00166 {
00167         bNode *node= ptr->data;
00168         CurveMapping *cumap= node->storage;
00169 
00170         if(_sample_col) {
00171                 cumap->flag |= CUMA_DRAW_SAMPLE;
00172                 VECCOPY(cumap->sample, _sample_col);
00173         }
00174         else 
00175                 cumap->flag &= ~CUMA_DRAW_SAMPLE;
00176 
00177         uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0);
00178 }
00179 
00180 static void node_normal_cb(bContext *C, void *ntree_v, void *node_v)
00181 {
00182         Main *bmain = CTX_data_main(C);
00183 
00184         ED_node_generic_update(bmain, ntree_v, node_v);
00185         WM_event_add_notifier(C, NC_NODE|NA_EDITED, ntree_v);
00186 }
00187 
00188 static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00189 {
00190         uiBlock *block= uiLayoutAbsoluteBlock(layout);
00191         bNodeTree *ntree= ptr->id.data;
00192         bNode *node= ptr->data;
00193         rctf *butr= &node->butr;
00194         bNodeSocket *sock= node->outputs.first;         /* first socket stores normal */
00195         uiBut *bt;
00196         
00197         bt= uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "", 
00198                           (short)butr->xmin, (short)butr->xmin, butr->xmax-butr->xmin, butr->xmax-butr->xmin, 
00199                           sock->ns.vec, 0.0f, 1.0f, 0, 0, "");
00200         uiButSetFunc(bt, node_normal_cb, ntree, node);
00201 }
00202 #if 0 // not used in 2.5x yet
00203 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
00204 {
00205         Main *bmain= CTX_data_main(C);
00206         bNodeTree *ntree= ntree_v;
00207         bNode *node= node_v;
00208         Tex *tex;
00209         
00210         if(node->menunr<1) return;
00211         
00212         if(node->id) {
00213                 node->id->us--;
00214                 node->id= NULL;
00215         }
00216         tex= BLI_findlink(&bmain->tex, node->menunr-1);
00217 
00218         node->id= &tex->id;
00219         id_us_plus(node->id);
00220         BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
00221         
00222         nodeSetActive(ntree, node);
00223         
00224         if( ntree->type == NTREE_TEXTURE )
00225                 ntreeTexCheckCyclics( ntree );
00226         
00227         // allqueue(REDRAWBUTSSHADING, 0);
00228         // allqueue(REDRAWNODE, 0);
00229         NodeTagChanged(ntree, node); 
00230         
00231         node->menunr= 0;
00232 }
00233 #endif
00234 static void node_dynamic_update_cb(bContext *C, void *UNUSED(ntree_v), void *node_v)
00235 {
00236         Main *bmain= CTX_data_main(C);
00237         Material *ma;
00238         bNode *node= (bNode *)node_v;
00239         ID *id= node->id;
00240         int error= 0;
00241 
00242         if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) error= 1;
00243 
00244         /* Users only have to press the "update" button in one pynode
00245          * and we also update all others sharing the same script */
00246         for (ma= bmain->mat.first; ma; ma= ma->id.next) {
00247                 if (ma->nodetree) {
00248                         bNode *nd;
00249                         for (nd= ma->nodetree->nodes.first; nd; nd= nd->next) {
00250                                 if ((nd->type == NODE_DYNAMIC) && (nd->id == id)) {
00251                                         nd->custom1= 0;
00252                                         nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_REPARSE);
00253                                         nd->menunr= 0;
00254                                         if (error)
00255                                                 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_ERROR);
00256                                 }
00257                         }
00258                 }
00259         }
00260 
00261         // allqueue(REDRAWBUTSSHADING, 0);
00262         // allqueue(REDRAWNODE, 0);
00263         // XXX BIF_preview_changed(ID_MA);
00264 }
00265 
00266 static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00267 {
00268         bNode *node= ptr->data;
00269 
00270         short multi = (
00271                 node->id &&
00272                 ((Tex*)node->id)->use_nodes &&
00273                 (node->type != CMP_NODE_TEXTURE) &&
00274                 (node->type != TEX_NODE_TEXTURE)
00275         );
00276         
00277         uiItemR(layout, ptr, "texture", 0, "", ICON_NONE);
00278         
00279         if(multi) {
00280                 /* Number Drawing not optimal here, better have a list*/
00281                 uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE);
00282         }
00283 }
00284 
00285 static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00286 { 
00287         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
00288 }
00289 
00290 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
00291 
00292 static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v)
00293 {
00294         Main *bmain= CTX_data_main(C);
00295         bNodeTree *ntree= ntree_v;
00296         bNode *node= node_v;
00297         ID *oldid;
00298         
00299         if(node->menunr<1) return;
00300         
00301         if(node->id) {
00302                 node->id->us--;
00303         }
00304         oldid= node->id;
00305         node->id= BLI_findlink(&bmain->text, node->menunr-1);
00306         id_us_plus(node->id);
00307         BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
00308 
00309         node->custom1= BSET(node->custom1, NODE_DYNAMIC_NEW);
00310         
00311         nodeSetActive(ntree, node);
00312 
00313         // allqueue(REDRAWBUTSSHADING, 0);
00314         // allqueue(REDRAWNODE, 0);
00315 
00316         node->menunr= 0;
00317 }
00318 
00319 static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
00320 {
00321         bNode *node= ptr->data;
00322         uiLayout *col;
00323         
00324         uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL);
00325         
00326         if(!node->id) return;
00327         
00328         col= uiLayoutColumn(layout, 0);
00329         uiItemR(col, ptr, "use_diffuse", 0, NULL, ICON_NONE);
00330         uiItemR(col, ptr, "use_specular", 0, NULL, ICON_NONE);
00331         uiItemR(col, ptr, "invert_normal", 0, NULL, ICON_NONE);
00332 }
00333 
00334 static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00335 {
00336         uiLayout *row;
00337         
00338         uiItemL(layout, "Location:", ICON_NONE);
00339         row= uiLayoutRow(layout, 1);
00340         uiItemR(row, ptr, "location", 0, "", ICON_NONE);
00341         
00342         uiItemL(layout, "Rotation:", ICON_NONE);
00343         row= uiLayoutRow(layout, 1);
00344         uiItemR(row, ptr, "rotation", 0, "", ICON_NONE);
00345         
00346         uiItemL(layout, "Scale:", ICON_NONE);
00347         row= uiLayoutRow(layout, 1);
00348         uiItemR(row, ptr, "scale", 0, "", ICON_NONE);
00349         
00350         row= uiLayoutRow(layout, 1);
00351         uiItemR(row, ptr, "use_min", 0, "Min", ICON_NONE);
00352         uiItemR(row, ptr, "min", 0, "", ICON_NONE);
00353         
00354         row= uiLayoutRow(layout, 1);
00355         uiItemR(row, ptr, "use_max", 0, "Max", ICON_NONE);
00356         uiItemR(row, ptr, "max", 0, "", ICON_NONE);
00357         
00358 }
00359 
00360 static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00361 { 
00362         uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
00363 }
00364 
00365 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
00366 {
00367         PointerRNA obptr= CTX_data_pointer_get(C, "active_object");
00368         uiLayout *col;
00369 
00370         col= uiLayoutColumn(layout, 0);
00371 
00372         if(obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
00373                 PointerRNA dataptr= RNA_pointer_get(&obptr, "data");
00374 
00375                 uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
00376                 uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
00377         }
00378         else {
00379                 uiItemR(col, ptr, "uv_layer", 0, "UV", ICON_NONE);
00380                 uiItemR(col, ptr, "color_layer", 0, "VCol", ICON_NONE);
00381         }
00382 }
00383 
00384 static void node_shader_buts_dynamic(uiLayout *layout, bContext *C, PointerRNA *ptr)
00385 { 
00386         Main *bmain= CTX_data_main(C);
00387         uiBlock *block= uiLayoutAbsoluteBlock(layout);
00388         bNode *node= ptr->data;
00389         bNodeTree *ntree= ptr->id.data;
00390         rctf *butr= &node->butr;
00391         uiBut *bt;
00392         // XXX SpaceNode *snode= curarea->spacedata.first;
00393         short dy= (short)butr->ymin;
00394         int xoff=0;
00395 
00396         /* B_NODE_EXEC is handled in butspace.c do_node_buts */
00397         if(!node->id) {
00398                         const char *strp;
00399                         IDnames_to_pupstring(&strp, NULL, "", &(bmain->text), NULL, NULL);
00400                         node->menunr= 0;
00401                         bt= uiDefButS(block, MENU, B_NODE_EXEC/*+node->nr*/, strp, 
00402                                                         butr->xmin, dy, 19, 19, 
00403                                                         &node->menunr, 0, 0, 0, 0, "Browses existing choices");
00404                         uiButSetFunc(bt, node_browse_text_cb, ntree, node);
00405                         xoff=19;
00406                         if(strp) MEM_freeN((void *)strp);
00407         }
00408         else {
00409                 bt = uiDefBut(block, BUT, B_NOP, "Update",
00410                                 butr->xmin+xoff, butr->ymin+20, 50, 19,
00411                                 &node->menunr, 0.0, 19.0, 0, 0, "Refresh this node (and all others that use the same script)");
00412                 uiButSetFunc(bt, node_dynamic_update_cb, ntree, node);
00413 
00414                 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) {
00415                         // UI_ThemeColor(TH_REDALERT);
00416                         // XXX ui_rasterpos_safe(butr->xmin + xoff, butr->ymin + 5, snode->aspect);
00417                         // XXX snode_drawstring(snode, "Error! Check console...", butr->xmax - butr->xmin);
00418                         ;
00419                 }
00420         }
00421 }
00422 
00423 /* only once called */
00424 static void node_shader_set_butfunc(bNodeType *ntype)
00425 {
00426         ntype->uifuncbut = NULL;
00427         switch(ntype->type) {
00428                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
00429 
00430                 case SH_NODE_MATERIAL:
00431                 case SH_NODE_MATERIAL_EXT:
00432                         ntype->uifunc= node_shader_buts_material;
00433                         break;
00434                 case SH_NODE_TEXTURE:
00435                         ntype->uifunc= node_buts_texture;
00436                         break;
00437                 case SH_NODE_NORMAL:
00438                         ntype->uifunc= node_buts_normal;
00439                         break;
00440                 case SH_NODE_CURVE_VEC:
00441                         ntype->uifunc= node_buts_curvevec;
00442                         break;
00443                 case SH_NODE_CURVE_RGB:
00444                         ntype->uifunc= node_buts_curvecol;
00445                         break;
00446                 case SH_NODE_MAPPING:
00447                         ntype->uifunc= node_shader_buts_mapping;
00448                         break;
00449                 case SH_NODE_VALUE:
00450                         ntype->uifunc= node_buts_value;
00451                         break;
00452                 case SH_NODE_RGB:
00453                         ntype->uifunc= node_buts_rgb;
00454                         break;
00455                 case SH_NODE_MIX_RGB:
00456                         ntype->uifunc= node_buts_mix_rgb;
00457                         break;
00458                 case SH_NODE_VALTORGB:
00459                         ntype->uifunc= node_buts_colorramp;
00460                         break;
00461                 case SH_NODE_MATH: 
00462                         ntype->uifunc= node_buts_math;
00463                         break; 
00464                 case SH_NODE_VECT_MATH: 
00465                         ntype->uifunc= node_shader_buts_vect_math;
00466                         break; 
00467                 case SH_NODE_GEOMETRY:
00468                         ntype->uifunc= node_shader_buts_geometry;
00469                         break;
00470                 case NODE_DYNAMIC:
00471                         ntype->uifunc= node_shader_buts_dynamic;
00472                         break;
00473                 default:
00474                         ntype->uifunc= NULL;
00475         }
00476                 if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
00477 }
00478 
00479 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
00480 
00481 static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
00482 {
00483         uiLayout *col;
00484         bNode *node= ptr->data;
00485         PointerRNA imaptr;
00486         PropertyRNA *prop;
00487         int source;
00488         
00489         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
00490         
00491         if(!node->id) return;
00492         
00493         prop = RNA_struct_find_property(ptr, "image");
00494         if (!prop || RNA_property_type(prop) != PROP_POINTER) return;
00495         imaptr= RNA_property_pointer_get(ptr, prop);
00496         
00497         col= uiLayoutColumn(layout, 0);
00498         
00499         uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE);
00500         
00501         source= RNA_enum_get(&imaptr, "source");
00502 
00503         if(source == IMA_SRC_SEQUENCE) {
00504                 /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
00505                 Scene *scene= CTX_data_scene(C);
00506                 ImageUser *iuser= node->storage;
00507                 char tstr[32];
00508                 const int framenr= BKE_image_user_get_frame(iuser, CFRA, 0);
00509                 BLI_snprintf(tstr, sizeof(tstr), "Frame: %d", framenr);
00510                 uiItemL(layout, tstr, ICON_NONE);
00511         }
00512 
00513         if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
00514                 col= uiLayoutColumn(layout, 1);
00515                 uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
00516                 uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
00517                 uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
00518                 uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
00519                 uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
00520         }
00521 
00522         col= uiLayoutColumn(layout, 0);
00523         
00524         if (RNA_enum_get(&imaptr, "type")== IMA_TYPE_MULTILAYER)
00525                 uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
00526 }
00527 
00528 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
00529 {
00530         bNode *node= ptr->data;
00531         uiLayout *col, *row;
00532         PointerRNA op_ptr;
00533         PointerRNA scn_ptr;
00534         PropertyRNA *prop;
00535         const char *layer_name;
00536         char scene_name[MAX_ID_NAME-2];
00537         
00538         uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
00539         
00540         if(!node->id) return;
00541 
00542         col= uiLayoutColumn(layout, 0);
00543         row = uiLayoutRow(col, 0);
00544         uiItemR(row, ptr, "layer", 0, "", ICON_NONE);
00545         
00546         prop = RNA_struct_find_property(ptr, "layer");
00547         if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)))
00548                 return;
00549         
00550         scn_ptr = RNA_pointer_get(ptr, "scene");
00551         RNA_string_get(&scn_ptr, "name", scene_name);
00552         
00553         WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
00554         RNA_string_set(&op_ptr, "layer", layer_name);
00555         RNA_string_set(&op_ptr, "scene", scene_name);
00556         uiItemFullO(row, "RENDER_OT_render", "", ICON_RENDER_STILL, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
00557 
00558 }
00559 
00560 
00561 static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00562 {
00563         uiLayout *col, *row;
00564         
00565         col= uiLayoutColumn(layout, 0);
00566         
00567         uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE);
00568         if (RNA_enum_get(ptr, "filter_type")!= R_FILTER_FAST_GAUSS) {
00569                 uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE);
00570                 uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
00571         }
00572         
00573         uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE);
00574         
00575         if (RNA_boolean_get(ptr, "use_relative")) {
00576                 uiItemL(col, "Aspect Correction", 0);
00577                 row= uiLayoutRow(layout, 1);
00578                 uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0);
00579                 
00580                 col= uiLayoutColumn(layout, 1);
00581                 uiItemR(col, ptr, "factor_x", 0, "X", ICON_NONE);
00582                 uiItemR(col, ptr, "factor_y", 0, "Y", ICON_NONE);
00583         }
00584         else {
00585                 col= uiLayoutColumn(layout, 1);
00586                 uiItemR(col, ptr, "size_x", 0, "X", ICON_NONE);
00587                 uiItemR(col, ptr, "size_y", 0, "Y", ICON_NONE);
00588         }
00589 }
00590 
00591 static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00592 {
00593         uiLayout *col;
00594         
00595         uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
00596         uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE);
00597         
00598         col= uiLayoutColumn(layout, 1);
00599         uiItemL(col, "Center:", ICON_NONE);
00600         uiItemR(col, ptr, "center_x", 0, "X", ICON_NONE);
00601         uiItemR(col, ptr, "center_y", 0, "Y", ICON_NONE);
00602         
00603         uiItemS(layout);
00604         
00605         col= uiLayoutColumn(layout, 1);
00606         uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE);
00607         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
00608         
00609         uiItemS(layout);
00610         
00611         uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE);
00612         uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE);
00613 }
00614 
00615 static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00616 {       
00617         uiLayout *col;
00618         
00619         col= uiLayoutColumn(layout, 1);
00620         uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
00621         uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE);
00622         uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
00623 }
00624 
00625 static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00626 {
00627         uiLayout *sub, *col;
00628         
00629         col= uiLayoutColumn(layout, 0);
00630         uiItemL(col, "Bokeh Type:", ICON_NONE);
00631         uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE);
00632         uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
00633 
00634         uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
00635 
00636         col = uiLayoutColumn(layout, 0);
00637         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer")==1);
00638         uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE);
00639 
00640         uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
00641         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
00642 
00643         col = uiLayoutColumn(layout, 0);
00644         uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
00645         sub = uiLayoutColumn(col, 0);
00646         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_preview"));
00647         uiItemR(sub, ptr, "samples", 0, NULL, ICON_NONE);
00648         
00649         col = uiLayoutColumn(layout, 0);
00650         uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
00651         sub = uiLayoutColumn(col, 0);
00652         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer")==0);
00653         uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE);
00654 }
00655 
00656 /* qdn: glare node */
00657 static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00658 {       
00659         uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE);
00660         uiItemR(layout, ptr, "quality", 0, "", ICON_NONE);
00661 
00662         if (RNA_enum_get(ptr, "glare_type")!= 1) {
00663                 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
00664         
00665                 if (RNA_enum_get(ptr, "glare_type")!= 0) 
00666                         uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00667         }
00668         
00669         uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE);
00670         uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
00671 
00672         if (RNA_enum_get(ptr, "glare_type")== 2) {
00673                 uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE);
00674                 uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE);
00675         }
00676         if (RNA_enum_get(ptr, "glare_type")== 0 || RNA_enum_get(ptr, "glare_type")== 2) {
00677                 uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00678                 
00679                 if (RNA_enum_get(ptr, "glare_type")== 0) 
00680                         uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE);
00681         }
00682         if (RNA_enum_get(ptr, "glare_type")== 1) {
00683                 uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE);
00684         }
00685 }
00686 
00687 static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00688 {       
00689         uiLayout *col;
00690 
00691         col = uiLayoutColumn(layout, 0);
00692         uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE);
00693         if (RNA_enum_get(ptr, "tonemap_type")== 0) {
00694                 uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00695                 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
00696                 uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE);
00697         }
00698         else {
00699                 uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE);
00700                 uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00701                 uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00702                 uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00703         }
00704 }
00705 
00706 static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00707 {
00708         uiLayout *col;
00709 
00710         col= uiLayoutColumn(layout, 0);
00711         uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE);
00712 
00713         col = uiLayoutColumn(col, 0);
00714         uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector")==0);
00715         uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE);
00716         uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE);
00717 }
00718 
00719 static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00720 {
00721         uiLayout *col;
00722         
00723         col= uiLayoutColumn(layout, 0);
00724         uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE);
00725         uiItemR(col, ptr, "factor", 0, "Blur", ICON_NONE);
00726         
00727         col= uiLayoutColumn(layout, 1);
00728         uiItemL(col, "Speed:", ICON_NONE);
00729         uiItemR(col, ptr, "speed_min", 0, "Min", ICON_NONE);
00730         uiItemR(col, ptr, "speed_max", 0, "Max", ICON_NONE);
00731 
00732         uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE);
00733 }
00734 
00735 static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00736 {
00737         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
00738 }
00739 
00740 static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00741 {
00742         uiItemR(layout, ptr, "axis", 0, "", ICON_NONE);
00743 }
00744 
00745 static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00746 {
00747         uiLayout *col;
00748 
00749         uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE);
00750         uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE);
00751 
00752         col= uiLayoutColumn(layout, 1);
00753         if (RNA_boolean_get(ptr, "relative")){
00754                 uiItemR(col, ptr, "rel_min_x", 0, "Left", ICON_NONE);
00755                 uiItemR(col, ptr, "rel_max_x", 0, "Right", ICON_NONE);
00756                 uiItemR(col, ptr, "rel_min_y", 0, "Up", ICON_NONE);
00757                 uiItemR(col, ptr, "rel_max_y", 0, "Down", ICON_NONE);
00758         } else {
00759                 uiItemR(col, ptr, "min_x", 0, "Left", ICON_NONE);
00760                 uiItemR(col, ptr, "max_x", 0, "Right", ICON_NONE);
00761                 uiItemR(col, ptr, "min_y", 0, "Up", ICON_NONE);
00762                 uiItemR(col, ptr, "max_y", 0, "Down", ICON_NONE);
00763         }
00764 }
00765 
00766 static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00767 {
00768         uiLayout *row, *col;
00769         
00770         col= uiLayoutColumn(layout, 0);
00771         row= uiLayoutRow(col, 0);
00772         uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00773         uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
00774 }
00775 
00776 static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00777 {
00778         uiLayout *sub, *col;
00779         
00780         col =uiLayoutColumn(layout, 1);
00781         uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
00782         uiItemR(col, ptr, "size", 0, NULL, ICON_NONE);
00783         
00784         col =uiLayoutColumn(layout, 1);
00785         uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE);
00786         sub =uiLayoutColumn(col, 0);
00787         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min"));
00788         uiItemR(sub, ptr, "min", 0, "", ICON_NONE);
00789         
00790         col =uiLayoutColumn(layout, 1);
00791         uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE);
00792         sub =uiLayoutColumn(col, 0);
00793         uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max"));
00794         uiItemR(sub, ptr, "max", 0, "", ICON_NONE);
00795 }
00796 
00797 static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00798 {       
00799         uiLayout *col;
00800         
00801         col =uiLayoutColumn(layout, 1);
00802         uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE);
00803         uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE);
00804 }
00805 
00806 static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00807 {       
00808         uiLayout *col;
00809         
00810         col =uiLayoutColumn(layout, 1);
00811         uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE);
00812 }
00813 
00814 
00815 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00816 {
00817         uiLayout *col;
00818         
00819         col =uiLayoutColumn(layout, 0);
00820         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00821         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00822         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00823 }
00824 
00825 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00826 {
00827         uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
00828 }
00829 
00830 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00831 {
00832         uiLayout *col;
00833         
00834         col =uiLayoutColumn(layout, 1);
00835         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00836         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00837 }
00838 
00839 static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00840 {
00841         uiLayout *col;
00842         
00843         col =uiLayoutColumn(layout, 1);
00844         uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00845         uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00846 }
00847 
00848 static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00849 {
00850         uiLayout *row, *col;
00851         
00852         uiItemL(layout, "Despill Channel:", ICON_NONE);
00853         row =uiLayoutRow(layout,0);
00854         uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00855 
00856         col= uiLayoutColumn(layout, 0);
00857         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
00858 
00859         if(RNA_enum_get(ptr, "limit_method")==0) {
00860                 uiItemL(col, "Limiting Channel:", ICON_NONE);
00861                 row=uiLayoutRow(col,0);
00862                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00863         }
00864 
00865         uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00866         uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE);
00867         if (RNA_boolean_get(ptr, "use_unspill")== 1) {
00868                 uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00869                 uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00870                 uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00871         }
00872 }
00873 
00874 static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00875 {
00876         uiLayout *col;
00877         
00878         col= uiLayoutColumn(layout, 0);
00879         uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE);
00880         uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
00881         
00882         col= uiLayoutColumn(layout, 1);
00883         /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now */
00884         uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00885         /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE);  Removed for now*/
00886 }
00887 
00888 static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00889 {
00890         uiLayout *col;
00891         
00892         col= uiLayoutColumn(layout, 1);
00893         uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00894         uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00895         uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00896 }
00897 
00898 static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00899 {       
00900         uiLayout *col, *row;
00901 
00902         uiItemL(layout, "Color Space:", ICON_NONE);
00903         row= uiLayoutRow(layout, 0);
00904         uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00905 
00906         col=uiLayoutColumn(layout, 0);
00907         uiItemL(col, "Key Channel:", ICON_NONE);
00908         row= uiLayoutRow(col, 0);
00909         uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00910 
00911         col =uiLayoutColumn(layout, 0);
00912 
00913         uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
00914         if(RNA_enum_get(ptr, "limit_method")==0) {
00915                 uiItemL(col, "Limiting Channel:", ICON_NONE);
00916                 row=uiLayoutRow(col,0);
00917                 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00918         }
00919 
00920         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00921         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00922 }
00923 
00924 static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00925 {
00926         uiLayout *col;
00927         
00928         col= uiLayoutColumn(layout, 1);
00929         uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00930         uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
00931 }
00932 
00933 static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00934 {
00935         uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE);
00936 }
00937 
00938 static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00939 {
00940         uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE);
00941 }
00942 
00943 static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00944 {
00945         uiLayout *col, *row;
00946 
00947         col= uiLayoutColumn(layout, 0);
00948         uiItemR(col, ptr, "filepath", 0, "", ICON_NONE);
00949         uiItemR(col, ptr, "image_type", 0, "", ICON_NONE);
00950         
00951         row= uiLayoutRow(layout, 0);
00952         if (RNA_enum_get(ptr, "image_type")== R_OPENEXR) {
00953                 uiItemR(row, ptr, "use_exr_half", 0, NULL, ICON_NONE);
00954                 uiItemR(row, ptr, "exr_codec", 0, "", ICON_NONE);
00955         }
00956         else if (RNA_enum_get(ptr, "image_type")== R_JPEG90) {
00957                 uiItemR(row, ptr, "quality", UI_ITEM_R_SLIDER, "Quality", ICON_NONE);
00958         }
00959         else if (RNA_enum_get(ptr, "image_type")== R_PNG) {
00960                 uiItemR(row, ptr, "quality", UI_ITEM_R_SLIDER, "Compression", ICON_NONE);
00961         }
00962         
00963         row= uiLayoutRow(layout, 1);
00964         uiItemR(row, ptr, "frame_start", 0, "Start", ICON_NONE);
00965         uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
00966 }
00967 
00968 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00969 {
00970         uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
00971 }
00972 
00973 static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00974 {
00975         uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
00976 }
00977 
00978 static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00979 {
00980         uiLayout *col;
00981         
00982         col= uiLayoutColumn(layout, 0);
00983         uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE);
00984         uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE);
00985 }
00986 
00987 static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00988 {
00989         uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
00990 }
00991 
00992 static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00993 {
00994         uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
00995 }
00996 
00997 static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
00998 {
00999         uiLayout *split, *col, *row;
01000         
01001         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
01002         
01003         if (RNA_enum_get(ptr, "correction_method")== 0) {
01004         
01005                 split = uiLayoutSplit(layout, 0, 0);
01006                 col = uiLayoutColumn(split, 0);
01007                 uiTemplateColorWheel(col, ptr, "lift", 1, 1, 0, 1);
01008                 row = uiLayoutRow(col, 0);
01009                 uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE);
01010                 
01011                 col = uiLayoutColumn(split, 0);
01012                 uiTemplateColorWheel(col, ptr, "gamma", 1, 1, 1, 1);
01013                 row = uiLayoutRow(col, 0);
01014                 uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE);
01015                 
01016                 col = uiLayoutColumn(split, 0);
01017                 uiTemplateColorWheel(col, ptr, "gain", 1, 1, 1, 1);
01018                 row = uiLayoutRow(col, 0);
01019                 uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE);
01020 
01021         } else {
01022                 
01023                 split = uiLayoutSplit(layout, 0, 0);
01024                 col = uiLayoutColumn(split, 0);
01025                 uiTemplateColorWheel(col, ptr, "offset", 1, 1, 0, 1);
01026                 row = uiLayoutRow(col, 0);
01027                 uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE);
01028                 
01029                 col = uiLayoutColumn(split, 0);
01030                 uiTemplateColorWheel(col, ptr, "power", 1, 1, 0, 1);
01031                 row = uiLayoutRow(col, 0);
01032                 uiItemR(row, ptr, "power", 0, NULL, ICON_NONE);
01033                 
01034                 col = uiLayoutColumn(split, 0);
01035                 uiTemplateColorWheel(col, ptr, "slope", 1, 1, 0, 1);
01036                 row = uiLayoutRow(col, 0);
01037                 uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE);
01038         }
01039 
01040 }
01041 static void node_composit_buts_colorbalance_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
01042 {
01043         uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
01044 
01045         if (RNA_enum_get(ptr, "correction_method")== 0) {
01046 
01047         uiTemplateColorWheel(layout, ptr, "lift", 1, 1, 0, 1);
01048                 uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE);
01049 
01050                 uiTemplateColorWheel(layout, ptr, "gamma", 1, 1, 1, 1);
01051                 uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE);
01052 
01053                 uiTemplateColorWheel(layout, ptr, "gain", 1, 1, 1, 1);
01054                 uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE);
01055         } else {
01056                 uiTemplateColorWheel(layout, ptr, "offset", 1, 1, 0, 1);
01057                 uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE);
01058 
01059                 uiTemplateColorWheel(layout, ptr, "power", 1, 1, 0, 1);
01060                 uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE);
01061 
01062                 uiTemplateColorWheel(layout, ptr, "slope", 1, 1, 0, 1);
01063                 uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE);
01064         }
01065 }
01066 
01067 
01068 static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
01069 {
01070         uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0);
01071 }
01072 
01073 static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
01074 { 
01075         uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
01076 }
01077 
01078 /* only once called */
01079 static void node_composit_set_butfunc(bNodeType *ntype)
01080 {
01081         ntype->uifuncbut = NULL;
01082         switch(ntype->type) {
01083                 /* case NODE_GROUP:      note, typeinfo for group is generated... see "XXX ugly hack" */
01084 
01085                 case CMP_NODE_IMAGE:
01086                         ntype->uifunc= node_composit_buts_image;
01087                         break;
01088                 case CMP_NODE_R_LAYERS:
01089                         ntype->uifunc= node_composit_buts_renderlayers;
01090                         break;
01091                 case CMP_NODE_NORMAL:
01092                         ntype->uifunc= node_buts_normal;
01093                         break;
01094                 case CMP_NODE_CURVE_VEC:
01095                         ntype->uifunc= node_buts_curvevec;
01096                         break;
01097                 case CMP_NODE_CURVE_RGB:
01098                         ntype->uifunc= node_buts_curvecol;
01099                         break;
01100                 case CMP_NODE_VALUE:
01101                         ntype->uifunc= node_buts_value;
01102                         break;
01103                 case CMP_NODE_RGB:
01104                         ntype->uifunc= node_buts_rgb;
01105                         break;
01106                 case CMP_NODE_FLIP:
01107                         ntype->uifunc= node_composit_buts_flip;
01108                         break;
01109                 case CMP_NODE_SPLITVIEWER:
01110                         ntype->uifunc= node_composit_buts_splitviewer;
01111                         break;
01112                 case CMP_NODE_MIX_RGB:
01113                         ntype->uifunc= node_buts_mix_rgb;
01114                         break;
01115                 case CMP_NODE_VALTORGB:
01116                         ntype->uifunc= node_buts_colorramp;
01117                         break;
01118                 case CMP_NODE_CROP:
01119                         ntype->uifunc= node_composit_buts_crop;
01120                         break;
01121                 case CMP_NODE_BLUR:
01122                         ntype->uifunc= node_composit_buts_blur;
01123                         break;
01124                 case CMP_NODE_DBLUR:
01125                         ntype->uifunc= node_composit_buts_dblur;
01126                         break;
01127                 case CMP_NODE_BILATERALBLUR:
01128                         ntype->uifunc= node_composit_buts_bilateralblur;
01129                         break;
01130                 case CMP_NODE_DEFOCUS:
01131                         ntype->uifunc = node_composit_buts_defocus;
01132                         break;
01133                 case CMP_NODE_GLARE:
01134                         ntype->uifunc = node_composit_buts_glare;
01135                         break;
01136                 case CMP_NODE_TONEMAP:
01137                         ntype->uifunc = node_composit_buts_tonemap;
01138                         break;
01139                 case CMP_NODE_LENSDIST:
01140                         ntype->uifunc = node_composit_buts_lensdist;
01141                         break;
01142                 case CMP_NODE_VECBLUR:
01143                         ntype->uifunc= node_composit_buts_vecblur;
01144                         break;
01145                 case CMP_NODE_FILTER:
01146                         ntype->uifunc= node_composit_buts_filter;
01147                         break;
01148                 case CMP_NODE_MAP_VALUE:
01149                         ntype->uifunc= node_composit_buts_map_value;
01150                         break;
01151                 case CMP_NODE_TIME:
01152                         ntype->uifunc= node_buts_time;
01153                         break;
01154                 case CMP_NODE_ALPHAOVER:
01155                         ntype->uifunc= node_composit_buts_alphaover;
01156                         break;
01157                 case CMP_NODE_HUE_SAT:
01158                         ntype->uifunc= node_composit_buts_hue_sat;
01159                         break;
01160                 case CMP_NODE_TEXTURE:
01161                         ntype->uifunc= node_buts_texture;
01162                         break;
01163                 case CMP_NODE_DILATEERODE:
01164                         ntype->uifunc= node_composit_buts_dilateerode;
01165                         break;
01166                 case CMP_NODE_OUTPUT_FILE:
01167                         ntype->uifunc= node_composit_buts_file_output;
01168                         break;
01169                 case CMP_NODE_DIFF_MATTE:
01170                         ntype->uifunc=node_composit_buts_diff_matte;
01171                         break;
01172                 case CMP_NODE_DIST_MATTE:
01173                         ntype->uifunc=node_composit_buts_distance_matte;
01174                         break;
01175                 case CMP_NODE_COLOR_SPILL:
01176                         ntype->uifunc=node_composit_buts_color_spill;
01177                         break;
01178                 case CMP_NODE_CHROMA_MATTE:
01179                         ntype->uifunc=node_composit_buts_chroma_matte;
01180                         break;
01181                 case CMP_NODE_COLOR_MATTE:
01182                         ntype->uifunc=node_composit_buts_color_matte;
01183                         break;
01184                 case CMP_NODE_SCALE:
01185                         ntype->uifunc= node_composit_buts_scale;
01186                         break;
01187                 case CMP_NODE_ROTATE:
01188                         ntype->uifunc=node_composit_buts_rotate;
01189                         break;
01190                 case CMP_NODE_CHANNEL_MATTE:
01191                         ntype->uifunc= node_composit_buts_channel_matte;
01192                         break;
01193                 case CMP_NODE_LUMA_MATTE:
01194                         ntype->uifunc= node_composit_buts_luma_matte;
01195                         break;
01196                 case CMP_NODE_MAP_UV:
01197                         ntype->uifunc= node_composit_buts_map_uv;
01198                         break;
01199                 case CMP_NODE_ID_MASK:
01200                         ntype->uifunc= node_composit_buts_id_mask;
01201                         break;
01202                 case CMP_NODE_MATH:
01203                         ntype->uifunc= node_buts_math;
01204                         break;
01205                 case CMP_NODE_INVERT:
01206                         ntype->uifunc= node_composit_buts_invert;
01207                         break;
01208                 case CMP_NODE_PREMULKEY:
01209                         ntype->uifunc= node_composit_buts_premulkey;
01210                         break;
01211                 case CMP_NODE_VIEW_LEVELS:
01212                         ntype->uifunc=node_composit_buts_view_levels;
01213                         break;
01214                 case CMP_NODE_COLORBALANCE:
01215                         ntype->uifunc=node_composit_buts_colorbalance;
01216                         ntype->uifuncbut=node_composit_buts_colorbalance_but;
01217                         break;
01218                 case CMP_NODE_HUECORRECT:
01219                         ntype->uifunc=node_composit_buts_huecorrect;
01220                         break;
01221                 case CMP_NODE_ZCOMBINE:
01222                         ntype->uifunc=node_composit_buts_zcombine;
01223                         break;
01224                 case CMP_NODE_COMBYCCA:
01225                 case CMP_NODE_SEPYCCA:
01226                         ntype->uifunc=node_composit_buts_ycc;
01227                         break;
01228                 default:
01229                         ntype->uifunc= NULL;
01230         }
01231         if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
01232 
01233 }
01234 
01235 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
01236 
01237 static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
01238 {
01239         uiLayout *col;
01240         
01241         col= uiLayoutColumn(layout, 1);
01242         uiItemR(col, ptr, "offset", 0, "Offset", ICON_NONE);
01243         uiItemR(col, ptr, "offset_frequency", 0, "Frequency", ICON_NONE);
01244         
01245         col= uiLayoutColumn(layout, 1);
01246         uiItemR(col, ptr, "squash", 0, "Squash", ICON_NONE);
01247         uiItemR(col, ptr, "squash_frequency", 0, "Frequency", ICON_NONE);
01248 }
01249 
01250 static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
01251 {
01252         PointerRNA tex_ptr;
01253         bNode *node= ptr->data;
01254         ID *id= ptr->id.data;
01255         Tex *tex = (Tex *)node->storage;
01256         uiLayout *col, *row;
01257         
01258         RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr);
01259 
01260         col= uiLayoutColumn(layout, 0);
01261 
01262         switch( tex->type ) {
01263                 case TEX_BLEND:
01264                         uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE);
01265                         row= uiLayoutRow(col, 0);
01266                         uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01267                         break;
01268 
01269                 case TEX_MARBLE:
01270                         row= uiLayoutRow(col, 0);
01271                         uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01272                         row= uiLayoutRow(col, 0);
01273                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01274                         row= uiLayoutRow(col, 0);
01275                         uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
01276                         row= uiLayoutRow(col, 0);
01277                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01278                         break;
01279 
01280                 case TEX_MAGIC:
01281                         uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE);
01282                         break;
01283 
01284                 case TEX_STUCCI:
01285                         row= uiLayoutRow(col, 0);
01286                         uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01287                         row= uiLayoutRow(col, 0);
01288                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01289                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
01290                         break;
01291 
01292                 case TEX_WOOD:
01293                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
01294                         uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE);
01295                         row= uiLayoutRow(col, 0);
01296                         uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01297                         row= uiLayoutRow(col, 0);
01298                         uiLayoutSetActive(row, !(RNA_enum_get(&tex_ptr, "wood_type")==TEX_BAND || RNA_enum_get(&tex_ptr, "wood_type")==TEX_RING)); 
01299                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01300                         break;
01301                         
01302                 case TEX_CLOUDS:
01303                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
01304                         row= uiLayoutRow(col, 0);
01305                         uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01306                         row= uiLayoutRow(col, 0);
01307                         uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
01308                         uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, "Depth", ICON_NONE);
01309                         break;
01310                         
01311                 case TEX_DISTNOISE:
01312                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
01313                         uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE);
01314                         break;
01315 
01316                 case TEX_MUSGRAVE:
01317                         uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE);
01318                         uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
01319                         break;
01320                 case TEX_VORONOI:
01321                         uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE);
01322                         if(tex->vn_distm == TEX_MINKOVSKY) {
01323                                 uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE);
01324                         }
01325                         uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE);
01326                         break;
01327         }
01328 }
01329 
01330 static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
01331 {
01332         uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
01333 }
01334 
01335 static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
01336 {
01337         uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
01338 }
01339 
01340 /* only once called */
01341 static void node_texture_set_butfunc(bNodeType *ntype)
01342 {
01343     ntype->uifuncbut = NULL;
01344         if( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
01345                 ntype->uifunc = node_texture_buts_proc;
01346         }
01347         else switch(ntype->type) {
01348                 
01349                 case TEX_NODE_MATH:
01350                         ntype->uifunc = node_buts_math;
01351                         break;
01352                 
01353                 case TEX_NODE_MIX_RGB:
01354                         ntype->uifunc = node_buts_mix_rgb;
01355                         break;
01356                         
01357                 case TEX_NODE_VALTORGB:
01358                         ntype->uifunc = node_buts_colorramp;
01359                         break;
01360                         
01361                 case TEX_NODE_CURVE_RGB:
01362                         ntype->uifunc= node_buts_curvecol;
01363                         break;
01364                         
01365                 case TEX_NODE_CURVE_TIME:
01366                         ntype->uifunc = node_buts_time;
01367                         break;
01368                         
01369                 case TEX_NODE_TEXTURE:
01370                         ntype->uifunc = node_buts_texture;
01371                         break;
01372                         
01373                 case TEX_NODE_BRICKS:
01374                         ntype->uifunc = node_texture_buts_bricks;
01375                         break;
01376                         
01377                 case TEX_NODE_IMAGE:
01378                         ntype->uifunc = node_texture_buts_image;
01379                         break;
01380                         
01381                 case TEX_NODE_OUTPUT:
01382                         ntype->uifunc = node_texture_buts_output;
01383                         break;
01384                         
01385                 default:
01386                         ntype->uifunc= NULL;
01387         }
01388         if (ntype->uifuncbut == NULL) ntype->uifuncbut = ntype->uifunc;
01389 }
01390 
01391 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
01392 
01393 void ED_init_node_butfuncs(void)
01394 {
01395         bNodeType *ntype;
01396         
01397         /* shader nodes */
01398         ntype= node_all_shaders.first;
01399         while(ntype) {
01400                 node_shader_set_butfunc(ntype);
01401                 ntype= ntype->next;
01402         }
01403         /* composit nodes */
01404         ntype= node_all_composit.first;
01405         while(ntype) {
01406                 node_composit_set_butfunc(ntype);
01407                 ntype= ntype->next;
01408         }
01409         ntype = node_all_textures.first;
01410         while(ntype) {
01411                 node_texture_set_butfunc(ntype);
01412                 ntype= ntype->next;
01413         }
01414 }
01415 
01416 /* ************** Generic drawing ************** */
01417 
01418 void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
01419 {
01420         
01421         if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
01422                 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
01423                 void *lock;
01424                 ImBuf *ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
01425                 if(ibuf) {
01426                         float x, y; 
01427                         
01428                         glMatrixMode(GL_PROJECTION);
01429                         glPushMatrix();
01430                         glMatrixMode(GL_MODELVIEW);
01431                         glPushMatrix();
01432 
01433                         /* keep this, saves us from a version patch */
01434                         if(snode->zoom==0.0f) snode->zoom= 1.0f;
01435                         
01436                         /* somehow the offset has to be calculated inverse */
01437                         
01438                         glaDefine2DArea(&ar->winrct);
01439                         /* ortho at pixel level curarea */
01440                         wmOrtho2(-0.375, ar->winx-0.375, -0.375, ar->winy-0.375);
01441                         
01442                         x = (ar->winx-snode->zoom*ibuf->x)/2 + snode->xof;
01443                         y = (ar->winy-snode->zoom*ibuf->y)/2 + snode->yof;
01444                         
01445                         if(!ibuf->rect) {
01446                                 if(color_manage)
01447                                         ibuf->profile = IB_PROFILE_LINEAR_RGB;
01448                                 else
01449                                         ibuf->profile = IB_PROFILE_NONE;
01450                                 IMB_rect_from_float(ibuf);
01451                         }
01452 
01453                         if(ibuf->rect) {
01454                                 if (snode->flag & SNODE_SHOW_ALPHA) {
01455                                         glPixelZoom(snode->zoom, snode->zoom);
01456                                         /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
01457                                         if(ENDIAN_ORDER == B_ENDIAN)
01458                                                 glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
01459                                         
01460                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
01461                                         
01462                                         glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
01463                                         glPixelZoom(1.0f, 1.0f);
01464                                 } else if (snode->flag & SNODE_USE_ALPHA) {
01465                                         glEnable(GL_BLEND);
01466                                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
01467                                         glPixelZoom(snode->zoom, snode->zoom);
01468                                         
01469                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
01470                                         
01471                                         glPixelZoom(1.0f, 1.0f);
01472                                         glDisable(GL_BLEND);
01473                                 } else {
01474                                         glPixelZoom(snode->zoom, snode->zoom);
01475                                         
01476                                         glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
01477                                         
01478                                         glPixelZoom(1.0f, 1.0f);
01479                                 }
01480                         }
01481                         
01482                         glMatrixMode(GL_PROJECTION);
01483                         glPopMatrix();
01484                         glMatrixMode(GL_MODELVIEW);
01485                         glPopMatrix();
01486                 }
01487 
01488                 BKE_image_release_ibuf(ima, lock);
01489         }
01490 }
01491 
01492 void draw_nodespace_color_info(ARegion *ar, int color_manage, int channels, int x, int y, char *cp, float *fp)
01493 {
01494         char str[256];
01495         float dx= 6;
01496         /* text colors */
01497         /* XXX colored text not allowed in Blender UI */
01498         #if 0
01499         unsigned char red[3] = {255, 50, 50};
01500         unsigned char green[3] = {0, 255, 0};
01501         unsigned char blue[3] = {100, 100, 255};
01502         #else
01503         unsigned char red[3] = {255, 255, 255};
01504         unsigned char green[3] = {255, 255, 255};
01505         unsigned char blue[3] = {255, 255, 255};
01506         #endif
01507         float hue=0, sat=0, val=0, lum=0, u=0, v=0;
01508         float col[4], finalcol[4];
01509 
01510         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01511         glEnable(GL_BLEND);
01512 
01513         /* noisy, high contrast make impossible to read if lower alpha is used. */
01514         glColor4ub(0, 0, 0, 190);
01515         glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
01516         glDisable(GL_BLEND);
01517 
01518         BLF_size(blf_mono_font, 11, 72);
01519 
01520         glColor3ub(255, 255, 255);
01521         sprintf(str, "X:%-4d  Y:%-4d |", x, y);
01522         // UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
01523         BLF_position(blf_mono_font, dx, 6, 0);
01524         BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01525         dx += BLF_width(blf_mono_font, str);
01526 
01527         #if 0   /* XXX no Z value in compo backdrop atm */
01528         if(zp) {
01529                 glColor3ub(255, 255, 255);
01530                 sprintf(str, " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
01531                 BLF_position(blf_mono_font, dx, 6, 0);
01532                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01533                 dx += BLF_width(blf_mono_font, str);
01534         }
01535         if(zpf) {
01536                 glColor3ub(255, 255, 255);
01537                 sprintf(str, " Z:%-.3f |", *zpf);
01538                 BLF_position(blf_mono_font, dx, 6, 0);
01539                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01540                 dx += BLF_width(blf_mono_font, str);
01541         }
01542         #endif
01543 
01544         if(channels >= 3) {
01545                 glColor3ubv(red);
01546                 if (fp)
01547                         sprintf(str, "  R:%-.4f", fp[0]);
01548                 else if (cp)
01549                         sprintf(str, "  R:%-3d", cp[0]);
01550                 else
01551                         sprintf(str, "  R:-");
01552                 BLF_position(blf_mono_font, dx, 6, 0);
01553                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01554                 dx += BLF_width(blf_mono_font, str);
01555                 
01556                 glColor3ubv(green);
01557                 if (fp)
01558                         sprintf(str, "  G:%-.4f", fp[1]);
01559                 else if (cp)
01560                         sprintf(str, "  G:%-3d", cp[1]);
01561                 else
01562                         sprintf(str, "  G:-");
01563                 BLF_position(blf_mono_font, dx, 6, 0);
01564                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01565                 dx += BLF_width(blf_mono_font, str);
01566                 
01567                 glColor3ubv(blue);
01568                 if (fp)
01569                         sprintf(str, "  B:%-.4f", fp[2]);
01570                 else if (cp)
01571                         sprintf(str, "  B:%-3d", cp[2]);
01572                 else
01573                         sprintf(str, "  B:-");
01574                 BLF_position(blf_mono_font, dx, 6, 0);
01575                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01576                 dx += BLF_width(blf_mono_font, str);
01577                 
01578                 if(channels == 4) {
01579                         glColor3ub(255, 255, 255);
01580                         if (fp)
01581                                 sprintf(str, "  A:%-.4f", fp[3]);
01582                         else if (cp)
01583                                 sprintf(str, "  A:%-3d", cp[3]);
01584                         else
01585                                 sprintf(str, "- ");
01586                         BLF_position(blf_mono_font, dx, 6, 0);
01587                         BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01588                         dx += BLF_width(blf_mono_font, str);
01589                 }
01590         }
01591         
01592         /* color rectangle */
01593         if (channels==1) {
01594                 if (fp)
01595                         col[0] = col[1] = col[2] = fp[0];
01596                 else if (cp)
01597                         col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
01598                 else
01599                         col[0] = col[1] = col[2] = 0.0f;
01600         }
01601         else if (channels==3) {
01602                 if (fp)
01603                         copy_v3_v3(col, fp);
01604                 else if (cp) {
01605                         col[0] = (float)cp[0]/255.0f;
01606                         col[1] = (float)cp[1]/255.0f;
01607                         col[2] = (float)cp[2]/255.0f;
01608                 }
01609                 else
01610                         zero_v3(col);
01611         }
01612         else if (channels==4) {
01613                 if (fp)
01614                         copy_v4_v4(col, fp);
01615                 else if (cp) {
01616                         col[0] = (float)cp[0]/255.0f;
01617                         col[1] = (float)cp[1]/255.0f;
01618                         col[2] = (float)cp[2]/255.0f;
01619                         col[3] = (float)cp[3]/255.0f;
01620                 }
01621                 else
01622                         zero_v4(col);
01623         }
01624         if (color_manage) {
01625                 linearrgb_to_srgb_v3_v3(finalcol, col);
01626                 finalcol[3] = col[3];
01627         }
01628         else {
01629                 copy_v4_v4(finalcol, col);
01630         }
01631         glDisable(GL_BLEND);
01632         glColor3fv(finalcol);
01633         dx += 5;
01634         glBegin(GL_QUADS);
01635         glVertex2f(dx, 3);
01636         glVertex2f(dx, 17);
01637         glVertex2f(dx+30, 17);
01638         glVertex2f(dx+30, 3);
01639         glEnd();
01640         dx += 35;
01641 
01642         glColor3ub(255, 255, 255);
01643         if(channels == 1) {
01644                 if (fp) {
01645                         rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
01646                         rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v);
01647                 }
01648                 else if (cp) {
01649                         rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val);
01650                         rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v);
01651                 }
01652                 
01653                 sprintf(str, "V:%-.4f", val);
01654                 BLF_position(blf_mono_font, dx, 6, 0);
01655                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01656                 dx += BLF_width(blf_mono_font, str);
01657 
01658                 sprintf(str, "   L:%-.4f", lum);
01659                 BLF_position(blf_mono_font, dx, 6, 0);
01660                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01661                 dx += BLF_width(blf_mono_font, str);
01662         }
01663         else if(channels >= 3) {
01664                 if (fp) {
01665                         rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val);
01666                         rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v);
01667                 }
01668                 else if (cp) {
01669                         rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val);
01670                         rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v);
01671                 }
01672 
01673                 sprintf(str, "H:%-.4f", hue);
01674                 BLF_position(blf_mono_font, dx, 6, 0);
01675                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01676                 dx += BLF_width(blf_mono_font, str);
01677 
01678                 sprintf(str, "  S:%-.4f", sat);
01679                 BLF_position(blf_mono_font, dx, 6, 0);
01680                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01681                 dx += BLF_width(blf_mono_font, str);
01682 
01683                 sprintf(str, "  V:%-.4f", val);
01684                 BLF_position(blf_mono_font, dx, 6, 0);
01685                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01686                 dx += BLF_width(blf_mono_font, str);
01687 
01688                 sprintf(str, "   L:%-.4f", lum);
01689                 BLF_position(blf_mono_font, dx, 6, 0);
01690                 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
01691                 dx += BLF_width(blf_mono_font, str);
01692         }
01693 
01694         (void)dx;
01695 }
01696 
01697 #if 0
01698 /* note: needs to be userpref or opengl profile option */
01699 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
01700 {
01701 
01702         draw_nodespace_grid(snode);
01703         
01704         if(snode->flag & SNODE_BACKDRAW) {
01705                 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
01706                 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
01707                 if(ibuf) {
01708                         int x, y;
01709                         float zoom = 1.0;
01710 
01711                         glMatrixMode(GL_PROJECTION);
01712                         glPushMatrix();
01713                         glMatrixMode(GL_MODELVIEW);
01714                         glPushMatrix();
01715                         
01716                         glaDefine2DArea(&sa->winrct);
01717 
01718                         if(ibuf->x > sa->winx || ibuf->y > sa->winy) {
01719                                 float zoomx, zoomy;
01720                                 zoomx= (float)sa->winx/ibuf->x;
01721                                 zoomy= (float)sa->winy/ibuf->y;
01722                                 zoom = MIN2(zoomx, zoomy);
01723                         }
01724                         
01725                         x = (sa->winx-zoom*ibuf->x)/2 + snode->xof;
01726                         y = (sa->winy-zoom*ibuf->y)/2 + snode->yof;
01727 
01728                         glPixelZoom(zoom, zoom);
01729 
01730                         glColor4f(1.0, 1.0, 1.0, 1.0);
01731                         if(ibuf->rect)
01732                                 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
01733                         else if(ibuf->channels==4)
01734                                 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
01735 
01736                         glPixelZoom(1.0, 1.0);
01737 
01738                         glMatrixMode(GL_PROJECTION);
01739                         glPopMatrix();
01740                         glMatrixMode(GL_MODELVIEW);
01741                         glPopMatrix();
01742                 }
01743         }
01744 }
01745 #endif
01746 
01747 /* if v2d not NULL, it clips and returns 0 if not visible */
01748 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
01749 {
01750         float dist, vec[4][2];
01751         
01752         /* in v0 and v3 we put begin/end points */
01753         if(link->fromsock) {
01754                 vec[0][0]= link->fromsock->locx;
01755                 vec[0][1]= link->fromsock->locy;
01756         }
01757         else {
01758                 if(snode==NULL) return 0;
01759                 vec[0][0]= snode->mx;
01760                 vec[0][1]= snode->my;
01761         }
01762         if(link->tosock) {
01763                 vec[3][0]= link->tosock->locx;
01764                 vec[3][1]= link->tosock->locy;
01765         }
01766         else {
01767                 if(snode==NULL) return 0;
01768                 vec[3][0]= snode->mx;
01769                 vec[3][1]= snode->my;
01770         }
01771 
01772         dist= UI_GetThemeValue(TH_NODE_CURVING)*0.10f*ABS(vec[0][0] - vec[3][0]);
01773         
01774         /* check direction later, for top sockets */
01775         vec[1][0]= vec[0][0]+dist;
01776         vec[1][1]= vec[0][1];
01777         
01778         vec[2][0]= vec[3][0]-dist;
01779         vec[2][1]= vec[3][1];
01780         
01781         if(v2d && MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax); /* clipped */      
01782         else if (v2d && MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin); /* clipped */
01783         else {
01784                 
01785                 /* always do all three, to prevent data hanging around */
01786                 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
01787                 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
01788                 
01789                 return 1;
01790         }
01791         return 0;
01792 }
01793 
01794 #define LINK_RESOL      24
01795 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 )
01796 {
01797         float coord_array[LINK_RESOL+1][2];
01798         
01799         if(node_link_bezier_points(v2d, snode, link, coord_array, LINK_RESOL)) {
01800                 float dist, spline_step = 0.0f;
01801                 int i;
01802                 
01803                 /* store current linewidth */
01804                 float linew;
01805                 glGetFloatv(GL_LINE_WIDTH, &linew);
01806                 
01807                 /* we can reuse the dist variable here to increment the GL curve eval amount*/
01808                 dist = 1.0f/(float)LINK_RESOL;
01809                 
01810                 glEnable(GL_LINE_SMOOTH);
01811                 
01812                 if(do_triple) {
01813                         UI_ThemeColorShadeAlpha(th_col3, -80, -120);
01814                         glLineWidth(4.0f);
01815                         
01816                         glBegin(GL_LINE_STRIP);
01817                         for(i=0; i<=LINK_RESOL; i++) {
01818                                 glVertex2fv(coord_array[i]);
01819                         }
01820                         glEnd();
01821                 }
01822                 
01823                 UI_ThemeColor(th_col1);
01824                 glLineWidth(1.5f);
01825                 
01826                 glBegin(GL_LINE_STRIP);
01827                 for(i=0; i<=LINK_RESOL; i++) {
01828                         if(do_shaded) {
01829                                 UI_ThemeColorBlend(th_col1, th_col2, spline_step);
01830                                 spline_step += dist;
01831                         }
01832                         glVertex2fv(coord_array[i]);
01833                 }
01834                 glEnd();
01835                 
01836                 glDisable(GL_LINE_SMOOTH);
01837                 
01838                 /* restore previuos linewidth */
01839                 glLineWidth(linew);
01840         }
01841 }
01842 
01843 /* note; this is used for fake links in groups too */
01844 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
01845 {
01846         int do_shaded= 0, th_col1= TH_HEADER, th_col2= TH_HEADER;
01847         int do_triple= 0, th_col3= TH_WIRE;
01848         
01849         if(link->fromsock==NULL && link->tosock==NULL)
01850                 return;
01851         
01852         /* new connection */
01853         if(!link->fromsock || !link->tosock) {
01854                 th_col1 = TH_ACTIVE;
01855                 do_triple = 1;
01856         }
01857         else {
01858                 /* going to give issues once... */
01859                 if(link->tosock->flag & SOCK_UNAVAIL)
01860                         return;
01861                 if(link->fromsock->flag & SOCK_UNAVAIL)
01862                         return;
01863                 
01864                 /* a bit ugly... but thats how we detect the internal group links */
01865                 if(!link->fromnode || !link->tonode) {
01866                         UI_ThemeColorBlend(TH_BACK, TH_WIRE, 0.5f);
01867                         do_shaded= 0;
01868                 }
01869                 else {
01870                         /* check cyclic */
01871                         if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
01872                                 /* special indicated link, on drop-node */
01873                                 if(link->flag & NODE_LINKFLAG_HILITE) {
01874                                         th_col1= th_col2= TH_ACTIVE;
01875                                 }
01876                                 else {
01877                                         /* regular link */
01878                                         if(link->fromnode->flag & SELECT)
01879                                                 th_col1= TH_EDGE_SELECT;
01880                                         if(link->tonode->flag & SELECT)
01881                                                 th_col2= TH_EDGE_SELECT;
01882                                 }
01883                                 do_shaded= 1;
01884                                 do_triple= 1;
01885                         }                               
01886                         else {
01887                                 th_col1 = TH_REDALERT;
01888                         }
01889                 }
01890         }
01891         
01892         node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
01893 }
01894 
01895