4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2005 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Bob Holcomb, Thomas Dinges
27 * ***** END GPL LICENSE BLOCK *****
30 /** \file blender/editors/space_node/drawnode.c
39 #include "BLI_blenlib.h"
41 #include "BLI_utildefines.h"
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"
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"
61 #include "BIF_glutil.h"
65 #include "MEM_guardedalloc.h"
68 #include "RNA_access.h"
75 #include "UI_interface.h"
76 #include "UI_resources.h"
78 #include "IMB_imbuf.h"
79 #include "IMB_imbuf_types.h"
81 #include "node_intern.h"
84 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
86 static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
91 /* first socket stores value */
92 prop = RNA_struct_find_property(ptr, "outputs");
93 RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
95 uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE);
98 static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
104 /* first socket stores value */
105 prop = RNA_struct_find_property(ptr, "outputs");
106 RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
108 col = uiLayoutColumn(layout, 0);
109 uiTemplateColorWheel(col, &sockptr, "default_value", 1, 0, 0, 0);
110 uiItemR(col, &sockptr, "default_value", 0, "", ICON_NONE);
113 static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
117 bNodeTree *ntree= (bNodeTree*)ptr->id.data;
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);
125 static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
129 /* XXX no context access here .. */
130 bNode *node= ptr->data;
131 CurveMapping *cumap= node->storage;
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);
140 uiTemplateCurveMapping(layout, ptr, "curve", 's', 0, 0);
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);
147 static void node_buts_colorramp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
149 uiTemplateColorRamp(layout, ptr, "color_ramp", 0);
152 static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
154 uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0);
157 static float *_sample_col= NULL; // bad bad, 2.5 will do better?
159 static void node_curvemap_sample(float *col)
165 static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
167 bNode *node= ptr->data;
168 CurveMapping *cumap= node->storage;
171 cumap->flag |= CUMA_DRAW_SAMPLE;
172 VECCOPY(cumap->sample, _sample_col);
175 cumap->flag &= ~CUMA_DRAW_SAMPLE;
177 uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0);
180 static void node_normal_cb(bContext *C, void *ntree_v, void *node_v)
182 Main *bmain = CTX_data_main(C);
184 ED_node_generic_update(bmain, ntree_v, node_v);
185 WM_event_add_notifier(C, NC_NODE|NA_EDITED, ntree_v);
188 static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
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 */
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);
202 #if 0 // not used in 2.5x yet
203 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
205 Main *bmain= CTX_data_main(C);
206 bNodeTree *ntree= ntree_v;
210 if(node->menunr<1) return;
216 tex= BLI_findlink(&bmain->tex, node->menunr-1);
219 id_us_plus(node->id);
220 BLI_strncpy(node->name, node->id->name+2, sizeof(node->name));
222 nodeSetActive(ntree, node);
224 if( ntree->type == NTREE_TEXTURE )
225 ntreeTexCheckCyclics( ntree );
227 // allqueue(REDRAWBUTSSHADING, 0);
228 // allqueue(REDRAWNODE, 0);
229 NodeTagChanged(ntree, node);
234 static void node_dynamic_update_cb(bContext *C, void *UNUSED(ntree_v), void *node_v)
236 Main *bmain= CTX_data_main(C);
238 bNode *node= (bNode *)node_v;
242 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) error= 1;
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) {
249 for (nd= ma->nodetree->nodes.first; nd; nd= nd->next) {
250 if ((nd->type == NODE_DYNAMIC) && (nd->id == id)) {
252 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_REPARSE);
255 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_ERROR);
261 // allqueue(REDRAWBUTSSHADING, 0);
262 // allqueue(REDRAWNODE, 0);
263 // XXX BIF_preview_changed(ID_MA);
266 static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
268 bNode *node= ptr->data;
272 ((Tex*)node->id)->use_nodes &&
273 (node->type != CMP_NODE_TEXTURE) &&
274 (node->type != TEX_NODE_TEXTURE)
277 uiItemR(layout, ptr, "texture", 0, "", ICON_NONE);
280 /* Number Drawing not optimal here, better have a list*/
281 uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE);
285 static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
287 uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
290 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
292 static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v)
294 Main *bmain= CTX_data_main(C);
295 bNodeTree *ntree= ntree_v;
299 if(node->menunr<1) return;
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));
309 node->custom1= BSET(node->custom1, NODE_DYNAMIC_NEW);
311 nodeSetActive(ntree, node);
313 // allqueue(REDRAWBUTSSHADING, 0);
314 // allqueue(REDRAWNODE, 0);
319 static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
321 bNode *node= ptr->data;
324 uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL);
326 if(!node->id) return;
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);
334 static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
338 uiItemL(layout, "Location:", ICON_NONE);
339 row= uiLayoutRow(layout, 1);
340 uiItemR(row, ptr, "location", 0, "", ICON_NONE);
342 uiItemL(layout, "Rotation:", ICON_NONE);
343 row= uiLayoutRow(layout, 1);
344 uiItemR(row, ptr, "rotation", 0, "", ICON_NONE);
346 uiItemL(layout, "Scale:", ICON_NONE);
347 row= uiLayoutRow(layout, 1);
348 uiItemR(row, ptr, "scale", 0, "", ICON_NONE);
350 row= uiLayoutRow(layout, 1);
351 uiItemR(row, ptr, "use_min", 0, "Min", ICON_NONE);
352 uiItemR(row, ptr, "min", 0, "", ICON_NONE);
354 row= uiLayoutRow(layout, 1);
355 uiItemR(row, ptr, "use_max", 0, "Max", ICON_NONE);
356 uiItemR(row, ptr, "max", 0, "", ICON_NONE);
360 static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
362 uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
365 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
367 PointerRNA obptr= CTX_data_pointer_get(C, "active_object");
370 col= uiLayoutColumn(layout, 0);
372 if(obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
373 PointerRNA dataptr= RNA_pointer_get(&obptr, "data");
375 uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
376 uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
379 uiItemR(col, ptr, "uv_layer", 0, "UV", ICON_NONE);
380 uiItemR(col, ptr, "color_layer", 0, "VCol", ICON_NONE);
384 static void node_shader_buts_dynamic(uiLayout *layout, bContext *C, PointerRNA *ptr)
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;
392 // XXX SpaceNode *snode= curarea->spacedata.first;
393 short dy= (short)butr->ymin;
396 /* B_NODE_EXEC is handled in butspace.c do_node_buts */
399 IDnames_to_pupstring(&strp, NULL, "", &(bmain->text), NULL, NULL);
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);
406 if(strp) MEM_freeN((void *)strp);
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);
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);
423 /* only once called */
424 static void node_shader_set_butfunc(bNodeType *ntype)
426 switch(ntype->type) {
427 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
429 case SH_NODE_MATERIAL:
430 case SH_NODE_MATERIAL_EXT:
431 ntype->uifunc= node_shader_buts_material;
433 case SH_NODE_TEXTURE:
434 ntype->uifunc= node_buts_texture;
437 ntype->uifunc= node_buts_normal;
439 case SH_NODE_CURVE_VEC:
440 ntype->uifunc= node_buts_curvevec;
442 case SH_NODE_CURVE_RGB:
443 ntype->uifunc= node_buts_curvecol;
445 case SH_NODE_MAPPING:
446 ntype->uifunc= node_shader_buts_mapping;
449 ntype->uifunc= node_buts_value;
452 ntype->uifunc= node_buts_rgb;
454 case SH_NODE_MIX_RGB:
455 ntype->uifunc= node_buts_mix_rgb;
457 case SH_NODE_VALTORGB:
458 ntype->uifunc= node_buts_colorramp;
461 ntype->uifunc= node_buts_math;
463 case SH_NODE_VECT_MATH:
464 ntype->uifunc= node_shader_buts_vect_math;
466 case SH_NODE_GEOMETRY:
467 ntype->uifunc= node_shader_buts_geometry;
470 ntype->uifunc= node_shader_buts_dynamic;
477 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
479 static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
482 bNode *node= ptr->data;
486 uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
488 if(!node->id) return;
490 prop = RNA_struct_find_property(ptr, "image");
491 if (!prop || RNA_property_type(prop) != PROP_POINTER) return;
492 imaptr= RNA_property_pointer_get(ptr, prop);
494 col= uiLayoutColumn(layout, 0);
496 uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE);
498 if (ELEM(RNA_enum_get(&imaptr, "source"), IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
499 col= uiLayoutColumn(layout, 1);
500 uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
501 uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
502 uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
503 uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
504 uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
507 col= uiLayoutColumn(layout, 0);
509 if (RNA_enum_get(&imaptr, "type")== IMA_TYPE_MULTILAYER)
510 uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
513 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
515 bNode *node= ptr->data;
520 const char *layer_name;
521 char scene_name[MAX_ID_NAME-2];
523 uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
525 if(!node->id) return;
527 col= uiLayoutColumn(layout, 0);
528 row = uiLayoutRow(col, 0);
529 uiItemR(row, ptr, "layer", 0, "", ICON_NONE);
531 prop = RNA_struct_find_property(ptr, "layer");
532 if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)))
535 scn_ptr = RNA_pointer_get(ptr, "scene");
536 RNA_string_get(&scn_ptr, "name", scene_name);
538 WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
539 RNA_string_set(&op_ptr, "layer", layer_name);
540 RNA_string_set(&op_ptr, "scene", scene_name);
541 uiItemFullO(row, "RENDER_OT_render", "", ICON_RENDER_STILL, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
546 static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
550 col= uiLayoutColumn(layout, 0);
552 uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE);
553 if (RNA_enum_get(ptr, "filter_type")!= R_FILTER_FAST_GAUSS) {
554 uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE);
555 uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
558 uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE);
560 if (RNA_boolean_get(ptr, "use_relative")) {
561 uiItemL(col, "Aspect Correction", 0);
562 row= uiLayoutRow(layout, 1);
563 uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0);
565 col= uiLayoutColumn(layout, 1);
566 uiItemR(col, ptr, "factor_x", 0, "X", ICON_NONE);
567 uiItemR(col, ptr, "factor_y", 0, "Y", ICON_NONE);
570 col= uiLayoutColumn(layout, 1);
571 uiItemR(col, ptr, "size_x", 0, "X", ICON_NONE);
572 uiItemR(col, ptr, "size_y", 0, "Y", ICON_NONE);
576 static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
580 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
581 uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE);
583 col= uiLayoutColumn(layout, 1);
584 uiItemL(col, "Center:", ICON_NONE);
585 uiItemR(col, ptr, "center_x", 0, "X", ICON_NONE);
586 uiItemR(col, ptr, "center_y", 0, "Y", ICON_NONE);
590 col= uiLayoutColumn(layout, 1);
591 uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE);
592 uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
596 uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE);
597 uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE);
600 static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
604 col= uiLayoutColumn(layout, 1);
605 uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
606 uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE);
607 uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
610 static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
614 col= uiLayoutColumn(layout, 0);
615 uiItemL(col, "Bokeh Type:", ICON_NONE);
616 uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE);
617 uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
619 uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
621 col = uiLayoutColumn(layout, 0);
622 uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer")==1);
623 uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE);
625 uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
626 uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
628 col = uiLayoutColumn(layout, 0);
629 uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
630 sub = uiLayoutColumn(col, 0);
631 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_preview"));
632 uiItemR(sub, ptr, "samples", 0, NULL, ICON_NONE);
634 col = uiLayoutColumn(layout, 0);
635 uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
636 sub = uiLayoutColumn(col, 0);
637 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer")==0);
638 uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE);
641 /* qdn: glare node */
642 static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
644 uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE);
645 uiItemR(layout, ptr, "quality", 0, "", ICON_NONE);
647 if (RNA_enum_get(ptr, "glare_type")!= 1) {
648 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
650 if (RNA_enum_get(ptr, "glare_type")!= 0)
651 uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
654 uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE);
655 uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
657 if (RNA_enum_get(ptr, "glare_type")== 2) {
658 uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE);
659 uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE);
661 if (RNA_enum_get(ptr, "glare_type")== 0 || RNA_enum_get(ptr, "glare_type")== 2) {
662 uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
664 if (RNA_enum_get(ptr, "glare_type")== 0)
665 uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE);
667 if (RNA_enum_get(ptr, "glare_type")== 1) {
668 uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE);
672 static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
676 col = uiLayoutColumn(layout, 0);
677 uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE);
678 if (RNA_enum_get(ptr, "tonemap_type")== 0) {
679 uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
680 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
681 uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE);
684 uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE);
685 uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
686 uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
687 uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
691 static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
695 col= uiLayoutColumn(layout, 0);
696 uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE);
698 col = uiLayoutColumn(col, 0);
699 uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector")==0);
700 uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE);
701 uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE);
704 static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
708 col= uiLayoutColumn(layout, 0);
709 uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE);
710 uiItemR(col, ptr, "factor", 0, "Blur", ICON_NONE);
712 col= uiLayoutColumn(layout, 1);
713 uiItemL(col, "Speed:", ICON_NONE);
714 uiItemR(col, ptr, "speed_min", 0, "Min", ICON_NONE);
715 uiItemR(col, ptr, "speed_max", 0, "Max", ICON_NONE);
717 uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE);
720 static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
722 uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
725 static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
727 uiItemR(layout, ptr, "axis", 0, "", ICON_NONE);
730 static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
734 uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE);
735 uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE);
737 col= uiLayoutColumn(layout, 1);
738 if (RNA_boolean_get(ptr, "relative")){
739 uiItemR(col, ptr, "rel_min_x", 0, "Left", ICON_NONE);
740 uiItemR(col, ptr, "rel_max_x", 0, "Right", ICON_NONE);
741 uiItemR(col, ptr, "rel_min_y", 0, "Up", ICON_NONE);
742 uiItemR(col, ptr, "rel_max_y", 0, "Down", ICON_NONE);
744 uiItemR(col, ptr, "min_x", 0, "Left", ICON_NONE);
745 uiItemR(col, ptr, "max_x", 0, "Right", ICON_NONE);
746 uiItemR(col, ptr, "min_y", 0, "Up", ICON_NONE);
747 uiItemR(col, ptr, "max_y", 0, "Down", ICON_NONE);
751 static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
755 col= uiLayoutColumn(layout, 0);
756 row= uiLayoutRow(col, 0);
757 uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
758 uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
761 static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
765 col =uiLayoutColumn(layout, 1);
766 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
767 uiItemR(col, ptr, "size", 0, NULL, ICON_NONE);
769 col =uiLayoutColumn(layout, 1);
770 uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE);
771 sub =uiLayoutColumn(col, 0);
772 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min"));
773 uiItemR(sub, ptr, "min", 0, "", ICON_NONE);
775 col =uiLayoutColumn(layout, 1);
776 uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE);
777 sub =uiLayoutColumn(col, 0);
778 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max"));
779 uiItemR(sub, ptr, "max", 0, "", ICON_NONE);
782 static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
786 col =uiLayoutColumn(layout, 1);
787 uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE);
788 uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE);
791 static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
795 col =uiLayoutColumn(layout, 1);
796 uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE);
800 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
804 col =uiLayoutColumn(layout, 0);
805 uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
806 uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
807 uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
810 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
812 uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
815 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
819 col =uiLayoutColumn(layout, 1);
820 uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
821 uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
824 static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
828 col =uiLayoutColumn(layout, 1);
829 uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
830 uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
833 static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
837 uiItemL(layout, "Despill Channel:", ICON_NONE);
838 row =uiLayoutRow(layout,0);
839 uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
841 col= uiLayoutColumn(layout, 0);
842 uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
844 if(RNA_enum_get(ptr, "limit_method")==0) {
845 uiItemL(col, "Limiting Channel:", ICON_NONE);
846 row=uiLayoutRow(col,0);
847 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
850 uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
851 uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE);
852 if (RNA_enum_get(ptr, "use_unspill")== 1) {
853 uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
854 uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
855 uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
859 static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
863 col= uiLayoutColumn(layout, 0);
864 uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE);
865 uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
867 col= uiLayoutColumn(layout, 1);
868 /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now */
869 uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
870 /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now*/
873 static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
877 col= uiLayoutColumn(layout, 1);
878 uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
879 uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
880 uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
883 static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
887 uiItemL(layout, "Color Space:", ICON_NONE);
888 row= uiLayoutRow(layout, 0);
889 uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
891 col=uiLayoutColumn(layout, 0);
892 uiItemL(col, "Key Channel:", ICON_NONE);
893 row= uiLayoutRow(col, 0);
894 uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
896 col =uiLayoutColumn(layout, 0);
898 uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
899 if(RNA_enum_get(ptr, "limit_method")==0) {
900 uiItemL(col, "Limiting Channel:", ICON_NONE);
901 row=uiLayoutRow(col,0);
902 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
905 uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
906 uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
909 static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
913 col= uiLayoutColumn(layout, 1);
914 uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
915 uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
918 static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
920 uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE);
923 static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
925 uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE);
928 static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
932 col= uiLayoutColumn(layout, 0);
933 uiItemR(col, ptr, "filepath", 0, "", ICON_NONE);
934 uiItemR(col, ptr, "image_type", 0, "", ICON_NONE);
936 row= uiLayoutRow(layout, 0);
937 if (RNA_enum_get(ptr, "image_type")== R_OPENEXR) {
938 uiItemR(row, ptr, "use_exr_half", 0, NULL, ICON_NONE);
939 uiItemR(row, ptr, "exr_codec", 0, "", ICON_NONE);
941 else if (RNA_enum_get(ptr, "image_type")== R_JPEG90) {
942 uiItemR(row, ptr, "quality", UI_ITEM_R_SLIDER, "Quality", ICON_NONE);
944 else if (RNA_enum_get(ptr, "image_type")== R_PNG) {
945 uiItemR(row, ptr, "quality", UI_ITEM_R_SLIDER, "Compression", ICON_NONE);
948 row= uiLayoutRow(layout, 1);
949 uiItemR(row, ptr, "frame_start", 0, "Start", ICON_NONE);
950 uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
953 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
955 uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
958 static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
960 uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
963 static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
967 col= uiLayoutColumn(layout, 0);
968 uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE);
969 uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE);
972 static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
974 uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
977 static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
979 uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
982 static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
984 uiLayout *split, *col, *row;
986 uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
988 if (RNA_enum_get(ptr, "correction_method")== 0) {
990 split = uiLayoutSplit(layout, 0, 0);
991 col = uiLayoutColumn(split, 0);
992 uiTemplateColorWheel(col, ptr, "lift", 1, 1, 0, 1);
993 row = uiLayoutRow(col, 0);
994 uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE);
996 col = uiLayoutColumn(split, 0);
997 uiTemplateColorWheel(col, ptr, "gamma", 1, 1, 1, 1);
998 row = uiLayoutRow(col, 0);
999 uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE);
1001 col = uiLayoutColumn(split, 0);
1002 uiTemplateColorWheel(col, ptr, "gain", 1, 1, 1, 1);
1003 row = uiLayoutRow(col, 0);
1004 uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE);
1008 split = uiLayoutSplit(layout, 0, 0);
1009 col = uiLayoutColumn(split, 0);
1010 uiTemplateColorWheel(col, ptr, "offset", 1, 1, 0, 1);
1011 row = uiLayoutRow(col, 0);
1012 uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE);
1014 col = uiLayoutColumn(split, 0);
1015 uiTemplateColorWheel(col, ptr, "power", 1, 1, 0, 1);
1016 row = uiLayoutRow(col, 0);
1017 uiItemR(row, ptr, "power", 0, NULL, ICON_NONE);
1019 col = uiLayoutColumn(split, 0);
1020 uiTemplateColorWheel(col, ptr, "slope", 1, 1, 0, 1);
1021 row = uiLayoutRow(col, 0);
1022 uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE);
1027 static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1029 uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0);
1032 static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1034 uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
1037 /* only once called */
1038 static void node_composit_set_butfunc(bNodeType *ntype)
1040 switch(ntype->type) {
1041 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
1043 case CMP_NODE_IMAGE:
1044 ntype->uifunc= node_composit_buts_image;
1046 case CMP_NODE_R_LAYERS:
1047 ntype->uifunc= node_composit_buts_renderlayers;
1049 case CMP_NODE_NORMAL:
1050 ntype->uifunc= node_buts_normal;
1052 case CMP_NODE_CURVE_VEC:
1053 ntype->uifunc= node_buts_curvevec;
1055 case CMP_NODE_CURVE_RGB:
1056 ntype->uifunc= node_buts_curvecol;
1058 case CMP_NODE_VALUE:
1059 ntype->uifunc= node_buts_value;
1062 ntype->uifunc= node_buts_rgb;
1065 ntype->uifunc= node_composit_buts_flip;
1067 case CMP_NODE_SPLITVIEWER:
1068 ntype->uifunc= node_composit_buts_splitviewer;
1070 case CMP_NODE_MIX_RGB:
1071 ntype->uifunc= node_buts_mix_rgb;
1073 case CMP_NODE_VALTORGB:
1074 ntype->uifunc= node_buts_colorramp;
1077 ntype->uifunc= node_composit_buts_crop;
1080 ntype->uifunc= node_composit_buts_blur;
1082 case CMP_NODE_DBLUR:
1083 ntype->uifunc= node_composit_buts_dblur;
1085 case CMP_NODE_BILATERALBLUR:
1086 ntype->uifunc= node_composit_buts_bilateralblur;
1088 case CMP_NODE_DEFOCUS:
1089 ntype->uifunc = node_composit_buts_defocus;
1091 case CMP_NODE_GLARE:
1092 ntype->uifunc = node_composit_buts_glare;
1094 case CMP_NODE_TONEMAP:
1095 ntype->uifunc = node_composit_buts_tonemap;
1097 case CMP_NODE_LENSDIST:
1098 ntype->uifunc = node_composit_buts_lensdist;
1100 case CMP_NODE_VECBLUR:
1101 ntype->uifunc= node_composit_buts_vecblur;
1103 case CMP_NODE_FILTER:
1104 ntype->uifunc= node_composit_buts_filter;
1106 case CMP_NODE_MAP_VALUE:
1107 ntype->uifunc= node_composit_buts_map_value;
1110 ntype->uifunc= node_buts_time;
1112 case CMP_NODE_ALPHAOVER:
1113 ntype->uifunc= node_composit_buts_alphaover;
1115 case CMP_NODE_HUE_SAT:
1116 ntype->uifunc= node_composit_buts_hue_sat;
1118 case CMP_NODE_TEXTURE:
1119 ntype->uifunc= node_buts_texture;
1121 case CMP_NODE_DILATEERODE:
1122 ntype->uifunc= node_composit_buts_dilateerode;
1124 case CMP_NODE_OUTPUT_FILE:
1125 ntype->uifunc= node_composit_buts_file_output;
1127 case CMP_NODE_DIFF_MATTE:
1128 ntype->uifunc=node_composit_buts_diff_matte;
1130 case CMP_NODE_DIST_MATTE:
1131 ntype->uifunc=node_composit_buts_distance_matte;
1133 case CMP_NODE_COLOR_SPILL:
1134 ntype->uifunc=node_composit_buts_color_spill;
1136 case CMP_NODE_CHROMA_MATTE:
1137 ntype->uifunc=node_composit_buts_chroma_matte;
1139 case CMP_NODE_COLOR_MATTE:
1140 ntype->uifunc=node_composit_buts_color_matte;
1142 case CMP_NODE_SCALE:
1143 ntype->uifunc= node_composit_buts_scale;
1145 case CMP_NODE_ROTATE:
1146 ntype->uifunc=node_composit_buts_rotate;
1148 case CMP_NODE_CHANNEL_MATTE:
1149 ntype->uifunc= node_composit_buts_channel_matte;
1151 case CMP_NODE_LUMA_MATTE:
1152 ntype->uifunc= node_composit_buts_luma_matte;
1154 case CMP_NODE_MAP_UV:
1155 ntype->uifunc= node_composit_buts_map_uv;
1157 case CMP_NODE_ID_MASK:
1158 ntype->uifunc= node_composit_buts_id_mask;
1161 ntype->uifunc= node_buts_math;
1163 case CMP_NODE_INVERT:
1164 ntype->uifunc= node_composit_buts_invert;
1166 case CMP_NODE_PREMULKEY:
1167 ntype->uifunc= node_composit_buts_premulkey;
1169 case CMP_NODE_VIEW_LEVELS:
1170 ntype->uifunc=node_composit_buts_view_levels;
1172 case CMP_NODE_COLORBALANCE:
1173 ntype->uifunc=node_composit_buts_colorbalance;
1175 case CMP_NODE_HUECORRECT:
1176 ntype->uifunc=node_composit_buts_huecorrect;
1178 case CMP_NODE_ZCOMBINE:
1179 ntype->uifunc=node_composit_buts_zcombine;
1181 case CMP_NODE_COMBYCCA:
1182 case CMP_NODE_SEPYCCA:
1183 ntype->uifunc=node_composit_buts_ycc;
1186 ntype->uifunc= NULL;
1190 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
1192 static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1196 col= uiLayoutColumn(layout, 1);
1197 uiItemR(col, ptr, "offset", 0, "Offset", ICON_NONE);
1198 uiItemR(col, ptr, "offset_frequency", 0, "Frequency", ICON_NONE);
1200 col= uiLayoutColumn(layout, 1);
1201 uiItemR(col, ptr, "squash", 0, "Squash", ICON_NONE);
1202 uiItemR(col, ptr, "squash_frequency", 0, "Frequency", ICON_NONE);
1205 static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1208 bNode *node= ptr->data;
1209 ID *id= ptr->id.data;
1210 Tex *tex = (Tex *)node->storage;
1211 uiLayout *col, *row;
1213 RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr);
1215 col= uiLayoutColumn(layout, 0);
1217 switch( tex->type ) {
1219 uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE);
1220 row= uiLayoutRow(col, 0);
1221 uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1225 row= uiLayoutRow(col, 0);
1226 uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1227 row= uiLayoutRow(col, 0);
1228 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1229 row= uiLayoutRow(col, 0);
1230 uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1231 row= uiLayoutRow(col, 0);
1232 uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1236 uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE);
1240 row= uiLayoutRow(col, 0);
1241 uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1242 row= uiLayoutRow(col, 0);
1243 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1244 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1248 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1249 uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE);
1250 row= uiLayoutRow(col, 0);
1251 uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1252 row= uiLayoutRow(col, 0);
1253 uiLayoutSetActive(row, !(RNA_enum_get(&tex_ptr, "wood_type")==TEX_BAND || RNA_enum_get(&tex_ptr, "wood_type")==TEX_RING));
1254 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1258 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1259 row= uiLayoutRow(col, 0);
1260 uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1261 row= uiLayoutRow(col, 0);
1262 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1263 uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, "Depth", ICON_NONE);
1267 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1268 uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE);
1272 uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE);
1273 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
1276 uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE);
1277 if(tex->vn_distm == TEX_MINKOVSKY) {
1278 uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE);
1280 uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE);
1285 static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1287 uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1290 static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1292 uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
1295 /* only once called */
1296 static void node_texture_set_butfunc(bNodeType *ntype)
1298 if( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
1299 ntype->uifunc = node_texture_buts_proc;
1301 else switch(ntype->type) {
1304 ntype->uifunc = node_buts_math;
1307 case TEX_NODE_MIX_RGB:
1308 ntype->uifunc = node_buts_mix_rgb;
1311 case TEX_NODE_VALTORGB:
1312 ntype->uifunc = node_buts_colorramp;
1315 case TEX_NODE_CURVE_RGB:
1316 ntype->uifunc= node_buts_curvecol;
1319 case TEX_NODE_CURVE_TIME:
1320 ntype->uifunc = node_buts_time;
1323 case TEX_NODE_TEXTURE:
1324 ntype->uifunc = node_buts_texture;
1327 case TEX_NODE_BRICKS:
1328 ntype->uifunc = node_texture_buts_bricks;
1331 case TEX_NODE_IMAGE:
1332 ntype->uifunc = node_texture_buts_image;
1335 case TEX_NODE_OUTPUT:
1336 ntype->uifunc = node_texture_buts_output;
1340 ntype->uifunc= NULL;
1344 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
1346 void ED_init_node_butfuncs(void)
1351 ntype= node_all_shaders.first;
1353 node_shader_set_butfunc(ntype);
1356 /* composit nodes */
1357 ntype= node_all_composit.first;
1359 node_composit_set_butfunc(ntype);
1362 ntype = node_all_textures.first;
1364 node_texture_set_butfunc(ntype);
1369 /* ************** Generic drawing ************** */
1371 void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
1374 if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
1375 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
1377 ImBuf *ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
1381 glMatrixMode(GL_PROJECTION);
1383 glMatrixMode(GL_MODELVIEW);
1386 /* keep this, saves us from a version patch */
1387 if(snode->zoom==0.0f) snode->zoom= 1.0f;
1389 /* somehow the offset has to be calculated inverse */
1391 glaDefine2DArea(&ar->winrct);
1392 /* ortho at pixel level curarea */
1393 wmOrtho2(-0.375, ar->winx-0.375, -0.375, ar->winy-0.375);
1395 x = (ar->winx-snode->zoom*ibuf->x)/2 + snode->xof;
1396 y = (ar->winy-snode->zoom*ibuf->y)/2 + snode->yof;
1400 ibuf->profile = IB_PROFILE_LINEAR_RGB;
1402 ibuf->profile = IB_PROFILE_NONE;
1403 IMB_rect_from_float(ibuf);
1407 if (snode->flag & SNODE_SHOW_ALPHA) {
1408 glPixelZoom(snode->zoom, snode->zoom);
1409 /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
1410 if(ENDIAN_ORDER == B_ENDIAN)
1411 glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
1413 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
1415 glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
1416 glPixelZoom(1.0f, 1.0f);
1417 } else if (snode->flag & SNODE_USE_ALPHA) {
1419 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1420 glPixelZoom(snode->zoom, snode->zoom);
1422 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1424 glPixelZoom(1.0f, 1.0f);
1425 glDisable(GL_BLEND);
1427 glPixelZoom(snode->zoom, snode->zoom);
1429 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1431 glPixelZoom(1.0f, 1.0f);
1435 glMatrixMode(GL_PROJECTION);
1437 glMatrixMode(GL_MODELVIEW);
1441 BKE_image_release_ibuf(ima, lock);
1445 void draw_nodespace_color_info(ARegion *ar, int color_manage, int channels, int x, int y, char *cp, float *fp)
1450 /* XXX colored text not allowed in Blender UI */
1452 unsigned char red[3] = {255, 50, 50};
1453 unsigned char green[3] = {0, 255, 0};
1454 unsigned char blue[3] = {100, 100, 255};
1456 unsigned char red[3] = {255, 255, 255};
1457 unsigned char green[3] = {255, 255, 255};
1458 unsigned char blue[3] = {255, 255, 255};
1460 float hue=0, sat=0, val=0, lum=0, u=0, v=0;
1461 float col[4], finalcol[4];
1463 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1466 /* noisy, high contrast make impossible to read if lower alpha is used. */
1467 glColor4ub(0, 0, 0, 190);
1468 glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
1469 glDisable(GL_BLEND);
1471 BLF_size(blf_mono_font, 11, 72);
1473 glColor3ub(255, 255, 255);
1474 sprintf(str, "X:%-4d Y:%-4d |", x, y);
1475 // UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
1476 BLF_position(blf_mono_font, dx, 6, 0);
1477 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1478 dx += BLF_width(blf_mono_font, str);
1480 #if 0 /* XXX no Z value in compo backdrop atm */
1482 glColor3ub(255, 255, 255);
1483 sprintf(str, " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
1484 BLF_position(blf_mono_font, dx, 6, 0);
1485 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1486 dx += BLF_width(blf_mono_font, str);
1489 glColor3ub(255, 255, 255);
1490 sprintf(str, " Z:%-.3f |", *zpf);
1491 BLF_position(blf_mono_font, dx, 6, 0);
1492 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1493 dx += BLF_width(blf_mono_font, str);
1500 sprintf(str, " R:%-.4f", fp[0]);
1502 sprintf(str, " R:%-3d", cp[0]);
1504 sprintf(str, " R:-");
1505 BLF_position(blf_mono_font, dx, 6, 0);
1506 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1507 dx += BLF_width(blf_mono_font, str);
1511 sprintf(str, " G:%-.4f", fp[1]);
1513 sprintf(str, " G:%-3d", cp[1]);
1515 sprintf(str, " G:-");
1516 BLF_position(blf_mono_font, dx, 6, 0);
1517 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1518 dx += BLF_width(blf_mono_font, str);
1522 sprintf(str, " B:%-.4f", fp[2]);
1524 sprintf(str, " B:%-3d", cp[2]);
1526 sprintf(str, " B:-");
1527 BLF_position(blf_mono_font, dx, 6, 0);
1528 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1529 dx += BLF_width(blf_mono_font, str);
1532 glColor3ub(255, 255, 255);
1534 sprintf(str, " A:%-.4f", fp[3]);
1536 sprintf(str, " A:%-3d", cp[3]);
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);
1545 /* color rectangle */
1548 col[0] = col[1] = col[2] = fp[0];
1550 col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
1552 col[0] = col[1] = col[2] = 0.0f;
1554 else if (channels==3) {
1556 copy_v3_v3(col, fp);
1558 col[0] = (float)cp[0]/255.0f;
1559 col[1] = (float)cp[1]/255.0f;
1560 col[2] = (float)cp[2]/255.0f;
1565 else if (channels==4) {
1567 copy_v4_v4(col, fp);
1569 col[0] = (float)cp[0]/255.0f;
1570 col[1] = (float)cp[1]/255.0f;
1571 col[2] = (float)cp[2]/255.0f;
1572 col[3] = (float)cp[3]/255.0f;
1578 linearrgb_to_srgb_v3_v3(finalcol, col);
1579 finalcol[3] = col[3];
1582 copy_v4_v4(finalcol, col);
1584 glDisable(GL_BLEND);
1585 glColor3fv(finalcol);
1590 glVertex2f(dx+30, 17);
1591 glVertex2f(dx+30, 3);
1595 glColor3ub(255, 255, 255);
1598 rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
1599 rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v);
1602 rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val);
1603 rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v);
1606 sprintf(str, "V:%-.4f", val);
1607 BLF_position(blf_mono_font, dx, 6, 0);
1608 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1609 dx += BLF_width(blf_mono_font, str);
1611 sprintf(str, " L:%-.4f", lum);
1612 BLF_position(blf_mono_font, dx, 6, 0);
1613 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1614 dx += BLF_width(blf_mono_font, str);
1616 else if(channels >= 3) {
1618 rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val);
1619 rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v);
1622 rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val);
1623 rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v);
1626 sprintf(str, "H:%-.4f", hue);
1627 BLF_position(blf_mono_font, dx, 6, 0);
1628 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1629 dx += BLF_width(blf_mono_font, str);
1631 sprintf(str, " S:%-.4f", sat);
1632 BLF_position(blf_mono_font, dx, 6, 0);
1633 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1634 dx += BLF_width(blf_mono_font, str);
1636 sprintf(str, " V:%-.4f", val);
1637 BLF_position(blf_mono_font, dx, 6, 0);
1638 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1639 dx += BLF_width(blf_mono_font, str);
1641 sprintf(str, " L:%-.4f", lum);
1642 BLF_position(blf_mono_font, dx, 6, 0);
1643 BLF_draw_ascii(blf_mono_font, str, sizeof(str));
1644 dx += BLF_width(blf_mono_font, str);
1649 /* note: needs to be userpref or opengl profile option */
1650 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
1653 draw_nodespace_grid(snode);
1655 if(snode->flag & SNODE_BACKDRAW) {
1656 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
1657 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
1662 glMatrixMode(GL_PROJECTION);
1664 glMatrixMode(GL_MODELVIEW);
1667 glaDefine2DArea(&sa->winrct);
1669 if(ibuf->x > sa->winx || ibuf->y > sa->winy) {
1671 zoomx= (float)sa->winx/ibuf->x;
1672 zoomy= (float)sa->winy/ibuf->y;
1673 zoom = MIN2(zoomx, zoomy);
1676 x = (sa->winx-zoom*ibuf->x)/2 + snode->xof;
1677 y = (sa->winy-zoom*ibuf->y)/2 + snode->yof;
1679 glPixelZoom(zoom, zoom);
1681 glColor4f(1.0, 1.0, 1.0, 1.0);
1683 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
1684 else if(ibuf->channels==4)
1685 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
1687 glPixelZoom(1.0, 1.0);
1689 glMatrixMode(GL_PROJECTION);
1691 glMatrixMode(GL_MODELVIEW);
1698 /* if v2d not NULL, it clips and returns 0 if not visible */
1699 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
1701 float dist, vec[4][2];
1703 /* in v0 and v3 we put begin/end points */
1704 if(link->fromsock) {
1705 vec[0][0]= link->fromsock->locx;
1706 vec[0][1]= link->fromsock->locy;
1709 if(snode==NULL) return 0;
1710 vec[0][0]= snode->mx;
1711 vec[0][1]= snode->my;
1714 vec[3][0]= link->tosock->locx;
1715 vec[3][1]= link->tosock->locy;
1718 if(snode==NULL) return 0;
1719 vec[3][0]= snode->mx;
1720 vec[3][1]= snode->my;
1723 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
1725 /* check direction later, for top sockets */
1726 vec[1][0]= vec[0][0]+dist;
1727 vec[1][1]= vec[0][1];
1729 vec[2][0]= vec[3][0]-dist;
1730 vec[2][1]= vec[3][1];
1732 if(v2d && MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax); /* clipped */
1733 else if (v2d && MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin); /* clipped */
1736 /* always do all three, to prevent data hanging around */
1737 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
1738 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
1745 #define LINK_RESOL 24
1746 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 )
1748 float coord_array[LINK_RESOL+1][2];
1750 if(node_link_bezier_points(v2d, snode, link, coord_array, LINK_RESOL)) {
1751 float dist, spline_step = 0.0f;
1754 /* store current linewidth */
1756 glGetFloatv(GL_LINE_WIDTH, &linew);
1758 /* we can reuse the dist variable here to increment the GL curve eval amount*/
1759 dist = 1.0f/(float)LINK_RESOL;
1761 glEnable(GL_LINE_SMOOTH);
1764 UI_ThemeColorShadeAlpha(th_col3, -80, -120);
1767 glBegin(GL_LINE_STRIP);
1768 for(i=0; i<=LINK_RESOL; i++) {
1769 glVertex2fv(coord_array[i]);
1774 UI_ThemeColor(th_col1);
1777 glBegin(GL_LINE_STRIP);
1778 for(i=0; i<=LINK_RESOL; i++) {
1780 UI_ThemeColorBlend(th_col1, th_col2, spline_step);
1781 spline_step += dist;
1783 glVertex2fv(coord_array[i]);
1787 glDisable(GL_LINE_SMOOTH);
1789 /* restore previuos linewidth */
1794 /* note; this is used for fake links in groups too */
1795 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
1797 int do_shaded= 0, th_col1= TH_HEADER, th_col2= TH_HEADER;
1798 int do_triple= 0, th_col3= TH_WIRE;
1800 if(link->fromsock==NULL && link->tosock==NULL)
1803 /* new connection */
1804 if(!link->fromsock || !link->tosock) {
1805 th_col1 = TH_ACTIVE;
1809 /* going to give issues once... */
1810 if(link->tosock->flag & SOCK_UNAVAIL)
1812 if(link->fromsock->flag & SOCK_UNAVAIL)
1815 /* a bit ugly... but thats how we detect the internal group links */
1816 if(!link->fromnode || !link->tonode) {
1817 UI_ThemeColorBlend(TH_BACK, TH_WIRE, 0.5f);
1822 if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
1823 if(link->fromnode->flag & SELECT)
1824 th_col1= TH_EDGE_SELECT;
1825 if(link->tonode->flag & SELECT)
1826 th_col2= TH_EDGE_SELECT;
1831 th_col1 = TH_REDALERT;
1836 node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);